shithub: mc

Download patch

ref: f58f2ae13065c5338a7b81218b123e3f4859fece
parent: e15b9b8ff63de5a461257b1ecfa9689e853c90ab
parent: 62f197bc9c8a7d3493596e55462d7eb9bbe21ae1
author: Ori Bernstein <[email protected]>
date: Wed Jul 25 17:00:18 EDT 2012

Merge branch 'master' of git+ssh://mimir.eigenstate.org/git/ori/mc2

--- a/8/isel.c
+++ b/8/isel.c
@@ -14,6 +14,8 @@
 #include "opt.h"
 #include "asm.h"
 
+#include "platform.h"
+
 /* string tables */
 char *insnfmts[] = {
 #define Insn(val, fmt, use, def) fmt,
@@ -753,7 +755,7 @@
 {
     size_t i, j;
 
-    if (fn->isexport || !strcmp(fn->name, "main"))
+    if (fn->isexport || !strcmp(fn->name, Fprefix "main"))
         fprintf(fd, ".globl %s\n", fn->name);
     fprintf(fd, "%s:\n", fn->name);
     for (j = 0; j < s->cfg->nbb; j++) {
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -399,8 +399,9 @@
 Node *specializedcl(Node *n, Type *to, Node **name);
 
 /* usefiles */
+int  loaduse(FILE *f, Stab *into);
 void readuse(Node *use, Stab *into);
-void writeuse(Node *file, FILE *out);
+void writeuse(FILE *fd, Node *file);
 
 /* typechecking/inference */
 void infer(Node *file);
--- a/parse/use.c
+++ b/parse/use.c
@@ -27,7 +27,7 @@
     return s;
 }
 
-static int loaduse(FILE *f, Stab *st)
+int loaduse(FILE *f, Stab *st)
 {
     char *pkg;
     Stab *s;
@@ -111,7 +111,7 @@
  * G<pickled-decl><pickled-initializer>
  * Z
  */
-void writeuse(Node *file, FILE *f)
+void writeuse(FILE *f, Node *file)
 {
     Stab *st;
     void **k;
--- a/util/muse.c
+++ b/util/muse.c
@@ -14,6 +14,7 @@
 /* FIXME: move into one place...? */
 Node *file;
 char *outfile;
+int merge;
 int debug;
 char debugopt[128];
 char **incpaths;
@@ -21,31 +22,74 @@
 
 static void usage(char *prog)
 {
-    printf("%s [-h] [-o outfile] inputs\n", prog);
-    printf("\t-h\tPrint this help\n");
+    printf("%s [-hIdos] [-o outfile] [-m] inputs\n", prog);
+    printf("\t-h\tprint this help\n");
+    printf("\t-m\ttreat the inputs as usefiles and merge them\n");
     printf("\t-I path\tAdd 'path' to use search path\n");
     printf("\t-d\tPrint debug dumps\n");
-    printf("\t-o\tOutput to outfile\n");
+    printf("\t-o out\tOutput to outfile\n");
     printf("\t-s\tShow the contents of usefiles `inputs`\n");
 }
 
+static void dumpuse(char *path)
+{
+    Stab *globls;
+    FILE *f;
 
+    globls = file->file.globls;
+    loaduse(f, globls);
+    f = fopen(path, "r");
+    dumpstab(globls, stdout);
+    fclose(f);
+}
+
+static void genuse(char *path)
+{
+    Stab *globls;
+    FILE *f;
+
+    globls = file->file.globls;
+    tyinit(globls);
+    tokinit(path);
+    yyparse();
+
+    infer(file);
+    if (!outfile)
+        die("need output file name right now. FIX THIS.");
+    f = fopen(outfile, "w");
+    writeuse(f, file);
+    fclose(f);
+}
+
+static void mergeuse(char *path)
+{
+    FILE *f;
+    Stab *st;
+
+    st = file->file.exports;
+    f = fopen(path, "r");
+    loaduse(f, st);
+    fclose(f);
+}
+
 int main(int argc, char **argv)
 {
+    FILE *f;
     int opt;
     int i;
-    Stab *globls;
-    FILE *f;
 
-    while ((opt = getopt(argc, argv, "d::ho:I:")) != -1) {
+    while ((opt = getopt(argc, argv, "d::hmo:I:")) != -1) {
         switch (opt) {
-            case 'o':
-                outfile = optarg;
-                break;
             case 'h':
                 usage(argv[0]);
                 exit(0);
                 break;
+            case 'm':
+                merge = 1;
+                break;
+            case 'o':
+                outfile = optarg;
+                break;
             case 'd':
                 debug = 1;
                 while (optarg && *optarg)
@@ -61,31 +105,21 @@
         }
     }
 
-    if (debugopt['s']) {
-        for (i = optind; i < argc; i++) {
-            globls = mkstab();
-            f = fopen(argv[i], "r");
-            readuse(file, globls);
-            dumpstab(globls, stdout);
-        }
-        exit(0);
-    }
-
     for (i = optind; i < argc; i++) {
-        globls = mkstab();
-        tyinit(globls);
-        tokinit(argv[i]);
         file = mkfile(argv[i]);
         file->file.exports = mkstab();
-        file->file.globls = globls;
-        yyparse();
-
-        infer(file);
-	if (!outfile)
-	    die("need output file name right now. FIX THIS.");
-	f = fopen(outfile, "w");
-	writeuse(file, f);
-	fclose(f);
+        file->file.globls = mkstab();
+        if (merge)
+            mergeuse(argv[i]);
+        else if (debugopt['s'])
+            dumpuse(argv[i]);
+        else
+            genuse(argv[i]);
+    }
+    if (merge) {
+        f = fopen(outfile, "w");
+        writeuse(f, file);
+        fclose(f);
     }
 
     return 0;