/* generate a test. set 'inv' to invert test. Stack entry is popped */ int gtst(int inv, int t) { int v, *p; v = vtop->r & VT_VALMASK; if (v == VT_CMP) { /* fast case : can jump directly since flags are set */ g(0x0f); t = psym((vtop->c.i - 16) ^ inv, t); } else if (v == VT_JMP || v == VT_JMPI) { /* && or || optimization */ if ((v & 1) == inv) { /* insert vtop->c jump list in t */ p = &vtop->c.i; while (*p != 0) p = (int *)(cur_text_section->data + *p); *p = t; t = vtop->c.i; } else { t = gjmp(t); gsym(vtop->c.i); } } else { if (is_float(vtop->type.t) || (vtop->type.t & VT_BTYPE) == VT_LLONG) { vpushi(0); gen_op(TOK_NE); } if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { /* constant jmp optimization */ if ((vtop->c.i != 0) != inv) t = gjmp(t); } else { v = gv(RC_INT); o(0x85); o(0xc0 + v * 9); g(0x0f); t = psym(0x85 ^ inv, t); } } vtop--; return t; }
static void mksym(SymTab *st) { PipeStage *s; Symbol *t; int i; for(s = stlist.next; s != &stlist; s = s->next){ s->invars = emalloc(-(-s->nvars & -VARBLOCK) * sizeof(Symbol *)); s->outvars = emalloc(-(-s->nvars & -VARBLOCK) * sizeof(Symbol *)); for(i = 0; i < s->nvars; i++){ t = s->vars[i]; if(bstest(s->kill, i) || bstest(s->live, i)) s->invars[i] = psym(st, t, s->sym->name, ""); if(bstest(s->kill, i) && bstest(s->gen, i)) s->outvars[i] = psym(st, t, s->sym->name, "_out"); else s->outvars[i] = s->invars[i]; } } }
/* * get the symbol table from an executable file, if it has one */ void execsyms(int fd) { Fhdr f; Sym *s; int32_t n; seek(fd, 0, 0); if (crackhdr(fd, &f) == 0) { error("Can't read header for %s", filename); return; } if (syminit(fd, &f) < 0) return; s = symbase(&n); nsym = 0; while(n--) psym(s++, 0); printsyms(symptr, nsym); }
/* generate a jump to a label */ int gjmp(int t) { return psym(0xe9, t); }