Commit 1222cc46 authored by Austin Clements's avatar Austin Clements

[dev.power64] 6g,9g: formatters for Prog and Addr details

The pretty printers for these make it hard to understand
what's actually in the fields of these structures.  These
"ugly printers" show exactly what's in each field, which can
be useful for understanding and debugging code.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/175780043
parent a11f2564
......@@ -338,6 +338,8 @@ enum
D_STATIC = (D_NONE+4),
D_AUTO = (D_NONE+5),
D_PARAM = (D_NONE+6),
D_LAST = (D_NONE+26),
};
/*
......
......@@ -865,6 +865,8 @@ enum
D_INDIR, /* additive */
D_LAST,
T_TYPE = 1<<0,
T_INDEX = 1<<1,
T_OFFSET = 1<<2,
......
......@@ -654,6 +654,8 @@ enum
D_CONST2 = D_INDIR+D_INDIR,
D_LAST,
T_TYPE = 1<<0,
T_INDEX = 1<<1,
T_OFFSET = 1<<2,
......
......@@ -497,6 +497,8 @@ enum
D_DCONST,
D_ADDR, // not used, use D_CONST with non-empty sym.
D_LAST,
/* reg names for 9g OREGISTER */
D_R0 = 0, // type is D_REG
D_F0 = D_R0+NREG, // type is D_FREG
......
......@@ -184,12 +184,14 @@ mkanames(char *dir, char *file)
continue;
p = lines.p[i] + 3;
if(xstrcmp(p, "LAST") == 0)
continue;
vadd(&dnames[n], p);
j++;
}
}
if(j>0){
bwritestr(&out, bprintf(&b, "char* dnames%c[] = {\n", ch));
bwritestr(&out, bprintf(&b, "char* dnames%c[D_LAST] = {\n", ch));
for(i=0; i<nelem(dnames); i++) {
if(dnames[i].len == 0)
continue;
......
......@@ -82,6 +82,19 @@ Pconv(Fmt *fp)
p = va_arg(fp->args, Prog*);
bigP = p;
if(fp->flags & FmtSharp) {
char *s = str;
s += sprint(s, "%.5lld (%L) %A", p->pc, p->lineno, p->as);
if(p->from.type != D_NONE)
s += sprint(s, " from={%#D}", &p->from);
if(p->reg)
s += sprint(s, " reg=%d", p->reg);
if(p->to.type != D_NONE)
s += sprint(s, " to={%#D}", &p->to);
return fmtstrcpy(fp, str);
}
switch(p->as) {
case ADATA:
sprint(str, "%.5lld (%L) %A %D/%d,%D",
......@@ -126,6 +139,31 @@ Dconv(Fmt *fp)
a = va_arg(fp->args, Addr*);
i = a->type;
if(fp->flags & FmtSharp) {
char *s = str;
s += sprint(s, "type=");
if(i == D_NONE) {
sprint(s, "NONE");
goto brk;
}
if(i >= D_INDIR) {
i -= D_INDIR;
s += sprint(s, "INDIR+");
}
if(i >= 0 && i < D_LAST && dnames6[i] != nil)
s += sprint(s, "%s ", dnames6[i]);
else
s += sprint(s, "%d ", i);
s += sprint(s, "offset=%ld etype=%E width=%d", a->offset, a->etype, a->width);
if(a->class != 0)
s += sprint(s, " class=%s", cnames9[a->class]);
if(a->sym != nil)
s += sprint(s, " sym=%s", a->sym->name);
if(a->type == D_BRANCH && a->u.branch != nil)
s += sprint(s, " branch=%.5lld", a->u.branch->pc);
goto brk;
}
if(fp->flags & FmtLong) {
if(i == D_CONST)
sprint(str, "$%lld-%lld", a->offset&0xffffffffLL, a->offset>>32);
......
......@@ -91,6 +91,21 @@ Pconv(Fmt *fp)
p = va_arg(fp->args, Prog*);
bigP = p;
a = p->as;
if(fp->flags & FmtSharp) {
s = str;
s += sprint(s, "%.5lld (%L) %A", p->pc, p->lineno, a);
if(p->from.type != D_NONE)
s += sprint(s, " from={%#D}", &p->from);
if(p->reg)
s += sprint(s, " reg=%d", p->reg);
if(p->from3.type != D_NONE)
s += sprint(s, " from3={%#D}", &p->from3);
if(p->to.type != D_NONE)
s += sprint(s, " to={%#D}", &p->to);
return fmtstrcpy(fp, str);
}
if(a == ADATA || a == AINIT || a == ADYNT)
sprint(str, "%.5lld (%L) %A %D/%d,%D", p->pc, p->lineno, a, &p->from, p->reg, &p->to);
else if(a == ATEXT) {
......@@ -153,6 +168,32 @@ Dconv(Fmt *fp)
a = va_arg(fp->args, Addr*);
if(fp->flags & FmtSharp) {
char *s = str;
if(a->type == D_NONE) {
sprint(s, "type=NONE");
goto ret;
}
if(a->type >= 0 && a->type < D_LAST && dnames9[a->type] != nil)
s += sprint(s, "type=%s ", dnames9[a->type]);
else
s += sprint(s, "type=%d ", a->type);
if(a->name >= 0 && a->name < D_LAST && dnames9[a->name] != nil)
s += sprint(s, "name=%s ", dnames9[a->name]);
else
s += sprint(s, "name=%d ", a->name);
s += sprint(s, "offset=%ld etype=%E width=%d", a->offset, a->etype, a->width);
if(a->class != 0)
s += sprint(s, " class=%s", cnames9[a->class]);
if(a->reg != NREG)
s += sprint(s, " reg=%d", a->reg);
if(a->sym != nil)
s += sprint(s, " sym=%s", a->sym->name);
if(a->type == D_BRANCH && a->u.branch != nil)
s += sprint(s, " branch=%.5lld", a->u.branch->pc);
goto ret;
}
if(fp->flags & FmtLong) {
if(a->type == D_CONST)
sprint(str, "$%d-%d", (int32)a->offset, (int32)(a->offset>>32));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment