void funcbottom() { nl(); check_table(&lsyms); lc_auto = 0; fprintf(list,"\n\n*** local symbol table ***\n\n"); ListTable(&lsyms,0); fprintf(list,"\n\n\n"); ReleaseLocalMemory(); /* release local symbols */ isPascal = FALSE; isOscall = FALSE; isInterrupt = FALSE; isNocall = FALSE; }
void funcbottom(Statement *stmt) { Statement *s, *s1; nl(); check_table(lsyms.head); lc_auto = 0; fprintf(list,"\n\n*** local symbol table ***\n\n"); ListTable(&lsyms,0); // Should recurse into all the compound statements if (stmt==NULL) printf("DIAG: null statement in funcbottom.\r\n"); else { if (stmt->stype==st_compound) ListCompound(stmt); } fprintf(list,"\n\n\n"); ReleaseLocalMemory(); /* release local symbols */ isPascal = FALSE; isKernel = FALSE; isOscall = FALSE; isInterrupt = FALSE; isNocall = FALSE; }
/* * funcbody starts with the current symbol being either * the first parameter id or the begin for the local * block. If begin is the current symbol then funcbody * assumes that the function has no parameters. */ int ParseFunction(SYM *sp) { int poffset, i; int oldglobal; SYM *sp1, *sp2; Statement *stmt; if (sp==NULL) { fatal("Compiler error: ParseFunction: SYM is NULL\r\n"); } sp->stkname = stkname; if (verbose) printf("Parsing function: %s\r\n", sp->name); oldglobal = global_flag; global_flag = 0; poffset = 24; /* size of return block */ nparms = 0; iflevel = 0; // There could be unnamed parameters in a function prototype. if(lastst == id || 1) { /* declare parameters */ //while(lastst == id) { // names[nparms++] = litlate(lastid); // NextToken(); // if( lastst == comma) // NextToken(); // else // break; // } //needpunc(closepa); // dodecl(sc_member); /* declare parameters */ sp->parms = (SYM *)NULL; ParseParameterDeclarations(1); for(i = 0;i < nparms;++i) { if( (sp1 = search(names[i],&lsyms)) == NULL) sp1 = makeint(names[i]); //if( sp1->tp->size < 8 ) //{ // sp1->value.i = poffset;// + (8 - sp1->tp->size); // poffset += 8; //} //else //{ // sp1->value.i = poffset; // poffset += sp1->tp->size; //} sp1->value.i = poffset; // Check for aggregate types passed as parameters. Structs // and unions use the type size. // if (sp1->tp->type==bt_struct || sp1->tp->type==bt_union) { poffset += round8(sp1->tp->size); if (round8(sp1->tp->size) > 8) sp->IsLeaf = FALSE; // } // else // poffset += 8; //sp1->value.i = poffset; //poffset += 8; sp1->storage_class = sc_auto; sp1->nextparm = (SYM *)NULL; // record parameter list if (sp->parms == (SYM *)NULL) { sp->parms = sp1; } else { sp1->nextparm = sp->parms; sp->parms = sp1; } } // Process extra hidden parameter if (sp->tp->btp->type==bt_struct || sp->tp->btp->type==bt_union) { sp1 = makeint(litlate("_pHiddenStructPtr")); sp1->value.i = poffset; poffset += 8; sp1->storage_class = sc_auto; sp1->nextparm = (SYM *)NULL; // record parameter list if (sp->parms == (SYM *)NULL) { sp->parms = sp1; } else { sp1->nextparm = sp->parms; sp->parms = sp1; } nparms++; } } if (lastst == closepa) NextToken(); if (sp->tp->type == bt_pointer) { if (lastst==assign) { doinit(sp); } sp->IsNocall = isNocall; sp->IsPascal = isPascal; sp->IsKernel = isKernel; sp->IsInterrupt = isInterrupt; sp->IsTask = isTask; sp->NumParms = nparms; isPascal = FALSE; isKernel = FALSE; isOscall = FALSE; isInterrupt = FALSE; isTask = FALSE; isNocall = FALSE; ReleaseLocalMemory(); /* release local symbols (parameters)*/ global_flag = oldglobal; return 1; } if (lastst == semicolon) { // Function prototype sp->IsPrototype = 1; sp->IsNocall = isNocall; sp->IsPascal = isPascal; sp->IsKernel = isKernel; sp->IsInterrupt = isInterrupt; sp->IsTask = isTask; sp->NumParms = nparms; isPascal = FALSE; isKernel = FALSE; isOscall = FALSE; isInterrupt = FALSE; isTask = FALSE; isNocall = FALSE; ReleaseLocalMemory(); /* release local symbols (parameters)*/ goto j1; } else if(lastst != begin) { // NextToken(); ParseParameterDeclarations(2); // for old-style parameter list //needpunc(closepa); if (lastst==semicolon) { sp->IsPrototype = 1; sp->IsNocall = isNocall; sp->IsPascal = isPascal; sp->IsKernel = isKernel; sp->IsInterrupt = isInterrupt; sp->IsTask = isTask; sp->NumParms = nparms; isPascal = FALSE; isKernel = FALSE; isOscall = FALSE; isInterrupt = FALSE; isTask = FALSE; isNocall = FALSE; ReleaseLocalMemory(); /* release local symbols (parameters)*/ } // Check for end of function parameter list. else if (funcdecl==2 && lastst==closepa) { ; } else { sp->IsNocall = isNocall; sp->IsPascal = isPascal; sp->IsKernel = isKernel; sp->IsInterrupt = isInterrupt; sp->IsTask = isTask; isPascal = FALSE; isKernel = FALSE; isOscall = FALSE; isInterrupt = FALSE; isTask = FALSE; isNocall = FALSE; sp->NumParms = nparms; stmt = ParseFunctionBody(sp); funcbottom(stmt); } } // error(ERR_BLOCK); else { sp->IsNocall = isNocall; sp->IsPascal = isPascal; sp->IsKernel = isKernel; sp->IsInterrupt = isInterrupt; sp->IsTask = isTask; isPascal = FALSE; isKernel = FALSE; isOscall = FALSE; isInterrupt = FALSE; isTask = FALSE; isNocall = FALSE; sp->NumParms = nparms; stmt = ParseFunctionBody(sp); funcbottom(stmt); } j1: global_flag = oldglobal; return 0; }
/* * funcbody starts with the current symbol being either * the first parameter id or the begin for the local * block. If begin is the current symbol then funcbody * assumes that the function has no parameters. */ void ParseFunction(SYM *sp) { int poffset, i; int oldglobal; SYM *sp1, *sp2, *makeint(); oldglobal = global_flag; global_flag = 0; poffset = 24; /* size of return block */ nparms = 0; if(lastst == id || 1) { /* declare parameters */ //while(lastst == id) { // names[nparms++] = litlate(lastid); // NextToken(); // if( lastst == comma) // NextToken(); // else // break; // } //needpunc(closepa); // dodecl(sc_member); /* declare parameters */ sp->parms = NULL; ParseParameterDeclarations(1); for(i = 0;i < nparms;++i) { if( (sp1 = search(names[i],&lsyms)) == NULL) sp1 = makeint(names[i]); //if( sp1->tp->size < 8 ) //{ // sp1->value.i = poffset;// + (8 - sp1->tp->size); // poffset += 8; //} //else //{ // sp1->value.i = poffset; // poffset += sp1->tp->size; //} sp1->value.i = poffset; poffset += 8; sp1->storage_class = sc_auto; sp1->nextparm = NULL; // record parameter list if (sp->parms == NULL) { sp->parms = sp1; } else { sp1->nextparm = sp->parms; sp->parms = sp1; } } } if (lastst == closepa) NextToken(); if (lastst == semicolon) { // Function prototype sp->IsPrototype = 1; sp->IsNocall = isNocall; sp->IsPascal = isPascal; sp->IsInterrupt = isInterrupt; sp->NumParms = nparms; isPascal = FALSE; isOscall = FALSE; isInterrupt = FALSE; isNocall = FALSE; ReleaseLocalMemory(); /* release local symbols (parameters)*/ } else if(lastst != begin) { NextToken(); ParseParameterDeclarations(2); sp->IsNocall = isNocall; sp->IsPascal = isPascal; sp->IsInterrupt = isInterrupt; sp->NumParms = nparms; ParseFunctionBody(sp); funcbottom(); } // error(ERR_BLOCK); else { sp->IsNocall = isNocall; sp->IsPascal = isPascal; sp->IsInterrupt = isInterrupt; sp->NumParms = nparms; ParseFunctionBody(sp); funcbottom(); } global_flag = oldglobal; }