- switch (SPEC_NOUN(p)) { /* depending on the specifier type */
- case V_INT:
- return (IS_LONG(p) ? LONGSIZE : ( IS_SHORT(p) ? SHORTSIZE: INTSIZE)) ;
- case V_FLOAT:
- return FLOATSIZE ;
- case V_CHAR:
- return CHARSIZE ;
- case V_VOID:
- return 0 ;
- case V_STRUCT:
- return SPEC_STRUCT(p)->size ;
- case V_LABEL:
- return 0 ;
- case V_SBIT:
- return BITSIZE ;
- case V_BIT:
- return ((SPEC_BLEN(p) / 8) + (SPEC_BLEN(p) % 8 ? 1 : 0)) ;
- default :
- return 0 ;
- }
+ switch (SPEC_NOUN(p)) { /* depending on the specifier type */
+ case V_INT:
+ return (IS_LONG(p) ? LONGSIZE : ( IS_SHORT(p) ? SHORTSIZE: INTSIZE)) ;
+ case V_FLOAT:
+ return FLOATSIZE ;
+ case V_CHAR:
+ return CHARSIZE ;
+ case V_VOID:
+ return 0 ;
+ case V_STRUCT:
+ return SPEC_STRUCT(p)->size ;
+ case V_LABEL:
+ return 0 ;
+ case V_SBIT:
+ return BITSIZE ;
+ case V_BIT:
+ return ((SPEC_BLEN(p) / 8) + (SPEC_BLEN(p) % 8 ? 1 : 0)) ;
+ default :
+ return 0 ;
+ }
- sscanf(rs,"%d,%d,%d",&i,
- &(SPEC_INTN(func->sym->etype)),
- &(SPEC_BANK(func->sym->etype)));
+ sscanf(rs,"%d,%d,%hd",&i,
+ &(SPEC_INTN(func->sym->etype)),
+ &(SPEC_BANK(func->sym->etype)));
- link *type;
- type = Safe_calloc(1,sizeof(link));
- if (*s == ',') s++;
-
- /* is a declarator */
- if (*s == 'D') {
- s++;
- switch (*s) {
- case 'F':
- DCL_TYPE(type) = FUNCTION;
- s++;
- break;
- case 'G':
- DCL_TYPE(type) = GPOINTER;
- s++;
- break;
- case 'C':
- DCL_TYPE(type) = CPOINTER;
- s++;
- break;
- case 'X':
- DCL_TYPE(type) = FPOINTER;
- s++;
- break;
- case 'D':
- DCL_TYPE(type) = POINTER;
- s++;
- break;
- case 'I':
- DCL_TYPE(type) = IPOINTER;
- s++;
- break;
- case 'P':
- DCL_TYPE(type) = PPOINTER;
- s++;
- break;
- case 'A':
- s++;
- DCL_TYPE(type) = ARRAY ;
- DCL_ELEM(type) = strtol(s,&s,10);
- break;
- }
- } else {
- /* is a specifier */
- type->class = SPECIFIER ;
- s++;
- switch (*s) {
- case 'L':
- SPEC_NOUN(type) = V_INT;
- SPEC_LONG(type) = 1;
- s++;
- break;
- case 'I':
- SPEC_NOUN(type) = V_INT;
- s++;
- break;
- case 'S':
- case 'C':
- SPEC_NOUN(type) = V_CHAR ;
- s++;
- break;
- case 'V':
- SPEC_NOUN(type) = V_VOID;
- s++;
- break;
- case 'F':
- SPEC_NOUN(type) = V_FLOAT;
- s++;
- break;
- case 'T':
- s++;
- SPEC_NOUN(type) = V_STRUCT;
- {
- char *ss = strtok(strdup(s),",):");
-
- SPEC_STRUCT(type) = structWithName(ss);
- free(ss);
- }
- break;
- case 'X':
- s++;
- SPEC_NOUN(type) = V_SBIT;
- break;
- case 'B':
- SPEC_NOUN(type) = V_BIT;
- s++;
- SPEC_BSTR(type) = strtol(s,&s,10);
- s++;
- SPEC_BLEN(type) = strtol(s,&s,10);
- break;
- }
- while (*s != ':') s++;
- s++;
- if (*s++ == 'S')
- SPEC_USIGN(type) = 0;
- else
- SPEC_USIGN(type) = 1;
-
- }
-
- /* add the type to the symbol's type chain */
- if (sym->type)
- sym->etype = sym->etype->next = type;
- else
- sym->type = sym->etype = type;
+ link *type;
+ type = Safe_calloc(1,sizeof(link));
+ if (*s == ',') s++;
+
+ /* is a declarator */
+ if (*s == 'D') {
+ s++;
+ switch (*s) {
+ case 'F':
+ DCL_TYPE(type) = FUNCTION;
+ s++;
+ break;
+ case 'G':
+ DCL_TYPE(type) = GPOINTER;
+ s++;
+ break;
+ case 'C':
+ DCL_TYPE(type) = CPOINTER;
+ s++;
+ break;
+ case 'X':
+ DCL_TYPE(type) = FPOINTER;
+ s++;
+ break;
+ case 'D':
+ DCL_TYPE(type) = POINTER;
+ s++;
+ break;
+ case 'I':
+ DCL_TYPE(type) = IPOINTER;
+ s++;
+ break;
+ case 'P':
+ DCL_TYPE(type) = PPOINTER;
+ s++;
+ break;
+ case 'A':
+ s++;
+ DCL_TYPE(type) = ARRAY ;
+ DCL_ELEM(type) = strtol(s,&s,10);
+ break;
+ }
+ } else {
+ /* is a specifier */
+ type->class = SPECIFIER ;
+ s++;
+ switch (*s) {
+ case 'L':
+ SPEC_NOUN(type) = V_INT;
+ SPEC_LONG(type) = 1;
+ s++;
+ break;
+ case 'I':
+ SPEC_NOUN(type) = V_INT;
+ s++;
+ break;
+ case 'S':
+ case 'C':
+ SPEC_NOUN(type) = V_CHAR ;
+ s++;
+ break;
+ case 'V':
+ SPEC_NOUN(type) = V_VOID;
+ s++;
+ break;
+ case 'F':
+ SPEC_NOUN(type) = V_FLOAT;
+ s++;
+ break;
+ case 'T':
+ s++;
+ SPEC_NOUN(type) = V_STRUCT;
+ {
+ char *ss = strtok(strdup(s),",):");
+
+ SPEC_STRUCT(type) = structWithName(ss);
+ free(ss);
+ }
+ break;
+ case 'X':
+ s++;
+ SPEC_NOUN(type) = V_SBIT;
+ break;
+ case 'B':
+ SPEC_NOUN(type) = V_BIT;
+ s++;
+ SPEC_BSTR(type) = strtol(s,&s,10);
+ s++;
+ SPEC_BLEN(type) = strtol(s,&s,10);
+ break;
+ }
+ while (*s != ':') s++;
+ s++;
+ if (*s++ == 'S')
+ SPEC_USIGN(type) = 0;
+ else
+ SPEC_USIGN(type) = 1;
+
+ }
+
+ /* add the type to the symbol's type chain */
+ if (sym->type)
+ sym->etype = sym->etype->next = type;
+ else
+ sym->type = sym->etype = type;
- nsym = Safe_calloc(1,sizeof(symbol));
-
- /* copy over the mangled name */
- while (*bp != '(') bp++;
- bp -= 1;
- nsym->rname = alloccpy(s,bp - s);
-
+ /* go the mangled name */
+ for ( bp = s; *bp && *bp != '('; bp++ );
+ save_ch = *--bp;
+ *bp = '\0';
+ nsym = NULL;
+ if ( doadd == 2 )
+ {
+ /* add only if not present and if linkrecord before symbol record*/
+ if ( applyToSetFTrue(symbols,symWithRName,s,&nsym))
+ {
+ if ( nsym->rname != nsym->name )
+ return NULL;
+ doadd = 0;
+ }
+ }
+ if ( ! nsym )
+ {
+ nsym = Safe_calloc(1,sizeof(symbol));
+ nsym->rname = alloccpy(s,bp - s);
+ }
+ *bp = save_ch;
- int offset ;
- symbol *sym ;
- while (!isdigit(*s)) s++;
- offset = strtol(s,&s,10);
- while (*s != ':') s++;
- s++;
- sym = parseSymbol(s,&s);
- sym->offset = offset ;
- s += 3;
- if (!fields)
- fields = nsdef->fields = sym;
- else
- fields = fields->next = sym;
-
+ int offset ;
+ symbol *sym ;
+ while (!isdigit(*s)) s++;
+ offset = strtol(s,&s,10);
+ while (*s != ':') s++;
+ s++;
+ sym = parseSymbol(s,&s,0);
+ sym->offset = offset ;
+ s += 3;
+ if (!fields)
+ fields = nsdef->fields = sym;
+ else
+ fields = fields->next = sym;
+ nsdef->size += sym->size;
- sprintf(buffer,"%s.asm",s);
- nmod->asm_name = Safe_malloc(strlen(buffer)+1);
- strcpy(nmod->asm_name,buffer);
+ sprintf(buffer,"%s.asm",s);
+ nmod->asm_name = Safe_malloc(strlen(buffer)+1);
+ strcpy(nmod->asm_name,buffer);
- sym->scopetype != 'G' && /* local scope */
- (sym->sname && strcmp(sym->sname,sname) == 0) && /* scope == specified scope */
- sym->block <= block && /* block & level kindo matches */
- sym->level <= level) {
-
- /* if a symbol was previously found then
- sure that ones block & level are less
- then this one */
- if (*rsym && (*rsym)->block >= block &&
- (*rsym)->level >= level)
- return 0;
-
- *rsym = sym;
- return 1;
+ sym->scopetype != 'G' && /* local scope */
+ (sym->sname && strcmp(sym->sname,sname) == 0) && /* scope == specified scope */
+ sym->block <= block && /* block & level kindo matches */
+ sym->level <= level) {
+
+ /* if a symbol was previously found then
+ sure that ones block & level are less
+ then this one */
+ if (*rsym && (*rsym)->block >= block &&
+ (*rsym)->level >= level)
+ return 0;
+
+ *rsym = sym;
+ return 1;
- /* first try & find a local variable for the
- given name */
- if ( applyToSet(symbols,symLocal,
- name,
- ctxt->func->sym->name,
- ctxt->block,
- ctxt->level,
- &sym))
- return sym;
+ if ((ctxt) && (ctxt->func) &&
+ (ctxt->func->sym) && (ctxt->func->sym->name)) {
+ /* first try & find a local variable for the given name */
+ if ( applyToSet(symbols,symLocal,
+ name,
+ ctxt->func->sym->name,
+ ctxt->block,
+ ctxt->level,
+ &sym))
+ return sym;
+ sym = NULL;
+ }
+
+ if ((ctxt) && (ctxt->func) &&
+ (ctxt->func->mod) && (ctxt->func->mod->name)) {
+ /* then try local to this module */
+ if (applyToSet(symbols,symLocal,
+ name,
+ ctxt->func->mod->name,
+ 0,0,&sym))
+ return sym;
+ sym = NULL;
+ }
- if (!applyToSet(symbols,symWithRName,sname,&sym))
- return ;
-
- s++;
- sscanf(s,"%x",&sym->addr);
-#ifdef SDCDB_DEBUG
- printf("%s(%x)\n",sym->name,sym->addr);
-#endif
+ applyToSetFTrue(symbols,symWithRName,s,&sym);
+ if (! sym)
+ {
+ sym = Safe_calloc(1,sizeof(symbol));
+ sym->rname = alloccpy(s,bp - s);
+ sym->scopetype = *s;
+ sym->name = sym->rname;
+ addSet(&symbols,sym);
+ }
+ *bp = save_ch;
+ if ( *bp )
+ {
+ sscanf(bp+2,"%x",&sym->addr);
+ }
+ Dprintf(D_symtab, ("symtab: lnk %s(0x%x)\n",sym->name,sym->addr));
- mod = parseModule(mname,FALSE);
- mod->c_name = alloccpy(mname,strlen(mname));
- mod->cfullname=searchDirsFname(mod->c_name);
- mod->cLines = loadFile(mod->c_name,&mod->ncLines);
+ mod = parseModule(mname, FALSE);
+ mod->c_name = alloccpy(mname,strlen(mname));
+ mod->cfullname=searchDirsFname(mod->c_name);
+ mod->cLines = loadFile(mod->c_name,&mod->ncLines);
- if (line < mod->ncLines && line > 0) {
- mod->cLines[line]->addr = addr;
- mod->cLines[line]->block = block;
- mod->cLines[line]->level = level;
-#ifdef SDCDB_DEBUG
- printf("%s(%d:%x) %s",mod->c_name,
- line+1,addr,mod->cLines[line]->src);
-#endif
+ /* one line can have more than one address : (for loops !)*/
+ if (line < mod->ncLines && line > 0 /*&&
+ ( !mod->cLines[line]->addr ||
+ mod->cLines[line]->level > level )*/ )
+ {
+ if ( mod->cLines[line]->addr != INT_MAX )
+ {
+ /* save double line information for exepoints */
+ exePoint *ep ;
+ ep = Safe_calloc(1,sizeof(exePoint));
+ ep->addr = mod->cLines[line]->addr ;
+ ep->line = line;
+ ep->block= mod->cLines[line]->block;
+ ep->level= mod->cLines[line]->level;
+ addSet(&mod->cfpoints,ep);
+ Dprintf(D_symtab, ("symtab: exe %s(%d:0x%x) %s",mod->c_name,
+ line+1,addr,mod->cLines[line]->src));
+ }
+ mod->cLines[line]->addr = addr;
+ mod->cLines[line]->block = block;
+ mod->cLines[line]->level = level;
+ Dprintf(D_symtab, ("symtab: ccc %s(%d:0x%x) %s",mod->c_name,
+ line+1,addr,mod->cLines[line]->src));