SC_FUNC stringlist *insert_dbgsymbol(symbol *sym) { if (sc_status==statWRITE && (sc_debug & sSYMBOLIC)!=0) { char string[2*sNAMEMAX+128]; char symname[2*sNAMEMAX+16]; funcdisplayname(symname,sym->name); /* address tag:name codestart codeend ident vclass [tag:dim ...] */ if (sym->ident==iFUNCTN) { sprintf(string,"S:%" PRIxC " %x:%s %" PRIxC " %" PRIxC " %x %x", sym->addr,sym->tag,symname,sym->addr,sym->codeaddr,sym->ident,sym->vclass); } else { sprintf(string,"S:%" PRIxC " %x:%s %" PRIxC " %" PRIxC " %x %x", sym->addr,sym->tag,symname,sym->codeaddr,code_idx,sym->ident,sym->vclass); } /* if */ if (sym->ident==iARRAY || sym->ident==iREFARRAY) { #if !defined NDEBUG int count=sym->dim.array.level; #endif symbol *sub; strcat(string," [ "); for (sub=sym; sub!=NULL; sub=finddepend(sub)) { assert(sub->dim.array.level==count--); sprintf(string+strlen(string),"%x:%x ",sub->x.tags.index,sub->dim.array.length); } /* for */ strcat(string,"]"); } /* if */ return insert_string(&dbgstrings,string); } /* if */ return NULL; }
static int find_closestsymbol_table(const char *name,const symbol *root,int symboltype,symbol **closestsym) { int dist,closestdist=INT_MAX; char symname[2*sNAMEMAX+16]; symbol *sym=root->next; int ident,critdist; assert(closestsym!=NULL); *closestsym=NULL; assert(name!=NULL); critdist=strlen(name)/2; /* for short names, allow only a single edit */ if (critdist>MAX_EDIT_DIST) critdist=MAX_EDIT_DIST; while (sym!=NULL) { funcdisplayname(symname,sym->name); ident=sym->ident; if (symboltype==iARRAY && ident==iREFARRAY) ident=iARRAY; /* reference arrays match arrays */ else if (symboltype==iVARIABLE && (sym->ident==iCONSTEXPR || sym->ident==iREFERENCE || sym->ident==iARRAY || sym->ident==iREFARRAY)) ident=iVARIABLE; /* when requesting variables, constants are also ok */ if (symboltype==ident || (symboltype==iVARIABLE && ident==iFUNCTN)) { dist=levenshtein_distance(name,symname); if (dist<closestdist && dist<=critdist) { *closestsym=sym; closestdist=dist; } /* if */ } /* if */ sym=sym->next; } /* while */ return closestdist; }
/* * Call specified function */ SC_FUNC void ffcall(symbol *sym,const char *label,int numargs) { char symname[2*sNAMEMAX+16]; char aliasname[sNAMEMAX+1]; int wasAlias = 0; assert(sym!=NULL); assert(sym->ident==iFUNCTN); if (sc_asmfile) funcdisplayname(symname,sym->name); if ((sym->usage & uNATIVE)!=0) { /* reserve a SYSREQ id if called for the first time */ assert(label==NULL); stgwrite("\tsysreq.c "); if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->addr>=0) sym->addr=ntv_funcid++; /* Look for an alias */ if (lookup_alias(aliasname, sym->name)) { symbol *asym = findglb(aliasname, sGLOBAL); if (asym && asym->ident==iFUNCTN && ((sym->usage & uNATIVE) != 0)) { sym = asym; if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->addr>=0) { sym->addr=ntv_funcid++; markusage(sym, uREAD); } } } outval(sym->addr,FALSE); if (sc_asmfile) { stgwrite("\t; "); stgwrite(symname); } /* if */ stgwrite("\n"); /* write on a separate line, to mark a sequence point for the peephole optimizer */ stgwrite("\tstack "); outval((numargs+1)*sizeof(cell), TRUE); code_idx+=opcodes(2)+opargs(2); } else { /* normal function */ stgwrite("\tcall "); if (label!=NULL) { stgwrite("l."); stgwrite(label); } else { stgwrite(sym->name); } /* if */ if (sc_asmfile && (label!=NULL || (!isalpha(sym->name[0]) && sym->name[0]!='_' && sym->name[0]!=sc_ctrlchar))) { stgwrite("\t; "); stgwrite(symname); } /* if */ stgwrite("\n"); code_idx+=opcodes(1)+opargs(1); } /* if */ }
/* * Call specified function */ SC_FUNC void ffcall(symbol *sym,const char *label,int numargs) { char symname[2*sNAMEMAX+16]; assert(sym!=NULL); assert(sym->ident==iFUNCTN); if (sc_asmfile) funcdisplayname(symname,sym->name); if ((sym->usage & uNATIVE)!=0) { /* reserve a SYSREQ id if called for the first time */ assert(label==NULL); if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->index>=0) sym->index=ntv_funcid++; stgwrite("\tsysreq.c "); outval(sym->index,TRUE,FALSE); if (sc_asmfile) { stgwrite("\t; "); stgwrite(symname); } /* if */ stgwrite("\n"); /* write on a separate line, to mark a sequence point for the peephole optimizer */ stgwrite("\tstack "); outval((numargs+1)*sizeof(cell),TRUE,TRUE); code_idx+=opcodes(2)+opargs(2); } else { /* normal function */ if (pc_overlays>0) stgwrite("\ticall "); else stgwrite("\tcall "); if (pc_overlays>0) { if (label!=NULL) stgwrite(label); else outval(sym->index,TRUE,FALSE); } else { if (label!=NULL) { stgwrite("l."); stgwrite(label); } else { stgwrite(sym->name); } /* if */ } /* if */ if (sc_asmfile && (label!=NULL || pc_overlays>0 || !isalpha(sym->name[0]) && sym->name[0]!='_' && sym->name[0]!=sc_ctrlchar)) { stgwrite("\t; "); stgwrite(symname); } /* if */ stgwrite("\n"); code_idx+=opcodes(1)+opargs(1); } /* if */ }
/* startfunc - declare a CODE entry point (function start) * * Global references: funcstatus (referred to only) */ SC_FUNC void startfunc(char *fname) { stgwrite("\tproc"); if (sc_asmfile) { char symname[2*sNAMEMAX+16]; funcdisplayname(symname,fname); stgwrite("\t; "); stgwrite(symname); } /* if */ stgwrite("\n"); code_idx+=opcodes(1); }
/* startfunc - declare a CODE entry point (function start) * * Global references: funcstatus (referred to only) */ SC_FUNC void startfunc(const char *fname,int index) { stgwrite("\tproc"); if (sc_asmfile) { char symname[2*sNAMEMAX+16]; funcdisplayname(symname,fname); stgwrite("\t; "); stgwrite(symname); if (pc_overlays>0) { /* add overlay index */ stgwrite("/"); outval(index,FALSE,FALSE); } /* if */ } /* if */ stgwrite("\n"); code_idx+=opcodes(1); }
SC_FUNC stringlist *insert_dbgsymbol(const symbol *sym) { if (sc_status==statWRITE && (sc_debug & sSYMBOLIC)!=0) { char string[2*sNAMEMAX+128]; char symname[2*sNAMEMAX+16]; funcdisplayname(symname,sym->name); /* address tag:name codestart codeend ident scope [tag:dim ...] */ if (sym->ident==iFUNCTN) { sprintf(string,"S:%" PRIxC " %x:%s %" PRIxC " %" PRIxC " %x %x", CELLCAST(sym->addr),sym->tag,symname,CELLCAST(sym->addr), CELLCAST(sym->codeaddr),sym->ident,sym->scope); } else { sprintf(string,"S:%" PRIxC " %x:%s %" PRIxC " %" PRIxC " %x %x", CELLCAST(sym->addr),sym->tag,symname,CELLCAST(sym->codeaddr), CELLCAST(code_idx),sym->ident,sym->scope); } /* if */ if (sym->ident==iARRAY || sym->ident==iREFARRAY) { #if !defined NDEBUG int count=sym->dim.array.level; #endif const symbol *sub; strcat(string," [ "); for (sub=sym; sub!=NULL; sub=finddepend(sub)) { #if !defined NDEBUG assert(sub->dim.array.level==count); count-=1; #endif sprintf(string+strlen(string),"%x ",(unsigned)sub->dim.array.length); /* ??? also indicate whether the last dimension is packed */ /* ??? also dump the index field names (but need a dynamically growing string for this) */ } /* for */ strcat(string,"]"); } /* if */ return insert_string(&dbgstrings,string,1); } /* if */ return NULL; }