-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
53 lines (46 loc) · 1.18 KB
/
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
51
52
53
#include "9cc.h"
#include "util.h"
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
SYM_TAB *sym_tab = NULL;
int main(int argc, char **argv) {
bool ast_flg = false;
// process options
if (argc >= 2 && strcmp(argv[1], "-test") == 0) {
run_util_test();
run_symbol_test();
run_pointer_test();
printf("========================\n");
printf(" All unit tests passed.\n");
printf("========================\n");
return 0;
}
if (argc >= 2 && strcmp(argv[1], "-ast") == 0) {
ast_flg = true;
argc--;
argv++;
}
if (argc != 2) {
fprintf(stderr, "引数の数が正しくありません\n");
fprintf(stderr, "%s [-ast] [-e program]\n", argv[0]);
fprintf(stderr, "%s [-ast] [programfile]\n", argv[0]);
fprintf(stderr, "%s -test\n", argv[0]);
return EXIT_FAILURE;
}
init();
Vector *tokens = tokenize(argv[1]);
Vector *code = parse(tokens);
sema(code);
if (ast_flg == true) {
printf("graph graphname {\n");
for (int i = 0; i < code->len; i++)
p_tree((Node *)vec_at(code, i));
printf("}\n");
return EXIT_SUCCESS;
}
gen_x86(code);
return EXIT_SUCCESS;
}