summaryrefslogtreecommitdiff
path: root/src/cmd/6c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/6c')
-rw-r--r--src/cmd/6c/gc.h75
-rw-r--r--src/cmd/6c/list.c355
-rw-r--r--src/cmd/6c/peep.c16
-rw-r--r--src/cmd/6c/reg.c31
-rw-r--r--src/cmd/6c/sgen.c2
-rw-r--r--src/cmd/6c/swt.c297
-rw-r--r--src/cmd/6c/txt.c75
7 files changed, 119 insertions, 732 deletions
diff --git a/src/cmd/6c/gc.h b/src/cmd/6c/gc.h
index c466a3afe..a196e55a8 100644
--- a/src/cmd/6c/gc.h
+++ b/src/cmd/6c/gc.h
@@ -46,11 +46,8 @@
#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 Var Var;
typedef struct Reg Reg;
typedef struct Rgn Rgn;
typedef struct Renv Renv;
@@ -64,29 +61,9 @@ EXTERN struct
short ptr;
} idx;
-struct Adr
-{
- vlong offset;
- double dval;
- char sval[NSNAME];
-
- Sym* sym;
- uchar type;
- uchar index;
- uchar etype;
- uchar scale; /* doubles as width in DATA op */
-};
-#define A ((Adr*)0)
-
#define INDEXED 9
-struct Prog
-{
- Adr from;
- Adr to;
- Prog* link;
- int32 lineno;
- short as;
-};
+
+#define A ((Addr*)0)
#define P ((Prog*)0)
struct Case
@@ -105,14 +82,6 @@ struct C1
int32 label;
};
-struct Var
-{
- vlong offset;
- Sym* sym;
- char name;
- char etype;
-};
-
struct Reg
{
int32 pc;
@@ -171,7 +140,6 @@ EXTERN Node vconstnode;
EXTERN int32 continpc;
EXTERN int32 curarg;
EXTERN int32 cursafe;
-EXTERN Prog* firstp;
EXTERN Prog* lastp;
EXTERN int32 maxargsafe;
EXTERN int mnstring;
@@ -226,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;
@@ -282,7 +249,7 @@ void regaalloc1(Node*, Node*);
void regaalloc(Node*, Node*);
void regind(Node*, Node*);
void gprep(Node*, Node*);
-void naddr(Node*, Adr*);
+void naddr(Node*, Addr*);
void gcmp(int, Node*, vlong);
void gmove(Node*, Node*);
void gins(int a, Node*, Node*);
@@ -310,19 +277,11 @@ void nullwarn(Node*, Node*);
void sextern(Sym*, Node*, int32, int32);
void gextern(Sym*, Node*, int32, int32);
void outcode(void);
-void ieeedtod(Ieee*, double);
/*
* list
*/
void listinit(void);
-int Pconv(Fmt*);
-int Aconv(Fmt*);
-int Dconv(Fmt*);
-int Sconv(Fmt*);
-int Rconv(Fmt*);
-int Xconv(Fmt*);
-int Bconv(Fmt*);
/*
* reg.c
@@ -331,7 +290,7 @@ Reg* rega(void);
int rcmp(const void*, const void*);
void regopt(Prog*);
void addmove(Reg*, int, int, int);
-Bits mkvar(Reg*, Adr*);
+Bits mkvar(Reg*, Addr*);
void prop(Reg*, Bits, Bits);
void loopit(Reg*, int32);
void synch(Reg*, Bits);
@@ -339,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
@@ -348,17 +307,17 @@ void peep(void);
void excise(Reg*);
Reg* uniqp(Reg*);
Reg* uniqs(Reg*);
-int regtyp(Adr*);
-int anyvar(Adr*);
+int regtyp(Addr*);
+int anyvar(Addr*);
int subprop(Reg*);
int copyprop(Reg*);
-int copy1(Adr*, Adr*, Reg*, int);
-int copyu(Prog*, Adr*, Adr*);
+int copy1(Addr*, Addr*, Reg*, int);
+int copyu(Prog*, Addr*, Addr*);
-int copyas(Adr*, Adr*);
-int copyau(Adr*, Adr*);
-int copysub(Adr*, Adr*, Adr*, int);
-int copysub1(Prog*, Adr*, Adr*, int);
+int copyas(Addr*, Addr*);
+int copyau(Addr*, Addr*);
+int copysub(Addr*, Addr*, Addr*, int);
+int copysub1(Prog*, Addr*, Addr*, int);
int32 RtoB(int);
int32 FtoB(int);
@@ -396,14 +355,6 @@ void mulgen(Type*, Node*, Node*);
void genmuladd(Node*, Node*, int, Node*);
void shiftit(Type*, Node*, Node*);
-#pragma varargck type "A" int
-#pragma varargck type "B" Bits
-#pragma varargck type "D" Adr*
-#pragma varargck type "lD" Adr*
-#pragma varargck type "P" Prog*
-#pragma varargck type "R" int
-#pragma varargck type "S" char*
-
#define D_X7 (D_X0+7)
void fgopcode(int, Node*, Node*, int, int);
diff --git a/src/cmd/6c/list.c b/src/cmd/6c/list.c
index b5a60ac9a..28f5b8df7 100644
--- a/src/cmd/6c/list.c
+++ b/src/cmd/6c/list.c
@@ -34,358 +34,5 @@
void
listinit(void)
{
-
- fmtinstall('A', Aconv);
- fmtinstall('B', Bconv);
- fmtinstall('P', Pconv);
- fmtinstall('S', Sconv);
- 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, "$%lld", 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);
-}
-
-int
-Pconv(Fmt *fp)
-{
- char str[STRINGSZ];
- Prog *p;
-
- p = va_arg(fp->args, Prog*);
- switch(p->as) {
- case ADATA:
- sprint(str, "(%L) %A %D/%d,%D",
- p->lineno, p->as, &p->from, p->from.scale, &p->to);
- break;
-
- case ATEXT:
- if(p->from.scale) {
- sprint(str, "(%L) %A %D,%d,%lD",
- p->lineno, p->as, &p->from, p->from.scale, &p->to);
- break;
- }
- sprint(str, "(%L) %A %D,%lD",
- p->lineno, p->as, &p->from, &p->to);
- break;
-
- default:
- sprint(str, "(%L) %A %D,%D",
- p->lineno, p->as, &p->from, &p->to);
- break;
- }
- 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[STRINGSZ], s[STRINGSZ];
- Adr *a;
- int i;
-
- a = va_arg(fp->args, Adr*);
- i = a->type;
-
- if(fp->flags & FmtLong) {
- if(i == D_CONST)
- sprint(str, "$%lld-%lld", a->offset&0xffffffffLL, a->offset>>32);
- else {
- // ATEXT dst is not constant
- sprint(str, "!!%D", a);
- }
- goto brk;
- }
-
- 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:
- sprint(str, "%lld", a->offset);
- break;
-
- case D_EXTERN:
- sprint(str, "%s+%lld(SB)", a->sym->name, a->offset);
- break;
-
- case D_STATIC:
- sprint(str, "%s<>+%lld(SB)", a->sym->name, a->offset);
- break;
-
- case D_AUTO:
- if(a->sym)
- sprint(str, "%s+%lld(SP)", a->sym->name, a->offset);
- else
- sprint(str, "%lld(SP)", a->offset);
- break;
-
- case D_PARAM:
- if(a->sym)
- sprint(str, "%s+%lld(FP)", a->sym->name, a->offset);
- else
- sprint(str, "%lld(FP)", a->offset);
- break;
-
- case D_CONST:
- sprint(str, "$%lld", a->offset);
- break;
-
- case D_FCONST:
- sprint(str, "$(%.17e)", a->dval);
- break;
-
- case D_SCONST:
- sprint(str, "$\"%S\"", a->sval);
- 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)", (int)a->index, (int)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[STRINGSZ];
- 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[STRINGSZ], *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);
+ listinit6();
}
diff --git a/src/cmd/6c/peep.c b/src/cmd/6c/peep.c
index 0a3bd84bc..a11067c84 100644
--- a/src/cmd/6c/peep.c
+++ b/src/cmd/6c/peep.c
@@ -276,7 +276,7 @@ uniqs(Reg *r)
}
int
-regtyp(Adr *a)
+regtyp(Addr *a)
{
int t;
@@ -306,7 +306,7 @@ int
subprop(Reg *r0)
{
Prog *p;
- Adr *v1, *v2;
+ Addr *v1, *v2;
Reg *r;
int t;
@@ -445,7 +445,7 @@ int
copyprop(Reg *r0)
{
Prog *p;
- Adr *v1, *v2;
+ Addr *v1, *v2;
Reg *r;
p = r0->prog;
@@ -459,7 +459,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;
@@ -544,7 +544,7 @@ copy1(Adr *v1, Adr *v2, Reg *r, int f)
* 0 otherwise (not touched)
*/
int
-copyu(Prog *p, Adr *v, Adr *s)
+copyu(Prog *p, Addr *v, Addr *s)
{
switch(p->as) {
@@ -835,7 +835,7 @@ copyu(Prog *p, Adr *v, Adr *s)
* semantics
*/
int
-copyas(Adr *a, Adr *v)
+copyas(Addr *a, Addr *v)
{
if(a->type != v->type)
return 0;
@@ -851,7 +851,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))
@@ -870,7 +870,7 @@ copyau(Adr *a, 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)
{
int t;
diff --git a/src/cmd/6c/reg.c b/src/cmd/6c/reg.c
index edd93a0a0..348d747b7 100644
--- a/src/cmd/6c/reg.c
+++ b/src/cmd/6c/reg.c
@@ -663,8 +663,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;
}
@@ -691,7 +693,7 @@ void
addmove(Reg *r, int bn, int rn, int f)
{
Prog *p, *p1;
- Adr *a;
+ Addr *a;
Var *v;
p1 = alloc(sizeof(*p1));
@@ -715,7 +717,7 @@ addmove(Reg *r, int bn, int rn, int f)
p1->as = AMOVB;
if(v->etype == TSHORT || v->etype == TUSHORT)
p1->as = AMOVW;
- if(v->etype == TVLONG || v->etype == TUVLONG || v->etype == TIND)
+ if(v->etype == TVLONG || v->etype == TUVLONG || (v->etype == TIND && ewidth[TIND] == 8))
p1->as = AMOVQ;
if(v->etype == TFLOAT)
p1->as = AMOVSS;
@@ -759,13 +761,13 @@ doregbits(int r)
}
Bits
-mkvar(Reg *r, Adr *a)
+mkvar(Reg *r, Addr *a)
{
Var *v;
int i, t, n, et, z;
int32 o;
Bits bit;
- Sym *s;
+ LSym *s;
/*
* mark registers used
@@ -792,7 +794,7 @@ mkvar(Reg *r, Adr *a)
break;
}
s = a->sym;
- if(s == S)
+ if(s == nil)
goto none;
if(s->name[0] == '.')
goto none;
@@ -1181,7 +1183,7 @@ uint32
regset(Reg *r, uint32 bb)
{
uint32 b, set;
- Adr v;
+ Addr v;
int c;
set = 0;
@@ -1202,7 +1204,7 @@ uint32
reguse(Reg *r, uint32 bb)
{
uint32 b, set;
- Adr v;
+ Addr v;
int c;
set = 0;
@@ -1349,7 +1351,7 @@ paint3(Reg *r, int bn, int32 rb, int rn)
}
void
-addreg(Adr *a, int rn)
+addreg(Addr *a, int rn)
{
a->sym = 0;
@@ -1371,6 +1373,8 @@ BtoR(int32 b)
{
b &= 0xffffL;
+ if(nacl)
+ b &= ~((1<<(D_BP-D_AX)) | (1<<(D_R15-D_AX)));
if(b == 0)
return 0;
return bitno(b) + D_AX;
@@ -1459,10 +1463,11 @@ fixjmp(Reg *firstr)
for(r=firstr; r; r=r->link) {
p = r->prog;
if(debug['R'] && debug['v'])
- print("%04d %P\n", r->pc, p);
+ print("%04d %P\n", (int)r->pc, p);
if(p->as != ACALL && p->to.type == D_BRANCH && r->s2 && r->s2->prog->as == AJMP) {
r->s2 = chasejmp(r->s2, &jmploop);
p->to.offset = r->s2->pc;
+ p->to.u.branch = r->s2->prog;
if(debug['R'] && debug['v'])
print("->%P\n", p);
}
@@ -1483,7 +1488,7 @@ fixjmp(Reg *firstr)
// Let it stay.
} else {
if(debug['R'] && debug['v'])
- print("del %04d %P\n", r->pc, p);
+ print("del %04d %P\n", (int)r->pc, p);
p->as = ANOP;
}
}
@@ -1496,7 +1501,7 @@ fixjmp(Reg *firstr)
p = r->prog;
if(p->as == AJMP && p->to.type == D_BRANCH && r->s2 == r->link) {
if(debug['R'] && debug['v'])
- print("del %04d %P\n", r->pc, p);
+ print("del %04d %P\n", (int)r->pc, p);
p->as = ANOP;
}
}
@@ -1517,7 +1522,7 @@ fixjmp(Reg *firstr)
if(debug['R'] && debug['v']) {
print("\n");
for(r=firstr; r; r=r->link)
- print("%04d %P\n", r->pc, r->prog);
+ print("%04d %P\n", (int)r->pc, r->prog);
print("\n");
}
}
diff --git a/src/cmd/6c/sgen.c b/src/cmd/6c/sgen.c
index 744a60222..ba1c1f652 100644
--- a/src/cmd/6c/sgen.c
+++ b/src/cmd/6c/sgen.c
@@ -207,7 +207,7 @@ xcom(Node *n)
n->addable = 8;
break;
}
- if(n->addable == 8 && !side(n)) {
+ if(n->addable == 8 && !side(n) && !nacl) {
indx(n);
l = new1(OINDEX, idx.basetree, idx.regtree);
l->scale = idx.scale;
diff --git a/src/cmd/6c/swt.c b/src/cmd/6c/swt.c
index 2496da477..d7713648d 100644
--- a/src/cmd/6c/swt.c
+++ b/src/cmd/6c/swt.c
@@ -164,7 +164,7 @@ outstring(char *s, int32 n)
p->from.offset += nstring - NSNAME;
p->from.scale = NSNAME;
p->to.type = D_SCONST;
- memmove(p->to.sval, string, NSNAME);
+ memmove(p->to.u.sval, string, NSNAME);
mnstring = 0;
}
n--;
@@ -185,7 +185,7 @@ sextern(Sym *s, Node *a, int32 o, int32 w)
p->from.offset += o+e;
p->from.scale = lw;
p->to.type = D_SCONST;
- memmove(p->to.sval, a->cstring+e, lw);
+ memmove(p->to.u.sval, a->cstring+e, lw);
}
}
@@ -215,30 +215,12 @@ gextern(Sym *s, Node *a, int32 o, int32 w)
}
}
-void zname(Biobuf*, Sym*, int);
-void zaddr(Biobuf*, Adr*, int);
-void outhist(Biobuf*);
-
void
outcode(void)
{
- struct { Sym *sym; short type; } h[NSYM];
- Prog *p;
- Sym *s;
- int f, sf, st, t, sym;
+ int f;
Biobuf b;
- 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++;
- }
- }
-
f = open(outfile, OWRITE);
if(f < 0) {
diag(Z, "cannot open %s", outfile);
@@ -246,7 +228,7 @@ outcode(void)
}
Binit(&b, f, OWRITE);
- Bprint(&b, "go object %s %s %s\n", getgoos(), thestring, getgoversion());
+ Bprint(&b, "go object %s %s %s\n", getgoos(), getgoarch(), getgoversion());
if(pragcgobuf.to > pragcgobuf.start) {
Bprint(&b, "\n");
Bprint(&b, "$$ // exports\n\n");
@@ -257,261 +239,12 @@ outcode(void)
}
Bprint(&b, "!\n");
- outhist(&b);
- 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.type;
- if(t == D_ADDR)
- t = p->from.index;
- if(h[sf].type == t)
- if(h[sf].sym == s)
- break;
- s->sym = sym;
- zname(&b, 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.type;
- if(t == D_ADDR)
- t = p->to.index;
- if(h[st].type == t)
- if(h[st].sym == s)
- break;
- s->sym = sym;
- zname(&b, s, t);
- h[sym].sym = s;
- h[sym].type = t;
- st = sym;
- sym++;
- if(sym >= NSYM)
- sym = 1;
- if(st == sf)
- goto jackpot;
- break;
- }
- BPUTLE2(&b, p->as);
- BPUTLE4(&b, p->lineno);
- zaddr(&b, &p->from, sf);
- zaddr(&b, &p->to, st);
- }
+ writeobj(ctxt, &b);
Bterm(&b);
close(f);
- firstp = P;
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) {
- BPUTLE2(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;
-
- BPUTLE2(b, pg.as);
- BPUTLE4(b, pg.lineno);
- zaddr(b, &pg.from, 0);
- zaddr(b, &pg.to, 0);
-
- if(tofree) {
- free(tofree);
- tofree = nil;
- }
- }
-}
-
-void
-zname(Biobuf *b, Sym *s, int t)
-{
- char *n;
- uint32 sig;
-
- if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
- sig = sign(s);
- BPUTLE2(b, ASIGNAME);
- BPUTLE4(b, sig);
- s->sig = SIGDONE;
- }
- else{
- BPUTLE2(b, ANAME); /* as */
- }
- BPUTC(b, t); /* type */
- BPUTC(b, s->sym); /* sym */
- n = s->name;
- while(*n) {
- BPUTC(b, *n);
- n++;
- }
- BPUTC(b, 0);
-}
-
-void
-zaddr(Biobuf *b, Adr *a, int s)
-{
- int32 l;
- int i, t;
- char *n;
- Ieee e;
-
- t = 0;
- if(a->index != D_NONE || a->scale != 0)
- t |= T_INDEX;
- if(s != 0)
- t |= T_SYM;
-
- switch(a->type) {
- default:
- t |= T_TYPE;
- case D_NONE:
- if(a->offset != 0) {
- t |= T_OFFSET;
- l = a->offset;
- if((vlong)l != a->offset)
- t |= T_64;
- }
- break;
- case D_FCONST:
- t |= T_FCONST;
- break;
- case D_SCONST:
- t |= T_SCONST;
- break;
- }
- BPUTC(b, t);
-
- if(t & T_INDEX) { /* implies index, scale */
- BPUTC(b, a->index);
- BPUTC(b, a->scale);
- }
- if(t & T_OFFSET) { /* implies offset */
- l = a->offset;
- BPUTLE4(b, l);
- if(t & T_64) {
- l = a->offset>>32;
- BPUTLE4(b, l);
- }
- }
- if(t & T_SYM) /* implies sym */
- BPUTC(b, s);
- if(t & T_FCONST) {
- ieeedtod(&e, a->dval);
- l = e.l;
- BPUTLE4(b, l);
- l = e.h;
- BPUTLE4(b, l);
- return;
- }
- if(t & T_SCONST) {
- n = a->sval;
- for(i=0; i<NSNAME; i++) {
- BPUTC(b, *n);
- n++;
- }
- return;
- }
- if(t & T_TYPE)
- BPUTC(b, a->type);
-}
-
int32
align(int32 i, Type *t, int op, int32 *maxalign)
{
@@ -559,6 +292,21 @@ align(int32 i, Type *t, int op, int32 *maxalign)
break;
case Aarg1: /* initial align of parameter */
+ if(ewidth[TIND] == 4) {
+ if(typesu[t->etype]) {
+ for(v = t->link; v != T; v = v->down)
+ o = align(o, v, Aarg1, maxalign);
+ goto out;
+ }
+ w = ewidth[t->etype];
+ if(typev[t->etype] || t->etype == TDOUBLE)
+ w = 8;
+ else if(w <= 0 || w >= 4)
+ w = 4;
+ else
+ w = 1;
+ break;
+ }
w = ewidth[t->etype];
if(w <= 0 || w >= SZ_VLONG) {
w = SZ_VLONG;
@@ -569,6 +317,10 @@ align(int32 i, Type *t, int op, int32 *maxalign)
case Aarg2: /* width of a parameter */
o += t->width;
+ if(ewidth[TIND] == 4) {
+ o = align(o, t, Aarg1, maxalign);
+ goto out;
+ }
w = t->width;
if(w > SZ_VLONG)
w = SZ_VLONG;
@@ -582,6 +334,7 @@ align(int32 i, Type *t, int op, int32 *maxalign)
o = xround(o, w);
if(maxalign && *maxalign < w)
*maxalign = w;
+out:
if(debug['A'])
print("align %s %d %T = %d\n", bnames[op], i, t, o);
return o;
diff --git a/src/cmd/6c/txt.c b/src/cmd/6c/txt.c
index 6f5d42da5..4d07436c3 100644
--- a/src/cmd/6c/txt.c
+++ b/src/cmd/6c/txt.c
@@ -30,15 +30,27 @@
#include "gc.h"
+int thechar = '6';
+char *thestring = "amd64";
+
+LinkArch *thelinkarch = &linkamd64;
+
+void
+linkarchinit(void)
+{
+ if(strcmp(getgoarch(), "amd64p32") == 0)
+ thelinkarch = &linkamd64p32;
+}
+
void
ginit(void)
{
int i;
Type *t;
- thechar = '6';
- thestring = "amd64";
- dodefine("_64BIT");
+ dodefine("_64BITREG");
+ if(ewidth[TIND] == 8)
+ dodefine("_64BIT");
listinit();
nstring = 0;
mnstring = 0;
@@ -47,7 +59,6 @@ ginit(void)
breakpc = -1;
continpc = -1;
cases = C;
- firstp = P;
lastp = P;
tfield = types[TINT];
@@ -129,6 +140,10 @@ ginit(void)
if(i >= D_X0 && i <= D_X7)
reg[i] = 0;
}
+ if(nacl) {
+ reg[D_BP] = 1;
+ reg[D_R15] = 1;
+ }
}
void
@@ -138,6 +153,10 @@ gclean(void)
Sym *s;
reg[D_SP]--;
+ if(nacl) {
+ reg[D_BP]--;
+ reg[D_R15]--;
+ }
for(i=D_AX; i<=D_R15; i++)
if(reg[i])
diag(Z, "reg %R left allocated", i);
@@ -168,17 +187,18 @@ gclean(void)
void
nextpc(void)
{
+ Plist *pl;
p = alloc(sizeof(*p));
*p = zprog;
p->lineno = nearln;
+ p->pc = pc;
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;
}
@@ -441,7 +461,7 @@ regaalloc1(Node *n, Node *nn)
return;
}
nodreg(n, nn, REGARG);
- reg[REGARG]++;
+ reg[(uchar)REGARG]++;
curarg = align(curarg, nn->type, Aarg1, nil);
curarg = align(curarg, nn->type, Aarg2, nil);
maxargsafe = maxround(maxargsafe, cursafe+curarg);
@@ -474,7 +494,7 @@ regind(Node *n, Node *nn)
}
void
-naddr(Node *n, Adr *a)
+naddr(Node *n, Addr *a)
{
int32 v;
@@ -489,11 +509,11 @@ naddr(Node *n, Adr *a)
case OREGISTER:
a->type = n->reg;
- a->sym = S;
+ a->sym = nil;
break;
case OEXREG:
- a->type = D_INDIR + D_GS;
+ a->type = D_INDIR + D_TLS;
a->offset = n->reg - 1;
break;
@@ -534,14 +554,14 @@ naddr(Node *n, Adr *a)
case OINDREG:
a->type = n->reg+D_INDIR;
- a->sym = S;
+ a->sym = nil;
a->offset = n->xoffset;
break;
case ONAME:
a->etype = n->etype;
a->type = D_STATIC;
- a->sym = n->sym;
+ a->sym = linksym(n->sym);
a->offset = n->xoffset;
if(n->class == CSTATIC)
break;
@@ -562,12 +582,12 @@ naddr(Node *n, Adr *a)
case OCONST:
if(typefd[n->type->etype]) {
a->type = D_FCONST;
- a->dval = n->fconst;
+ a->u.dval = n->fconst;
break;
}
- a->sym = S;
+ a->sym = nil;
a->type = D_CONST;
- if(typev[n->type->etype] || n->type->etype == TIND)
+ if(typev[n->type->etype] || (n->type->etype == TIND && ewidth[TIND] == 8))
a->offset = n->vconst;
else
a->offset = convvtox(n->vconst, typeu[n->type->etype]? TULONG: TLONG);
@@ -630,6 +650,12 @@ gmove(Node *f, Node *t)
ft = f->type->etype;
tt = t->type->etype;
+ if(ewidth[TIND] == 4) {
+ if(ft == TIND)
+ ft = TUINT;
+ if(tt == TIND)
+ tt = TUINT;
+ }
t64 = tt == TVLONG || tt == TUVLONG || tt == TIND;
if(debug['M'])
print("gop: %O %O[%s],%O[%s]\n", OAS,
@@ -721,6 +747,8 @@ gmove(Node *f, Node *t)
goto ld;
case TIND:
a = AMOVQ;
+ if(ewidth[TIND] == 4)
+ a = AMOVL;
ld:
regalloc(&nod, f, t);
@@ -1226,6 +1254,8 @@ gopcode(int o, Type *ty, Node *f, Node *t)
et = TLONG;
if(ty != T)
et = ty->etype;
+ if(et == TIND && ewidth[TIND] == 4)
+ et = TUINT;
if(debug['M']) {
if(f != Z && f->type != T)
print("gop: %O %O[%s],", o, f->op, tnames[et]);
@@ -1487,9 +1517,10 @@ gbranch(int o)
void
patch(Prog *op, int32 pc)
{
-
op->to.offset = pc;
op->to.type = D_BRANCH;
+ op->to.u.branch = nil;
+ op->pcond = nil;
}
void
@@ -1499,7 +1530,7 @@ gpseudo(int a, Sym *s, Node *n)
nextpc();
p->as = a;
p->from.type = D_EXTERN;
- p->from.sym = s;
+ p->from.sym = linksym(s);
switch(a) {
case ATEXT:
@@ -1561,7 +1592,7 @@ exreg(Type *t)
if(exregoffset >= 64)
return 0;
o = exregoffset;
- exregoffset += 8;
+ exregoffset += ewidth[TIND];
return o+1; // +1 to avoid 0 == failure; naddr's case OEXREG will subtract 1.
}
return 0;