-
Notifications
You must be signed in to change notification settings - Fork 155
/
main.c
50 lines (40 loc) · 879 Bytes
/
main.c
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
44
45
46
47
48
49
50
#include "9cc.h"
void usage() {
error("Usage: 9cc [-test] [-dump-ir1] [-dump-ir2] <file>");
}
int main(int argc, char **argv) {
if (argc == 1)
usage();
if (argc == 2 && !strcmp(argv[1], "-test")) {
util_test();
return 0;
}
char *path;
bool dump_ir1 = false;
bool dump_ir2 = false;
if (argc == 3 && !strcmp(argv[1], "-dump-ir1")) {
dump_ir1 = true;
path = argv[2];
} else if (argc == 3 && !strcmp(argv[1], "-dump-ir2")) {
dump_ir2 = true;
path = argv[2];
} else {
if (argc != 2)
usage();
path = argv[1];
}
// Tokenize and parse.
Vector *tokens = tokenize(path, true);
Program *prog = parse(tokens);
sema(prog);
gen_ir(prog);
if (dump_ir1)
dump_ir(prog->funcs);
optimize(prog);
liveness(prog);
alloc_regs(prog);
if (dump_ir2)
dump_ir(prog->funcs);
gen_x86(prog);
return 0;
}