c-gen.cxx File Reference

#include <stdlib.h>
#include <errno.h>
#include <dirent.h>
#include <fstream>
#include <iostream>
#include <string>
#include <assert.h>
#include <sstream>
#include "AST.hxx"
#include "Type.hxx"
#include "Options.hxx"
#include "inter-pass.hxx"

Go to the source code of this file.

Data Structures

struct  INOstream
struct  MangleMap

Defines

#define CD_FNCONST   1u
#define CD_IN_STRUCT   2u

Enumerations

enum  DeclsOrDefs {
  WantForward, WantDecl, WantGC, WantConstructors,
  WantDefs
}
enum  { nkwd = (sizeof(kwd_blacklist)/sizeof(kwd_blacklist[0])) - 1 }
enum  { nSpecial = sizeof(mangleMap) / sizeof(MangleMap) }

Functions

void AlphaRename (GCPtr< AST > ast)
GCPtr< ASTloop2letrec (GCPtr< AST >)
INOstreamoperator<< (INOstream &inostrm, ostream &(*pf)(ostream &))
INOstreamoperator<< (INOstream &inostrm, const char *s)
INOstreamoperator<< (INOstream &inostrm, const uint64_t ull)
INOstreamoperator<< (INOstream &inostrm, const std::string &s)
template<typename T>
INOstreamoperator<< (INOstream &inostrm, T ob)
bool getDefs (std::ostream &errStream, GCPtr< AST > bp, GCPtr< CVector< GCPtr< AST > > > defs)
void getDefNames (GCPtr< AST > bp, CVector< std::string > &names)
bool pureLoop (std::ostream &errStream, const GCPtr< AST > &ast, std::string nm, bool isTail)
bool hasPureLoops (std::ostream &errStream, const GCPtr< AST > &ast)
bool hasLambda (std::ostream &errStream, const GCPtr< AST > &ast)
bool hasInnerLambdas (std::ostream &errStream, const GCPtr< AST > &ast)
bool hasPatternBindings (std::ostream &errStream, const GCPtr< AST > &ast)
static bool SimplifyAST (std::ostream &errStream, const GCPtr< AST > &ast)
int istrcmp (const void *vp1, const void *vp2)
bool is_kwd (const std::string &s)
std::string mangleComponent (const std::string &s)
static std::string xmangle (std::string s, const char *pfx)
static std::string xmangle (const FQName &fqn, const char *pfx)
static std::string idname (GCPtr< AST > ast, const char *pfx="")
std::string c_decl (TvPrinter &tvp, GCPtr< Type > ty, const std::string &id, unsigned flags=0)
static std::string EmitTypeScheme (TvPrinter &tvp, const GCPtr< AST > &id, DeclsOrDefs what)
std::string EmitTypeExpansion (TvPrinter &tvp, const GCPtr< AST > &id, DeclsOrDefs what)
static void EmitExpr (INOstream &ino, TvPrinter &tvp, GCPtr< AST > ast)
static void EmitDeclValue (INOstream &ino, GCPtr< AST > ast, DeclsOrDefs what)
static void EmitDefine (INOstream &ino, GCPtr< AST > ast, DeclsOrDefs what)
static void EmitDefexcept (INOstream &ino, GCPtr< AST > ast, DeclsOrDefs what)
static void EmitDefstruct (INOstream &ino, GCPtr< AST > ast, DeclsOrDefs what)
static void EmitDefunion (INOstream &ino, GCPtr< AST > ast, DeclsOrDefs what)
static void EmitSUDecl (INOstream &ino, GCPtr< AST > ast, DeclsOrDefs what)
static void EmitAst (INOstream &ino, GCPtr< AST > ast, DeclsOrDefs what)
static void GenerateInterface (INOstream &ino, const GCPtr< UocInfo > &uoc, DeclsOrDefs what)
bool CheckBootstrapConstraints (std::ostream &errStream, const GCPtr< UocInfo > &uoc)
bool GenerateC ()

