-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
39 lines (37 loc) · 1.21 KB
/
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
#include "parser.hpp"
#include "passes.hpp"
#include "codegen_x86.hpp"
#include "codegen_c.hpp"
#include "codegen_js.hpp"
#include <string>
class Arguments {
public:
const char* source_path = nullptr;
void (*codegen)(const Program& program, const char* source_path, const TailCallData& tail_call_data) = CodegenC::codegen;
void parse(int argc, char** argv) {
for (int i = 1; i < argc; ++i) {
if (StringView(argv[i]) == "-c") codegen = CodegenC::codegen;
else if (StringView(argv[i]) == "-js") codegen = CodegenJS::codegen;
else source_path = argv[i];
}
}
};
int main(int argc, char** argv) {
Arguments arguments;
arguments.parse(argc, argv);
if (arguments.source_path == nullptr) {
print_error(Printer(std::cerr), "no input file");
return EXIT_FAILURE;
}
Program program = Pass1::run(arguments.source_path);
program = Lowering::run(program);
program = Pass3::run(program);
program = DeadCodeElimination::run(program);
program = Inlining::run(program);
program = Pass1::run(program);
program = DeadCodeElimination::run(program);
program = MemoryManagement::run(program);
TailCallData tail_call_data;
Pass5::run(program, tail_call_data);
arguments.codegen(program, arguments.source_path, tail_call_data);
}