summaryrefslogtreecommitdiff
path: root/src/cmd/5c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/5c')
-rw-r--r--src/cmd/5c/cgen.c4
-rw-r--r--src/cmd/5c/doc.go6
-rw-r--r--src/cmd/5c/gc.h1
-rw-r--r--src/cmd/5c/peep.c3
-rw-r--r--src/cmd/5c/reg.c24
-rw-r--r--src/cmd/5c/swt.c46
-rw-r--r--src/cmd/5c/txt.c18
7 files changed, 72 insertions, 30 deletions
diff --git a/src/cmd/5c/cgen.c b/src/cmd/5c/cgen.c
index 9e74f515b..5ff4f633d 100644
--- a/src/cmd/5c/cgen.c
+++ b/src/cmd/5c/cgen.c
@@ -950,9 +950,9 @@ sugen(Node *n, Node *nn, int32 w)
case OSTRUCT:
/*
- * rewrite so lhs has no fn call
+ * rewrite so lhs has no side effect.
*/
- if(nn != Z && nn->complex >= FNX) {
+ if(nn != Z && side(nn)) {
nod1 = *n;
nod1.type = typ(TIND, n->type);
regret(&nod2, &nod1);
diff --git a/src/cmd/5c/doc.go b/src/cmd/5c/doc.go
index 0874293bf..7291d45f4 100644
--- a/src/cmd/5c/doc.go
+++ b/src/cmd/5c/doc.go
@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// +build ignore
+
/*
5c is a version of the Plan 9 C compiler. The original is documented at
- http://plan9.bell-labs.com/magic/man2html/1/2c
+ http://plan9.bell-labs.com/magic/man2html/1/8c
Its target architecture is the ARM, referred to by these tools as arm.
*/
-package documentation
+package main
diff --git a/src/cmd/5c/gc.h b/src/cmd/5c/gc.h
index 20652682b..a0fc63c60 100644
--- a/src/cmd/5c/gc.h
+++ b/src/cmd/5c/gc.h
@@ -297,6 +297,7 @@ void patch(Prog*, int32);
int sconst(Node*);
int sval(int32);
void gpseudo(int, Sym*, Node*);
+void gprefetch(Node*);
/*
* swt.c
diff --git a/src/cmd/5c/peep.c b/src/cmd/5c/peep.c
index 3a905f099..2f902e02a 100644
--- a/src/cmd/5c/peep.c
+++ b/src/cmd/5c/peep.c
@@ -824,7 +824,7 @@ xtramodes(Reg *r, Adr *a)
Adr v;
p = r->prog;
- if(debug['h'] && p->as == AMOVB && p->from.type == D_OREG) /* byte load */
+ if(p->as == AMOVB && p->from.type == D_OREG) /* byte load */
return 0;
v = *a;
v.type = D_REG;
@@ -1067,6 +1067,7 @@ copyu(Prog *p, Adr *v, Adr *s)
case ABLT:
case ABGT:
case ABLE:
+ case APLD:
if(s != A) {
if(copysub(&p->from, v, s, 1))
return 1;
diff --git a/src/cmd/5c/reg.c b/src/cmd/5c/reg.c
index 1ccf74a35..42c5193de 100644
--- a/src/cmd/5c/reg.c
+++ b/src/cmd/5c/reg.c
@@ -66,12 +66,6 @@ rcmp(const void *a1, const void *a2)
void
regopt(Prog *p)
{
- USED(p);
- // TODO(kaib): optimizer disabled because it smashes R8 when running out of registers
- // the disable is unconventionally here because the call is in common code shared by 5c/6c/8c
- return;
-
-#ifdef NOTDEF
Reg *r, *r1, *r2;
Prog *p1;
int i, z;
@@ -191,6 +185,14 @@ regopt(Prog *p)
break;
/*
+ * right side read
+ */
+ case APLD:
+ for(z=0; z<BITS; z++)
+ r->use2.b[z] |= bit.b[z];
+ break;
+
+ /*
* funny
*/
case ABL:
@@ -492,7 +494,6 @@ brk:
r1->link = freer;
freer = firstr;
}
-#endif
}
void
@@ -1149,12 +1150,13 @@ addreg(Adr *a, int rn)
* 1 R1
* ... ...
* 10 R10
+ * 12 R12
*/
int32
RtoB(int r)
{
- if(r < 2 || r >= REGTMP-2) // excluded R9 and R10 for m and g
+ if(r < 2 || (r >= REGTMP-2 && r != 12)) // excluded R9 and R10 for m and g, but not R12
return 0;
return 1L << r;
}
@@ -1162,7 +1164,7 @@ RtoB(int r)
int
BtoR(int32 b)
{
- b &= 0x01fcL; // excluded R9 and R10 for m and g
+ b &= 0x11fcL; // excluded R9 and R10 for m and g, but not R12
if(b == 0)
return 0;
return bitno(b);
@@ -1173,7 +1175,7 @@ BtoR(int32 b)
* 18 F2
* 19 F3
* ... ...
- * 23 F7
+ * 31 F15
*/
int32
FtoB(int f)
@@ -1188,7 +1190,7 @@ int
BtoF(int32 b)
{
- b &= 0xfc0000L;
+ b &= 0xfffc0000L;
if(b == 0)
return 0;
return bitno(b) - 16;
diff --git a/src/cmd/5c/swt.c b/src/cmd/5c/swt.c
index 7268f9af2..87b77518b 100644
--- a/src/cmd/5c/swt.c
+++ b/src/cmd/5c/swt.c
@@ -393,18 +393,12 @@ outcode(void)
}
Bprint(&outbuf, "go object %s %s %s\n", getgoos(), thestring, getgoversion());
- if(ndynimp > 0 || ndynexp > 0) {
- int i;
-
+ if(pragcgobuf.to > pragcgobuf.start) {
Bprint(&outbuf, "\n");
Bprint(&outbuf, "$$ // exports\n\n");
Bprint(&outbuf, "$$ // local types\n\n");
- Bprint(&outbuf, "$$ // dynimport\n");
- for(i=0; i<ndynimp; i++)
- Bprint(&outbuf, "dynimport %s %s %s\n", dynimp[i].local, dynimp[i].remote, dynimp[i].path);
- Bprint(&outbuf, "\n$$ // dynexport\n");
- for(i=0; i<ndynexp; i++)
- Bprint(&outbuf, "dynexport %s %s\n", dynexp[i].local, dynexp[i].remote);
+ Bprint(&outbuf, "$$ // cgo\n");
+ Bprint(&outbuf, "%s", fmtstrflush(&pragcgobuf));
Bprint(&outbuf, "\n$$\n\n");
}
Bprint(&outbuf, "!\n");
@@ -472,12 +466,38 @@ outhist(Biobuf *b)
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];
@@ -525,6 +545,11 @@ outhist(Biobuf *b)
pg.to.type = D_CONST;
zwrite(b, &pg, 0, 0);
+
+ if(tofree) {
+ free(tofree);
+ tofree = nil;
+ }
}
}
@@ -566,7 +591,8 @@ zaddr(char *bp, Adr *a, int s)
bp[1] = a->reg;
bp[2] = s;
bp[3] = a->name;
- bp += 4;
+ bp[4] = 0;
+ bp += 5;
switch(a->type) {
default:
diag(Z, "unknown type %d in zaddr", a->type);
diff --git a/src/cmd/5c/txt.c b/src/cmd/5c/txt.c
index 1a189e3af..b8675fe60 100644
--- a/src/cmd/5c/txt.c
+++ b/src/cmd/5c/txt.c
@@ -1176,17 +1176,15 @@ patch(Prog *op, int32 pc)
void
gpseudo(int a, Sym *s, Node *n)
{
-
nextpc();
p->as = a;
p->from.type = D_OREG;
p->from.sym = s;
p->from.name = D_EXTERN;
- if(a == ATEXT) {
+ if(a == ATEXT || a == AGLOBL) {
p->reg = textflag;
textflag = 0;
- } else if(a == AGLOBL)
- p->reg = 0;
+ }
if(s->class == CSTATIC)
p->from.name = D_STATIC;
naddr(n, &p->to);
@@ -1194,6 +1192,18 @@ gpseudo(int a, Sym *s, Node *n)
pc--;
}
+void
+gprefetch(Node *n)
+{
+ Node n1;
+
+ regalloc(&n1, n, Z);
+ gmove(n, &n1);
+ n1.op = OINDREG;
+ gins(APLD, &n1, Z);
+ regfree(&n1);
+}
+
int
sconst(Node *n)
{