summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
Diffstat (limited to '6')
-rw-r--r--6/gen.c16
-rw-r--r--6/gengas.c5
-rw-r--r--6/genp9.c16
-rw-r--r--6/isel.c12
-rw-r--r--6/locs.c8
-rw-r--r--6/main.c4
-rw-r--r--6/simp.c30
7 files changed, 34 insertions, 57 deletions
diff --git a/6/gen.c b/6/gen.c
index 76d15f5..285b2d2 100644
--- a/6/gen.c
+++ b/6/gen.c
@@ -24,22 +24,6 @@ static int islocal(Node *dcl)
return 1;
}
-static int nextlbl;
-char *genlocallblstr(char *buf, size_t sz)
-{
- if (asmsyntax == Plan9)
- snprintf(buf, 128, ".L%d<>", nextlbl++);
- else
- snprintf(buf, 128, ".L%d", nextlbl++);
- return buf;
-}
-
-char *genlblstr(char *buf, size_t sz)
-{
- snprintf(buf, 128, ".L%d", nextlbl++);
- return buf;
-}
-
/*
* For x86, the assembly names are generated as follows:
* local symbols: .name
diff --git a/6/gengas.c b/6/gengas.c
index 16f29a4..926fff9 100644
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -298,7 +298,7 @@ static size_t writelit(FILE *fd, Htab *strtab, Node *v, Type *ty)
if (hthas(strtab, &v->lit.strval)) {
lbl = htget(strtab, &v->lit.strval);
} else {
- lbl = genlocallblstr(buf, sizeof buf);
+ lbl = genlblstr(buf, sizeof buf);
htput(strtab, &v->lit.strval, strdup(lbl));
}
fprintf(fd, "\t.quad %s\n", lbl);
@@ -307,6 +307,9 @@ static size_t writelit(FILE *fd, Htab *strtab, Node *v, Type *ty)
case Lfunc:
die("Generating this shit ain't ready yet ");
break;
+ case Ljtab:
+ die("jtab as data?");
+ break;
case Llbl:
die("Can't generate literal labels, ffs. They're not data.");
break;
diff --git a/6/genp9.c b/6/genp9.c
index ee93db3..0a9082e 100644
--- a/6/genp9.c
+++ b/6/genp9.c
@@ -265,7 +265,7 @@ static size_t writebytes(FILE *fd, char *name, size_t off, char *p, size_t sz)
static size_t writelit(FILE *fd, char *name, size_t off, Htab *strtab, Node *v, Type *ty)
{
char buf[128];
- char *lbl;
+ char *lbl, *local;
size_t sz;
union {
float fv;
@@ -299,14 +299,17 @@ static size_t writelit(FILE *fd, char *name, size_t off, Htab *strtab, Node *v,
if (hthas(strtab, &v->lit.strval)) {
lbl = htget(strtab, &v->lit.strval);
} else {
- lbl = genlocallblstr(buf, sizeof buf);
+ lbl = genlblstr(buf, sizeof buf);
htput(strtab, &v->lit.strval, strdup(lbl));
}
+ local = "";
+ if (*name == '.')
+ local = "<>";
if (v->lit.strval.len > 0)
- fprintf(fd, "DATA %s+%zd(SB)/8,$%s+0(SB)\n", name, off, lbl);
+ fprintf(fd, "DATA %s%s+%zd(SB)/8,$%s+0(SB)\n", name, local, off, lbl);
else
- fprintf(fd, "DATA %s+%zd(SB)/8,$0\n", name, off);
- fprintf(fd, "DATA %s+%zd(SB)/8,$%zd\n", name, off+8, v->lit.strval.len);
+ fprintf(fd, "DATA %s%s+%zd(SB)/8,$0\n", name, local, off);
+ fprintf(fd, "DATA %s%s+%zd(SB)/8,$%zd\n", name, local, off+8, v->lit.strval.len);
break;
case Lfunc:
die("Generating this shit ain't ready yet ");
@@ -314,6 +317,9 @@ static size_t writelit(FILE *fd, char *name, size_t off, Htab *strtab, Node *v,
case Llbl:
die("Can't generate literal labels, ffs. They're not data.");
break;
+ case Ljtab:
+ die("jump table in data section?");
+ break;
}
return sz;
}
diff --git a/6/isel.c b/6/isel.c
index 22d763c..c044464 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -524,6 +524,12 @@ static Loc *gencall(Isel *s, Node *n)
return ret;
}
+void seljtab(Isel *s, Node *n, Node **args)
+{
+ dump(n, stdout);
+ die("jtab not yet implemented");
+}
+
Loc *selexpr(Isel *s, Node *n)
{
Loc *a, *b, *c, *d, *r;
@@ -711,9 +717,9 @@ Loc *selexpr(Isel *s, Node *n)
case Ocjmp:
selcjmp(s, n, args);
break;
- case Ojtab:
- die("jump tables not yet implemented\n");
- break;
+ case Ojtab:
+ seljtab(s, n, args);
+ break;
case Olit: /* fall through */
r = loc(s, n);
break;
diff --git a/6/locs.c b/6/locs.c
index 994e7f4..d460690 100644
--- a/6/locs.c
+++ b/6/locs.c
@@ -31,14 +31,6 @@ int isfloatmode(Mode m)
return m == ModeF || m == ModeD;
}
-Node *genlbl(Srcloc loc)
-{
- char buf[128];
-
- genlblstr(buf, 128);
- return mklbl(loc, buf);
-}
-
Loc *locstrlbl(char *lbl)
{
Loc *l;
diff --git a/6/main.c b/6/main.c
index 8b72843..80d1c1a 100644
--- a/6/main.c
+++ b/6/main.c
@@ -98,7 +98,7 @@ static void assemble(char *asmsrc, char *path)
}
}
-static char *gentemp(char *buf, size_t bufsz, char *path, char *suffix)
+static char *tempfile(char *buf, size_t bufsz, char *path, char *suffix)
{
char *tmpdir;
char *base;
@@ -219,7 +219,7 @@ int main(int argc, char **argv)
else
swapsuffix(buf, sizeof buf, ctx.args[i], ".myr", ".s");
} else {
- gentemp(buf, sizeof buf, ctx.args[i], ".s");
+ tempfile(buf, sizeof buf, ctx.args[i], ".s");
}
gen(file, buf);
assemble(buf, ctx.args[i]);
diff --git a/6/simp.c b/6/simp.c
index 428c804..cb7fc2b 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -295,29 +295,12 @@ static Node *word(Srcloc loc, uint v)
return n;
}
-static Node *gentemp(Simp *simp, Node *e, Type *ty, Node **dcl)
-{
- char buf[128];
- static int nexttmp;
- Node *t, *r, *n;
-
- snprintf(buf, 128, ".t%d", nexttmp++);
- n = mkname(e->loc, buf);
- t = mkdecl(e->loc, n, ty);
- r = mkexpr(e->loc, Ovar, n, NULL);
- r->expr.type = t->decl.type;
- r->expr.did = t->decl.did;
- if (dcl)
- *dcl = t;
- return r;
-}
-
-static Node *temp(Simp *simp, Node *e)
+Node *temp(Simp *simp, Node *e)
{
Node *t, *dcl;
assert(e->type == Nexpr);
- t = gentemp(simp, e, e->expr.type, &dcl);
+ t = gentemp(e, e->expr.type, &dcl);
if (stacknode(e))
declarelocal(simp, dcl);
return t;
@@ -472,7 +455,7 @@ static void simpiter(Simp *s, Node *n)
zero->expr.type = tyintptr;
seq = rval(s, n->iterstmt.seq, NULL);
- idx = gentemp(s, n, tyintptr, &dcl);
+ idx = gentemp(n, tyintptr, &dcl);
declarelocal(s, dcl);
/* setup */
@@ -1450,6 +1433,9 @@ static Node *rval(Simp *s, Node *n, Node *dst)
case Lfunc:
r = simpblob(s, n, &file->file.stmts, &file->file.nstmts);
break;
+ case Ljtab:
+ die("jump table as lit");
+ break;
}
break;
case Ovar:
@@ -1643,11 +1629,11 @@ static void flatten(Simp *s, Node *f)
ty = f->func.type->sub[0];
if (stacktype(ty)) {
s->isbigret = 1;
- s->ret = gentemp(s, f, mktyptr(f->loc, ty), &dcl);
+ s->ret = gentemp(f, mktyptr(f->loc, ty), &dcl);
declarearg(s, dcl);
} else if (ty->type != Tyvoid) {
s->isbigret = 0;
- s->ret = gentemp(s, f, ty, &dcl);
+ s->ret = gentemp(f, ty, &dcl);
}
for (i = 0; i < f->func.nargs; i++) {