Variables

static char * kwd_blacklist []
MangleMap mangleMap []


Define Documentation

#define CD_FNCONST   1u

Definition at line 917 of file c-gen.cxx.

Referenced by c_decl(), EmitDeclValue(), and EmitDefine().

#define CD_IN_STRUCT   2u

Definition at line 918 of file c-gen.cxx.

Referenced by c_decl(), EmitDefstruct(), and EmitDefunion().


Enumeration Type Documentation

anonymous enum

Enumerator:
nkwd 

Definition at line 796 of file c-gen.cxx.

anonymous enum

Enumerator:
nSpecial 

Definition at line 843 of file c-gen.cxx.

enum DeclsOrDefs

Enumerator:
WantForward 
WantDecl 
WantGC 
WantConstructors 
WantDefs 

Definition at line 57 of file c-gen.cxx.


Function Documentation

void AlphaRename ( GCPtr< AST ast  ) 

std::string c_decl ( TvPrinter tvp,
GCPtr< Type ty,
const std::string &  id,
unsigned  flags = 0 
)

Definition at line 920 of file c-gen.cxx.

References assert(), CD_FNCONST, CD_IN_STRUCT, flags, idname(), and TvPrinter::tvName().

Referenced by EmitDeclValue(), EmitDefexcept(), EmitDefine(), EmitDefstruct(), EmitDefunion(), and EmitExpr().

bool CheckBootstrapConstraints ( std::ostream &  errStream,
const GCPtr< UocInfo > &  uoc 
)

Definition at line 2429 of file c-gen.cxx.

References hasInnerLambdas(), hasPatternBindings(), and hasPureLoops().

Referenced by GenerateC().

static void EmitAst ( INOstream ino,
GCPtr< AST ast,
DeclsOrDefs  what 
) [static]

Definition at line 2360 of file c-gen.cxx.

References at_defexception, at_define, at_defstruct, at_defunion, EmitDeclValue(), EmitDefexcept(), EmitDefine(), EmitDefstruct(), EmitDefunion(), and EmitSUDecl().

Referenced by GenerateInterface().

static void EmitDeclValue ( INOstream ino,
GCPtr< AST ast,
DeclsOrDefs  what 
) [static]

Definition at line 1678 of file c-gen.cxx.

References c_decl(), CD_FNCONST, EmitTypeScheme(), idname(), and WantForward.

Referenced by EmitAst().

static void EmitDefexcept ( INOstream ino,
GCPtr< AST ast,
DeclsOrDefs  what 
) [static]

Definition at line 1770 of file c-gen.cxx.

References assert(), c_decl(), EmitTypeExpansion(), idname(), sherpa::INOstream::less(), sherpa::INOstream::more(), WantConstructors, WantDecl, WantForward, and WantGC.

Referenced by EmitAst().

static void EmitDefine ( INOstream ino,
GCPtr< AST ast,
DeclsOrDefs  what 
) [static]

Definition at line 1697 of file c-gen.cxx.

References c_decl(), CD_FNCONST, EmitExpr(), EmitTypeScheme(), idname(), sherpa::INOstream::indent(), sherpa::INOstream::less(), sherpa::INOstream::more(), WantDecl, and WantDefs.

Referenced by EmitAst().

static void EmitDefstruct ( INOstream ino,
GCPtr< AST ast,
DeclsOrDefs  what 
) [static]

Definition at line 1910 of file c-gen.cxx.

References c_decl(), CD_IN_STRUCT, EmitTypeExpansion(), EmitTypeScheme(), idname(), if(), sherpa::INOstream::less(), sherpa::INOstream::more(), WantConstructors, WantDecl, WantForward, and WantGC.

Referenced by EmitAst().

static void EmitDefunion ( INOstream ino,
GCPtr< AST ast,
DeclsOrDefs  what 
) [static]

Definition at line 2053 of file c-gen.cxx.

