gen-c.cxx File Reference

#include "../config.h"
#include <stdint.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <fstream>
#include <iostream>
#include <string>
#include <set>
#include <sstream>
#include <cctype>
#include <sys/wait.h>
#include <libsherpa/utf8.hxx>
#include <libsherpa/INOstream.hxx>
#include <libsherpa/BigNum.hxx>
#include <boost/filesystem/operations.hpp>
#include "config.h"
#include "Version.hxx"
#include "Options.hxx"
#include "UocInfo.hxx"
#include "AST.hxx"
#include "Environment.hxx"
#include "inter-pass.hxx"
#include "backend.hxx"

Go to the source code of this file.

Data Structures

struct  MangleMap

Defines

#define TOC_HEADER_MODE   0x01u
#define CMGL_ID_FLD   0x1u
#define CTYP_EMIT_BF   0x01u
#define CTYP_BYREF   0x02u
#define TOC(errStream, uoc, ast, out, IDname,decla, parent, chno,flags)

Enumerations

enum  { nSpecial = sizeof(mangleMap) / sizeof(MangleMap) }

Functions

const char * punctMangle (uint32_t codePoint)
std::string CMangle (std::string idName)
std::string CMangle (shared_ptr< AST > ast, unsigned long flags=0)
bool toc (std::ostream &errStream, shared_ptr< UocInfo > uoc, shared_ptr< AST > ast, INOstream &out, const string &IDname, set< string > &decls, shared_ptr< AST > parent, const size_t chno, unsigned long flags)
static string toCtype (shared_ptr< Type > typ, string IDname="", unsigned long flags=0, uint64_t arrsz=0)
static bool isUnitType (shared_ptr< Type > ty)
static bool isUnitType (shared_ptr< AST > ast)
static std::string decl (shared_ptr< Type > typ, string idName, unsigned flags=0, size_t field_bits=0)
static std::string decl (shared_ptr< AST > id, string idPrefix="", unsigned flags=0, unsigned long cmFlags=0)
static void declare (INOstream &out, shared_ptr< AST > id, string prefix="", unsigned flags=0)
static void emit_ct_args (INOstream &out, shared_ptr< AST > fields, size_t start=0)
static void emit_ct_inits (INOstream &out, shared_ptr< AST > fields, string pre="", size_t start=0)
static void emit_fnxn_type (INOstream &out, std::string &id, shared_ptr< Type > fn, bool makePointer=false)
static void emit_fnxn_decl (INOstream &out, shared_ptr< AST > ast, bool oneLine, std::string pfx="", size_t startParam=0)
static bool emit_fnxn_label (std::ostream &errStream, shared_ptr< UocInfo > uoc, shared_ptr< AST > ast, INOstream &out, set< string > &decls, shared_ptr< AST > parent, const size_t chno, unsigned long flags)
bool typeIsUnmangled (shared_ptr< Type > typ)
static bool needsBackslashEscape (uint32_t c)
static bool asciiPrintableCharacter (uint32_t c)
static bool alreadyEmitted (shared_ptr< Type > t, const set< string > &theSet)
static void emit_arr_vec_fn_types (shared_ptr< Type > candidate, INOstream &out, set< string > &arrSet, set< string > &arrByrefSet, set< string > &vecSet, set< string > &fnSet)
static void emit_arr_vec_fn_types (shared_ptr< AST > ast, INOstream &out, set< string > &arrSet, set< string > &arrByrefSet, set< string > &vecSet, set< string > &fnSet)
static bool TypesTOC (std::ostream &errStream, shared_ptr< UocInfo > uoc, INOstream &out, set< string > &decls, unsigned long flags)
static bool emitInitProc (std::ostream &errStream, shared_ptr< AST > ast, shared_ptr< UocInfo > uoc, INOstream &out, INOstream &initStream, set< string > &decls, unsigned long flags)
static bool EmitGlobalInitializers (std::ostream &errStream, shared_ptr< UocInfo > uoc, INOstream &out, set< string > &decls, unsigned long flags)
static bool EmitMain (INOstream &out)
static bool ValuesTOH (std::ostream &errStream, shared_ptr< UocInfo > uoc, INOstream &out, set< string > &decls, unsigned long flags)
bool GenerateCoutput (std::ostream &errStream, INOstream &out, unsigned long flags, shared_ptr< UocInfo > uoc)
bool EmitHeader (std::ostream &optStream, std::ostream &errStream, shared_ptr< UocInfo > uoc)
bool EmitC (std::ostream &optStream, std::ostream &errStream, shared_ptr< UocInfo > uoc)
bool EmitExe (std::ostream &optStream, std::ostream &errStream, shared_ptr< UocInfo > uoc)

