-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
43 lines (38 loc) · 1.05 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "driver.hh"
#include "parser.hh"
#include <cstring>
#include <string>
int main(int argc, char** argv){
bool bison_verbose = false;
bool imcode_verbose = false;
const char * filename = nullptr;
const char * outputfile = nullptr;
for(int i = 1; i < argc; i++) {
if(strcmp(argv[i], "--bison-verbose") == 0) {
bison_verbose = true;
} else if(strcmp(argv[i], "--imcode-verbose") == 0) {
imcode_verbose = true;
} else if(strcmp(argv[i], "-o") == 0) {
i++;
outputfile = argv[i];
} else if(argv[i][0] != '-') {
filename = argv[i];
}
}
if(filename) {
freopen(filename, "r", stdin);
}
driver drv;
yy::parser parse(drv);
parse.set_debug_level(bison_verbose);
if(parse() == 0) {
drv.compile();
if(imcode_verbose){
drv.dump_to(stderr);
}
codegen(drv.imProgram, filename, std::string(outputfile));
return 0;
}
fprintf(stderr, "failed to parse\n");
return 1;
}