10 extern int yylex_destroy(void);
12 void usage(FILE *out
, char *arg0
)
15 "Usage: %s [OPTS] [FILE]\n"
17 "Compile an spl file. If FILE is not specified stdin is used.\n"
20 "\t-p\tPretty print the parsed abstract syntax tree\n"
21 "\t-t\tPretty print the typed abstract syntax tree\n"
22 "\t-g LANG\tGenerate LANG code (default: C)\n"
23 "\t \tSupported languages: C\n"
24 "\t-o FILE\tOutput code to FILE (default: a.suf)\n"
25 "\t-h\tShow this help\n"
29 int main(int argc
, char *argv
[])
32 bool pparse
= false, ptype
= false;
34 enum {langc
} lang
= langc
;
35 const char *suffix
[] = { [langc
] = "c" };
36 struct ast
*result
= NULL
;
39 while ((opt
= getopt(argc
, argv
, "g:ho:tp")) != -1) {
42 if (strcmp(optarg
, "c") == 0
43 || strcmp(optarg
, "C") == 0) {
46 usage(stderr
, argv
[0]);
50 cfile
= safe_strdup(optarg
);
59 usage(stdout
, argv
[0]);
62 usage(stderr
, argv
[0]);
66 if (optind
+ 1 == argc
&& strcmp(argv
[optind
], "-") != 0)
67 if ((yyin
= fopen(argv
[optind
], "r")) == NULL
)
78 ast_print(result
, stdout
);
81 if ((result
= sem(result
)) == NULL
) {
85 ast_print(result
, stdout
);
89 sprintf(cfile
= safe_malloc(10), "a.%s", suffix
[lang
]);
90 cout
= safe_fopen(cfile
, "w+");
94 // genc(result, cout);
97 die("unsupported language\n");