-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
47 lines (38 loc) · 831 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
#include "50cc.h"
Token *token;
char *user_input;
void error(char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
exit(1);
}
void error_at(char *loc, char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
int pos = loc - user_input;
fprintf(stderr, "%s\n", user_input);
fprintf(stderr, "%*s", pos, " ");
fprintf(stderr, "^ ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
exit(1);
}
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "引数の個数が正しくありません\n");
return 1;
}
user_input = argv[1];
token = tokenize();
program();
printf(".intel_syntax noprefix\n");
printf(".global main\n");
cur_func = 0;
for (int i = 0; code[i]; i++) {
cur_func++;
gen(code[i]);
}
return 0;
}