commit e53054c0764bd088b51f893dcb33b5321422eff7
parent b5d98b762f5838a9d2659ac6619f343f61970201
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Thu, 8 Oct 2015 22:02:32 -0400
allow multiple functions in file
Diffstat:
4 files changed, 45 insertions(+), 44 deletions(-)
diff --git a/lisc/emit.c b/lisc/emit.c
@@ -383,7 +383,6 @@ emitdat(Dat *d, FILE *f)
fprintf(f, ".data\n");
break;
case DEnd:
- fprintf(f, "\n");
break;
case DName:
fprintf(f,
diff --git a/lisc/lisc.h b/lisc/lisc.h
@@ -307,7 +307,7 @@ Ref getcon(int64_t, Fn *);
/* parse.c */
extern OpDesc opdesc[NOp];
-Fn *parse(FILE *, void (Dat *));
+void parse(FILE *, void (Dat *), void (Fn *));
void printfn(Fn *, FILE *);
/* ssa.c */
diff --git a/lisc/main.c b/lisc/main.c
@@ -10,6 +10,8 @@ char debug['Z'+1] = {
['R'] = 0, /* reg. allocation */
};
+static int dbg;
+
void
dumpts(Bits *b, Tmp *tmp, FILE *f)
{
@@ -25,18 +27,51 @@ dumpts(Bits *b, Tmp *tmp, FILE *f)
static void
data(Dat *d)
{
+ if (d->type == DEnd) {
+ puts("/* end data */\n");
+ freeall();
+ }
emitdat(d, stdout);
}
+static void
+func(Fn *fn)
+{
+ int n;
+
+ if (debug['P']) {
+ fprintf(stderr, "\n> After parsing:\n");
+ printfn(fn, stderr);
+ }
+ isel(fn);
+ fillrpo(fn);
+ fillpreds(fn);
+ filllive(fn);
+ fillcost(fn);
+ fillphi(fn);
+ spill(fn);
+ rega(fn);
+ fillrpo(fn);
+ assert(fn->rpo[0] == fn->start);
+ for (n=0;; n++)
+ if (n == fn->nblk-1) {
+ fn->rpo[n]->link = 0;
+ break;
+ } else
+ fn->rpo[n]->link = fn->rpo[n+1];
+ if (!dbg) {
+ emitfn(fn, stdout);
+ puts("/* end function */\n");
+ } else
+ fprintf(stderr, "\n");
+ freeall();
+}
+
int
main(int ac, char *av[])
{
char *o, *f;
FILE *inf;
- Fn *fn;
- int n, dbg;
-
- dbg = 0;
if (ac > 1 && strncmp(av[1], "-d", 2) == 0) {
if (av[1][2] == 0) {
@@ -66,33 +101,8 @@ main(int ac, char *av[])
}
}
- fn = parse(inf, data);
+ parse(inf, data, func);
fclose(inf);
- if (debug['P']) {
- fprintf(stderr, "\n> After parsing:\n");
- printfn(fn, stderr);
- }
- isel(fn);
- fillrpo(fn);
- fillpreds(fn);
- filllive(fn);
- fillcost(fn);
- fillphi(fn);
- spill(fn);
- rega(fn);
- fillrpo(fn);
- assert(fn->rpo[0] == fn->start);
- for (n=0;; n++)
- if (n == fn->nblk-1) {
- fn->rpo[n]->link = 0;
- break;
- } else
- fn->rpo[n]->link = fn->rpo[n+1];
- if (!dbg)
- emitfn(fn, stdout);
- else
- fprintf(stderr, "\n");
- freeall();
exit(0);
Usage:
diff --git a/lisc/parse.c b/lisc/parse.c
@@ -778,12 +778,9 @@ parsedat(void cb(Dat *))
cb(&d);
}
-Fn *
-parse(FILE *f, void data(Dat *))
+void
+parse(FILE *f, void data(Dat *), void func(Fn *))
{
- Fn *fn;
-
- fn = 0;
inf = f;
lnum = 1;
thead = TXXX;
@@ -791,12 +788,7 @@ parse(FILE *f, void data(Dat *))
for (;;)
switch (nextnl()) {
case TFunc:
- if (fn)
- /* todo, support multiple
- * functions per file
- */
- diag("too many functions");
- fn = parsefn();
+ func(parsefn());
break;
case TType:
parsetyp();
@@ -805,7 +797,7 @@ parse(FILE *f, void data(Dat *))
parsedat(data);
break;
case TEOF:
- return fn;
+ return;
default:
err("top-level definition expected");
break;