/*-----------------------------------------------------------------*/ const char * format_opcode (const char *inst, const char *fmt, va_list ap) { struct dbuf_s dbuf; dbuf_init (&dbuf, INITIAL_INLINEASM); if (inst && *inst) { dbuf_append_str (&dbuf, inst); if (fmt && *fmt) { dbuf_append_char (&dbuf, '\t'); dbuf_tvprintf (&dbuf, fmt, ap); } } else { if (fmt && *fmt) { dbuf_tvprintf (&dbuf, fmt, ap); } } return dbuf_detach_c_str (&dbuf); }
int enum_symbols (FILE * fp, long size, int (*func) (const char *sym, void *param), void *param) { long end; struct dbuf_s buf; struct dbuf_s symname; assert (func != NULL); dbuf_init (&buf, 512); dbuf_init (&symname, 32); end = (size >= 0) ? ftell (fp) + size : -1; /* * Read in the object file. Look for lines that * begin with "S" and end with "D". These are * symbol table definitions. If we find one, see * if it is our symbol. Make sure we only read in * our object file and don't go into the next one. */ while (end < 0 || ftell (fp) < end) { const char *p; dbuf_set_length (&buf, 0); if (dbuf_getline (&buf, fp) == 0) break; p = dbuf_c_str (&buf); if ('T' == p[0]) break; /* * Skip everything that's not a symbol record. */ if ('S' == p[0] && ' ' == p[1]) { dbuf_set_length (&symname, 0); for (p += 2; *p && ' ' != *p; ++p) dbuf_append_char (&symname, *p); /* If it's an actual symbol, record it */ if (' ' == p[0] && 'D' == p[1]) if (func != NULL) if ((*func) (dbuf_c_str (&symname), NULL)) return 1; } } dbuf_destroy (&buf); dbuf_destroy (&symname); return 0; }
/*-----------------------------------------------------------------*/ static void printAllocInfoSeg (memmap * map, symbol * func, struct dbuf_s *oBuf) { symbol *sym; if (!map) return; if (!map->syms) return; for (sym = setFirstItem (map->syms); sym; sym = setNextItem (map->syms)) { if (sym->level == 0) continue; if (sym->localof != func) continue; dbuf_printf (oBuf, ";%-25s Allocated ", sym->name); /* if assigned to registers */ if (!sym->allocreq && sym->reqv) { int i; sym = OP_SYMBOL (sym->reqv); if (!sym->isspilt || sym->remat) { dbuf_append_str (oBuf, "to registers "); for (i = 0; i < 4 && sym->regs[i]; i++) dbuf_printf (oBuf, "%s ", port->getRegName (sym->regs[i])); dbuf_append_char (oBuf, '\n'); continue; } else { sym = sym->usl.spillLoc; } } /* if on stack */ if (sym->onStack) { dbuf_printf (oBuf, "to stack - offset %d\n", sym->stack); continue; } /* otherwise give rname */ dbuf_printf (oBuf, "with name '%s'\n", sym->rname); } }
/*-----------------------------------------------------------------*/ void printLine (lineNode * head, struct dbuf_s *oBuf) { iCode *last_ic = NULL; bool debug_iCode_tracking = (getenv ("DEBUG_ICODE_TRACKING") != NULL); while (head) { if (head->ic != last_ic) { last_ic = head->ic; if (debug_iCode_tracking) { if (head->ic) dbuf_printf (oBuf, "; block = %d, seq = %d\n", head->ic->block, head->ic->seq); else dbuf_append_str (oBuf, "; iCode lost\n"); } } /* don't indent comments & labels */ if (head->line && (head->isComment || head->isLabel)) { dbuf_printf (oBuf, "%s\n", head->line); } else { if (head->isInline && *head->line == '#') { /* comment out preprocessor directives in inline asm */ dbuf_append_char (oBuf, ';'); } dbuf_printf (oBuf, "\t%s\n", head->line); } head = head->next; } }
/*-----------------------------------------------------------------*/ static int printAllocInfoSeg (memmap * map, symbol * func, struct dbuf_s *oBuf) { symbol *sym; int flg = FALSE; if (!map || !map->syms) return 0; for (sym = setFirstItem (map->syms); sym; sym = setNextItem (map->syms)) { if (sym->level == 0) continue; if (sym->localof != func) continue; dbuf_printf (oBuf, ";%-25s Allocated ", sym->name); flg = TRUE; /* if assigned to registers */ if (!sym->allocreq && sym->reqv) { int i; sym = OP_SYMBOL (sym->reqv); if (!sym->isspilt || sym->remat) { dbuf_append_str (oBuf, "to registers "); for (i = 0; i < 4 && sym->regs[i]; i++) dbuf_printf (oBuf, "%s ", port->getRegName (sym->regs[i])); dbuf_append_char (oBuf, '\n'); continue; } else { sym = sym->usl.spillLoc; } } /* if on stack */ if (sym->onStack) { int stack_offset = 0; if (options.omitFramePtr) { if (SPEC_OCLS (sym->etype)->paged) stack_offset = func->xstack; else stack_offset = func->stack; } dbuf_printf (oBuf, "to stack - %s %+d\n", SYM_BP (sym), sym->stack - stack_offset); continue; } /* otherwise give rname */ dbuf_printf (oBuf, "with name '%s'\n", sym->rname); } return flg; }
int enum_symbols (FILE * fp, long size, int (*func) (const char *sym, void *param), void *param) { long end; struct dbuf_s buf; struct dbuf_s symname; assert (func != NULL); dbuf_init (&buf, 512); dbuf_init (&symname, 32); end = (size >= 0) ? ftell (fp) + size : -1; /* * Read in the object file. Look for lines that * begin with "S" and end with "D". These are * symbol table definitions. If we find one, see * if it is our symbol. Make sure we only read in * our object file and don't go into the next one. */ while (end < 0 || ftell (fp) < end) { const char *p; dbuf_set_length (&buf, 0); if (dbuf_getline (&buf, fp) == 0) break; p = dbuf_c_str (&buf); /* Skip whitespace */ while (isspace (*p)) p++; /* Skip local symbols or directives */ if ('.' == p[0]) continue; /* * Skip everything that's not a symbol. */ if (isalpha (*p) || '_' == *p) { bool found = false; dbuf_set_length (&symname, 0); while (isalnum (*p) || '_' == *p) dbuf_append_char (&symname, *p++); if (':' == *p) /* a label */ { if (':' == *++p) /* a global label */ found = true; } else /* no label */ { size_t i; /* Skip whitespace */ while (isspace (*p)) p++; for (found = false, i = 0; !found && i < sizeof(directives) / sizeof(symbol_t); i++) { if (0 == strncmp(p, directives[i].text, strlen(directives[i].text))) { switch (directives[i].subtype) { case stEQU: case stBYTE: case stWORD_BE: case stWORD_LE: case stLONG_BE: case stLONG_LE: case stBUFFER: case stTEXT: case stDS: case stDSIN: case stDSOUT: case stDSIO: case stDSROM: case stDSRAM: /* It's a symbol */ found = true; break; default: break; } } } } /* If it's an actual symbol, record it */ if (found) if (func != NULL) if ((*func) (dbuf_c_str (&symname), NULL)) return 1; } } dbuf_destroy (&buf); dbuf_destroy (&symname); return 0; }