shithub: mc

Download patch

ref: 48ba62d332c9b9ddf74ab71877d39242f493979b
parent: 594d18234e9f3c0591dfe2da55e6d0b9e0d97c9c
author: Ori Bernstein <[email protected]>
date: Tue Jun 5 09:29:33 EDT 2012

Silence debug prints by default.

    We were too noisy. The dumps weren't useful enough. Remove or
    silence them.

--- a/8/isel.c
+++ b/8/isel.c
@@ -221,7 +221,6 @@
     for (i = 0; i < Nmode; i++)
         s->rtaken[reginterferes[l.reg][i]] = 1;
 
-    printf("Got reg %s\n", regnames[l.reg]);
     return l;
 }
 
@@ -608,6 +607,17 @@
     g(s, Iret, NULL);
 }
 
+static void writeasm(Fn *fn, Isel *is, FILE *fd)
+{
+    int i;
+
+    if (fn->isglobl)
+        fprintf(fd, ".globl %s\n", fn->name);
+    fprintf(fd, "%s:\n", fn->name);
+    for (i = 0; i < is->ni; i++)
+        iprintf(fd, is->il[i]);
+}
+
 /* genasm requires all nodes in 'nl' to map cleanly to operations that are
  * natively supported, as promised in the output of reduce().  No 64-bit
  * operations on x32, no structures, and so on. */
@@ -627,17 +637,10 @@
     }
     epilogue(&is);
 
-    if (fn->isglobl)
-        fprintf(stdout, ".globl %s\n", fn->name);
-    fprintf(stdout, "%s:\n", fn->name);
-    for (i = 0; i < is.ni; i++)
-        iprintf(stdout, is.il[i]);
+    if (debug)
+      writeasm(fn, &is, stdout);
 
     fd = fopen("a.s", "w");
-    if (fn->isglobl)
-        fprintf(fd, ".globl %s\n", fn->name);
-    fprintf(fd, "%s:\n", fn->name);
-    for (i = 0; i < is.ni; i++)
-        iprintf(fd, is.il[i]);
+    writeasm(fn, &is, fd);
     fclose(fd);
 }
--- a/8/main.c
+++ b/8/main.c
@@ -20,6 +20,7 @@
 {
     printf("%s [-h] [-o outfile] inputs\n", prog);
     printf("\t-h\tPrint this help\n");
+    printf("\t-d\tPrint debug dumps\n");
     printf("\t-o\tOutput to outfile\n");
 }
 
@@ -56,27 +57,30 @@
         file->file.globls = globls;
         yyparse();
 
-        /* before we do anything to the parse */
-        dump(file, stdout);
+        if (debug) {
+          /* before we do anything to the parse */
+          dump(file, stdout);
+        }
 
         infer(file);
 
         /* test storing tree to file */
-        tmp = fopen("test.pkl", "w");
+        tmp = fopen("a.pkl", "w");
         pickle(file, tmp);
         fclose(tmp);
 
-        /* and reading it back */
-        tmp = fopen("test.pkl", "r");
-        rdback = unpickle(tmp);
-        dump(rdback, stdout);
-        fclose(tmp);
+        if (debug) {
+          /* and reading it back */
+          tmp = fopen("test.pkl", "r");
+          rdback = unpickle(tmp);
+          dump(rdback, stdout);
+          fclose(tmp);
 
-        /* after all processing */
-        dump(file, stdout);
+          /* after all processing */
+          dump(file, stdout);
+        }
         gen(file, "a.s");
     }
 
     return 0;
 }
-
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -389,7 +389,8 @@
 
     assert(n->type == Ndecl);
     f = s->fn;
-    printf("DECLARE %s(%ld) at %zd\n", declname(n), n->decl.sym->id, f->stksz);
+    if (debug)
+        printf("DECLARE %s(%ld) at %zd\n", declname(n), n->decl.sym->id, f->stksz);
     htput(f->locs, (void*)n->decl.sym->id, (void*)f->stksz);
     f->stksz += size(n);
 }
--- a/8/simp.c
+++ b/8/simp.c
@@ -81,8 +81,10 @@
 
     nl = reduce(fn, n->func.body, &nn);
 
