#include "gc.h" void listinit(void) { fmtinstall('R', Rconv); fmtinstall('A', Aconv); fmtinstall('D', Dconv); fmtinstall('P', Pconv); fmtinstall('S', Sconv); fmtinstall('X', Xconv); fmtinstall('B', Bconv); } int Pconv(void *o, int f1, int f2, int f3, int chr) { char str[STRINGSZ], s[20]; Prog *p; USED(chr); p = *(Prog**)o; sprint(str, " %A %D,%D", p->as, &p->from, &p->to); if(p->from.field) { sprint(s, ",%d,%d", p->to.field, p->from.field); strcat(str, s); } strconv(str, f1, f2, f3); return sizeof(p); } int Aconv(void *o, int f1, int f2, int f3, int chr) { USED(chr); strconv(anames[*(int*)o], f1, f2, f3); return sizeof(int); } int Xconv(void *ao, int f1, int f2, int f3, int chr) { char str[20], s[10]; int i, *o; USED(chr); o = (int*)ao; str[0] = 0; i = o[0] & D_MASK; if(i != D_NONE) { sprint(str, "(%R.", i); i = o[1]; sprint(s, "%c*%c)", "WWWWLLLL"[i], "12481248"[i]); strcat(str, s); } strconv(str, f1, f2, f3); return 2*sizeof(int); } int Dconv(void *o, int f1, int f2, int f3, int chr) { char str[40], s[20]; Adr *a; int i, j; long d; USED(chr); a = *(Adr**)o; i = a->index; if(i != D_NONE) { a->index = D_NONE; d = a->displace; j = a->scale; a->displace = 0; switch(i & I_MASK) { default: sprint(str, "???%ld(%D%X)", d, a, i, j); break; case I_INDEX1: sprint(str, "%D%X", a, i, a->scale); break; case I_INDEX2: if(d) sprint(str, "%ld(%D)%X", d, a, i, j); else sprint(str, "(%D)%X", a, i, j); break; case I_INDEX3: if(d) sprint(str, "%ld(%D%X)", d, a, i, j); else sprint(str, "(%D%X)", a, i, j); break; } a->displace = d; a->index = i; goto out; } i = a->type; j = i & I_MASK; if(j) { a->type = i & D_MASK; d = a->offset; a->offset = 0; switch(j) { case I_INDINC: sprint(str, "(%D)+", a); break; case I_INDDEC: sprint(str, "-(%D)", a); break; case I_INDIR: if(a->type == D_CONST) sprint(str, "%ld", d); else if(d) sprint(str, "%ld(%D)", d, a); else sprint(str, "(%D)", a); break; case I_ADDR: a->offset = d; sprint(str, "$%D", a); break; } a->type = i; a->offset = d; goto out; } switch(i) { default: sprint(str, "%R", i); break; case D_NONE: str[0] = 0; break; case D_BRANCH: sprint(str, "%ld(PC)", a->offset-pc); break; case D_EXTERN: sprint(str, "%s+%ld(SB)", a->sym->name, a->offset); break; case D_STATIC: sprint(str, "%s<>+%ld(SB)", a->sym->name, a->offset); break; case D_AUTO: sprint(str, "%s-%ld(SP)", a->sym->name, -a->offset); break; case D_PARAM: sprint(str, "%s+%ld(FP)", a->sym->name, a->offset); break; case D_CONST: sprint(str, "$%ld", a->offset); break; case D_STACK: sprint(str, "TOS+%ld", a->offset); break; case D_FCONST: if(FPCHIP) sprint(str, "$%.8e", a->dval); else sprint(str, "$"); goto out; case D_SCONST: sprint(str, "$\"%S\"", a->sval); goto out; } if(a->displace) { sprint(s, "/%ld", a->displace); strcat(str, s); } out: strconv(str, f1, f2, f3); return sizeof(a); } int Rconv(void *o, int f1, int f2, int f3, int chr) { char str[20]; int r; USED(chr); r = *(int*)o; if(r >= D_R0 && r < D_R0+NREG) sprint(str, "R%d", r-D_R0); else if(r >= D_A0 && r < D_A0+NREG) sprint(str, "A%d", r-D_A0); else if(r >= D_F0 && r < D_F0+NREG) sprint(str, "F%d", r-D_F0); else switch(r) { default: sprint(str, "gok(%d)", r); break; case D_NONE: sprint(str, "NONE"); break; case D_TOS: sprint(str, "TOS"); break; case D_CCR: sprint(str, "CCR"); break; case D_SR: sprint(str, "SR"); break; case D_SFC: sprint(str, "SFC"); break; case D_DFC: sprint(str, "DFC"); break; case D_CACR: sprint(str, "CACR"); break; case D_USP: sprint(str, "USP"); break; case D_VBR: sprint(str, "VBR"); break; case D_CAAR: sprint(str, "CAAR"); break; case D_MSP: sprint(str, "MSP"); break; case D_ISP: sprint(str, "ISP"); break; case D_TREE: sprint(str, "TREE"); break; case D_FPCR: sprint(str, "FPCR"); break; case D_FPSR: sprint(str, "FPSR"); break; case D_FPIAR: sprint(str, "FPIAR"); break; case D_TC: sprint(str, "TC"); break; case D_ITT0: sprint(str, "ITT0"); break; case D_ITT1: sprint(str, "ITT1"); break; case D_DTT0: sprint(str, "DTT0"); break; case D_DTT1: sprint(str, "DTT1"); break; case D_MMUSR: sprint(str, "MMUSR"); break; case D_URP: sprint(str, "URP"); break; case D_SRP: sprint(str, "SRP"); break; } strconv(str, f1, f2, f3); return sizeof(r); } int Sconv(void *o, int f1, int f2, int f3, int chr) { int i, c; char str[30], *p, *s; USED(chr); s = *(char**)o; p = str; for(i=0; i>6) & 7) + '0'; *p++ = ((c>>3) & 7) + '0'; *p++ = ((c>>0) & 7) + '0'; } *p = 0; strconv(str, f1, f2, f3); return sizeof(s); }