summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2012-07-25 11:01:28 -0400
committerOri Bernstein <ori@eigenstate.org>2012-07-25 11:01:28 -0400
commite27b298f60cf74d25179ceb09326735b724e8d6e (patch)
treea10d8e1d0e48f5dda01bc86394387e0daafb1913 /util
parent416a47f74171d93f9237afede0d434bcc841e3fd (diff)
downloadmc-e27b298f60cf74d25179ceb09326735b724e8d6e.tar.gz
refactor muse and add merging.
Diffstat (limited to 'util')
-rw-r--r--util/muse.c89
1 files changed, 60 insertions, 29 deletions
diff --git a/util/muse.c b/util/muse.c
index b3f203e..3ae823c 100644
--- 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,71 @@ size_t nincpaths;
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-s\tShow the contents of usefiles `inputs`\n");
}
+static void dumpuse(char *path)
+{
+ Stab *globls;
+ FILE *f;
+
+ globls = file->file.globls;
+ readuse(file, 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(file, f);
+ fclose(f);
+}
+
+static void mergeuse(char *path)
+{
+ Stab *globls;
+
+ globls = file->file.globls;
+ readuse(file, globls);
+}
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) {
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 +102,21 @@ int main(int argc, char **argv)
}
}
- 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(file, f);
+ fclose(f);
}
return 0;