ref: e27b298f60cf74d25179ceb09326735b724e8d6e
parent: 416a47f74171d93f9237afede0d434bcc841e3fd
author: Ori Bernstein <[email protected]>
date: Wed Jul 25 07:01:28 EDT 2012
refactor muse and add merging.
--- 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,8 +22,9 @@
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");
@@ -29,23 +31,62 @@
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 @@
}
}
- 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;