shithub: mc

Download patch

ref: 96f5d2d5bc1b212d843f8b8aa41ec6ed7c3382b7
parent: 3535b00498a9812b689a8fee281b73d426b92aff
author: Ori Bernstein <[email protected]>
date: Tue Jun 19 21:06:30 EDT 2012

Start to cut down and specialize debug dumps.

    They grew to the point of uselessness. Dump them.

--- a/8/isel.c
+++ b/8/isel.c
@@ -817,7 +817,5 @@
     epilogue(&is);
     regalloc(&is);
 
-    if (debug)
-        writeasm(stdout, &is, fn);
     writeasm(fd, &is, fn);
 }
--- a/8/main.c
+++ b/8/main.c
@@ -17,6 +17,7 @@
 /* FIXME: move into one place...? */
 Node *file;
 int debug;
+char debugopt[128];
 char *outfile;
 char **incpaths;
 size_t nincpaths;
@@ -23,10 +24,15 @@
 
 static void usage(char *prog)
 {
-    printf("%s [-h] [-o outfile] inputs\n", prog);
+    printf("%s [-h] [-o outfile] [-d[dbgopts]] inputs\n", prog);
     printf("\t-h\tPrint this help\n");
     printf("\t-I path\tAdd 'path' to use search path\n");
-    printf("\t-d\tPrint debug dumps\n");
+    printf("\t-d\tPrint debug dumps. Recognized options: f r p i\n");
+    printf("\t\t\tno options: print most common debug information\n");
+    printf("\t\t\tf: additionally log folded trees\n");
+    printf("\t\t\tr: additionally log reduced pre-cfg trees\n");
+    printf("\t\t\tp: additionally log tree immediately before parsing\n");
+    printf("\t\t\ti: additionally log tree after type inference\n");
     printf("\t-o\tOutput to outfile\n");
     printf("\t-S\tGenerate assembly instead of object code\n");
 }
@@ -49,7 +55,7 @@
     Stab *globls;
     char buf[1024];
 
