void dumpInlines(void) { #ifndef PARSER_ONLY LIST *funcList = inlineHead, *vtabList; cseg(); while (funcList) { SYMBOL *sym = (SYMBOL *)funcList->data; if (sym->genreffed && sym->inlineFunc.stmt) { sym->genreffed = FALSE; UndoPreviousCodegen(sym); genfunc(sym); } funcList = funcList->next; } vtabList = inlineVTabHead; while (vtabList) { SYMBOL *sym = (SYMBOL *)vtabList->data; if (sym->genreffed) { sym->genreffed = FALSE; dumpVTab(sym); } vtabList = vtabList->next; } #endif }
Statement *ParseCatchStatement() { Statement *snp; SYM *sp; TYP *tp,*tp1,*tp2; ENODE *node; static char buf[200]; snp = NewStatement(st_catch, TRUE); currentStmt = snp; if (lastst != openpa) { snp->label = (int64_t *)NULL; snp->s2 = (Statement *)99999; snp->s1 = ParseStatement(); // Empty statements return NULL if (snp->s1) snp->s1->outer = snp; return snp; } needpunc(openpa,33); tp = head; tp1 = tail; catchdecl = TRUE; AutoDeclaration::Parse(NULL,&snp->ssyms); cseg(); catchdecl = FALSE; tp2 = head; head = tp; tail = tp1; needpunc(closepa,34); if( (sp = snp->ssyms.Find(*declid,false)) == NULL) sp = makeint((char *)declid->c_str()); node = makenode(sp->storage_class==sc_static ? en_labcon : en_autocon,NULL,NULL); // nameref looks up the symbol using lastid, so we need to back it up and // restore it. strncpy(buf,lastid,199); strncpy(lastid, declid->c_str(),sizeof(lastid)-1); nameref(&node,FALSE); strcpy(lastid,buf); snp->s1 = ParseStatement(); // Empty statements return NULL if (snp->s1) snp->s1->outer = snp; snp->label = (int64_t *)node; // save name reference if (sp->tp->typeno >= bt_last) error(ERR_CATCHSTRUCT); snp->s2 = (Statement *)GetTypeHash(sp->tp); // Empty statements return NULL // if (snp->s2) // snp->s2->outer = snp; return snp; }
void genASM(STATEMENT *st) { cseg(); contlab = breaklab = - 1; structret_imode = 0 ; tempCount = 0; blockCount = 0; blockMax = 0; exitBlock = 0; genstmt(st, NULL); rewrite_icode(); /* Translate to machine code & dump */ }
void dumpvc1Thunks(void) { #ifndef PARSER_ONLY HASHREC *hr; cseg(); hr = vc1Thunks->table[0]; while (hr) { gen_virtual((SYMBOL *)hr->p, FALSE); gen_vc1((SYMBOL *)hr->p); gen_endvirtual((SYMBOL *)hr->p); hr = hr->next; } #endif }
void dumplits(void) /* * dump the string literal pool. */ { while( strtab != 0) { cseg(); nl(); put_label(strtab->label); genstring(strtab->str,strtab->type); if (strtab->type) genword(0); else genbyte(0); strtab = strtab->next; } nl(); }
Statement *ParseCompoundStatement() { Statement *head, *tail; head = 0; ParseAutoDeclarations(); cseg(); while( lastst != end ) { if( head == NULL ) head = tail = ParseStatement(); else { tail->next = ParseStatement(); if( tail->next != NULL ) tail = tail->next; } } NextToken(); return head; }
/* * dump the string literal pool. */ void dumplits() { char *cp; cseg(); nl(); align(8); nl(); while( strtab != NULL) { nl(); put_label(strtab->label,strtab->str); cp = strtab->str; while(*cp) GenerateChar(*cp++); GenerateChar(0); strtab = strtab->next; } nl(); }
/* Handling for special C++ situations */ SNODE *cppblockedstatement(void) { SNODE *snp; TABLE oldoldlsym; long oldlcauto; #ifdef CPLUSPLUS if (prm_cplusplus) { oldoldlsym = oldlsym; oldlsym = lsyms; } #endif snp = statement(); #ifdef CPLUSPLUS if (prm_cplusplus) { check_funcused(&oldlsym,&lsyms); gather_labels(&oldlsym,&lsyms); cseg(); lsyms = oldlsym; oldlsym.head = oldoldlsym.head; } #endif return(snp); }
void ParseFunctionBody(SYM *sp) { char lbl[200]; needpunc(begin); ParseAutoDeclarations(); cseg(); if (sp->storage_class == sc_static) { strcpy(lbl,GetNamespace()); strcat(lbl,"_"); strcat(lbl,sp->name); gen_strlab(lbl); } // put_label((unsigned int) sp->value.i); else gen_strlab(sp->name); currentFn = sp; currentFn->IsLeaf = TRUE; currentFn->DoesThrow = FALSE; GenerateFunction(sp, ParseCompoundStatement()); // if (optimize) flush_peep(); }
SNODE *switchstmt(void) /* * Handle the SWITCH statement */ { SNODE *snp; SNODE *head, *tail; TYP *tp; SNODE *lst = 0; int ogc = goodcode,oswb=switchbreak; TABLE oldoldlsym; switchbreak = 0; #ifdef CPLUSPLUS if (prm_cplusplus) { oldoldlsym = oldlsym; oldlsym = lsyms; } #endif snp = xalloc(sizeof(SNODE)); snp->next = 0; snp->stype = st_switch; getsym(); needpunc(openpa,0); tp = doassign(&snp->exp,TRUE,0); if (tp) { switch (tp->type) { case bt_char: case bt_unsignedchar: case bt_short: case bt_unsignedshort: case bt_long: case bt_unsigned: case bt_enum: break; default: generror(ERR_SWITCHINT,0,0); } } needpunc(closepa, skm_closepa); needpunc(begin,0); head = 0; goodcode |= GF_UNREACH; goodcode &= ~GF_DEF; if (lastst == id) if (lastch == ':') lst = labelstmt(FALSE); while( lastst != end && lastst != eof) { goodcode &= ~(GF_RETURN | GF_BREAK | GF_CONTINUE | GF_GOTO); if( head == 0 ) head = tail = casestmt(lst); else { tail->next = casestmt(lst); if( tail->next != 0 ) tail = tail->next; } lst = 0; if (tail) tail->next = 0; } if (!switchbreak && goodcode & GF_RETURN) { if ((goodcode & GF_UNREACH) && (goodcode & GF_DEF)) ogc |= GF_RETURN; } goodcode = ogc; snp->s1 = head; getsym(); checkcases(head); switchbreak = oswb; #ifdef CPLUSPLUS if (prm_cplusplus) { check_funcused(&oldlsym,&lsyms); gather_labels(&oldlsym,&lsyms); cseg(); lsyms = oldlsym; oldlsym.head = oldoldlsym.head; } #endif return snp; }
void genfunc(SYMBOL *funcsp) /* * generate a function body and dump the icode */ { IMODE *allocaAP = NULL; SYMBOL *oldCurrentFunc; EXPRESSION *funcexp = varNode(en_global, funcsp); if (total_errors) return; // //printf("%s\n", funcsp->name); contlab = breaklab = - 1; structret_imode = 0 ; tempCount = 0; blockCount = 0; blockMax = 0; exitBlock = 0; oldCurrentFunc = theCurrentFunc; theCurrentFunc = funcsp; iexpr_func_init(); /* firstlabel = nextLabel;*/ cseg(); gen_line(funcsp->linedata); gen_func(funcexp, 1); /* in C99 inlines can clash if declared 'extern' in multiple modules */ /* in C++ we introduce virtual functions that get coalesced at link time */ if (cparams.prm_cplusplus && funcsp->linkage == lk_inline) gen_virtual(funcsp, FALSE); else { if (funcsp->storage_class == sc_global) globaldef(funcsp); else localdef(funcsp); gen_strlab(funcsp); /* name of function */ } addblock( - 1); if (funcsp->linkage == lk_interrupt || funcsp->linkage == lk_fault) { gen_icode(i_pushcontext, 0,0,0); /* if (funcsp->loadds) */ /* gen_icode(i_loadcontext, 0,0,0); */ } gen_icode(i_prologue,0,0,0); gen_label(startlab); /* if (funcsp->loadds && funcsp->farproc) */ /* gen_icode(i_loadcontext, 0,0,0); */ AllocateLocalContext(NULL, funcsp); if (funcsp->allocaUsed) { EXPRESSION *allocaExp = varNode(en_auto, anonymousVar(sc_auto, &stdpointer)); allocaAP = gen_expr(funcsp, allocaExp, 0, ISZ_ADDR); gen_icode(i_savestack, 0, allocaAP, 0); } /* Generate the icode */ /* LCSE is done while code is generated */ genstmt(funcsp->inlineFunc.stmt->lower, funcsp); if (funcsp->inlineFunc.stmt->blockTail) { gen_icode(i_functailstart, 0, 0, 0); genstmt(funcsp->inlineFunc.stmt->blockTail, funcsp); gen_icode(i_functailend, 0, 0, 0); } genreturn(0, funcsp, 1, 0, allocaAP); gen_func(funcexp, 0); tFree(); InsertParameterThunks(funcsp, blockArray[1]); optimize(funcsp); FreeLocalContext(NULL, funcsp); AllocateStackSpace(funcsp); FillInPrologue(intermed_head, funcsp); /* Code gen from icode */ rewrite_icode(); /* Translate to machine code & dump */ if (chosenAssembler->gen->post_function_gen) chosenAssembler->gen->post_function_gen(funcsp, intermed_head); if (cparams.prm_cplusplus && funcsp->linkage == lk_inline) gen_endvirtual(funcsp); intermed_head = NULL; dag_rundown(); oFree(); theCurrentFunc = oldCurrentFunc; if (blockCount > maxBlocks) maxBlocks = blockCount; if (tempCount > maxTemps) maxTemps = tempCount; }
static Statement *ParseFunctionBody(SYM *sp) { std::string lbl; char *p; Statement *stmt; Statement *plg; Statement *eplg; dfs.printf("<Parse function body>:%s|\n", (char *)sp->name->c_str()); lbl[0] = 0; needpunc(begin,47); tmpReset(); //ParseAutoDeclarations(); cseg(); if (sp->storage_class == sc_static) { //strcpy(lbl,GetNamespace()); //strcat(lbl,"_"); // strcpy(lbl,sp->name); lbl = *sp->mangledName; //gen_strlab(lbl); } // put_label((unsigned int) sp->value.i); else { if (sp->storage_class == sc_global) lbl = "public code "; // strcat(lbl,sp->name); lbl += *sp->mangledName; //gen_strlab(lbl); } dfs.printf("B"); p = my_strdup((char *)lbl.c_str()); dfs.printf("b"); GenerateMonadic(op_fnname,0,make_string(p)); currentFn = sp; currentFn->IsLeaf = TRUE; currentFn->DoesThrow = FALSE; currentFn->UsesPredicate = FALSE; regmask = 0; bregmask = 0; currentStmt = (Statement *)NULL; dfs.printf("C"); stmt = ParseCompoundStatement(); dfs.printf("D"); // stmt->stype = st_funcbody; if (isThor) GenerateFunction(sp, stmt); else if (isTable888) GenerateTable888Function(sp, stmt); else if (isRaptor64) GenerateRaptor64Function(sp, stmt); else if (is816) Generate816Function(sp, stmt); else if (isFISA64) GenerateFISA64Function(sp, stmt); dfs.putch('E'); flush_peep(); if (sp->storage_class == sc_global) { ofs.printf("endpublic\r\n\r\n"); } ofs.printf("%sSTKSIZE_ EQU %d\r\n", (char *)sp->mangledName->c_str(), tmpVarSpace() + lc_auto); isFuncBody = false; dfs.printf("</ParseFunctionBody>\n"); return stmt; }