-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
47 lines (38 loc) · 826 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
// vim:set filetype=c tabstop=8 shiftwidth=8 noexpandtab:
#include <stdio.h>
#include <string.h>
#include "9cc.h"
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <number>\n", argv[0]);
fprintf(stderr, "Usage: %s -test\n", argv[0]);
return 1;
}
if (strcmp(argv[1], "-test") == 0) {
runtest();
return 0;
}
// tokenize
init_tokens();
tokenize(argv[1]);
// dump_tokens();
// Parse tokens
init_global_scope();
program();
// dump_nodes();
sema();
// dump_nodes();
// output first part assembry
printf(".intel_syntax noprefix\n");
for (int i = 0; code(i) != NULL; i++) {
if (code(i)->kind == ND_DEFINE_FUNC) {
printf(".global %s\n", code(i)->name);
}
}
printf("\n");
// Generate code
for (int i = 0; code(i) != NULL; i++) {
gen(code(i));
}
return 0;
}