-    while ((opt = getopt(argc, argv, "dhSo:I:")) != -1) {
+    while ((opt = getopt(argc, argv, "d::hSo:I:")) != -1) {
         switch (opt) {
             case 'o':
                 outfile = optarg;
@@ -59,7 +65,9 @@
                 exit(0);
                 break;
             case 'd':
-                debug++;
+                debug = 1;
+                while (optarg && *optarg)
+                    debugopt[*optarg++ & 0x7f] = 1;
                 break;
             case 'I':
                 lappend(&incpaths, &nincpaths, optarg);
@@ -81,11 +89,11 @@
         yyparse();
 
         /* before we do anything to the parse */
-        if (debug)
+        if (debugopt['p'])
             dump(file, stdout);
         infer(file);
         /* after all processing */
-        if (debug)
+        if (debugopt['i'])
             dump(file, stdout);
 
         swapsuffix(buf, 1024, argv[i], ".myr", ".s");
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -399,6 +399,7 @@
 
 /* Options to control the compilation */
 extern int debug;
+extern char debugopt[128];
 extern int asmonly;
 extern char *outfile;
 extern char **incpaths;
--- a/test/hello/sys.myr
+++ b/test/hello/sys.myr
@@ -2,27 +2,6 @@
 pkg sys =
 	type scno = int
 	type fdopt = int
-
-	const Rdonly  	: fdopt = 0x0
-	const Wronly  	: fdopt = 0x1
-	const Rdwr    	: fdopt = 0x2
-	const Append  	: fdopt = 0x80
-	const Creat   	: fdopt = 0x40
-	const Nofollow	: fdopt = 0x20000
-	const Ndelay  	: fdopt = 0x800
-	const Trunc   	: fdopt = 0x200
-
-	const Sexit	: scno = 1
-	const Sread	: scno = 3
-	const Swrite	: scno = 4
-	const Sopen	: scno = 5
-	const Sclose	: scno = 6
-	const Screat	: scno = 8
-	const Slseek	: scno = 19
-	const Sfstat	: scno = 108
-	const Skill	: scno = 37
-	const Sgetpid	: scno = 20
-
 	type statbuf = struct
 		 dev     : uint
 		 ino     : uint
@@ -42,29 +21,49 @@
 		 ctimens : uint
 		 _unused1: uint
 		 _unused2: uint
-	 ;;
+	;;
 
+	const Rdonly  	: fdopt = 0x0
+	const Wronly  	: fdopt = 0x1
+	const Rdwr    	: fdopt = 0x2
+	const Append  	: fdopt = 0x80
+	const Creat   	: fdopt = 0x40
+	const Nofollow	: fdopt = 0x20000
+	const Ndelay  	: fdopt = 0x800
+	const Trunc   	: fdopt = 0x200
+
+	const Sysexit	: scno = 1
+	const Sysread	: scno = 3
+	const Syswrite	: scno = 4
+	const Sysopen	: scno = 5
+	const Sysclose	: scno = 6
+	const Syscreat	: scno = 8
+	const Syslseek	: scno = 19
+	const Sysfstat	: scno = 108
+	const Syskill	: scno = 37
+	const Sysgetpid	: scno = 20
+
 	extern const syscall : (sc:scno, count:int, args:... -> int)
 
-	const exit	: (status:int)
-	const getpid	: ()
-	const kill	: (pid:int, sig:int)
-	const open	: (path:char[,], opts:fdopt)
-	const close	: (fd:int)
-	const creat	: (path:char[,], mode:int)
-	const read	: (fd:int, buf:char[,])
-	const write	: (fd:int, buf:char[,])
-	const lseek	: (fd:int, off:uint, whence:int)
-	const fstat	: (fd:int, sb:statbuf*)
+	const exit	: (status:int -> int)
+	const getpid	: ( -> int)
+	const kill	: (pid:int, sig:int -> int)
+	const open	: (path:char[,], opts:fdopt -> int)
+	const close	: (fd:int -> int)
+	const creat	: (path:char[,], mode:int -> int)
+	const read	: (fd:int, buf:char[,] -> int)
+	const write	: (fd:int, buf:char[,] -> int)
+	const lseek	: (fd:int, off:uint, whence:int -> int)
+	const fstat	: (fd:int, sb:statbuf* -> int)
 ;;
 
-const exit	= {status;		-> syscall(Sexit, 1);}
-const getpid	= {;			-> syscall(Sgetpid, 1);}
-const kill	= {pid, sig;		-> syscall(Skill,  2, pid, sig);}
-const open	= {path, opts:fdopt;	-> syscall(Sopen,  2, path castto(char*), opts);}
-const close	= {fd;			-> syscall(Sclose, 1, fd);}
-const creat	= {path, mode;		-> syscall(Screat, 2, path castto(char*), mode);}
-const read	= {fd, buf;		-> syscall(Sread,  3, fd, buf castto(char*), buf.len);}
-const write	= {fd, buf;		-> syscall(Swrite, 3, fd, buf castto(char*), buf.len);}
-const lseek	= {fd, off:uint, whence;-> syscall(Slseek, 2, fd, off, whence);}
-const fstat	= {fd, sb;		-> syscall(Sfstat, 2, fd, sb);}
+const exit	= {status;		-> syscall(Sysexit, 1);}
+const getpid	= {;			-> syscall(Sysgetpid, 1);}
+const kill	= {pid, sig;		-> syscall(Syskill,  2, pid, sig);}
+const open	= {path, opts:fdopt;	-> syscall(Sysopen,  2, path castto(char*), opts);}
+const close	= {fd;			-> syscall(Sysclose, 1, fd);}
+const creat	= {path, mode;		-> syscall(Syscreat, 2, path castto(char*), mode);}
+const read	= {fd, buf;		-> syscall(Sysread,  3, fd, buf castto(char*), buf.len);}
+const write	= {fd, buf;		-> syscall(Syswrite, 3, fd, buf castto(char*), buf.len);}
+const lseek	= {fd, off:uint, whence;-> syscall(Syslseek, 2, fd, off, whence);}
+const fstat	= {fd, sb;		-> syscall(Sysfstat, 2, fd, sb);}
--- a/util/muse.c
+++ b/util/muse.c
@@ -15,6 +15,7 @@
 Node *file;
 char *outfile;
 int debug;
+char debugopt[128];
 char **incpaths;
 size_t nincpaths;
 
@@ -37,7 +38,7 @@
     FILE *tmp;
     FILE *f;
 
-    while ((opt = getopt(argc, argv, "dho:")) != -1) {
+    while ((opt = getopt(argc, argv, "d::ho:I:")) != -1) {
         switch (opt) {
             case 'o':
                 outfile = optarg;
@@ -44,7 +45,9 @@
                 break;
             case 'h':
             case 'd':
-                debug++;
+                debug = 1;
+                while (optarg && *optarg)
+                    debugopt[*optarg++ & 0x7f] = 1;
                 break;
 	    case 'I':
 		lappend(&incpaths, &nincpaths, optarg);
@@ -67,7 +70,7 @@
 
         infer(file);
 	/* before we do anything to the parse */
-        if (debug) {
+        if (debugopt['p']) {
             /* test storing tree to file */
             tmp = fopen("a.pkl", "w");
             pickle(file, tmp);