static PTREE doCopySubstitution( // EFFECT COPY SUBSTITUTION PTREE* a_repl, // - addr[ temporary to be replaced ] PTREE orig, // - addr[ original node ] PTREE tgt, // - target PTREE dtor ) // - NULL or CO_DTOR node on right { PTREE repl; // - temporary to be replaced repl = NodeRemoveCastsCommas( *a_repl ); DbgVerify( repl->op == PT_SYMBOL, "doCopySubstitution -- not symbol" ); DbgVerify( SymIsTemporary( repl->u.symcg.symbol ) , "doCopySubstitution -- not temporary" ); if( dtor != NULL ) { PTREE old = orig; DbgVerify( dtor->u.subtree[0]->u.symcg.symbol == repl->u.symcg.symbol , "doCopySubstitution -- not same temporary" ); orig = dtor->u.subtree[1]; dtor->u.subtree[1] = NULL; NodeFreeDupedExpr( old ); } repl->u.symcg.symbol->flag = 0; *a_repl = NodeReplace( *a_repl, tgt ); orig = NodeConvertFlags( ClassTypeForType( tgt->type ) , orig , PTF_LVALUE | PTF_MEMORY_EXACT | PTF_SIDE_EFF | PTF_MEANINGFUL ); return orig; }
void SymTransEmpty( // DEBUG: VERIFY SYMBOL TRANSLATIONS OVER void ) { DbgVerify( NULL == VstkTop( &stack_sym_trans ) , "SymTransEmpty -- stack not empty" ); DbgVerify( 0 == sym_trans_id , "SymTransEmpty -- id != 0" ); }
void IDEAPI IDEFiniDLL // DLL COMPLETION ( IDEDllHdl hdl ) // - handle { hdl = hdl; DbgVerify( hdl == CompInfo.idehdl , "FiniDLL -- handle mismatch" ); }
TYPE TypeAutoDefault( // ADD NEAR QUALIFIER FOR AUTO SYMBOL TYPE type, // - a type PTREE expr ) // - possible PT_SYMBOL of SC_AUTO { #if 0 if( PtreeOpFlags( expr ) & PTO_RVALUE ) { type = augmentWithNear( type ); } else if( expr->op == PT_SYMBOL ) { #else if( expr->op == PT_SYMBOL ) { #endif SYMBOL sym = expr->u.symcg.symbol; if( sym->id == SC_AUTO ) { type_flag flags; TypeGetActualFlags( sym->sym_type, &flags ); if( 0 == ( flags & TF1_MEM_MODEL ) ) { type = augmentWithNear( type ); } } } return( type ); } TYPE TypeForLvalue // GET TYPE FOR LVALUE ( PTREE expr ) // - lvalue expression { TYPE type_expr; // - expression type TYPE type_lv; // - type of LVALUE type_expr = NodeType( expr ); type_lv = TypeReference( type_expr ); DbgVerify( type_lv != NULL, "TypeForLvalue -- not lvalue" ); return( type_lv ); }
IDEBool IDEAPI IDEPassInitInfo( IDEDllHdl hdl, IDEInitInfo *info ) { hdl = hdl; DbgVerify( hdl == CompInfo.idehdl , "PassInitInfo -- handle mismatch" ); if( info->ver < 2 ) { return( true ); } if( info->ignore_env ) { CompFlags.ignore_environment = true; CompFlags.ignore_current_dir = true; } if( info->ver >= 2 ) { if( info->cmd_line_has_files ) { CompFlags.ide_cmd_line = true; } if( info->ver >= 3 ) { if( info->console_output ) { CompFlags.ide_console_output = true; } if( info->ver >= 4 ) { if( info->progress_messages ) { CompFlags.progress_messages = true; } } } } #if defined(wpp_dll) CompFlags.dll_active = true; #endif return( false ); }
void ScopeGenAccessSet( // SET ACCESS SCOPE FOR GENERATION TYPE cltype ) // - type for inlining { DbgVerify( tempScope == NULL, "ScopeAccessSet -- tempScope != NULL" ); tempScope = GetCurrScope(); SetCurrScope (TypeScope( cltype )); }
// Must be called after C++ memory-manager has been initialized // void IdePrintInit // INITIALIZE PRINTING ( void ) { printCtl.index = 0; printCtl.size_buf = 128; printCtl.buffer = allocMem( printCtl.size_buf ); DbgVerify( NULL != printCtl.buffer, "printInit -- alloc failure" ); }
static PTREE makeBooleanConst( PTREE expr, int value ) { DbgVerify( ( value & 1 ) == value, "invalid boolean constant fold" ); expr->u.int_constant = value; expr->op = PT_INT_CONSTANT; expr = NodeSetBooleanType( expr ); return( expr ); }
static fe_seg_id markSegmentComdat( // MARK SEGMENT AS COMDAT SEGMENT fe_seg_id seg_id ) // - segment id { PC_SEGMENT* seg = segIdLookup( seg_id ); DbgVerify( NULL != seg, "markSegmentComdat -- no segment" ); seg->attrs |= COMDAT; return( seg_id ); }
void CgExprDtored( // DTOR CG EXPRESSION cg_name expr, // - expression cg_type type, // - expression type DGRP_FLAGS pop_type, // - type of popping destruction FN_CTL* fctl ) // - function control { #if 0 cg_type type; // - expression type switch( CgExprStackSize() ) { case 0 : break; case 1 : { boolean temp_dtoring = fctl->temp_dtoring; SYMBOL temp = getExprTempSym( &type, fctl, pop_type ); if( temp_dtoring ) { if( fctl->ctor_test ) { pop_type |= DGRP_CTOR; } CgDestructExprTemps( pop_type, fctl ); if( NULL != temp ) { CgExprPush( CgFetchSym( temp ), type ); } } } break; DbgDefault( "CgExprDtored -- too many temps" ); } #else SYMBOL temp; // - NULL or copied temp DbgVerify( 0 == CgExprStackSize(), "CgExprDtored -- more than one expr" ); if( expr != NULL ) { if( pop_type & DGRP_DONE ) { CGDone( expr ); temp = NULL; } else if( pop_type & DGRP_TRASH ) { CGTrash( expr ); temp = NULL; } else if( fctl->temp_dtoring ) { temp = CgVarTempTyped( type ); CGDone( CGLVAssign( CgSymbol( temp ), expr, type ) ); } else { CgExprPush( expr, type ); temp = NULL; } if( fctl->temp_dtoring ) { fctl->temp_dtoring = FALSE; if( fctl->ctor_test ) { pop_type |= DGRP_CTOR; } CgDestructExprTemps( pop_type, fctl ); if( NULL != temp ) { CgExprPush( CgFetchSym( temp ), type ); } } } #endif }
PTREE NodeMakeCall( // FABRICATE A FUNCTION CALL EXPRESSION SYMBOL proc, // - procedure TYPE type, // - return type PTREE args ) // - arguments { DbgVerify( (PointerTypeEquivalent( type ) == NULL) == (PointerTypeEquivalent( SymFuncReturnType( proc ) ) == NULL) , "NodeMakeCall -- return type mismatch" ); return makeCall( NodeMakeCallee( proc ), type, args, TRUE ); }
IDEBool IDEAPI IDEProvideHelp // PROVIDE HELP INFORMATION ( IDEDllHdl hdl // - handle for this instantiation , char const* msg ) // - message { hdl = hdl; DbgVerify( hdl == CompInfo.idehdl , "ProvideHelp -- handle mismatch" ); msg = msg; return true; }
void BrinfSrcEndFile // END OF A SOURCE FILE ( SRCFILE srcfile ) // - file being closed { TOKEN_LOCN end_loc; // - maximum TOKEN_LOCN for file DbgVerify( NULL != srcfile, "SRCFILE required" ); end_loc.src_file = srcfile; end_loc.line = 0xFFFFFFFF; end_loc.column = 0xFFFFFFFF; queue( IC_BR_SRC_END, NULL, &end_loc ); }
static void* reallocMem // RE-ALLOCATE MEMORY ( void* old // - old memory , size_t old_size , size_t size ) // - new size { void* new_blk = allocMem( size ); DbgVerify( size > old_size, "reallocMem -- sizes messed" ); memcpy( new_blk, old, old_size ); freeMem( old ); return new_blk; }
void DgPtrSymOff( // GENERATE POINTER FOR A SYMBOL + OFFSET SYMBOL sym, // - the symbol target_size_t offset ) // - the offset { if( sym == NULL || SymIsFunction( sym ) ) { DbgVerify( offset == 0, "DgPtrSymOffset -- function with offset <> 0" ); dataGenPtrSym( NULL, offset, TY_CODE_PTR ); } else { dataGenPtrSym( sym, offset, TY_POINTER ); } }
PTREE RunTimeCall( // GENERATE A RUN-TIME CALL PARSE SUBTREE PTREE expr, // - expression for operands TYPE type, // - type for function return RTF code ) // - code for function { SYMBOL func; func = RunTimeCallSymbol( code ); DbgVerify( (PointerTypeEquivalent( type ) == NULL) == (PointerTypeEquivalent( SymFuncReturnType( func ) ) == NULL) , "RunTimeCall -- return type mismatch" ); return NodeMakeCall( func, type, expr ); }
static void patchForDtorDelEnd( // CALL-BACK: patch state for DTOR-DEL (end) void* data ) // - patch entry { patch_entry* pe = data; // - patching entry SE* prev; // - previous position _peDump( pe, "CallBack: patchForDtorDelEnd" ); DbgVerify( pe->se != NULL, "patchForDtorDelEnd -- ordering" ); prev = FstabPrevious( pe->se ); pe->se = prev; FstabSetSvSe( prev ); patchSE( pe ); }
bool CmdLnBatchRead( // READ NEXT LINE IN COMMAND BUFFER VBUF *buf ) // - virtual buffer { VbufInit( buf ); for(;;) { int c = nextChar(); if( CompFlags.batch_file_eof ) break; if( c == '\n' ) break; VbufConcChr( buf, c ); } DbgVerify( VbufLen( buf ) > 0, "CmdLnReadBatch -- nothing" ); ++ CompInfo.fc_file_line; return( VbufLen( buf ) ); }
static void dataGenPtrSym( // GENERATE POINTER FOR A SYMBOL + OFFSET SYMBOL sym, // - the symbol target_size_t offset, // - the offset cg_type type ) // - codegen type of pointer { if( sym == NULL ) { DbgVerify( offset == 0, "dataGenPtrSym -- NULL symbol with offset <> 0" ); DGInteger( 0, type ); } else { DGFEPtr( (cg_sym_handle)sym, type, offset ); if( type == TY_CODE_PTR && SymIsThunk( sym ) ) { CgioThunkAddrTaken( sym ); } } }
IDEBool IDEAPI IDEParseMessage // PARSE A MESSAGE ( IDEDllHdl hdl // - handle for this instantiation , char const* msg // - message , ErrorInfo* err ) // - error information { IDEBool retn; // - return: true ==> failed SCAN_INFO scan_info; // - scanning information NUMBER_STR number; // - used for number scanning hdl = hdl; DbgVerify( hdl == CompInfo.idehdl , "ParseMessage -- handle mismatch" ); scan_info.scan = msg; scan_info.tgt = err->filename; scan_info.left = sizeof( err->filename ) - 1; if( parseFileName( &scan_info ) && mustBeChar( &scan_info, '(' ) && collectNumber( &scan_info, number ) && mustBeText( &scan_info, "): " ) ) { err->linenum = atoi( number ); err->flags = ERRINFO_FILENAME | ERRINFO_LINENUM; if( ( mustBeText( &scan_info, "Error! E" ) || mustBeText( &scan_info, "Warning! W" ) || mustBeText( &scan_info, "Note! N" ) ) && collectNumber( &scan_info, number ) && mustBeText( &scan_info, ": " ) ) { err->flags |= ERRINFO_HELPINDEX; err->help_index = atoi( number ); mustBeChar( &scan_info, ' ' ); } if( mustBeText( &scan_info, "(col " ) && collectNumber( &scan_info, number ) && mustBeText( &scan_info, ") " ) ) { err->col = atoi( number ); err->flags |= ERRINFO_COLUMN; } retn = false; } else { err->flags = 0; retn = true; } return retn; }
void CgFunRegister( // REGISTER A FUNCTION FN_CTL* fctl, // - function information SYMBOL rw, // - symbol for R/W block SYMBOL ro ) // - symbol for R/O block { SE* se; // - current position #if _CPU == _AXP CgAssignPtr( CgSymbolPlusOffset( rw, 0 ), CgAddrSymbol( ro ) ); CompFlags.inline_fun_reg = TRUE; #else RT_DEF def; // - R/T call control cg_name opt_thr; // - optimized expression for addr[THREAD_CTL] DbgVerify( CompFlags.rw_registration, "not R/W Registration" ); if( CompFlags.fs_registration ) { CompFlags.inline_fun_reg = TRUE; CgRtCallInit( &def, RTF_FS_PUSH ); CgRtParamAddrSym( &def, rw ); CgRtCallExecDone( &def ); rw = registerHandler( rw, RTF_FS_HANDLER ); } else { opt_thr = pointOptSym( &optFuncReg ); if( opt_thr == NULL ) { rtRegister( rw, ro ); } else { CompFlags.inline_fun_reg = TRUE; CgAssignPtr( CgSymbolPlusOffset( rw, 0 ) , CgFetchPtr( opt_thr ) ); CgAssignPtr( CgSymbol( optFuncReg.sym ) , CgAddrSymbol( rw ) ); rw = registerHandler( rw, RTF_FS_HANDLER_RTN ); } } CgAssignPtr( CgSymbolPlusOffset ( rw, CgbkInfo.size_data_ptr + CgbkInfo.size_fs_hand ) , CgAddrSymbol( ro ) ); #endif if( fctl->is_dtor ) { se = BlkPosnCurr(); } else { se = NULL; } FstabAssignStateVar( se ); }
static void deQueue // TAKE (FIFO) INSTRUCTION FROM QUEUE ( void ) { PP_INS* ins; // - queued instruction ins = ins_queue->next; DbgVerify( NULL != ins, "Empty instruction queue" ); RingPrune( &ins_queue, ins ); IfDbgToggle( browse ) { DbgStmt( printf( "dequeued %s %x\n " , DbgIcOpcode( ins->opcode ) , ins->parm ) ); DbgStmt( DbgDumpTokenLocn( &ins->locn ) ); DbgStmt( printf( "\n" ) ); } writeIns( ins->opcode, ins->parm, &ins->locn ); CarveFree( carvePpIns, ins ); }
PTREE AnalyseReturnClassVal // RETURN CLASS VALUE ( PTREE expr ) // - expression for return { TYPE retn_type; // - return type TYPE retn_class; // - class for return PTREE tgt; // - target expression CNV_DIAG* diag; // - diagnosis retn_type = expr->u.subtree[0]->type; retn_class = StructType( retn_type ); DbgVerify( retn_class != NULL, "AnalyseReturnClassVal -- not class" ); if( ClassCorrupted( retn_class ) ) { PTreeErrorNode( expr ); } else if( TypeAbstract( retn_class ) ) { PTreeErrorExprType( expr, ERR_CONVERT_TO_ABSTRACT_TYPE, retn_class ); ScopeNotePureFunctions( retn_class ); } else { diag = DefargBeingCompiled() ? &diagDefarg : &diagReturn; tgt = NodeFetchReference( getReturnSym() ); expr = removeReturnNode( expr ); expr = CopyClassRetnVal( expr, tgt, retn_type, diag ); if( expr->op != PT_ERROR ) { if( NodeIsBinaryOp( expr, CO_DTOR ) ) { PTREE node = expr->u.subtree[0]; if( SymFunctionReturn() == node->u.symcg.symbol ) { PTreeFree( node ); node = expr; expr = expr->u.subtree[1]; PTreeFree( node ); } } } #if 0 // this is just so we can do some checking expr = CastImplicit( expr , retn_type , CNV_EXPR , DefargBeingCompiled() ? &diagDefarg : &diagReturn ); } #endif }
static void callBackEnd( // CALL-BACK: end of condition block void* data ) // - COND_STK entry { COND_STK* cond = data; // - COND_STK entry SE* posn; // - current position _Dump( cond, "CallBack(END)" ); posn = FstabCurrPosn(); #if 0 if( posn == cond->posn_true && posn == cond->posn_false ) { cond->mask_set = 0; cond->mask_clr = NOT_BITARR_MASK( 0 ); BlkPosnTempBegSet( posn ); } else { #else { #endif SE* test = FstabTestFlag( cond->offset , cond->posn_last , posn ); FstabAdd( test ); BlkPosnTempBegSet( test ); } callBackFini( cond ); } static void callBackNewCtorBeg( // CALL-BACK: start of new ctor void* data ) // - COND_STK entry { COND_STK* cond = data; // - COND_STK entry SE* posn; // - current position SE* se; // - new test_flag entry posn = callBackCurrent( cond ); DbgVerify( NULL != posn, "callBackNewCtorBeg -- no delete SE" ); se = FstabTestFlag( cond->offset, posn, FstabPrevious( posn ) ); cond->posn_true = se; FstabAdd( se ); BlkPosnTempBegSet( se ); }
static NAME nameAdd( idname **head, unsigned bucket, unsigned xhash, const char *id, unsigned len ) { idname *name; #ifdef XTRA_RPT if( *head == NULL ) { ExtraRptIncrementCtr( ctr_chains ); } #endif ExtraRptIncrementCtr( ctr_names ); DbgVerify( !nameFlags.no_creates_allowed, "name create occurred during precompiled header processing" ); name = CPermAlloc( NAME_SIZE + len + 1 ); memcpy( name->name, id, len + 1 ); name->xhash = xhash; name->hash = bucket; name->next = *head; *head = name; ++nameCount; return( NAME_RETVAL( name ) ); }
IDEBool IDEAPI IDERunYourSelf // COMPILE A PROGRAM ( IDEDllHdl hdl // - handle for this instantiation , const char* opts // - options , IDEBool* fatal_error ) // - addr[ fatality indication ] { DLL_DATA dllinfo; // - information passed to DLL auto char input[1+_MAX_PATH+1]; // - input file name ("<fname>") auto char output[4+1+_MAX_PATH+1];//- output file name (-fo="<fname>") hdl = hdl; DbgVerify( hdl == CompInfo.idehdl , "RunYourSelf -- handle mismatch" ); TBreak(); // clear any pending IDEStopRunning's initDLLInfo( &dllinfo ); dllinfo.cmd_line = (char*)opts; fillInputOutput( input, output ); WppCompile( &dllinfo, input, output ); *fatal_error = (IDEBool)CompFlags.fatal_error; return( (IDEBool)CompFlags.compile_failed ); }
void SymbolLocnDefine( // DEFINE LOCATION SYMBOL TOKEN_LOCN *sym_locn, // - symbol location (NULL for current source file) SYMBOL sym ) // - the symbol { SYM_TOKEN_LOCN *locn = NULL; if( sym_locn != NULL && sym_locn->src_file != NULL ) { locn = SymbolLocnAlloc( &sym->locn ); locn->tl = *sym_locn; sym->flag2 |= SF2_TOKEN_LOCN; } else { DbgVerify( sym_locn == NULL , "SymbolLocnDefine -- bad location" ); if( SrcFilesOpen() ) { locn = SymbolLocnAlloc( &sym->locn ); SrcFileGetTokenLocn( &locn->tl ); sym->flag2 |= SF2_TOKEN_LOCN; } } }
CALL_OPT AnalyseCallOpts // ANALYSE CALL OPTIMIZATIONS ( TYPE type // - class type of target operand , PTREE src // - source operand , PTREE* a_dtor // - addr[ CO_DTOR ] , PTREE* a_right ) // - addr[ base source operand ] { CALL_OPT retn; // - type of return PTREE right; // - bare source operand right = *NodeReturnSrc( &src, a_dtor ); *a_right = right; if( type == ClassTypeForType( right->type ) ) { if( NodeCallsCtor( right ) ) { retn = CALL_OPT_CTOR; } else if( NodeIsBinaryOp( right, CO_CALL_EXEC ) || NodeIsBinaryOp( right, CO_CALL_EXEC_IND ) ) { TYPE ftype; // - function type ftype = TypeFunctionCalled( NodeFuncForCall( right )->type ); DbgVerify( ftype != NULL , "AnalyseCLassCallOpts -- impossible parse tree" ); if( OMR_CLASS_REF == ObjModelFunctionReturn( ftype ) ) { retn = CALL_OPT_FUN_CALL; } else { retn = CALL_OPT_NONE; } } else if( NodeIsBinaryOp( right, CO_COPY_OBJECT ) ) { PTREE tgt = NodeRemoveCastsCommas( right->u.subtree[0] ); if( tgt->op == PT_SYMBOL && SymIsTemporary( tgt->u.symcg.symbol ) ) { retn = CALL_OPT_BIN_COPY; } else { retn = CALL_OPT_NONE; } } else { retn = CALL_OPT_NONE; } } else { retn = CALL_OPT_NONE; } return retn; }
void CallIndirectVirtual( // MARK INDIRECT CALL AS VIRTUAL SYMBOL vfunc, // - the virtual function boolean is_virtual, // - TRUE ==> an actual virtual call target_offset_t adj_this, // - adjustment for "this" target_offset_t adj_retn ) // - adjustment for return { CALL_STK* cstk; // - top of call stack SYMBOL virt_fun; // - dummy symbol for virtual call vfunc = vfunc; if( is_virtual ) { virt_fun = ind_call_stack; virt_fun->id = SC_VIRTUAL_FUNCTION; virt_fun->u.virt_fun = vfunc; } else { cstk = VstkTop( &stack_calls ); DbgVerify( cstk != NULL, "CallIndirectVirtual -- no call stack" ); cstk->adj_this = adj_this; cstk->adj_retn = adj_retn; } }
IDEBool IDEAPI IDERunYourSelfArgv(// COMPILE A PROGRAM (ARGV ARGS) IDEDllHdl hdl, // - handle for this instantiation int argc, // - # of arguments char **argv, // - argument vector IDEBool* fatal_error ) // - addr[ fatality indication ] { DLL_DATA dllinfo; // - information passed to DLL auto char input[1+_MAX_PATH+1]; // - input file name ("<fname>") auto char output[4+1+_MAX_PATH+1];//- output file name (-fo="<fname>") hdl = hdl; DbgVerify( hdl == CompInfo.idehdl , "RunYourSelf -- handle mismatch" ); TBreak(); // clear any pending IDEStopRunning's initDLLInfo( &dllinfo ); dllinfo.argc = argc; dllinfo.argv = argv; fillInputOutput( input, output ); WppCompile( &dllinfo, input, output ); *fatal_error = (IDEBool)CompFlags.fatal_error; return( (IDEBool)CompFlags.compile_failed ); }