void CgDeclParms( // DEFINE ARGS FOR CURRENT FN IN CORRECT ORDER FN_CTL *fctl, // - current function control pointer SCOPE scope ) // - argument scope { SYMBOL curr; SYMBOL stop; SYMBOL *psym; // - addr[ parameter symbol ] TYPE fn_type; auto VSTK_CTL sym_stack; SYMBOL ret_sym; NAME ret_name; fn_type = FunctionDeclarationType( fctl->func->sym_type ); VstkOpen( &sym_stack, sizeof( SYMBOL ), 16 ); stop = ScopeOrderedStart( scope ); ret_name = CppSpecialName( SPECIAL_RETURN_VALUE ); ret_sym = NULL; curr = NULL; for(;;) { curr = ScopeOrderedNext( stop, curr ); if( curr == NULL ) break; if( ( curr->name != NULL ) && ( ret_name == curr->name->name ) ) { ret_sym = curr; } else { psym = VstkPush( &sym_stack ); *psym = curr; } } IbpDefineParms(); declareParameter( fctl->this_sym ); declareParameter( fctl->cdtor_sym ); declareParameter( ret_sym ); switch( PcCallImpl( fn_type ) ) { case CALL_IMPL_REV_CPP : case CALL_IMPL_REV_C : for(;;) { psym = VstkPop( &sym_stack ); if( psym == NULL ) break; declareParameter( *psym ); } break; case CALL_IMPL_CPP : case CALL_IMPL_C : case CALL_IMPL_ELL_CPP : case CALL_IMPL_ELL_C : { unsigned index; // - parameter index unsigned max_parms; // - # parameters SYMBOL *psym1; // - addr[ parameter symbol ] max_parms = VstkDimension( &sym_stack ); for( index = 0; index < max_parms; ++index ) { psym1 = VstkIndex( &sym_stack, index ); declareParameter( *psym1 ); } } break; } VstkClose( &sym_stack ); CGLastParm(); }
void CgPushGarbage( // PUSH GARBAGE (TO BE TRASHED/POPPED) void ) { CGEXPR* top; // - next top of stack top = VstkPush( &expressions ); top->expr = NULL; top->type = 0; top->garbage = TRUE; }
void CgExprPush( // PUSH CG EXPRESSION RESULT cg_name expr, // - expression cg_type type ) // - expression type { CGEXPR* top; // - next top of stack top = VstkPush( &expressions ); top->expr = expr; top->type = type; top->garbage = FALSE; }
void SymTransPush( // ADD A SYMBOL TO BE TRANSLATED SYMBOL src, // - source SYMBOL SYMBOL tgt ) // - target SYMBOL { SYM_TRANS *tr; // - translation element tr = VstkPush( &stack_sym_trans ); tr->src = src; tr->tgt = tgt; tr->id = sym_trans_id; dump( "defined", tr ); }
static label_handle switch_label( // PLANT SWITCH LABEL void ) { label_handle tmp_label; // - new label handle label_handle *stacked; // - stacked label handle tmp_label = BENewLabel(); CgLabel( tmp_label ); ++ switch_ctl()->cases; stacked = VstkPush( &stack_labs_sw ); *stacked = tmp_label; return( tmp_label ); }
void CallStackPush( // PUSH CALL STACK SYMBOL func, // - NULL, or inlined function call_handle handle, // - handle for call cg_type cg_retn ) // - cg type of call { CALL_STK* curr; // - entry on call stack curr = VstkPush( &stack_calls ); curr->func = func; curr->handle = handle; curr->adj_this = 0; curr->adj_retn = 0; curr->retn_type = cg_retn; }
static DUMP_INFO* dumpStruct( // DUMP A STRUCTURE TYPE type, // - structure type DUMP_INFO* di, // - dump information char* title, // - title for dump ds_control control ) // - control word { CLASSINFO* info; // - class information NAME *parent; // - where parent ptr is stored control = control; type = StructType( type ); info = type->u.c.info; parent = VstkPush( &di->stack ); *parent = info->name; di = dumpTitle( di, title, NameStr( info->name ) ); if( type != di->original ) { di = bufferInit( di ); di = bufferStr( di, "embedded size: " ); di = bufferNmb( di, info->vsize ); di = bufferWrite( di ); di = dumpOffset( di ); di = dumpParentage( di ); } else { di = bufferInit( di ); di = bufferStr( di, "size: " ); di = bufferNmb( di, info->size ); di = bufferWrite( di ); } if( info->has_vbptr ) { di = dumpDataMemb( di , "[virtual" , "base pointer]" , info->vb_offset + di->offset , CgMemorySize( TypePtrToVoid() ) ); } if( info->has_vfptr ) { di = dumpDataMemb( di , "[virtual" , "functions pointer]" , info->vf_offset + di->offset , CgMemorySize( TypePtrToVoid() ) ); } ScopeWalkDataMembers( type->u.c.scope, dumpMember, di ); if( type == di->original ) { ScopeWalkVirtualBases( type->u.c.scope, dumpVirtual, di ); } ScopeWalkDirectBases( type->u.c.scope, dumpDirect, di ); VstkPop( &di->stack ); return di; }
static SYMBOL push_inline_sym( // PUSH AN INLINE SYMBOL SYMBOL model ) // - model for symbol { SYMBOL sym; // - new symbol SYM_TOKEN_LOCN* locn; // - new location entry for symbol sym = VstkPush( &stack_inline_args ); *sym = *model; if( model->locn != NULL ) { sym->flag2 &= ~SF2_CG_HANDLE; sym->locn = NULL; locn = SymbolLocnAlloc( &sym->locn ); locn->tl = model->locn->tl; } return sym; }
static CTX_CL* cmdLnCtxAlloc( // ALLOCATE NEW CONTEXT CTX_CLTYPE type ) // - type of context { CTX_CL* entry; entry = VstkPush( &cmdLnContexts ); entry->base.ctx_type = type; entry->base.sw_ptr = NULL; if( type == CTX_CLTYPE_PGM ) { entry->base.cmd_line = NULL; entry->base.cmd_scan = NULL; } else { entry->base.cmd_line = CmdScanAddr(); entry->base.cmd_scan = CtxGetSwitchAddr(); } return entry; }
SYMBOL CgDeclHiddenParm( // DECLARE HIDDEN ARG (THIS, CDTOR) SCOPE scope, // - function parameters scope TYPE type, // - symbol type SYMBOL symbol_model, // - model for symbol unsigned specname_index ) // - special name index { SYMBOL_NAME name; // - new symbol name SYMBOL sym; // - new symbol name = VstkPush( &stack_symbol_name ); memset( name, 0, sizeof( *name ) ); name->containing = scope; name->name = CppSpecialName( specname_index ); sym = push_inline_sym( symbol_model ); sym->sym_type = type; sym->name = name; return sym; }
label_handle CgSwitchBeg // GENERATE CODE FOR START OF SWITCH STMT ( FN_CTL* fctl ) // - function control { SW_CTL *ctl; // - control for switch cg_name sw_expr; // - switch expression cg_type sw_type; // - switch type sw_expr = CgExprPopType( &sw_type ); CgExprDtored( sw_expr, sw_type, DGRP_TEMPS, fctl ); sw_expr = CgExprPopType( &sw_type ); ctl = VstkPush( &stack_switches ); ctl->id = CGSelInit(); ctl->cases = 0; ctl->temp = CGTemp( sw_type ); ctl->type = sw_type; ctl->label = BENewLabel(); CgAssign( CGTempName( ctl->temp, sw_type ), sw_expr, sw_type ); return ctl->label; }
static void reportOnType // SET UP TYPE REFERENCE ( SRCFILE curr // - current source file , TYPE type // - a type , SYMBOL sym ) // - symbol for type { if( NULL != sym && ( SF2_TOKEN_LOCN & sym->flag2 ) ) { SRCFILE refed = sym->locn->tl.src_file; if( curr != refed ) { REPO_STAT* repo = reposStat( curr ); TYPE* last; for( last = VstkTop( &repo->typeset ); ; last = VstkNext( &repo->typeset, last ) ) { if( NULL == last ) { *(TYPE*)VstkPush( &repo->typeset ) = type; break; } if( type == *last ) break; } } } }
static REPO_STAT* reposStat // GET REPOSITORY STATISTICS FOR SRCFILE ( SRCFILE sf ) // - the source file { REPO_STAT** last; // - addr[ REPO_STAT ] REPO_STAT* retn; // - REPO_STAT for source file for( last = VstkTop( &srcFiles ); ; last = VstkNext( &srcFiles, last ) ) { if( NULL == last ) { retn = CarveAlloc( carve_sf ); *(REPO_STAT**)VstkPush( &srcFiles ) = retn; VstkOpen( &retn->refset, sizeof( SYMBOL ), 32 ); VstkOpen( &retn->typeset, sizeof( TYPE ), 32 ); retn->srcfile = sf; retn->defns = 0; break; } retn = *last; if( sf == retn->srcfile ) break; } return retn; }
void ExtraRptSymUsage( // REPORT SYMBOL USAGE FROM PRIMARY SOURCE SYMBOL sym ) { extraRptTypeUsage( sym->sym_type ); if( isReposSym( sym ) ) { SRCFILE current = SrcFileCurrent(); SRCFILE refed = sym->locn->tl.src_file; if( current != refed ) { REPO_STAT* repo = reposStat( current ); SYMBOL* last; for( last = VstkTop( &repo->refset ) ; ; last = VstkNext( &repo->refset, last ) ) { if( NULL == last ) { *(SYMBOL*)VstkPush( &repo->refset ) = sym; break; } if( sym == *last ) break; } } } }
static void writeIns // WRITE AN INSTRUCTION ( CGINTEROP opcode // - opcode , void const * parm // - parm for instruction , TOKEN_LOCN const * locn ) // - location for instruction { TOKEN_LOCN* curr_locn; // - location SRCDEP const* sd; // - dependency for open switch( opcode ) { case IC_BR_SRC_BEG : curr_locn = VstkPush( &open_src ); TokenLocnAssign( *curr_locn, cursor ); sd = parm; cursor.src_file = BrinfDepSrcfile( sd ); cursor.line = 0; cursor.column = 0; BrinfWriteIns( opcode, parm ); break; case IC_BR_SRC_END : locn = VstkPop( &open_src ); if( NULL == locn ) { cursor.src_file = NULL; } else { TokenLocnAssign( cursor, *locn ); } BrinfWriteIns( opcode, parm ); break; case IC_BR_REF_MACRO : TokenLocnAssign( cursor, *locn ); BrinfIcReference( opcode, parm, locn ); break; default : TokenLocnAssign( cursor, *locn ); BrinfWriteIns( opcode, parm ); break; } }