Variables

const char * TY_PFX = "ty_"
const char * CTOR_PFX = "ct_"
const char * CVAL_PFX = "val_"
const char * TAG_PFX = "tag_"
const char * ENUM_PFX = "en_"
const char * ARG_PFX = "arg_"
const char * RET_PFX = "ret_"
const char * ENV_PFX = "env_"
const char * XFN_PFX = "xfn_"
const char * MFN_PFX = "mfn_"
const char * WFN_PFX = "wfn_"
const char * LBL_PFX = "__escape___"
MangleMap mangleMap []


Define Documentation

#define CMGL_ID_FLD   0x1u

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

Referenced by CMangle(), emit_ct_args(), emit_ct_inits(), and toc().

#define CTYP_BYREF   0x02u

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

Referenced by decl(), and emit_fnxn_decl().

#define CTYP_EMIT_BF   0x01u

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

Referenced by decl(), toc(), and toCtype().

#define TOC ( errStream,
uoc,
ast,
out,
IDname,
decla,
parent,
chno,
flags   ) 

Value:

do {                                                                \
    answer = toc((errStream), (uoc), (ast), (out), (IDname),         \
                 (decla), (parent), (chno), (flags));                \
    if (answer == false)                                                \
      errorFree = false;                                        \
  }while (0)

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

Referenced by emitInitProc(), and toc().

#define TOC_HEADER_MODE   0x01u

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

Referenced by emit_fnxn_label(), EmitHeader(), GenerateCoutput(), and toc().


Enumeration Type Documentation

anonymous enum

Enumerator:
nSpecial 

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


Function Documentation

static bool alreadyEmitted ( shared_ptr< Type t,
const set< string > &  theSet 
) [static]

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

References CMangle(), and nm.

Referenced by emit_arr_vec_fn_types().

static bool asciiPrintableCharacter ( uint32_t  c  )  [static]

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

Referenced by LitValue::asString(), and toc().

std::string CMangle ( shared_ptr< AST ast,
unsigned long  flags = 0 
)

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

References assert(), at_ident, CMangle(), CMGL_ID_FLD, flags, ID_IS_GENSYM, ID_IS_GLOBAL, and if().

std::string CMangle ( std::string  idName  ) 

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

References punctMangle(), and sherpa::utf8_decode().

Referenced by alreadyEmitted(), CMangle(), decl(), emit_arr_vec_fn_types(), emit_ct_args(), emit_ct_inits(), emit_fnxn_decl(), emit_fnxn_label(), emit_fnxn_type(), EmitGlobalInitializers(), emitInitProc(), toc(), toCtype(), and TypesTOC().

static std::string decl ( shared_ptr< AST id,
string  idPrefix = "",
unsigned  flags = 0,
unsigned long  cmFlags = 0 
) [inline, static]

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

References assert(), at_ident, CMangle(), CTYP_BYREF, CTYP_EMIT_BF, flags, and toCtype().

static std::string decl ( shared_ptr< Type typ,
string  idName,
unsigned  flags = 0,
size_t  field_bits = 0 
) [inline, static]

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

References CTYP_BYREF, CTYP_EMIT_BF, flags, and toCtype().

Referenced by buildNewDeclaration(), declare(), emit_ct_args(), emit_fnxn_decl(), emit_fnxn_label(), EmitGlobalInitializers(), matchDefDecl(), and toc().

static void declare ( INOstream out,
shared_ptr< AST id,
string  prefix = "",
unsigned  flags = 0 
) [inline, static]

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

References decl(), flags, and prefix.

Referenced by EmitGlobalInitializers(), and toc().

static void emit_arr_vec_fn_types ( shared_ptr< AST ast,
INOstream out,
set< string > &  arrSet,
set< string > &  arrByrefSet,
set< string > &  vecSet,
set< string > &  fnSet 
) [static]

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