-    for (i = 0; i < nn; i++) {
+    if (debug) {
+      for (i = 0; i < nn; i++) {
         dump(nl[i], stdout);
+      }
     }
 
     fn->nl = nl;
--- a/a.s
+++ b/a.s
@@ -1,24 +1,25 @@
-.globl _main
-_main:
+.globl main
+main:
 	pushl %ebp
 	movl %esp,%ebp
 	subl $12,%esp
-	jmp .L2
-.L1:
-	movl 4(%esp),%eax
-	addl (%esp),%eax
-	movl %eax,4(%esp)
-.L2:
-	movl (%esp),%eax
-	cmpl $10,%eax
-	jl .L1
-	jmp .L3
-.L3:
-	movl 4(%esp),%eax
-	movl %eax,(%esp)
+	leal (%esp),%eax
+	addl $0,%eax
+	movl $12,(%eax)
+	leal (%esp),%eax
+	addl $4,%eax
+	movl $30,(%eax)
+	leal (%esp),%eax
+	addl $0,%eax
+	movl %eax,%ecx
+	leal (%esp),%edx
+	addl $4,%edx
+	movl %edx,%ebx
+	addl %ebx,%ecx
+	movl %ecx,8(%esp)
 	jmp .L0
 .L0:
-	movl (%esp),%eax
+	movl 8(%esp),%eax
 	movl %ebp,%esp
 	popl %ebp
 	ret
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -41,7 +41,6 @@
 /* find the most accurate type mapping */
 static Type *tf(Type *t)
 {
-    char buf[1024];
     Type *lu;
     assert(t != NULL);
 
@@ -53,12 +52,10 @@
             tyresolve(lu);
         }
 
-        printf("%s => ", tyfmt(buf, 1024, t));
         if (!tytab[t->tid])
             break;
         t = tytab[t->tid];
     }
-    printf("nil\n");
     return t;
 }
 
@@ -200,7 +197,6 @@
         b = t;
     }
 
-    printf("UNIFY %s ===> %s\n", tystr(a), tystr(b));
     mergecstrs(ctx, a, b);
     if (a->type == Tyvar) {
 	tytab[a->tid] = b;
@@ -334,7 +330,6 @@
             die("casts not implemented");
             break;
         case Oret:      /* -> @a -> void */
-            printf("INFERRING RET\n");
             if (sawret)
                 *sawret = 1;
             if (!ret)
@@ -344,7 +339,6 @@
             else
                 t =  unify(n, mkty(-1, Tyvoid), ret);
             settype(n, t);
-            printf("DONE");
             break;
         case Ojmp:     /* goto void* -> void */
             settype(n, mkty(-1, Tyvoid));
@@ -392,7 +386,6 @@
 {
     Type *t;
 
-    printf("====== decl %s\n", n->decl.sym->name->name.parts[n->decl.sym->name->name.nparts-1]);
     t = decltype(n);
     settype(n, t);
     if (n->decl.init) {
@@ -511,10 +504,8 @@
     Node *n;
     Node **nl;
 
-    printf("COMPONENTS INFERRED\n");
     for (i = 0; i < ncheckmemb; i++) {
         n = checkmemb[i];
-        printf("EXPR TYPE: %s\n", tystr(type(n)));
         if (n->expr.type->type == Typtr)
             n = n->expr.args[0];
         aggr = checkmemb[i]->expr.args[0];
@@ -528,7 +519,6 @@
             }
         }
     }
-    printf("DONE\n");
 }
 
 static void typesub(Node *n)
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -351,3 +351,6 @@
 /* convenience func */
 void lappend(void *l, size_t *len, void *n); /* ugly hack; nl is void* because void*** is incompatible with T*** */
 void lfree(void *l, size_t *len);
+
+/* Options to control the compilation */
+extern int debug;
--- a/test/build.sh
+++ b/test/build.sh
@@ -3,6 +3,7 @@
 MC=../8/8m
 
 function build {
+    echo $MC $1.myr && \
     $MC $1.myr && \
     mv a.s $1.s && \
     cc -m32 -o $1 $1.s