summaryrefslogtreecommitdiff
path: root/src/cmd/5c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/5c')
-rw-r--r--src/cmd/5c/gc.h83
-rw-r--r--src/cmd/5c/list.c303
-rw-r--r--src/cmd/5c/peep.c44
-rw-r--r--src/cmd/5c/reg.c20
-rw-r--r--src/cmd/5c/swt.c285
-rw-r--r--src/cmd/5c/txt.c44
6 files changed, 79 insertions, 700 deletions
diff --git a/src/cmd/5c/gc.h b/src/cmd/5c/gc.h
index 084da7e6a..40d3a2b07 100644
--- a/src/cmd/5c/gc.h
+++ b/src/cmd/5c/gc.h
@@ -46,46 +46,19 @@
#define SZ_DOUBLE 8
#define FNX 100
-typedef struct Adr Adr;
-typedef struct Prog Prog;
typedef struct Case Case;
typedef struct C1 C1;
typedef struct Multab Multab;
typedef struct Hintab Hintab;
-typedef struct Var Var;
typedef struct Reg Reg;
typedef struct Rgn Rgn;
#define R0ISZERO 0
-struct Adr
-{
- int32 offset;
- int32 offset2;
- double dval;
- char sval[NSNAME];
- Ieee ieee;
-
- Sym* sym;
- char type;
- uchar reg;
- char name;
- char etype;
-};
-#define A ((Adr*)0)
+#define A ((Addr*)0)
#define INDEXED 9
-struct Prog
-{
- Adr from;
- Adr to;
- Prog* link;
- int32 lineno;
- char as;
- uchar reg;
- uchar scond;
-};
#define P ((Prog*)0)
struct Case
@@ -116,14 +89,6 @@ struct Hintab
char hint[10];
};
-struct Var
-{
- int32 offset;
- Sym* sym;
- char name;
- char etype;
-};
-
struct Reg
{
int32 pc;
@@ -174,7 +139,6 @@ EXTERN Node fconstnode;
EXTERN int32 continpc;
EXTERN int32 curarg;
EXTERN int32 cursafe;
-EXTERN Prog* firstp;
EXTERN int32 isbigendian;
EXTERN Prog* lastp;
EXTERN int32 maxargsafe;
@@ -230,7 +194,6 @@ EXTERN Reg* firstr;
EXTERN Reg* lastr;
EXTERN Reg zreg;
EXTERN Reg* freer;
-EXTERN Var var[NVAR];
EXTERN int32* idom;
EXTERN Reg** rpo2r;
EXTERN int32 maxnr;
@@ -285,7 +248,7 @@ void regaalloc(Node*, Node*);
void regind(Node*, Node*);
void gprep(Node*, Node*);
void raddr(Node*, Prog*);
-void naddr(Node*, Adr*);
+void naddr(Node*, Addr*);
void gmovm(Node*, Node*, int);
void gmove(Node*, Node*);
void gmover(Node*, Node*);
@@ -314,19 +277,11 @@ int mulcon(Node*, Node*);
Multab* mulcon0(int32);
void nullwarn(Node*, Node*);
void outcode(void);
-void ieeedtod(Ieee*, double);
/*
* list
*/
void listinit(void);
-int Pconv(Fmt*);
-int Aconv(Fmt*);
-int Dconv(Fmt*);
-int Sconv(Fmt*);
-int Nconv(Fmt*);
-int Bconv(Fmt*);
-int Rconv(Fmt*);
/*
* reg.c
@@ -335,7 +290,7 @@ Reg* rega(void);
int rcmp(const void*, const void*);
void regopt(Prog*);
void addmove(Reg*, int, int, int);
-Bits mkvar(Adr*, int);
+Bits mkvar(Addr*, int);
void prop(Reg*, Bits, Bits);
void loopit(Reg*, int32);
void synch(Reg*, Bits);
@@ -343,7 +298,7 @@ uint32 allreg(uint32, Rgn*);
void paint1(Reg*, int);
uint32 paint2(Reg*, int);
void paint3(Reg*, int, int32, int);
-void addreg(Adr*, int);
+void addreg(Addr*, int);
/*
* peep.c
@@ -352,21 +307,21 @@ void peep(void);
void excise(Reg*);
Reg* uniqp(Reg*);
Reg* uniqs(Reg*);
-int regtyp(Adr*);
-int regzer(Adr*);
-int anyvar(Adr*);
+int regtyp(Addr*);
+int regzer(Addr*);
+int anyvar(Addr*);
int subprop(Reg*);
int copyprop(Reg*);
int shiftprop(Reg*);
-void constprop(Adr*, Adr*, Reg*);
-int copy1(Adr*, Adr*, Reg*, int);
-int copyu(Prog*, Adr*, Adr*);
+void constprop(Addr*, Addr*, Reg*);
+int copy1(Addr*, Addr*, Reg*, int);
+int copyu(Prog*, Addr*, Addr*);
-int copyas(Adr*, Adr*);
-int copyau(Adr*, Adr*);
-int copyau1(Prog*, Adr*);
-int copysub(Adr*, Adr*, Adr*, int);
-int copysub1(Prog*, Adr*, Adr*, int);
+int copyas(Addr*, Addr*);
+int copyau(Addr*, Addr*);
+int copyau1(Prog*, Addr*);
+int copysub(Addr*, Addr*, Addr*, int);
+int copysub1(Prog*, Addr*, Addr*, int);
int32 RtoB(int);
int32 FtoB(int);
@@ -377,11 +332,3 @@ void predicate(void);
int isbranch(Prog *);
int predicable(Prog *p);
int modifiescpsr(Prog *p);
-
-#pragma varargck type "A" int
-#pragma varargck type "B" Bits
-#pragma varargck type "D" Adr*
-#pragma varargck type "N" Adr*
-#pragma varargck type "R" Adr*
-#pragma varargck type "P" Prog*
-#pragma varargck type "S" char*
diff --git a/src/cmd/5c/list.c b/src/cmd/5c/list.c
index 30b88400f..98da424de 100644
--- a/src/cmd/5c/list.c
+++ b/src/cmd/5c/list.c
@@ -35,306 +35,5 @@
void
listinit(void)
{
-
- fmtinstall('A', Aconv);
- fmtinstall('P', Pconv);
- fmtinstall('S', Sconv);
- fmtinstall('N', Nconv);
- fmtinstall('B', Bconv);
- fmtinstall('D', Dconv);
- fmtinstall('R', Rconv);
-}
-
-int
-Bconv(Fmt *fp)
-{
- char str[STRINGSZ], ss[STRINGSZ], *s;
- Bits bits;
- int i;
-
- str[0] = 0;
- bits = va_arg(fp->args, Bits);
- while(bany(&bits)) {
- i = bnum(bits);
- if(str[0])
- strcat(str, " ");
- if(var[i].sym == S) {
- sprint(ss, "$%d", var[i].offset);
- s = ss;
- } else
- s = var[i].sym->name;
- if(strlen(str) + strlen(s) + 1 >= STRINGSZ)
- break;
- strcat(str, s);
- bits.b[i/32] &= ~(1L << (i%32));
- }
- return fmtstrcpy(fp, str);
-}
-
-char *extra [] = {
- ".EQ", ".NE", ".CS", ".CC",
- ".MI", ".PL", ".VS", ".VC",
- ".HI", ".LS", ".GE", ".LT",
- ".GT", ".LE", "", ".NV",
-};
-
-int
-Pconv(Fmt *fp)
-{
- char str[STRINGSZ], sc[20];
- Prog *p;
- int a, s;
-
- p = va_arg(fp->args, Prog*);
- a = p->as;
- s = p->scond;
- strcpy(sc, extra[s & C_SCOND]);
- if(s & C_SBIT)
- strcat(sc, ".S");
- if(s & C_PBIT)
- strcat(sc, ".P");
- if(s & C_WBIT)
- strcat(sc, ".W");
- if(s & C_UBIT) /* ambiguous with FBIT */
- strcat(sc, ".U");
- if(a == AMOVM) {
- if(p->from.type == D_CONST)
- sprint(str, " %A%s %R,%D", a, sc, &p->from, &p->to);
- else
- if(p->to.type == D_CONST)
- sprint(str, " %A%s %D,%R", a, sc, &p->from, &p->to);
- else
- sprint(str, " %A%s %D,%D", a, sc, &p->from, &p->to);
- } else
- if(a == ADATA)
- sprint(str, " %A %D/%d,%D", a, &p->from, p->reg, &p->to);
- else
- if(p->as == ATEXT)
- sprint(str, " %A %D,%d,%D", a, &p->from, p->reg, &p->to);
- else
- if(p->reg == NREG)
- sprint(str, " %A%s %D,%D", a, sc, &p->from, &p->to);
- else
- if(p->from.type != D_FREG)
- sprint(str, " %A%s %D,R%d,%D", a, sc, &p->from, p->reg, &p->to);
- else
- sprint(str, " %A%s %D,F%d,%D", a, sc, &p->from, p->reg, &p->to);
- return fmtstrcpy(fp, str);
-}
-
-int
-Aconv(Fmt *fp)
-{
- char *s;
- int a;
-
- a = va_arg(fp->args, int);
- s = "???";
- if(a >= AXXX && a < ALAST)
- s = anames[a];
- return fmtstrcpy(fp, s);
-}
-
-int
-Dconv(Fmt *fp)
-{
- char str[STRINGSZ];
- Adr *a;
- const char *op;
- int v;
-
- a = va_arg(fp->args, Adr*);
- 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_CONST2:
- sprint(str, "$%d-%d", a->offset, a->offset2);
- break;
-
- case D_SHIFT:
- v = a->offset;
- op = &"<<>>->@>"[(((v>>5) & 3) << 1)];
- if(v & (1<<4))
- sprint(str, "R%d%c%cR%d", v&15, op[0], op[1], (v>>8)&15);
- else
- sprint(str, "R%d%c%c%d", v&15, op[0], op[1], (v>>7)&31);
- if(a->reg != NREG)
- sprint(str+strlen(str), "(R%d)", a->reg);
- 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_PSR:
- sprint(str, "PSR");
- if(a->name != D_NONE || a->sym != S)
- sprint(str, "%N(PSR)(REG)", a);
- break;
-
- case D_BRANCH:
- sprint(str, "%d(PC)", a->offset-pc);
- break;
-
- case D_FCONST:
- sprint(str, "$%.17e", a->dval);
- break;
-
- case D_SCONST:
- sprint(str, "$\"%S\"", a->sval);
- break;
- }
- return fmtstrcpy(fp, str);
-}
-
-int
-Rconv(Fmt *fp)
-{
- char str[STRINGSZ];
- Adr *a;
- int i, v;
-
- a = va_arg(fp->args, Adr*);
- sprint(str, "GOK-reglist");
- switch(a->type) {
- case D_CONST:
- case D_CONST2:
- if(a->reg != NREG)
- break;
- if(a->sym != S)
- break;
- v = a->offset;
- strcpy(str, "");
- for(i=0; i<NREG; i++) {
- if(v & (1<<i)) {
- if(str[0] == 0)
- strcat(str, "[R");
- else
- strcat(str, ",R");
- sprint(strchr(str, 0), "%d", i);
- }
- }
- strcat(str, "]");
- }
- return fmtstrcpy(fp, str);
-}
-
-int
-Sconv(Fmt *fp)
-{
- int i, c;
- char str[STRINGSZ], *p, *a;
-
- a = va_arg(fp->args, char*);
- p = str;
- for(i=0; i<NSNAME; i++) {
- c = a[i] & 0xff;
- if(c >= '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;
- return fmtstrcpy(fp, str);
-}
-
-int
-Nconv(Fmt *fp)
-{
- char str[STRINGSZ];
- Adr *a;
- Sym *s;
-
- a = va_arg(fp->args, Adr*);
- s = a->sym;
- if(s == S) {
- sprint(str, "%d", a->offset);
- goto out;
- }
- switch(a->name) {
- default:
- sprint(str, "GOK-name(%d)", a->name);
- break;
-
- case D_NONE:
- sprint(str, "%d", a->offset);
- break;
-
- case D_EXTERN:
- sprint(str, "%s+%d(SB)", s->name, a->offset);
- break;
-
- case D_STATIC:
- sprint(str, "%s<>+%d(SB)", s->name, a->offset);
- break;
-
- case D_AUTO:
- sprint(str, "%s-%d(SP)", s->name, -a->offset);
- break;
-
- case D_PARAM:
- sprint(str, "%s+%d(FP)", s->name, a->offset);
- break;
- }
-out:
- return fmtstrcpy(fp, str);
+ listinit5();
}
diff --git a/src/cmd/5c/peep.c b/src/cmd/5c/peep.c
index 22328c18c..143400a63 100644
--- a/src/cmd/5c/peep.c
+++ b/src/cmd/5c/peep.c
@@ -31,7 +31,7 @@
#include "gc.h"
-int xtramodes(Reg*, Adr*);
+int xtramodes(Reg*, Addr*);
void
peep(void)
@@ -281,7 +281,7 @@ uniqs(Reg *r)
}
int
-regtyp(Adr *a)
+regtyp(Addr *a)
{
if(a->type == D_REG)
@@ -309,7 +309,7 @@ int
subprop(Reg *r0)
{
Prog *p;
- Adr *v1, *v2;
+ Addr *v1, *v2;
Reg *r;
int t;
@@ -427,7 +427,7 @@ int
copyprop(Reg *r0)
{
Prog *p;
- Adr *v1, *v2;
+ Addr *v1, *v2;
Reg *r;
p = r0->prog;
@@ -441,7 +441,7 @@ copyprop(Reg *r0)
}
int
-copy1(Adr *v1, Adr *v2, Reg *r, int f)
+copy1(Addr *v1, Addr *v2, Reg *r, int f)
{
int t;
Prog *p;
@@ -525,7 +525,7 @@ copy1(Adr *v1, Adr *v2, Reg *r, int f)
* The v1->v2 should be eliminated by copy propagation.
*/
void
-constprop(Adr *c1, Adr *v1, Reg *r)
+constprop(Addr *c1, Addr *v1, Reg *r)
{
Prog *p;
@@ -574,7 +574,7 @@ shiftprop(Reg *r)
Reg *r1;
Prog *p, *p1, *p2;
int n, o;
- Adr a;
+ Addr a;
p = r->prog;
if(p->to.type != D_REG)
@@ -710,7 +710,7 @@ shiftprop(Reg *r)
}
Reg*
-findpre(Reg *r, Adr *v)
+findpre(Reg *r, Addr *v)
{
Reg *r1;
@@ -730,7 +730,7 @@ findpre(Reg *r, Adr *v)
}
Reg*
-findinc(Reg *r, Reg *r2, Adr *v)
+findinc(Reg *r, Reg *r2, Addr *v)
{
Reg *r1;
Prog *p;
@@ -758,7 +758,7 @@ findinc(Reg *r, Reg *r2, Adr *v)
int
nochange(Reg *r, Reg *r2, Prog *p)
{
- Adr a[3];
+ Addr a[3];
int i, n;
if(r == r2)
@@ -788,7 +788,7 @@ nochange(Reg *r, Reg *r2, Prog *p)
}
int
-findu1(Reg *r, Adr *v)
+findu1(Reg *r, Addr *v)
{
for(; r != R; r = r->s1) {
if(r->active)
@@ -810,7 +810,7 @@ findu1(Reg *r, Adr *v)
}
int
-finduse(Reg *r, Adr *v)
+finduse(Reg *r, Addr *v)
{
Reg *r1;
@@ -820,11 +820,11 @@ finduse(Reg *r, Adr *v)
}
int
-xtramodes(Reg *r, Adr *a)
+xtramodes(Reg *r, Addr *a)
{
Reg *r1, *r2, *r3;
Prog *p, *p1;
- Adr v;
+ Addr v;
p = r->prog;
if((p->as == AMOVB || p->as == AMOVBS) && p->from.type == D_OREG) /* byte load */
@@ -911,7 +911,7 @@ xtramodes(Reg *r, Adr *a)
* 0 otherwise (not touched)
*/
int
-copyu(Prog *p, Adr *v, Adr *s)
+copyu(Prog *p, Addr *v, Addr *s)
{
switch(p->as) {
@@ -1106,7 +1106,7 @@ copyu(Prog *p, Adr *v, Adr *s)
if(v->type == D_REG) {
if(v->reg <= REGEXT && v->reg > exregoffset)
return 2;
- if(v->reg == (uchar)REGARG)
+ if(v->reg == REGARG)
return 2;
}
if(v->type == D_FREG)
@@ -1124,7 +1124,7 @@ copyu(Prog *p, Adr *v, Adr *s)
case ATEXT: /* funny */
if(v->type == D_REG)
- if(v->reg == (uchar)REGARG)
+ if(v->reg == REGARG)
return 3;
return 0;
}
@@ -1175,7 +1175,7 @@ a2type(Prog *p)
* semantics
*/
int
-copyas(Adr *a, Adr *v)
+copyas(Addr *a, Addr *v)
{
if(regtyp(v)) {
@@ -1197,7 +1197,7 @@ copyas(Adr *a, Adr *v)
* either direct or indirect
*/
int
-copyau(Adr *a, Adr *v)
+copyau(Addr *a, Addr *v)
{
if(copyas(a, v))
@@ -1217,7 +1217,7 @@ copyau(Adr *a, Adr *v)
}
int
-copyau1(Prog *p, Adr *v)
+copyau1(Prog *p, Addr *v)
{
if(regtyp(v)) {
@@ -1236,7 +1236,7 @@ copyau1(Prog *p, Adr *v)
* return failure to substitute
*/
int
-copysub(Adr *a, Adr *v, Adr *s, int f)
+copysub(Addr *a, Addr *v, Addr *s, int f)
{
if(f)
@@ -1253,7 +1253,7 @@ copysub(Adr *a, Adr *v, Adr *s, int f)
}
int
-copysub1(Prog *p1, Adr *v, Adr *s, int f)
+copysub1(Prog *p1, Addr *v, Addr *s, int f)
{
if(f)
diff --git a/src/cmd/5c/reg.c b/src/cmd/5c/reg.c
index 3d67872b4..b9ac21abd 100644
--- a/src/cmd/5c/reg.c
+++ b/src/cmd/5c/reg.c
@@ -480,8 +480,10 @@ brk:
r1 = 0; /* set */
for(r = firstr; r != R; r = r->link) {
p = r->prog;
- if(p->to.type == D_BRANCH)
+ if(p->to.type == D_BRANCH) {
p->to.offset = r->s2->pc;
+ p->to.u.branch = r->s2->prog;
+ }
r1 = r;
}
@@ -535,7 +537,7 @@ void
addmove(Reg *r, int bn, int rn, int f)
{
Prog *p, *p1;
- Adr *a;
+ Addr *a;
Var *v;
p1 = alloc(sizeof(*p1));
@@ -554,7 +556,7 @@ addmove(Reg *r, int bn, int rn, int f)
a->offset = v->offset;
a->etype = v->etype;
a->type = D_OREG;
- if(a->etype == TARRAY || a->sym == S)
+ if(a->etype == TARRAY || a->sym == nil)
a->type = D_CONST;
p1->as = AMOVW;
@@ -592,13 +594,13 @@ addmove(Reg *r, int bn, int rn, int f)
}
Bits
-mkvar(Adr *a, int docon)
+mkvar(Addr *a, int docon)
{
Var *v;
int i, t, n, et, z;
int32 o;
Bits bit;
- Sym *s;
+ LSym *s;
t = a->type;
if(t == D_REG && a->reg != NREG)
@@ -608,13 +610,13 @@ mkvar(Adr *a, int docon)
s = a->sym;
o = a->offset;
et = a->etype;
- if(s == S) {
+ if(s == nil) {
if(t != D_CONST || !docon || a->reg != NREG)
goto none;
et = TLONG;
}
if(t == D_CONST) {
- if(s == S && sval(o))
+ if(s == nil && sval(o))
goto none;
}
@@ -656,7 +658,7 @@ out:
for(z=0; z<BITS; z++)
addrs.b[z] |= bit.b[z];
if(t == D_CONST) {
- if(s == S) {
+ if(s == nil) {
for(z=0; z<BITS; z++)
consts.b[z] |= bit.b[z];
return bit;
@@ -1135,7 +1137,7 @@ paint3(Reg *r, int bn, int32 rb, int rn)
}
void
-addreg(Adr *a, int rn)
+addreg(Addr *a, int rn)
{
a->sym = 0;
diff --git a/src/cmd/5c/swt.c b/src/cmd/5c/swt.c
index 0f0c457f8..fd81a4e68 100644
--- a/src/cmd/5c/swt.c
+++ b/src/cmd/5c/swt.c
@@ -206,7 +206,7 @@ outstring(char *s, int32 n)
p->from.offset += nstring - NSNAME;
p->reg = NSNAME;
p->to.type = D_SCONST;
- memmove(p->to.sval, string, NSNAME);
+ memmove(p->to.u.sval, string, NSNAME);
mnstring = 0;
}
n--;
@@ -321,7 +321,7 @@ sextern(Sym *s, Node *a, int32 o, int32 w)
p->from.offset += o+e;
p->reg = lw;
p->to.type = D_SCONST;
- memmove(p->to.sval, a->cstring+e, lw);
+ memmove(p->to.u.sval, a->cstring+e, lw);
}
}
@@ -351,48 +351,10 @@ gextern(Sym *s, Node *a, int32 o, int32 w)
p->to.type = D_CONST;
}
-void zname(Biobuf*, Sym*, int);
-char* zaddr(char*, Adr*, int);
-void zwrite(Biobuf*, Prog*, int, int);
-void outhist(Biobuf*);
-
-void
-zwrite(Biobuf *b, Prog *p, int sf, int st)
-{
- char bf[100], *bp;
-
- bf[0] = p->as;
- bf[1] = p->scond;
- bf[2] = p->reg;
- bf[3] = p->lineno;
- bf[4] = p->lineno>>8;
- bf[5] = p->lineno>>16;
- bf[6] = p->lineno>>24;
- bp = zaddr(bf+7, &p->from, sf);
- bp = zaddr(bp, &p->to, st);
- Bwrite(b, bf, bp-bf);
-}
-
void
outcode(void)
{
- struct { Sym *sym; short type; } h[NSYM];
- Prog *p;
- Sym *s;
- int sf, st, t, sym;
-
- if(debug['S']) {
- for(p = firstp; p != P; p = p->link)
- if(p->as != ADATA && p->as != AGLOBL)
- pc--;
- for(p = firstp; p != P; p = p->link) {
- print("%P\n", p);
- if(p->as != ADATA && p->as != AGLOBL)
- pc++;
- }
- }
-
- Bprint(&outbuf, "go object %s %s %s\n", getgoos(), thestring, getgoversion());
+ Bprint(&outbuf, "go object %s %s %s\n", getgoos(), getgoarch(), getgoversion());
if(pragcgobuf.to > pragcgobuf.start) {
Bprint(&outbuf, "\n");
Bprint(&outbuf, "$$ // exports\n\n");
@@ -403,249 +365,10 @@ outcode(void)
}
Bprint(&outbuf, "!\n");
- outhist(&outbuf);
- for(sym=0; sym<NSYM; sym++) {
- h[sym].sym = S;
- h[sym].type = 0;
- }
- sym = 1;
- for(p = firstp; p != P; p = p->link) {
- jackpot:
- sf = 0;
- s = p->from.sym;
- while(s != S) {
- sf = s->sym;
- if(sf < 0 || sf >= NSYM)
- sf = 0;
- t = p->from.name;
- if(h[sf].type == t)
- if(h[sf].sym == s)
- break;
- s->sym = sym;
- zname(&outbuf, s, t);
- h[sym].sym = s;
- h[sym].type = t;
- sf = sym;
- sym++;
- if(sym >= NSYM)
- sym = 1;
- break;
- }
- st = 0;
- s = p->to.sym;
- while(s != S) {
- st = s->sym;
- if(st < 0 || st >= NSYM)
- st = 0;
- t = p->to.name;
- if(h[st].type == t)
- if(h[st].sym == s)
- break;
- s->sym = sym;
- zname(&outbuf, s, t);
- h[sym].sym = s;
- h[sym].type = t;
- st = sym;
- sym++;
- if(sym >= NSYM)
- sym = 1;
- if(st == sf)
- goto jackpot;
- break;
- }
- zwrite(&outbuf, p, sf, st);
- }
- firstp = P;
+ writeobj(ctxt, &outbuf);
lastp = P;
}
-void
-outhist(Biobuf *b)
-{
- Hist *h;
- char *p, *q, *op, c;
- Prog pg;
- int n;
- char *tofree;
- static int first = 1;
- static char *goroot, *goroot_final;
-
- if(first) {
- // Decide whether we need to rewrite paths from $GOROOT to $GOROOT_FINAL.
- first = 0;
- goroot = getenv("GOROOT");
- goroot_final = getenv("GOROOT_FINAL");
- if(goroot == nil)
- goroot = "";
- if(goroot_final == nil)
- goroot_final = goroot;
- if(strcmp(goroot, goroot_final) == 0) {
- goroot = nil;
- goroot_final = nil;
- }
- }
-
- tofree = nil;
- pg = zprog;
- pg.as = AHISTORY;
- c = pathchar();
- for(h = hist; h != H; h = h->link) {
- p = h->name;
- if(p != nil && goroot != nil) {
- n = strlen(goroot);
- if(strncmp(p, goroot, strlen(goroot)) == 0 && p[n] == '/') {
- tofree = smprint("%s%s", goroot_final, p+n);
- p = tofree;
- }
- }
- op = 0;
- if(systemtype(Windows) && p && p[1] == ':'){
- c = p[2];
- } else if(p && p[0] != c && h->offset == 0 && pathname){
- if(systemtype(Windows) && pathname[1] == ':') {
- op = p;
- p = pathname;
- c = p[2];
- } else if(pathname[0] == c){
- op = p;
- p = pathname;
- }
- }
- while(p) {
- q = utfrune(p, c);
- if(q) {
- n = q-p;
- if(n == 0){
- n = 1; /* leading "/" */
- *p = '/'; /* don't emit "\" on windows */
- }
- q++;
- } else {
- n = strlen(p);
- q = 0;
- }
- if(n) {
- BPUTC(b, ANAME);
- BPUTC(b, D_FILE);
- BPUTC(b, 1);
- BPUTC(b, '<');
- Bwrite(b, p, n);
- BPUTC(b, 0);
- }
- p = q;
- if(p == 0 && op) {
- p = op;
- op = 0;
- }
- }
- pg.lineno = h->line;
- pg.to.type = zprog.to.type;
- pg.to.offset = h->offset;
- if(h->offset)
- pg.to.type = D_CONST;
-
- zwrite(b, &pg, 0, 0);
-
- if(tofree) {
- free(tofree);
- tofree = nil;
- }
- }
-}
-
-void
-zname(Biobuf *b, Sym *s, int t)
-{
- char *n, bf[7];
- uint32 sig;
-
- n = s->name;
- if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
- sig = sign(s);
- bf[0] = ASIGNAME;
- bf[1] = sig;
- bf[2] = sig>>8;
- bf[3] = sig>>16;
- bf[4] = sig>>24;
- bf[5] = t;
- bf[6] = s->sym;
- Bwrite(b, bf, 7);
- s->sig = SIGDONE;
- }
- else{
- bf[0] = ANAME;
- bf[1] = t; /* type */
- bf[2] = s->sym; /* sym */
- Bwrite(b, bf, 3);
- }
- Bwrite(b, n, strlen(n)+1);
-}
-
-char*
-zaddr(char *bp, Adr *a, int s)
-{
- int32 l;
- Ieee e;
-
- bp[0] = a->type;
- bp[1] = a->reg;
- bp[2] = s;
- bp[3] = a->name;
- bp[4] = 0;
- bp += 5;
- switch(a->type) {
- default:
- diag(Z, "unknown type %d in zaddr", a->type);
-
- case D_NONE:
- case D_REG:
- case D_FREG:
- case D_PSR:
- break;
-
- case D_CONST2:
- l = a->offset2;
- bp[0] = l;
- bp[1] = l>>8;
- bp[2] = l>>16;
- bp[3] = l>>24;
- bp += 4; // fall through
- case D_OREG:
- case D_CONST:
- case D_BRANCH:
- case D_SHIFT:
- l = a->offset;
- bp[0] = l;
- bp[1] = l>>8;
- bp[2] = l>>16;
- bp[3] = l>>24;
- bp += 4;
- break;
-
- case D_SCONST:
- memmove(bp, a->sval, NSNAME);
- bp += NSNAME;
- break;
-
- case D_FCONST:
- ieeedtod(&e, a->dval);
- l = e.l;
- bp[0] = l;
- bp[1] = l>>8;
- bp[2] = l>>16;
- bp[3] = l>>24;
- bp += 4;
- l = e.h;
- bp[0] = l;
- bp[1] = l>>8;
- bp[2] = l>>16;
- bp[3] = l>>24;
- bp += 4;
- break;
- }
- return bp;
-}
-
int32
align(int32 i, Type *t, int op, int32 *maxalign)
{
diff --git a/src/cmd/5c/txt.c b/src/cmd/5c/txt.c
index 6d9b69d00..a753510ca 100644
--- a/src/cmd/5c/txt.c
+++ b/src/cmd/5c/txt.c
@@ -31,13 +31,22 @@
#include "gc.h"
+
+int thechar = '5';
+char *thestring = "arm";
+
+LinkArch *thelinkarch = &linkarm;
+
+void
+linkarchinit(void)
+{
+}
+
void
ginit(void)
{
Type *t;
- thechar = '5';
- thestring = "arm";
exregoffset = REGEXT;
exfregoffset = FREGEXT;
listinit();
@@ -48,7 +57,6 @@ ginit(void)
breakpc = -1;
continpc = -1;
cases = C;
- firstp = P;
lastp = P;
tfield = types[TLONG];
@@ -149,17 +157,17 @@ gclean(void)
void
nextpc(void)
{
+ Plist *pl;
p = alloc(sizeof(*p));
*p = zprog;
p->lineno = nearln;
pc++;
- if(firstp == P) {
- firstp = p;
- lastp = p;
- return;
- }
- lastp->link = p;
+ if(lastp == nil) {
+ pl = linknewplist(ctxt);
+ pl->firstpc = p;
+ } else
+ lastp->link = p;
lastp = p;
}
@@ -422,7 +430,7 @@ regind(Node *n, Node *nn)
void
raddr(Node *n, Prog *p)
{
- Adr a;
+ Addr a;
naddr(n, &a);
if(R0ISZERO && a.type == D_CONST && a.offset == 0) {
@@ -440,7 +448,7 @@ raddr(Node *n, Prog *p)
}
void
-naddr(Node *n, Adr *a)
+naddr(Node *n, Addr *a)
{
int32 v;
@@ -455,7 +463,7 @@ naddr(Node *n, Adr *a)
case OREGISTER:
a->type = D_REG;
- a->sym = S;
+ a->sym = nil;
a->reg = n->reg;
if(a->reg >= NREG) {
a->type = D_FREG;
@@ -477,7 +485,7 @@ naddr(Node *n, Adr *a)
case OINDREG:
a->type = D_OREG;
- a->sym = S;
+ a->sym = nil;
a->offset = n->xoffset;
a->reg = n->reg;
break;
@@ -486,7 +494,7 @@ naddr(Node *n, Adr *a)
a->etype = n->etype;
a->type = D_OREG;
a->name = D_STATIC;
- a->sym = n->sym;
+ a->sym = linksym(n->sym);
a->offset = n->xoffset;
if(n->class == CSTATIC)
break;
@@ -505,11 +513,11 @@ naddr(Node *n, Adr *a)
goto bad;
case OCONST:
- a->sym = S;
+ a->sym = nil;
a->reg = NREG;
if(typefd[n->type->etype]) {
a->type = D_FCONST;
- a->dval = n->fconst;
+ a->u.dval = n->fconst;
} else {
a->type = D_CONST;
a->offset = n->vconst;
@@ -930,7 +938,7 @@ void
gopcode(int o, Node *f1, Node *f2, Node *t)
{
int a, et;
- Adr ta;
+ Addr ta;
et = TLONG;
if(f1 != Z && f1->type != T)
@@ -1177,7 +1185,7 @@ gpseudo(int a, Sym *s, Node *n)
nextpc();
p->as = a;
p->from.type = D_OREG;
- p->from.sym = s;
+ p->from.sym = linksym(s);
p->from.name = D_EXTERN;
switch(a) {