References emit_arr_vec_fn_types().

static void emit_arr_vec_fn_types ( shared_ptr< Type candidate,
INOstream out,
set< string > &  arrSet,
set< string > &  arrByrefSet,
set< string > &  vecSet,
set< string > &  fnSet 
) [static]

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

References alreadyEmitted(), assert(), CMangle(), emit_fnxn_type(), sherpa::INOstream::less(), MARK_EMIT_ARR_VEC_FN_TYPES, sherpa::INOstream::more(), and toCtype().

Referenced by emit_arr_vec_fn_types(), and TypesTOC().

static void emit_ct_args ( INOstream out,
shared_ptr< AST fields,
size_t  start = 0 
) [static]

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

References at_field, CMangle(), CMGL_ID_FLD, decl(), and FLD_IS_DISCM.

Referenced by toc().

static void emit_ct_inits ( INOstream out,
shared_ptr< AST fields,
string  pre = "",
size_t  start = 0 
) [static]

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

References at_fill, at_methdecl, CMangle(), CMGL_ID_FLD, and FLD_IS_DISCM.

Referenced by toc().

static void emit_fnxn_decl ( INOstream out,
shared_ptr< AST ast,
bool  oneLine,
std::string  pfx = "",
size_t  startParam = 0 
) [static]

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

References assert(), at_identPattern, CMangle(), COMP_BYREF, CTYP_BYREF, decl(), flags, isUnitType(), and toCtype().

Referenced by emit_fnxn_label().

static bool emit_fnxn_label ( std::ostream &  errStream,
shared_ptr< UocInfo uoc,
shared_ptr< AST ast,
INOstream out,
set< string > &  decls,
shared_ptr< AST parent,
const size_t  chno,
unsigned long  flags 
) [static]

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

References assert(), at_container, at_define, at_identPattern, at_letStar, at_recdef, CHKERR, CMangle(), decl(), emit_fnxn_decl(), FEXPR, boost::GC_NULL, isUnitType(), LAM_NEEDS_TRANS, sherpa::INOstream::less(), sherpa::INOstream::more(), toc(), TOC_HEADER_MODE, and XFN_PFX.

Referenced by toc().

static void emit_fnxn_type ( INOstream out,
std::string &  id,
shared_ptr< Type fn,
bool  makePointer = false 
) [static]

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

References CMangle(), COMP_BYREF, isUnitType(), and toCtype().

Referenced by emit_arr_vec_fn_types(), EmitGlobalInitializers(), and toc().

bool EmitC ( std::ostream &  optStream,
std::ostream &  errStream,
shared_ptr< UocInfo uoc 
)

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

References GenerateCoutput(), and Options::outputFileName.

bool EmitExe ( std::ostream &  optStream,
std::ostream &  errStream,
shared_ptr< UocInfo uoc 
)

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

References Options::CompilePreOptionsGCC, GenerateCoutput(), Options::LinkPostOptionsGCC, Options::LinkPreOptionsGCC, Options::noGC, STD_CC_CMD, Options::useStdLib, and Options::verbose.

static bool EmitGlobalInitializers ( std::ostream &  errStream,
shared_ptr< UocInfo uoc,
INOstream out,
set< string > &  decls,
unsigned long  flags 
) [static]

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

References assert(), at_define, at_lambda, at_proclaim, at_recdef, CHKERR, CMangle(), decl(), declare(), DEF_IS_TRIVIAL_INIT, emit_fnxn_type(), emitInitProc(), boost::GC_NULL, isUnitType(), sherpa::INOstream::less(), UocInfo::mainIsDefined, AST::make(), MFN_PFX, sherpa::INOstream::more(), pp_Raw, sherpa::INOstream::setPostindent(), toc(), and WFN_PFX.

Referenced by GenerateCoutput().

bool EmitHeader ( std::ostream &  optStream,
std::ostream &  errStream,
shared_ptr< UocInfo uoc 
)

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

References GenerateCoutput(), Options::outputFileName, and TOC_HEADER_MODE.

