summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-07-14 22:41:42 -0400
committerOri Bernstein <ori@eigenstate.org>2014-07-14 22:41:42 -0400
commit70089e1bc3d39c6c0f5195a63f4beb7e586b4c99 (patch)
tree8a2c029f83b29190face9fa7395e97183661d701
parent65373d4ddad67da6f711b6ab962f18e9d8e6a558 (diff)
downloadmc-70089e1bc3d39c6c0f5195a63f4beb7e586b4c99.tar.gz
Indent trace information.
-rw-r--r--parse/dump.c40
-rw-r--r--parse/infer.c29
-rw-r--r--parse/parse.h5
-rw-r--r--parse/util.c25
-rwxr-xr-xtest/genericmakebin179952 -> 179952 bytes
5 files changed, 62 insertions, 37 deletions
diff --git a/parse/dump.c b/parse/dump.c
index e921b1c..dba4826 100644
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -11,13 +11,6 @@
#include "parse.h"
-static void indent(FILE *fd, int depth)
-{
- int i;
- for (i = 0; i < depth; i++)
- fprintf(fd, " ");
-}
-
/* outputs a fully qualified name */
static void outname(Node *n, FILE *fd)
{
@@ -33,11 +26,10 @@ static void outsym(Node *s, FILE *fd, int depth)
{
char buf[1024];
- indent(fd, depth);
if (s->decl.isconst)
- fprintf(fd, "const ");
+ findentf(fd, depth, "const ");
else
- fprintf(fd, "var ");
+ findentf(fd, depth, "var ");
outname(s->decl.name, fd);
fprintf(fd, " : %s\n", tyfmt(buf, 1024, s->decl.type));
}
@@ -63,16 +55,14 @@ static void outstab(Stab *st, FILE *fd, int depth)
char *ty;
Type *t;
- indent(fd, depth);
- fprintf(fd, "Stab %p (super = %p, name=\"%s\")\n", st, st->super, namestr(st->name));
+ findentf(fd, depth, "Stab %p (super = %p, name=\"%s\")\n", st, st->super, namestr(st->name));
if (!st)
return;
/* print types */
k = htkeys(st->ty, &n);
for (i = 0; i < n; i++) {
- indent(fd, depth + 1);
- fprintf(fd, "T ");
+ findentf(fd, depth, "T ");
/* already indented */
outname(k[i], fd);
t = gettype(st, k[i]);
@@ -85,8 +75,7 @@ static void outstab(Stab *st, FILE *fd, int depth)
/* dump declarations */
k = htkeys(st->dcl, &n);
for (i = 0; i < n; i++) {
- indent(fd, depth + 1);
- fprintf(fd, "S ");
+ findentf(fd, depth, "S ");
/* already indented */
outsym(getdcl(st, k[i]), fd, 0);
}
@@ -95,8 +84,7 @@ static void outstab(Stab *st, FILE *fd, int depth)
/* dump sub-namespaces */
k = htkeys(st->ns, &n);
for (i = 0; i < n; i++) {
- indent(fd, depth + 1);
- fprintf(fd, "N %s\n", (char*)k[i]);
+ findentf(fd, depth + 1, "N %s\n", (char*)k[i]);
outstab(getns_str(st, k[i]), fd, depth + 1);
}
free(k);
@@ -118,20 +106,17 @@ static void outnode(Node *n, FILE *fd, int depth)
int tid;
char buf[1024];
- indent(fd, depth);
if (!n) {
- fprintf(fd, "Nil\n");
+ findentf(fd, depth, "Nil\n");
return;
}
- fprintf(fd, "%s", nodestr(n->type));
+ findentf(fd, depth, "%s", nodestr(n->type));
switch(n->type) {
case Nfile:
fprintf(fd, "(name = %s)\n", n->file.name);
- indent(fd, depth + 1);
- fprintf(fd, "Globls:\n");
+ findentf(fd, depth + 1, "Globls:\n");
outstab(n->file.globls, fd, depth + 2);
- indent(fd, depth + 1);
- fprintf(fd, "Exports:\n");
+ findentf(fd, depth + 1, "Exports:\n");
outstab(n->file.exports, fd, depth + 2);
for (i = 0; i < n->file.nuses; i++)
outnode(n->file.uses[i], fd, depth + 1);
@@ -219,8 +204,7 @@ static void outnode(Node *n, FILE *fd, int depth)
fprintf(fd, " (args =\n");
for (i = 0; i < n->func.nargs; i++)
outnode(n->func.args[i], fd, depth+1);
- indent(fd, depth);
- fprintf(fd, ")\n");
+ findentf(fd, depth, ")\n");
outstab(n->func.scope, fd, depth + 1);
outnode(n->func.body, fd, depth+1);
break;
@@ -233,7 +217,7 @@ static void outnode(Node *n, FILE *fd, int depth)
break;
case Nimpl:
fprintf(fd, "(name = %s, type = %s)\n", namestr(n->impl.traitname), tyfmt(buf, sizeof buf, n->impl.type));
- indent(fd, depth);
+ findentf(fd, depth, "");
outnode(n->impl.traitname, fd, depth + 1);
for (i = 0; i < n->impl.ndecls; i++)
outnode(n->impl.decls[i], fd, depth+1);
diff --git a/parse/infer.c b/parse/infer.c
index 0e70b05..1b70b94 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -17,6 +17,7 @@ typedef struct Inferstate Inferstate;
struct Inferstate {
int ingeneric;
int sawret;
+ int indentdepth;
Type *ret;
/* bound by patterns turn into decls in the action block */
@@ -226,22 +227,26 @@ static int needfreshen(Inferstate *st, Type *t)
static Type *tyfreshen(Inferstate *st, Type *t)
{
Htab *ht;
+ char *from, *to;
if (!needfreshen(st, t)) {
if (debugopt['u'])
- printf("%s isn't generic: skipping freshen\n", tystr(t));
+ indentf(st->indentdepth, "%s isn't generic: skipping freshen\n", tystr(t));
return t;
}
- if (debugopt['u'])
- printf("Freshen %s => ", tystr(t));
+ from = tystr(t);
tybind(st, t);
ht = mkht(tyhash, tyeq);
t = tyspecialize(t, ht);
htfree(ht);
tyunbind(st, t);
- if (debugopt['u'])
- printf("%s\n", tystr(t));
+ if (debugopt['u']) {
+ to = tystr(t);
+ indentf(st->indentdepth, "Freshen %s => %s\n", from, to);
+ free(from);
+ free(to);
+ }
return t;
}
@@ -443,7 +448,7 @@ static void putbindings(Inferstate *st, Htab *bt, Type *t)
if (debugopt['u']) {
s = tystr(t);
- printf("Bind %s\n", s);
+ indentf(st->indentdepth, "Bind %s\n", s);
free(s);
}
if (hthas(bt, t->pname))
@@ -465,7 +470,7 @@ static void tybind(Inferstate *st, Type *t)
return;
if (debugopt['u']) {
s = tystr(t);
- printf("Binding %s\n", s);
+ indentf(st->indentdepth, "Binding %s\n", s);
free(s);
}
bt = mkht(strhash, streq);
@@ -662,7 +667,7 @@ static Type *unify(Inferstate *st, Node *ctx, Type *u, Type *v)
if (debugopt['u']) {
from = tystr(a);
to = tystr(b);
- printf("Unify %s => %s\n", from, to);
+ indentf(st->indentdepth, "Unify %s => %s\n", from, to);
free(from);
free(to);
}
@@ -751,7 +756,7 @@ static void unifycall(Inferstate *st, Node *n)
if (debugopt['u']) {
ret = tystr(ft->sub[0]);
ctx = ctxstr(st, n->expr.args[0]);
- printf("Call of %s returns %s\n", ctx, ret);
+ indentf(st->indentdepth, "Call of %s returns %s\n", ctx, ret);
free(ctx);
free(ret);
}
@@ -1506,11 +1511,17 @@ static void infernode(Inferstate *st, Node *n, Type *ret, int *sawret)
popstab();
break;
case Ndecl:
+ if (debugopt['u'])
+ indentf(st->indentdepth, "--- infer %s ---\n", declname(n));
+ st->indentdepth++;
bind(st, n);
inferdecl(st, n);
if (type(st, n)->type == Typaram && !st->ingeneric)
fatal(n->line, "Generic type %s in non-generic near %s\n", tystr(type(st, n)), ctxstr(st, n));
unbind(st, n);
+ st->indentdepth--;
+ if (debugopt['u'])
+ indentf(st->indentdepth, "--- done ---\n");
break;
case Nblock:
setsuper(n->block.scope, curstab());
diff --git a/parse/parse.h b/parse/parse.h
index c49951c..553946e 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -547,6 +547,11 @@ size_t align(size_t sz, size_t a);
/* suffix replacement */
char *swapsuffix(char *buf, size_t sz, char *s, char *suf, char *swap);
+/* indented printf */
+void indentf(int depth, char *fmt, ...);
+void findentf(FILE *fd, int depth, char *fmt, ...);
+void vfindentf(FILE *fd, int depth, char *fmt, va_list ap);
+
/* Options to control the compilation */
extern int yydebug;
extern char debugopt[128];
diff --git a/parse/util.c b/parse/util.c
index 6afe7e6..25fcdb0 100644
--- a/parse/util.c
+++ b/parse/util.c
@@ -383,3 +383,28 @@ size_t align(size_t sz, size_t a)
return (sz + a - 1) & ~(a - 1);
}
+void indentf(int depth, char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vfindentf(stdout, depth, fmt, ap);
+ va_end(ap);
+}
+
+void findentf(FILE *fd, int depth, char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vfindentf(fd, depth, fmt, ap);
+ va_end(ap);
+}
+
+void vfindentf(FILE *fd, int depth, char *fmt, va_list ap)
+{
+ ssize_t i;
+
+ for (i = 0; i < depth; i++)
+ fprintf(fd, "\t");
+ vfprintf(fd, fmt, ap);
+}
+
diff --git a/test/genericmake b/test/genericmake
index d86f873..497b3b2 100755
--- a/test/genericmake
+++ b/test/genericmake
Binary files differ