-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
48 lines (39 loc) · 978 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
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "compile.h"
// From parse.c
extern env_t *global_env;
void usage(void) {
printf("COMPILERBABY <filename>\n");
}
int main(int argc, char **argv) {
if (argc != 2) {
usage();
return -1;
}
char *filename = argv[1];
string_t *input = file_to_string(filename);
if (!input || !input->len)
return -1;
debug("Tokenizing...\n");
list_t *tokens = tokenize(input);
if (!tokens || !tokens->len)
return -1;
debug("Parsing...\n");
program_t *prog = parse(tokens);
if (!prog || !prog->fn_defs)
return -1;
/*
* TODO - do variable allocation here.
*/
debug("Allocating variable homes...\n");
alloc_homes(prog);
debug("Generating asm...\n");
list_t *instrs = gen_asm(prog);
if (!instrs || !instrs->len)
return -1;
debug("Outputting asm...\n");
print_asm(instrs);
return 0;
}