static bool emitInitProc ( std::ostream &  errStream,
shared_ptr< AST ast,
shared_ptr< UocInfo uoc,
INOstream out,
INOstream initStream,
set< string > &  decls,
unsigned long  flags 
) [static]

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

References assert(), at_container, at_define, at_letStar, at_recdef, CMangle(), FEXPR, sherpa::INOstream::less(), sherpa::INOstream::more(), TOC, and toCtype().

Referenced by EmitGlobalInitializers().

static bool EmitMain ( INOstream out  )  [static]

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

References sherpa::INOstream::less(), sherpa::INOstream::more(), and sherpa::INOstream::setPostindent().

Referenced by GenerateCoutput().

bool GenerateCoutput ( std::ostream &  errStream,
INOstream out,
unsigned long  flags,
shared_ptr< UocInfo uoc 
)

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

References assert(), CHKERR, EmitGlobalInitializers(), EmitMain(), Options::entryPts, UocInfo::mainIsDefined, sherpa::INOstream::setPostindent(), TOC_HEADER_MODE, TypesTOC(), ValuesTOH(), and Version().

Referenced by EmitC(), EmitExe(), and EmitHeader().

static bool isUnitType ( shared_ptr< AST ast  )  [inline, static]

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

References isUnitType().

static bool isUnitType ( shared_ptr< Type ty  )  [inline, static]

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

Referenced by emit_fnxn_decl(), emit_fnxn_label(), emit_fnxn_type(), EmitGlobalInitializers(), isUnitType(), and toc().

static bool needsBackslashEscape ( uint32_t  c  )  [static]

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

Referenced by LitValue::asString(), and toc().

const char* punctMangle ( uint32_t  codePoint  ) 

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

References mangleMap, and nSpecial.

Referenced by CMangle().

bool toc ( std::ostream &  errStream,
shared_ptr< UocInfo uoc,
shared_ptr< AST ast,
INOstream out,
const string &  IDname,
set< string > &  decls,
shared_ptr< AST parent,
const size_t  chno,
unsigned long  flags 
)

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

References agt_category, agt_CompilationUnit, agt_definition, agt_eform, agt_expr, agt_expr_or_define, agt_fielditem, agt_if_definition, agt_literal, agt_openclosed, agt_ow, agt_qtype, agt_tc_definition, agt_tvar, agt_type, agt_type_definition, agt_ucon, agt_uselhs, agt_value_definition, agt_var, ARG_BYREF, ARG_PFX, asciiPrintableCharacter(), assert(), at_allocREF, at_and, at_AnyGroup, at_apply, at_argVec, at_array, at_array_nth, at_array_ref_nth, at_arrayRefType, at_arrayType, at_begin, at_bitfieldType, at_bitsizeof, at_boolLiteral, at_boxedCat, at_boxedType, at_byRefType, at_charLiteral, at_cond, at_cond_leg, at_cond_legs, at_condelse, at_constraints, at_constructor, at_constructors, at_constType, at_container, at_copyREF, at_declare, at_declares, at_declrepr, at_declstruct, at_declunion, at_defexception, at_define, at_definstance, at_defrepr, at_defstruct, at_deftypeclass, at_defunion, at_deref, at_docString, at_dummyType, at_dup, at_exceptionType, at_field, at_fields, at_fieldType, at_fill, at_floatLiteral, at_fn, at_fnargVec, at_fqCtr, at_frameBindings, at_ident, at_identList, at_identPattern, at_if, at_ifident, at_ifsel, at_import, at_importAs, at_inner_ref, at_interface, at_intLiteral, at_labeledBlock, at_lambda, at_let, at_letbinding, at_letbindings, at_letGather, at_letrec, at_letStar, at_localFrame, at_loop, at_loopbinding, at_loopbindings, at_looptest, at_MakeVector, at_methdecl, at_method_decl, at_method_decls, at_methType, at_mkArrayRef, at_mkClosure, at_module, at_mutableType, at_nth, at_Null, at_object_apply, at_oc_closed, at_oc_open, at_opaqueCat, at_or, at_otherwise, at_primaryType, at_proclaim, at_provide, at_qualType, at_recdef, at_reprctr, at_reprctrs, at_reprrepr, at_return_from, at_sel_ctr, at_select, at_setbang, at_setClosure, at_sizeof, at_stringLiteral, at_struct_apply, at_suspend, at_tcapp, at_tcdecls, at_tcmethod_binding, at_tcmethods, at_throw, at_try, at_tvlist, at_tyfn, at_typeAnnotation, at_typeapp, at_ucon_apply, at_unboxedCat, at_unboxedType, at_unit, at_unless, at_usesel, at_usw_leg, at_usw_legs, at_uswitch, at_vector, at_vector_nth, at_vectorType, at_when, CARDELLI_UN, CHKERR, CMangle(), CMGL_ID_FLD, COMP_BYREF, CTOR_PFX, ctr, CTYP_EMIT_BF, CVAL_PFX, decl(), declare(), LitValue::DecodeStringCharacter(), emit_ct_args(), emit_ct_inits(), emit_fnxn_label(), emit_fnxn_type(), ENUM_PFX, FEXPR, FLD_IS_DISCM, boost::GC_NULL, ID_IS_GENSYM, ID_IS_PRIVATE, id_ucon0, sherpa::INOstream::indent(), INNER_REF_NDX, isUnitType(), LB_IS_DUMMY, LB_POSTPONED, LBL_PFX, lbs, sherpa::INOstream::less(), Type::make(), AST::make(), sherpa::INOstream::more(), needsBackslashEscape(), nm, NULLABLE_UN, ow, RET_PFX, SELF_TAIL, SINGLE_LEG_UN, TAG_PFX, TOC, TOC_HEADER_MODE, toCtype(), TY_PFX, typeIsUnmangled(), UNION_IS_REPR, sherpa::utf8_encode(), and XFN_PFX.

