-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlice.c
39 lines (34 loc) · 844 Bytes
/
lice.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
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include "lice.h"
void compile_error(const char *fmt, ...) {
va_list a;
va_start(a, fmt);
vfprintf(stderr, fmt, a);
fprintf(stderr, "\n");
va_end(a);
exit(EXIT_FAILURE);
}
int compile_begin(bool dump) {
list_t *block = parse_run();
if (!dump) {
gen_data_section();
}
for (list_iterator_t *it = list_iterator(block); !list_iterator_end(it); ) {
if (!dump) {
gen_function(list_iterator_next(it));
} else {
printf("%s", ast_string(list_iterator_next(it)));
}
}
return true;
}
int main(int argc, char **argv) {
argc--;
argv++;
return compile_begin(!!(argc && !strcmp(*argv, "--dump-ast")))
? EXIT_SUCCESS
: EXIT_FAILURE;
}