References c_decl(), CD_IN_STRUCT, EmitTypeExpansion(), EmitTypeScheme(), idname(), if(), sherpa::INOstream::less(), sherpa::INOstream::more(), WantConstructors, WantDecl, WantForward, and WantGC.

Referenced by EmitAst().

static void EmitExpr ( INOstream ino,
TvPrinter tvp,
GCPtr< AST ast 
) [static]

Definition at line 1276 of file c-gen.cxx.

References assert(), at_and, at_apply, at_array, at_begin, at_boolLiteral, at_charLiteral, at_cond, at_deref, at_floatLiteral, at_ident, at_identPattern, at_if, at_intLiteral, at_let, at_letrec, at_loop, at_or, at_select, at_setbang, at_stringLiteral, at_struct_apply, at_throw, at_try, at_ucon_apply, at_unit, at_vector, c_decl(), idname(), sherpa::INOstream::indent(), sherpa::INOstream::less(), sherpa::INOstream::more(), sherpa::INOstream::ostrm, and s.

Referenced by EmitDefine().

static void EmitSUDecl ( INOstream ino,
GCPtr< AST ast,
DeclsOrDefs  what 
) [static]

Definition at line 2346 of file c-gen.cxx.

References idname(), and WantDecl.

Referenced by EmitAst().

std::string EmitTypeExpansion ( TvPrinter tvp,
const GCPtr< AST > &  id,
DeclsOrDefs  what 
)

Definition at line 1255 of file c-gen.cxx.

References assert(), and TvPrinter::tvName().

Referenced by EmitDefexcept(), EmitDefstruct(), and EmitDefunion().

static std::string EmitTypeScheme ( TvPrinter tvp,
const GCPtr< AST > &  id,
DeclsOrDefs  what 
) [static]

Definition at line 1228 of file c-gen.cxx.

References assert(), TvPrinter::tvName(), and WantDecl.

Referenced by EmitDeclValue(), EmitDefine(), EmitDefstruct(), and EmitDefunion().

bool GenerateC (  ) 

Definition at line 2472 of file c-gen.cxx.

References AlphaRename(), CheckBootstrapConstraints(), GenerateInterface(), UocInfo::ifList, sherpa::INOstream::less(), sherpa::INOstream::more(), Options::outputFileName, SimplifyAST(), UocInfo::srcList, WantConstructors, WantDecl, WantDefs, WantForward, WantGC, and xmangle().

static void GenerateInterface ( INOstream ino,
const GCPtr< UocInfo > &  uoc,
DeclsOrDefs  what 
) [static]

Definition at line 2407 of file c-gen.cxx.

References assert(), at_interface, at_module, and EmitAst().

Referenced by GenerateC().

void getDefNames ( GCPtr< AST bp,
CVector< std::string > &  names 
)

Definition at line 219 of file c-gen.cxx.

References getDefs().

Referenced by pureLoop().

bool getDefs ( std::ostream &  errStream,
GCPtr< AST bp,
GCPtr< CVector< GCPtr< AST > > >  defs 
)

Definition at line 179 of file c-gen.cxx.

References at_identPattern, and CHKERR.

Referenced by getDefNames().

bool hasInnerLambdas ( std::ostream &  errStream,
const GCPtr< AST > &  ast 
)

Definition at line 568 of file c-gen.cxx.

References at_define, and hasLambda().

Referenced by CheckBootstrapConstraints().

bool hasLambda ( std::ostream &  errStream,
const GCPtr< AST > &  ast 
)

Definition at line 528 of file c-gen.cxx.

References at_lambda, at_loop, and loop2letrec().

Referenced by hasInnerLambdas().

bool hasPatternBindings ( std::ostream &  errStream,
const GCPtr< AST > &  ast 
)

Definition at line 601 of file c-gen.cxx.

References at_define, at_identPattern, at_letbinding, and if().

Referenced by CheckBootstrapConstraints().

bool hasPureLoops ( std::ostream &  errStream,
const GCPtr< AST > &  ast 
)

Definition at line 489 of file c-gen.cxx.

