summaryrefslogtreecommitdiff
path: root/utils/6c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/6c')
-rw-r--r--utils/6c/README1
-rw-r--r--utils/6c/cgen.c15
-rw-r--r--utils/6c/gc.h5
-rw-r--r--utils/6c/mkfile1
-rw-r--r--utils/6c/reg.c4
-rw-r--r--utils/6c/swt.c27
-rw-r--r--utils/6c/txt.c18
7 files changed, 31 insertions, 40 deletions
diff --git a/utils/6c/README b/utils/6c/README
deleted file mode 100644
index 602f5378..00000000
--- a/utils/6c/README
+++ /dev/null
@@ -1 +0,0 @@
-this is an intermediate version not yet ready for use
diff --git a/utils/6c/cgen.c b/utils/6c/cgen.c
index 74b6389f..6b1e9418 100644
--- a/utils/6c/cgen.c
+++ b/utils/6c/cgen.c
@@ -439,9 +439,10 @@ cgen(Node *n, Node *nn)
if(o == OLDIV || o == OLMOD)
zeroregm(&nod1);
if(r->addable < INDEXED || r->op == OCONST) {
- regsalloc(&nod3, r);
+ regalloc(&nod3, r, Z);
cgen(r, &nod3);
gopcode(o, n->type, &nod3, Z);
+ regfree(&nod3);
} else
gopcode(o, n->type, r, Z);
} else {
@@ -573,7 +574,7 @@ cgen(Node *n, Node *nn)
reglcgen(&nod, l, Z);
else
nod = *l;
- if(o != OASMUL && o != OASADD) {
+ if(o != OASMUL && o != OASADD || !typefd[l->type->etype]) {
regalloc(&nod2, r, Z);
gmove(&nod, &nod2);
gopcode(o, r->type, &nod1, &nod2);
@@ -1595,7 +1596,7 @@ copy:
regsalloc(&nod2, nn);
nn->type = t;
- gins(AMOVL, &nod1, &nod2);
+ gins(AMOVQ, &nod1, &nod2);
regfree(&nod1);
nod2.type = typ(TIND, t);
@@ -1696,7 +1697,7 @@ copy:
c = 0;
if(n->complex > nn->complex) {
t = n->type;
- n->type = types[TLONG];
+ n->type = types[TIND];
nodreg(&nod1, n, D_SI);
if(reg[D_SI]) {
gins(APUSHQ, &nod1, Z);
@@ -1707,7 +1708,7 @@ copy:
n->type = t;
t = nn->type;
- nn->type = types[TLONG];
+ nn->type = types[TIND];
nodreg(&nod2, nn, D_DI);
if(reg[D_DI]) {
warn(Z, "DI botch");
@@ -1719,7 +1720,7 @@ warn(Z, "DI botch");
nn->type = t;
} else {
t = nn->type;
- nn->type = types[TLONG];
+ nn->type = types[TIND];
nodreg(&nod2, nn, D_DI);
if(reg[D_DI]) {
warn(Z, "DI botch");
@@ -1731,7 +1732,7 @@ warn(Z, "DI botch");
nn->type = t;
t = n->type;
- n->type = types[TLONG];
+ n->type = types[TIND];
nodreg(&nod1, n, D_SI);
if(reg[D_SI]) {
gins(APUSHQ, &nod1, Z);
diff --git a/utils/6c/gc.h b/utils/6c/gc.h
index 57d3a999..22ae99bc 100644
--- a/utils/6c/gc.h
+++ b/utils/6c/gc.h
@@ -270,7 +270,7 @@ void gpseudo(int, Sym*, Node*);
/*
* swt.c
*/
-int swcmp(const void*, const void*);
+int swcmp(void*, void*);
void doswit(Node*);
void swit1(C1*, int, long, Node*);
void casf(void);
@@ -278,7 +278,6 @@ void bitload(Node*, Node*, Node*, Node*, Node*);
void bitstore(Node*, Node*, Node*, Node*, Node*);
long outstring(char*, long);
void nullwarn(Node*, Node*);
-void sextern(Sym*, Node*, long, long);
void gextern(Sym*, Node*, long, long);
void outcode(void);
void ieeedtod(Ieee*, double);
@@ -299,7 +298,7 @@ int Bconv(Fmt*);
* reg.c
*/
Reg* rega(void);
-int rcmp(const void*, const void*);
+int rcmp(void*, void*);
void regopt(Prog*);
void addmove(Reg*, int, int, int);
Bits mkvar(Reg*, Adr*);
diff --git a/utils/6c/mkfile b/utils/6c/mkfile
index 4f1803e6..e8aab371 100644
--- a/utils/6c/mkfile
+++ b/utils/6c/mkfile
@@ -1,6 +1,5 @@
<../../mkconfig
-TARG=6ca
TARG=6c
OFILES=\
diff --git a/utils/6c/reg.c b/utils/6c/reg.c
index 32b9abf5..e04cb5fb 100644
--- a/utils/6c/reg.c
+++ b/utils/6c/reg.c
@@ -16,7 +16,7 @@ rega(void)
}
int
-rcmp(const void *a1, const void *a2)
+rcmp(void *a1, void *a2)
{
Rgn *p1, *p2;
int c1, c2;
@@ -50,6 +50,8 @@ regopt(Prog *p)
lastr = R;
nvar = 0;
regbits = RtoB(D_SP) | RtoB(D_AX) | RtoB(D_X0);
+ if(REGEXT)
+ regbits |= RtoB(REGEXT) | RtoB(REGEXT-1);
for(z=0; z<BITS; z++) {
externs.b[z] = 0;
params.b[z] = 0;
diff --git a/utils/6c/swt.c b/utils/6c/swt.c
index b201c9ca..c0b4d844 100644
--- a/utils/6c/swt.c
+++ b/utils/6c/swt.c
@@ -9,7 +9,7 @@ swit1(C1 *q, int nc, long def, Node *n)
if(nc < 5) {
for(i=0; i<nc; i++) {
- if(debug['W'])
+ if(debug['K'])
print("case = %.8llux\n", q->val);
gcmp(OEQ, n, q->val);
patch(p, q->label);
@@ -21,7 +21,7 @@ swit1(C1 *q, int nc, long def, Node *n)
}
i = nc / 2;
r = q+i;
- if(debug['W'])
+ if(debug['K'])
print("case > %.8llux\n", r->val);
gcmp(OGT, n, r->val);
sp = p;
@@ -30,7 +30,7 @@ swit1(C1 *q, int nc, long def, Node *n)
patch(p, r->label);
swit1(q, i, def, n);
- if(debug['W'])
+ if(debug['K'])
print("case < %.8llux\n", r->val);
patch(sp, pc);
swit1(r+1, nc-i-1, def, n);
@@ -128,23 +128,6 @@ outstring(char *s, long n)
}
void
-sextern(Sym *s, Node *a, long o, long w)
-{
- long e, lw;
-
- for(e=0; e<w; e+=NSNAME) {
- lw = NSNAME;
- if(w-e < lw)
- lw = w-e;
- gpseudo(ADATA, s, nodconst(0L));
- p->from.offset += o+e;
- p->from.scale = lw;
- p->to.type = D_SCONST;
- memmove(p->to.sval, a->cstring+e, lw);
- }
-}
-
-void
gextern(Sym *s, Node *a, long o, long w)
{
if(0 && a->op == OCONST && typev[a->type->etype]) {
@@ -523,8 +506,8 @@ align(long i, Type *t, int op)
long
maxround(long max, long v)
{
- v += SZ_VLONG-1;
+ v = round(v, SZ_VLONG);
if(v > max)
- max = round(v, SZ_VLONG);
+ return v;
return max;
}
diff --git a/utils/6c/txt.c b/utils/6c/txt.c
index 9d9c86b1..e3b9a9ee 100644
--- a/utils/6c/txt.c
+++ b/utils/6c/txt.c
@@ -1,5 +1,7 @@
#include "gc.h"
+static int resvreg[nelem(reg)];
+
void
ginit(void)
{
@@ -23,6 +25,7 @@ ginit(void)
tfield = types[TINT];
typeword = typechlvp;
+ typeswitch = typechlv;
typecmplx = typesu;
/* TO DO */
@@ -93,6 +96,7 @@ ginit(void)
if(0)
com64init();
+ memset(reg, 0, sizeof(reg));
for(i=0; i<nelem(reg); i++) {
reg[i] = 1;
if(i >= D_AX && i <= D_R15 && i != D_SP)
@@ -100,6 +104,10 @@ ginit(void)
if(i >= D_X0 && i <= D_X7)
reg[i] = 0;
}
+ /* keep two external registers */
+ reg[REGEXT] = 1;
+ reg[REGEXT-1] = 1;
+ memmove(resvreg, reg, sizeof(resvreg));
}
void
@@ -110,10 +118,10 @@ gclean(void)
reg[D_SP]--;
for(i=D_AX; i<=D_R15; i++)
- if(reg[i])
+ if(reg[i] && !resvreg[i])
diag(Z, "reg %R left allocated", i);
for(i=D_X0; i<=D_X7; i++)
- if(reg[i])
+ if(reg[i] && !resvreg[i])
diag(Z, "reg %R left allocated", i);
while(mnstring)
outstring("", 1L);
@@ -178,7 +186,7 @@ nareg(void)
n = 0;
for(i=D_AX; i<=D_R15; i++)
- if(reg[i] == 0)
+ if(reg[i] == 0 && !resvreg[i])
n++;
return n;
}
@@ -336,7 +344,7 @@ regalloc(Node *n, Node *tn, Node *o)
goto out;
}
for(i=D_AX; i<=D_R15; i++)
- if(reg[i] == 0)
+ if(reg[i] == 0 && !resvreg[i])
goto out;
diag(tn, "out of fixed registers");
goto err;
@@ -349,7 +357,7 @@ regalloc(Node *n, Node *tn, Node *o)
goto out;
}
for(i=D_X0; i<=D_X7; i++)
- if(reg[i] == 0)
+ if(reg[i] == 0 && !resvreg[i])
goto out;
diag(tn, "out of float registers");
goto out;