ref: 04a014003d9dc62fc5fe80ad51958a39bb9d2f2a
parent: 5ebd3da62bc8a5e0633647dfb481ea9ecdb82286
author: Ori Bernstein <[email protected]>
date: Wed Apr 25 19:23:26 EDT 2012
Add in start to dumping compilations. So far, it seems to work; Will be useful for debugging as we develop the code gen.
--- a/8/Makefile
+++ b/8/Makefile
@@ -5,6 +5,7 @@
CFLAGS+=-I../parse
LDFLAGS+=-L../parse -lparse
+EXTRADEP=../parse/libparse.a
include ../mk/lexyacc.mk
include ../mk/c.mk
--- a/8/gen.h
+++ b/8/gen.h
@@ -43,7 +43,7 @@
/* edges */
Bb **in;
size_t nin;
- Bb *out;
+ Bb **out;
size_t nout;
};
@@ -51,6 +51,7 @@
Comp *mkcomp(Node *f);
void gen(Node *file, char *out);
void assemble(char *asmfile, char *out);
+void compdump(Comp *c, FILE *fd);
/* cfg */
Fn *mkfn(char *name);
--- a/8/simp.c
+++ b/8/simp.c
@@ -86,12 +86,10 @@
return mklbl(-1, strdup(buf));
}
-/* support functions */
static void jmp(Comp *c, Fn *fn, Node *targ)
{
}
-/* support functions */
static void cjmp(Comp *c, Fn *fn, Node *cond, Node *iftrue, Node *iffalse)
{
}
@@ -242,6 +240,66 @@
return s->isconst && s->type->type == Tyfunc;
}
+void blobdump(Blob *b, FILE *fd)
+{
+ int i;
+ char *p;
+
+ p = b->data;
+ fprintf(fd, "\t%s => ", b->name);
+ for (i = 0; i < b->ndata; i++)
+ if (isprint(p[i]))
+ fprintf(fd, "%c", p[i]);
+ else
+ fprintf(fd, "\\%x", p[i]);
+ fprintf(fd, "\n");
+}
+
+void bbdump(Bb *bb, FILE *fd)
+{
+ int i;
+ char *sep = "";
+
+ fprintf(fd, "\t\tbb %d\n", bb->id);
+ fprintf(fd, "\t\t\tin = [ ");
+ for (i = 0; i < bb->nin; i++) {
+ fprintf(fd, "%s%d ", sep, bb->in[i]->id);
+ sep = ",";
+ }
+ fprintf(fd, "]\n");
+ sep = "";
+ fprintf(fd, "\t\t\tout = [ ");
+ for (i = 0; i < bb->nout; i++) {
+ fprintf(fd, "%s%d ", sep, bb->out[i]->id);
+ sep = ",";
+ }
+ fprintf(fd, "]\n");
+
+ for (i = 0; i < bb->nn; i++)
+ dump(bb->n[i], fd);
+}
+
+void fndump(Fn *f, FILE *fd)
+{
+ int i;
+
+ fprintf(fd, "\tfn %s\n", f->name);
+ for (i = 0; i < f->nbb; i++)
+ bbdump(f->bb[i], fd);
+}
+
+void compdump(Comp *c, FILE *fd)
+{
+ int i;
+
+ fprintf(fd, "** globals **:\n");
+ for (i = 0; i < c->nglobl; i++)
+ blobdump(c->globl[i], fd);
+ fprintf(fd, "** funcs **:\n");
+ for (i = 0; i < c->nfunc; i++)
+ fndump(c->func[i], fd);
+}
+
void gen(Node *file, char *out)
{
Node **n;
@@ -274,6 +332,7 @@
break;
}
}
+ compdump(c, stdout);
/*
isel();
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -153,6 +153,7 @@
case Lbool: fprintf(fd, " Lbool %s\n", n->lit.boolval ? "true" : "false"); break;
case Lint: fprintf(fd, " Lint %llu\n", n->lit.intval); break;
case Lflt: fprintf(fd, " Lflt %lf\n", n->lit.fltval); break;
+ case Lstr: fprintf(fd, " Lstr %s\n", n->lit.strval); break;
case Lfunc:
fprintf(fd, " Lfunc\n");
outnode(n->lit.fnval, fd, depth+1);