123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- /*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
- #include "l.h"
- void
- listinit(void)
- {
- fmtinstall('R', Rconv);
- fmtinstall('A', Aconv);
- fmtinstall('D', Dconv);
- fmtinstall('S', Sconv);
- fmtinstall('P', Pconv);
- }
- static Prog *bigP;
- int
- Pconv(Fmt *fp)
- {
- char str[STRINGSZ];
- Prog *p;
- p = va_arg(fp->args, Prog*);
- bigP = p;
- switch(p->as) {
- case ATEXT:
- if(p->from.scale) {
- sprint(str, "(%ld) %A %D,%d,%D",
- p->line, p->as, &p->from, p->from.scale, &p->to);
- break;
- }
- default:
- sprint(str, "(%ld) %A %D,%D",
- p->line, p->as, &p->from, &p->to);
- break;
- case ADATA:
- case AINIT:
- case ADYNT:
- sprint(str, "(%ld) %A %D/%d,%D",
- p->line, p->as, &p->from, p->from.scale, &p->to);
- break;
- }
- bigP = P;
- return fmtstrcpy(fp, str);
- }
- int
- Aconv(Fmt *fp)
- {
- int i;
- i = va_arg(fp->args, int);
- return fmtstrcpy(fp, anames[i]);
- }
- int
- Dconv(Fmt *fp)
- {
- char str[40], s[20];
- Adr *a;
- int i;
- a = va_arg(fp->args, Adr*);
- i = a->type;
- if(i >= D_INDIR) {
- if(a->offset)
- sprint(str, "%lld(%R)", a->offset, i-D_INDIR);
- else
- sprint(str, "(%R)", i-D_INDIR);
- goto brk;
- }
- switch(i) {
- default:
- if(a->offset)
- sprint(str, "$%lld,%R", a->offset, i);
- else
- sprint(str, "%R", i);
- break;
- case D_NONE:
- str[0] = 0;
- break;
- case D_BRANCH:
- if(bigP != P && bigP->pcond != P)
- if(a->sym != S)
- sprint(str, "%llux+%s", bigP->pcond->pc,
- a->sym->name);
- else
- sprint(str, "%llux", bigP->pcond->pc);
- else
- sprint(str, "%lld(PC)", a->offset);
- break;
- case D_EXTERN:
- sprint(str, "%s+%lld(SB)", a->sym->name, a->offset);
- break;
- case D_STATIC:
- sprint(str, "%s<%d>+%lld(SB)", a->sym->name,
- a->sym->version, a->offset);
- break;
- case D_AUTO:
- sprint(str, "%s+%lld(SP)", a->sym->name, a->offset);
- break;
- case D_PARAM:
- if(a->sym)
- sprint(str, "%s+%lld(%s)", a->sym->name, a->offset, paramspace);
- else
- sprint(str, "%lld(%s)", a->offset, paramspace);
- break;
- case D_CONST:
- sprint(str, "$%lld", a->offset);
- break;
- case D_FCONST:
- sprint(str, "$(%.8lux,%.8lux)", a->ieee.h, a->ieee.l);
- break;
- case D_SCONST:
- sprint(str, "$\"%S\"", a->scon);
- break;
- case D_ADDR:
- a->type = a->index;
- a->index = D_NONE;
- sprint(str, "$%D", a);
- a->index = a->type;
- a->type = D_ADDR;
- goto conv;
- }
- brk:
- if(a->index != D_NONE) {
- sprint(s, "(%R*%d)", a->index, a->scale);
- strcat(str, s);
- }
- conv:
- return fmtstrcpy(fp, str);
- }
- char* regstr[] =
- {
- "AL", /* [D_AL] */
- "CL",
- "DL",
- "BL",
- "SPB",
- "BPB",
- "SIB",
- "DIB",
- "R8B",
- "R9B",
- "R10B",
- "R11B",
- "R12B",
- "R13B",
- "R14B",
- "R15B",
- "AX", /* [D_AX] */
- "CX",
- "DX",
- "BX",
- "SP",
- "BP",
- "SI",
- "DI",
- "R8",
- "R9",
- "R10",
- "R11",
- "R12",
- "R13",
- "R14",
- "R15",
- "AH",
- "CH",
- "DH",
- "BH",
- "F0", /* [D_F0] */
- "F1",
- "F2",
- "F3",
- "F4",
- "F5",
- "F6",
- "F7",
- "M0",
- "M1",
- "M2",
- "M3",
- "M4",
- "M5",
- "M6",
- "M7",
- "X0",
- "X1",
- "X2",
- "X3",
- "X4",
- "X5",
- "X6",
- "X7",
- "X8",
- "X9",
- "X10",
- "X11",
- "X12",
- "X13",
- "X14",
- "X15",
- "CS", /* [D_CS] */
- "SS",
- "DS",
- "ES",
- "FS",
- "GS",
- "GDTR", /* [D_GDTR] */
- "IDTR", /* [D_IDTR] */
- "LDTR", /* [D_LDTR] */
- "MSW", /* [D_MSW] */
- "TASK", /* [D_TASK] */
- "CR0", /* [D_CR] */
- "CR1",
- "CR2",
- "CR3",
- "CR4",
- "CR5",
- "CR6",
- "CR7",
- "CR8",
- "CR9",
- "CR10",
- "CR11",
- "CR12",
- "CR13",
- "CR14",
- "CR15",
- "DR0", /* [D_DR] */
- "DR1",
- "DR2",
- "DR3",
- "DR4",
- "DR5",
- "DR6",
- "DR7",
- "TR0", /* [D_TR] */
- "TR1",
- "TR2",
- "TR3",
- "TR4",
- "TR5",
- "TR6",
- "TR7",
- "NONE", /* [D_NONE] */
- };
- int
- Rconv(Fmt *fp)
- {
- char str[20];
- int r;
- r = va_arg(fp->args, int);
- if(r >= D_AL && r <= D_NONE)
- sprint(str, "%s", regstr[r-D_AL]);
- else
- sprint(str, "gok(%d)", r);
- return fmtstrcpy(fp, str);
- }
- int
- Sconv(Fmt *fp)
- {
- int i, c;
- char str[30], *p, *a;
- a = va_arg(fp->args, char*);
- p = str;
- for(i=0; i<sizeof(double); i++) {
- c = a[i] & 0xff;
- if(c >= 'a' && c <= 'z' ||
- c >= 'A' && c <= 'Z' ||
- c >= '0' && c <= '9') {
- *p++ = c;
- continue;
- }
- *p++ = '\\';
- switch(c) {
- default:
- if(c < 040 || c >= 0177)
- break; /* not portable */
- p[-1] = c;
- continue;
- case 0:
- *p++ = 'z';
- continue;
- case '\\':
- case '"':
- *p++ = c;
- continue;
- case '\n':
- *p++ = 'n';
- continue;
- case '\t':
- *p++ = 't';
- continue;
- }
- *p++ = (c>>6) + '0';
- *p++ = ((c>>3) & 7) + '0';
- *p++ = (c & 7) + '0';
- }
- *p = 0;
- return fmtstrcpy(fp, str);
- }
- void
- diag(char *fmt, ...)
- {
- char buf[STRINGSZ], *tn;
- va_list arg;
- tn = "??none??";
- if(curtext != P && curtext->from.sym != S)
- tn = curtext->from.sym->name;
- va_start(arg, fmt);
- vseprint(buf, buf+sizeof(buf), fmt, arg);
- va_end(arg);
- print("%s: %s\n", tn, buf);
- nerrors++;
- if(nerrors > 20) {
- print("too many errors\n");
- errorexit();
- }
- }
|