-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
45 lines (35 loc) · 869 Bytes
/
main.cpp
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
#include <iostream>
#include <codegen.hpp>
#include <scope.hpp>
#include <types.hpp>
#include <err.hpp>
void prettyprint(const AST *ast, int tabs)
{
if (!ast)
return;
for (int i = 0; i < tabs; ++i)
printf(" ");
if (ast->val)
printf("%s %d ptype: %d\n", NODE_NAMES[ast->type], ast->val, ast->ptype);
else if (ast->type == VAR)
printf("%s %s ptype: %d\n", NODE_NAMES[ast->type], ast->get_sym().name.c_str(), ast->ptype);
else
printf("%s\n", NODE_NAMES[ast->type]);
prettyprint(ast->lhs, tabs + 1);
prettyprint(ast->mid, tabs + 1);
prettyprint(ast->rhs, tabs + 1);
}
int main(int argc, const char *argv[]) {
if (argc == 1)
{
std::cerr << "Must specify input file!\n";
return 1;
}
Lexer l(argv[1]);
Parser p(l);
AST *ast = p.parse();
prettyprint(ast, 0);
init_cg("out.s");
gen_ast(ast, Ctx(NOREG, NONE, 0, 0, 0));
gen_globls();
}