#include "gc.h" void listinit(void) { fmtinstall('A', Aconv); fmtinstall('P', Pconv); fmtinstall('S', Sconv); fmtinstall('N', Nconv); fmtinstall('B', Bconv); fmtinstall('D', Dconv); } int Pconv(void *o, int f1, int f2, int f3, int chr) { char str[STRINGSZ]; Prog *p; int a; USED(chr); p = *(Prog**)o; a = p->as; if(a == ADATA) sprint(str, " %A %D/%d,%D", a, &p->from, p->reg, &p->to); else if(p->reg == NREG) sprint(str, " %A %D,%D", a, &p->from, &p->to); else if(p->from.type != D_FREG) sprint(str, " %A %D,R%d,%D", a, &p->from, p->reg, &p->to); else sprint(str, " %A %D,F%d,%D", a, &p->from, p->reg, &p->to); strconv(str, f1, f2, f3); return sizeof(p); } int Aconv(void *o, int f1, int f2, int f3, int chr) { char *s; int a; USED(chr); a = *(int*)o; s = "???"; if(a >= AXXX && a <= AEND) s = anames[a]; strconv(s, f1, f2, f3); return sizeof(a); } int Dconv(void *o, int f1, int f2, int f3, int chr) { char str[STRINGSZ]; Adr *a; USED(chr); a = *(Adr**)o; switch(a->type) { default: sprint(str, "GOK-type(%d)", a->type); break; case D_NONE: str[0] = 0; if(a->name != D_NONE || a->reg != NREG || a->sym != S) sprint(str, "%N(R%d)(NONE)", a, a->reg); break; case D_CONST: if(a->reg != NREG) sprint(str, "$%N(R%d)", a, a->reg); else sprint(str, "$%N", a); break; case D_OREG: if(a->reg != NREG) sprint(str, "%N(R%d)", a, a->reg); else sprint(str, "%N", a); break; case D_REG: sprint(str, "R%d", a->reg); if(a->name != D_NONE || a->sym != S) sprint(str, "%N(R%d)(REG)", a, a->reg); break; case D_FREG: sprint(str, "F%d", a->reg); if(a->name != D_NONE || a->sym != S) sprint(str, "%N(R%d)(REG)", a, a->reg); break; case D_FCREG: sprint(str, "FCR%d", a->reg); if(a->name != D_NONE || a->sym != S) sprint(str, "%N(R%d)(REG)", a, a->reg); break; case D_LO: sprint(str, "LO", a->reg); if(a->name != D_NONE || a->sym != S) sprint(str, "%N(LO)(REG)", a, a->reg); break; case D_HI: sprint(str, "HI", a->reg); if(a->name != D_NONE || a->sym != S) sprint(str, "%N(HI)(REG)", a, a->reg); break; case D_BRANCH: sprint(str, "%ld(PC)", a->offset-pc); break; case D_FCONST: sprint(str, "$%f", a->dval); break; case D_SCONST: sprint(str, "$\"%S\"", a->sval); break; } strconv(str, f1, f2, f3); return sizeof(a); } int Sconv(void *o, int f1, int f2, int f3, int chr) { int i, c; char str[STRINGSZ], *p, *a; USED(chr); a = *(char**)o; p = str; for(i=0; i= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == ' ' || c == '%') { *p++ = c; continue; } *p++ = '\\'; switch(c) { case 0: *p++ = 'z'; continue; case '\\': case '"': *p++ = c; continue; case '\n': *p++ = 'n'; continue; case '\t': *p++ = 't'; continue; case '\r': *p++ = 'r'; continue; case '\f': *p++ = 'f'; continue; } *p++ = (c>>6) + '0'; *p++ = ((c>>3) & 7) + '0'; *p++ = (c & 7) + '0'; } *p = 0; strconv(str, f1, f2, f3); return sizeof(a); } int Nconv(void *o, int f1, int f2, int f3, int chr) { char str[STRINGSZ]; Adr *a; Sym *s; USED(chr); a = *(Adr**)o; s = a->sym; if(s == S) { sprint(str, "%ld", a->offset); goto out; } switch(a->name) { default: sprint(str, "GOK-name(%d)", a->name); break; case D_NONE: sprint(str, "%ld", a->offset); break; case D_EXTERN: sprint(str, "%s+%ld(SB)", s->name, a->offset); break; case D_STATIC: sprint(str, "%s<>+%ld(SB)", s->name, a->offset); break; case D_AUTO: sprint(str, "%s-%ld(SP)", s->name, -a->offset); break; case D_PARAM: sprint(str, "%s+%ld(FP)", s->name, a->offset); break; } out: strconv(str, f1, f2, f3); return sizeof(a); }