References at_loop, loop2letrec(), and pureLoop().

Referenced by CheckBootstrapConstraints().

static std::string idname ( GCPtr< AST ast,
const char *  pfx = "" 
) [static]

Definition at line 906 of file c-gen.cxx.

References ID_IS_GENSYM, and xmangle().

Referenced by c_decl(), EmitDeclValue(), EmitDefexcept(), EmitDefine(), EmitDefstruct(), EmitDefunion(), EmitExpr(), and EmitSUDecl().

bool is_kwd ( const std::string &  s  ) 

Definition at line 805 of file c-gen.cxx.

References istrcmp(), and nkwd.

Referenced by mangleComponent().

int istrcmp ( const void *  vp1,
const void *  vp2 
)

Definition at line 798 of file c-gen.cxx.

Referenced by is_kwd().

GCPtr<AST> loop2letrec ( GCPtr< AST  ) 

Referenced by hasLambda(), hasPureLoops(), and pureLoop().

std::string mangleComponent ( const std::string &  s  ) 

Definition at line 846 of file c-gen.cxx.

References assert(), is_kwd(), mangleMap, and nSpecial.

Referenced by xmangle().

template<typename T>
INOstream& operator<< ( INOstream inostrm,
ob 
) [inline]

Definition at line 161 of file c-gen.cxx.

References sherpa::INOstream::doIndent(), and sherpa::INOstream::ostrm.

INOstream& operator<< ( INOstream inostrm,
const std::string &  s 
) [inline]

Definition at line 145 of file c-gen.cxx.

References sherpa::INOstream::doIndent(), and sherpa::INOstream::ostrm.

INOstream& operator<< ( INOstream inostrm,
const uint64_t  ull 
) [inline]

Definition at line 136 of file c-gen.cxx.

References sherpa::INOstream::doIndent(), and sherpa::INOstream::ostrm.

INOstream& operator<< ( INOstream inostrm,
const char *  s 
) [inline]

Definition at line 121 of file c-gen.cxx.

References sherpa::INOstream::doIndent(), and sherpa::INOstream::ostrm.

INOstream& operator<< ( INOstream inostrm,
ostream &(*)(ostream &)  pf 
) [inline]

Definition at line 111 of file c-gen.cxx.

References sherpa::INOstream::doIndent(), sherpa::INOstream::needIndent, and sherpa::INOstream::ostrm.

bool pureLoop ( std::ostream &  errStream,
const GCPtr< AST > &  ast,
std::string  nm,
bool  isTail 
)

Definition at line 235 of file c-gen.cxx.

References at_and, at_apply, at_array, at_begin, at_boolLiteral, at_charLiteral, at_cond, at_cond_leg, at_cond_legs, at_deref, at_floatLiteral, at_ident, at_if, at_intLiteral, at_lambda, at_let, at_letrec, at_loop, at_Null, at_or, at_otherwise, at_select, at_setbang, at_stringLiteral, at_throw, at_try, at_usesel, at_vector, child(), getDefNames(), if(), and loop2letrec().

Referenced by hasPureLoops().

static bool SimplifyAST ( std::ostream &  errStream,
const GCPtr< AST > &  ast 
) [static]

Definition at line 641 of file c-gen.cxx.

References at_and, and at_or.

Referenced by GenerateC().

static std::string xmangle ( const FQName fqn,
const char *  pfx 
) [inline, static]

Definition at line 900 of file c-gen.cxx.

References FQName::asString(), and xmangle().

static std::string xmangle ( std::string  s,
const char *  pfx 
) [static]

Definition at line 877 of file c-gen.cxx.

References mangleComponent().

Referenced by GenerateC(), idname(), and xmangle().


Variable Documentation

char* kwd_blacklist[] [static]

Definition at line 685 of file c-gen.cxx.

struct MangleMap mangleMap[]


Generated on Sat Feb 4 23:59:29 2012 for BitC Compiler by  doxygen 1.4.7