Referenced by emit_fnxn_label(), EmitGlobalInitializers(), TypesTOC(), and ValuesTOH().

static string toCtype ( shared_ptr< Type typ,
string  IDname = "",
unsigned long  flags = 0,
uint64_t  arrsz = 0 
) [static]

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

References assert(), CMangle(), CTYP_EMIT_BF, flags, and TY_PFX.

Referenced by decl(), emit_arr_vec_fn_types(), emit_fnxn_decl(), emit_fnxn_type(), emitInitProc(), and toc().

bool typeIsUnmangled ( shared_ptr< Type typ  ) 

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

Referenced by toc().

static bool TypesTOC ( std::ostream &  errStream,
shared_ptr< UocInfo uoc,
INOstream out,
set< string > &  decls,
unsigned long  flags 
) [static]

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

References at_declstruct, at_declunion, at_defexception, at_define, at_defstruct, at_defunion, at_proclaim, at_recdef, CHKERR, CMangle(), emit_arr_vec_fn_types(), pp_Raw, sherpa::INOstream::setPostindent(), toc(), and TY_PFX.

Referenced by GenerateCoutput().

static bool ValuesTOH ( std::ostream &  errStream,
shared_ptr< UocInfo uoc,
INOstream out,
set< string > &  decls,
unsigned long  flags 
) [static]

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

References at_proclaim, CHKERR, DEF_IS_EXTERNAL, pp_Raw, sherpa::INOstream::setPostindent(), and toc().

Referenced by GenerateCoutput().


Variable Documentation

const char* ARG_PFX = "arg_"

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

Referenced by toc().

const char* CTOR_PFX = "ct_"

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

Referenced by toc().

const char* CVAL_PFX = "val_"

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

Referenced by toc().

const char* ENUM_PFX = "en_"

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

Referenced by toc().

const char* ENV_PFX = "env_"

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

const char* LBL_PFX = "__escape___"

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

Referenced by toc().

struct MangleMap mangleMap[]

Referenced by mangleComponent(), and punctMangle().

const char* MFN_PFX = "mfn_"

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

Referenced by EmitGlobalInitializers().

const char* RET_PFX = "ret_"

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

Referenced by toc().

const char* TAG_PFX = "tag_"

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

Referenced by toc().

const char* TY_PFX = "ty_"

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

Referenced by toc(), toCtype(), and TypesTOC().

const char* WFN_PFX = "wfn_"

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

Referenced by EmitGlobalInitializers().

const char* XFN_PFX = "xfn_"

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

Referenced by emit_fnxn_label(), and toc().


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