1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:24:40 -07:00

5l: avoid fixed buffers in list

R=ken2
CC=golang-dev
https://golang.org/cl/2204045
This commit is contained in:
Russ Cox 2010-09-19 19:44:52 -04:00
parent b6ad32b183
commit 63623ba2d8

View File

@ -53,7 +53,6 @@ prasm(Prog *p)
int int
Pconv(Fmt *fp) Pconv(Fmt *fp)
{ {
char str[STRINGSZ], *s;
Prog *p; Prog *p;
int a; int a;
@ -62,42 +61,41 @@ Pconv(Fmt *fp)
a = p->as; a = p->as;
switch(a) { switch(a) {
default: default:
s = str; fmtprint(fp, "(%d)", p->line);
s += sprint(s, "(%d)", p->line);
if(p->reg == NREG) if(p->reg == NREG)
sprint(s, " %A%C %D,%D", fmtprint(fp, " %A%C %D,%D",
a, p->scond, &p->from, &p->to); a, p->scond, &p->from, &p->to);
else else
if(p->from.type != D_FREG) if(p->from.type != D_FREG)
sprint(s, " %A%C %D,R%d,%D", fmtprint(fp, " %A%C %D,R%d,%D",
a, p->scond, &p->from, p->reg, &p->to); a, p->scond, &p->from, p->reg, &p->to);
else else
sprint(s, " %A%C %D,F%d,%D", fmtprint(fp, " %A%C %D,F%d,%D",
a, p->scond, &p->from, p->reg, &p->to); a, p->scond, &p->from, p->reg, &p->to);
break; break;
case ASWPW: case ASWPW:
case ASWPBU: case ASWPBU:
sprint(str, "(%d) %A%C R%d,%D,%D", fmtprint(fp, "(%d) %A%C R%d,%D,%D",
p->line, a, p->scond, p->reg, &p->from, &p->to); p->line, a, p->scond, p->reg, &p->from, &p->to);
break; break;
case ADATA: case ADATA:
case AINIT: case AINIT:
case ADYNT: case ADYNT:
sprint(str, "(%d) %A%C %D/%d,%D", fmtprint(fp, "(%d) %A%C %D/%d,%D",
p->line, a, p->scond, &p->from, p->reg, &p->to); p->line, a, p->scond, &p->from, p->reg, &p->to);
break; break;
case AWORD: case AWORD:
sprint(str, "WORD %x", p->to.offset); fmtprint(fp, "WORD %x", p->to.offset);
break; break;
case ADWORD: case ADWORD:
sprint(str, "DWORD %x %x", p->from.offset, p->to.offset); fmtprint(fp, "DWORD %x %x", p->from.offset, p->to.offset);
break; break;
} }
return fmtstrcpy(fp, str); return 0;
} }
int int
@ -164,98 +162,98 @@ Dconv(Fmt *fp)
switch(a->type) { switch(a->type) {
default: default:
sprint(str, "GOK-type(%d)", a->type); snprint(str, sizeof str, "GOK-type(%d)", a->type);
break; break;
case D_NONE: case D_NONE:
str[0] = 0; str[0] = 0;
if(a->name != D_NONE || a->reg != NREG || a->sym != S) if(a->name != D_NONE || a->reg != NREG || a->sym != S)
sprint(str, "%N(R%d)(NONE)", a, a->reg); snprint(str, sizeof str, "%N(R%d)(NONE)", a, a->reg);
break; break;
case D_CONST: case D_CONST:
if(a->reg == NREG) if(a->reg == NREG)
sprint(str, "$%N", a); snprint(str, sizeof str, "$%N", a);
else else
sprint(str, "$%N(R%d)", a, a->reg); snprint(str, sizeof str, "$%N(R%d)", a, a->reg);
break; break;
case D_CONST2: case D_CONST2:
sprint(str, "$%d-%d", a->offset, a->offset2); snprint(str, sizeof str, "$%d-%d", a->offset, a->offset2);
break; break;
case D_SHIFT: case D_SHIFT:
v = a->offset; v = a->offset;
op = "<<>>->@>" + (((v>>5) & 3) << 1); op = "<<>>->@>" + (((v>>5) & 3) << 1);
if(v & (1<<4)) if(v & (1<<4))
sprint(str, "R%d%c%cR%d", v&15, op[0], op[1], (v>>8)&15); snprint(str, sizeof str, "R%d%c%cR%d", v&15, op[0], op[1], (v>>8)&15);
else else
sprint(str, "R%d%c%c%d", v&15, op[0], op[1], (v>>7)&31); snprint(str, sizeof str, "R%d%c%c%d", v&15, op[0], op[1], (v>>7)&31);
if(a->reg != NREG) if(a->reg != NREG)
sprint(str+strlen(str), "(R%d)", a->reg); seprint(str+strlen(str), str+sizeof str, "(R%d)", a->reg);
break; break;
case D_OCONST: case D_OCONST:
sprint(str, "$*$%N", a); snprint(str, sizeof str, "$*$%N", a);
if(a->reg != NREG) if(a->reg != NREG)
sprint(str, "%N(R%d)(CONST)", a, a->reg); snprint(str, sizeof str, "%N(R%d)(CONST)", a, a->reg);
break; break;
case D_OREG: case D_OREG:
if(a->reg != NREG) if(a->reg != NREG)
sprint(str, "%N(R%d)", a, a->reg); snprint(str, sizeof str, "%N(R%d)", a, a->reg);
else else
sprint(str, "%N", a); snprint(str, sizeof str, "%N", a);
break; break;
case D_REG: case D_REG:
sprint(str, "R%d", a->reg); snprint(str, sizeof str, "R%d", a->reg);
if(a->name != D_NONE || a->sym != S) if(a->name != D_NONE || a->sym != S)
sprint(str, "%N(R%d)(REG)", a, a->reg); snprint(str, sizeof str, "%N(R%d)(REG)", a, a->reg);
break; break;
case D_REGREG: case D_REGREG:
sprint(str, "(R%d,R%d)", a->reg, (int)a->offset); snprint(str, sizeof str, "(R%d,R%d)", a->reg, (int)a->offset);
if(a->name != D_NONE || a->sym != S) if(a->name != D_NONE || a->sym != S)
sprint(str, "%N(R%d)(REG)", a, a->reg); snprint(str, sizeof str, "%N(R%d)(REG)", a, a->reg);
break; break;
case D_FREG: case D_FREG:
sprint(str, "F%d", a->reg); snprint(str, sizeof str, "F%d", a->reg);
if(a->name != D_NONE || a->sym != S) if(a->name != D_NONE || a->sym != S)
sprint(str, "%N(R%d)(REG)", a, a->reg); snprint(str, sizeof str, "%N(R%d)(REG)", a, a->reg);
break; break;
case D_PSR: case D_PSR:
switch(a->reg) { switch(a->reg) {
case 0: case 0:
sprint(str, "CPSR"); snprint(str, sizeof str, "CPSR");
break; break;
case 1: case 1:
sprint(str, "SPSR"); snprint(str, sizeof str, "SPSR");
break; break;
default: default:
sprint(str, "PSR%d", a->reg); snprint(str, sizeof str, "PSR%d", a->reg);
break; break;
} }
if(a->name != D_NONE || a->sym != S) if(a->name != D_NONE || a->sym != S)
sprint(str, "%N(PSR%d)(REG)", a, a->reg); snprint(str, sizeof str, "%N(PSR%d)(REG)", a, a->reg);
break; break;
case D_FPCR: case D_FPCR:
switch(a->reg){ switch(a->reg){
case 0: case 0:
sprint(str, "FPSR"); snprint(str, sizeof str, "FPSR");
break; break;
case 1: case 1:
sprint(str, "FPCR"); snprint(str, sizeof str, "FPCR");
break; break;
default: default:
sprint(str, "FCR%d", a->reg); snprint(str, sizeof str, "FCR%d", a->reg);
break; break;
} }
if(a->name != D_NONE || a->sym != S) if(a->name != D_NONE || a->sym != S)
sprint(str, "%N(FCR%d)(REG)", a, a->reg); snprint(str, sizeof str, "%N(FCR%d)(REG)", a, a->reg);
break; break;
@ -263,22 +261,22 @@ Dconv(Fmt *fp)
if(curp->cond != P) { if(curp->cond != P) {
v = curp->cond->pc; v = curp->cond->pc;
if(a->sym != S) if(a->sym != S)
sprint(str, "%s+%.5lux(BRANCH)", a->sym->name, v); snprint(str, sizeof str, "%s+%.5lux(BRANCH)", a->sym->name, v);
else else
sprint(str, "%.5lux(BRANCH)", v); snprint(str, sizeof str, "%.5lux(BRANCH)", v);
} else } else
if(a->sym != S) if(a->sym != S)
sprint(str, "%s+%d(APC)", a->sym->name, a->offset); snprint(str, sizeof str, "%s+%d(APC)", a->sym->name, a->offset);
else else
sprint(str, "%d(APC)", a->offset); snprint(str, sizeof str, "%d(APC)", a->offset);
break; break;
case D_FCONST: case D_FCONST:
sprint(str, "$%e", ieeedtod(a->ieee)); snprint(str, sizeof str, "$%e", ieeedtod(a->ieee));
break; break;
case D_SCONST: case D_SCONST:
sprint(str, "$\"%S\"", a->sval); snprint(str, sizeof str, "$\"%S\"", a->sval);
break; break;
} }
return fmtstrcpy(fp, str); return fmtstrcpy(fp, str);