summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2019-02-26 14:07:58 -0800
committerOri Bernstein <ori@markovcorp.com>2019-02-26 14:07:58 -0800
commitd87c0959d85b40fcf60b9c6dd0a2f2111f888b55 (patch)
tree3d9ee97668eda3d4e2656ac069f8575250edc7e2 /6
parent02201160614e5f25a7a73d86ed26a1f90fa4f5bb (diff)
downloadmc-d87c0959d85b40fcf60b9c6dd0a2f2111f888b55.tar.gz
Accept that `file` isn't a node.
Shrink node sizes, simplify code a bit.
Diffstat (limited to '6')
-rw-r--r--6/asm.h6
-rw-r--r--6/blob.c2
-rw-r--r--6/gen.c14
-rw-r--r--6/gengas.c14
-rw-r--r--6/genp9.c10
-rw-r--r--6/isel.c6
-rw-r--r--6/main.c29
-rw-r--r--6/simp.c10
8 files changed, 46 insertions, 45 deletions
diff --git a/6/asm.h b/6/asm.h
index 0c6e13e..fe33b3f 100644
--- a/6/asm.h
+++ b/6/asm.h
@@ -256,9 +256,9 @@ void initconsts(Htab *globls);
void fillglobls(Stab *st, Htab *globls);
void simpglobl(Node *dcl, Htab *globls, Func ***fn, size_t *nfn, Node ***blob, size_t *nblob);
void selfunc(Isel *is, Func *fn, Htab *globls, Htab *strtab);
-void gen(Node *file, char *out);
-void gengas(Node *file, FILE *fd);
-void genp9(Node *file, FILE *fd);
+void gen(char *out);
+void gengas(FILE *fd);
+void genp9(FILE *fd);
/* blob stuff */
Blob *mkblobpad(size_t sz);
diff --git a/6/blob.c b/6/blob.c
index ffa2e1e..9301723 100644
--- a/6/blob.c
+++ b/6/blob.c
@@ -332,7 +332,7 @@ blobrec(Blob *b, Htab *globls, Htab *strtab, Node *n)
sz += blobpad(b, end - sz);
break;
default:
- dump(n, stdout);
+ dumpn(n, stdout);
die("Nonliteral initializer for global");
break;
}
diff --git a/6/gen.c b/6/gen.c
index abde13a..8b6e222 100644
--- a/6/gen.c
+++ b/6/gen.c
@@ -33,9 +33,9 @@ fillglobls(Stab *st, Htab *globls)
}
free(k);
- ns = htkeys(file->file.ns, &nns);
+ ns = htkeys(file.ns, &nns);
for (j = 0; j < nns; j++) {
- stab = htget(file->file.ns, ns[j]);
+ stab = htget(file.ns, ns[j]);
k = htkeys(stab->dcl, &nk);
for (i = 0; i < nk; i++) {
s = htget(stab->dcl, k[i]);
@@ -173,8 +173,8 @@ tydescid(char *buf, size_t bufsz, Type *ty)
for (i = 0; i < ty->narg; i++)
p += tyidfmt(p, end - p, ty->arg[i]);
} else {
- if (file->file.globls->name) {
- ns = file->file.globls->name;
+ if (file.globls->name) {
+ ns = file.globls->name;
sep = "$";
}
bprintf(buf, bufsz, "_tydesc%s%s$%d",sep, ns, ty->tid);
@@ -183,7 +183,7 @@ tydescid(char *buf, size_t bufsz, Type *ty)
}
void
-gen(Node *file, char *out)
+gen(char *out)
{
FILE *fd;
@@ -193,11 +193,11 @@ gen(Node *file, char *out)
switch (asmsyntax) {
case Plan9:
- genp9(file, fd);
+ genp9(fd);
break;
case Gnugaself:
case Gnugasmacho:
- gengas(file, fd);
+ gengas(fd);
break;
default:
die("unknown target"); break;
diff --git a/6/gengas.c b/6/gengas.c
index 1097b30..991e30b 100644
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -433,7 +433,7 @@ genblob(FILE *fd, Node *blob, Htab *globls, Htab *strtab)
}
void
-gengas(Node *file, FILE *fd)
+gengas(FILE *fd)
{
Htab *globls, *strtab;
Node *n, **blob;
@@ -456,11 +456,11 @@ gengas(Node *file, FILE *fd)
initconsts(globls);
/* We need to define all global variables before use */
- fillglobls(file->file.globls, globls);
+ fillglobls(file.globls, globls);
- pushstab(file->file.globls);
- for (i = 0; i < file->file.nstmts; i++) {
- n = file->file.stmts[i];
+ pushstab(file.globls);
+ for (i = 0; i < file.nstmts; i++) {
+ n = file.stmts[i];
switch (n->type) {
case Nuse: /* nothing to do */
case Nimpl:
@@ -478,8 +478,8 @@ gengas(Node *file, FILE *fd)
if (!getcwd(dir, sizeof dir))
die("could not get cwd: %s\n", strerror(errno));
- for (i = 0; i < file->file.nfiles; i++) {
- path = file->file.files[i];
+ for (i = 0; i < file.nfiles; i++) {
+ path = file.files[i];
fprintf(fd, ".file %zd \"%s/%s\"\n", i + 1, dir, path);
}
diff --git a/6/genp9.c b/6/genp9.c
index 4a19891..32af6de 100644
--- a/6/genp9.c
+++ b/6/genp9.c
@@ -431,7 +431,7 @@ genblob(FILE *fd, Node *blob, Htab *globls, Htab *strtab)
}
void
-genp9(Node *file, FILE *fd)
+genp9(FILE *fd)
{
Htab *globls, *strtab;
Node *n, **blob;
@@ -453,11 +453,11 @@ genp9(Node *file, FILE *fd)
initconsts(globls);
/* We need to define all global variables before use */
- fillglobls(file->file.globls, globls);
+ fillglobls(file.globls, globls);
- pushstab(file->file.globls);
- for (i = 0; i < file->file.nstmts; i++) {
- n = file->file.stmts[i];
+ pushstab(file.globls);
+ for (i = 0; i < file.nstmts; i++) {
+ n = file.stmts[i];
switch (n->type) {
case Nuse: /* nothing to do */
case Nimpl:
diff --git a/6/isel.c b/6/isel.c
index bb111ad..99988a3 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -948,7 +948,7 @@ selexpr(Isel *s, Node *n)
case Oslice: case Oidx: case Osize: case Otupget: case Otupmemb:
case Obreak: case Ocontinue:
case Numops:
- dump(n, stdout);
+ dumpn(n, stdout);
die("Should not see %s in isel", opstr[exprop(n)]);
break;
}
@@ -1116,7 +1116,7 @@ selfunc(Isel *is, Func *fn, Htab *globls, Htab *strtab)
fileid = fn->loc.file;
if (fileid >= 0 && fn->loc.line > 0) {
- path = file->file.files[fileid];
+ path = file.files[fileid];
bprintf(buf, sizeof buf, "%s/%s:%d", is->cwd, path, fn->loc.line);
g(is, Icomment, locstrlbl(buf), NULL);
bprintf(buf, sizeof buf, "%zd %d", fileid + 1, fn->loc.line);
@@ -1136,7 +1136,7 @@ selfunc(Isel *is, Func *fn, Htab *globls, Htab *strtab)
fileid = n->loc.file;
if (n->loc.file >= 0 && n->loc.line != -1 && n->loc.line != lastline) {
lastline = n->loc.line;
- path = file->file.files[fileid];
+ path = file.files[fileid];
bprintf(buf, sizeof buf, "%s/%s:%d", is->cwd, path, n->loc.line);
g(is, Icomment, locstrlbl(buf), NULL);
bprintf(buf, sizeof buf, "%zd %d", fileid + 1, n->loc.line);
diff --git a/6/main.c b/6/main.c
index c980887..618eb5f 100644
--- a/6/main.c
+++ b/6/main.c
@@ -21,7 +21,7 @@
#include "../config.h"
/* FIXME: move into one place...? */
-Node *file;
+File file;
char debugopt[128];
int writeasm;
int extracheck = 1;
@@ -161,12 +161,12 @@ gentempfile(char *buf, size_t bufsz, char *path, char *suffix)
}
static int
-hasmain(Node *file)
+hasmain(void)
{
Node *n, *name;
name = mknsname(Zloc, NULL, "main");
- n = getdcl(file->file.globls, name);
+ n = getdcl(file.globls, name);
if (!n)
return 0;
n = n->decl.name;
@@ -201,7 +201,7 @@ genuse(char *path)
fprintf(stderr, "could not open path %s\n", buf);
exit(1);
}
- writeuse(f, file);
+ writeuse(f);
fclose(f);
}
@@ -285,25 +285,26 @@ main(int argc, char **argv)
globls = mkstab(0);
tyinit(globls);
tokinit(ctx.args[i]);
- file = mkfile(ctx.args[i]);
- file->file.globls = globls;
+ file.ns = mkht(strhash, streq);
+ file.globls = globls;
+ lappend(&file.files, &file.nfiles, ctx.args[i]);
yyparse();
/* before we do anything to the parse */
if (debugopt['T'])
- dump(file, stdout);
+ dump(stdout);
loaduses();
- if (hasmain(file)) {
- genautocall(file->file.init, file->file.ninit,
- file->file.localinit, "__init__");
- genautocall(file->file.fini, file->file.nfini,
- file->file.localfini, "__fini__");
+ if (hasmain()) {
+ genautocall(file.init, file.ninit,
+ file.localinit, "__init__");
+ genautocall(file.fini, file.nfini,
+ file.localfini, "__fini__");
}
infer();
tagexports(0);
/* after all type inference */
if (debugopt['t'])
- dump(file, stdout);
+ dump(stdout);
if (writeasm) {
if (outfile != NULL)
@@ -314,7 +315,7 @@ main(int argc, char **argv)
gentempfile(buf, sizeof buf, ctx.args[i], ".s");
}
genuse(ctx.args[i]);
- gen(file, buf);
+ gen(buf);
assemble(buf, ctx.args[i]);
free(localincpath);
diff --git a/6/simp.c b/6/simp.c
index cff77ba..d175e4e 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -73,7 +73,7 @@ static void
append(Simp *s, Node *n)
{
if (debugopt['S'])
- dump(n, stdout);
+ dumpn(n, stdout);
assert(n->type != Ndecl);
lappend(&s->stmts, &s->nstmts, n);
}
@@ -172,7 +172,7 @@ forcelocal(Simp *s, Node *n)
s->stksz += size(n);
s->stksz = align(s->stksz, min(size(n), Ptrsz));
if (debugopt['i']) {
- dump(n, stdout);
+ dumpn(n, stdout);
printf("declared at %zd, size = %zd\n", s->stksz, size(n));
}
htput(s->stkoff, n, itop(s->stksz));
@@ -394,7 +394,7 @@ simpcode(Simp *s, Node *fn)
r->decl.isconst = 1;
r->decl.isglobl = 1;
htput(s->globls, d, asmname(d));
- lappend(&file->file.stmts, &file->file.nstmts, d);
+ lappend(&file.stmts, &file.nstmts, d);
return r;
}
@@ -1348,7 +1348,7 @@ simp(Simp *s, Node *n)
append(s, r);
break;
default:
- dump(n, stderr);
+ dumpn(n, stderr);
die("bad node passsed to simp()");
break;
}
@@ -1465,7 +1465,7 @@ simpfn(Simp *s, char *name, Node *dcl)
if (debugopt['f'] || debugopt['F'])
for (i = 0; i < s->nstmts; i++)
- dump(s->stmts[i], stdout);
+ dumpn(s->stmts[i], stdout);
for (i = 0; i < s->nstmts; i++) {
if (s->stmts[i]->type != Nexpr)
continue;