-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cc
54 lines (47 loc) · 1.04 KB
/
main.cc
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
49
50
51
52
53
54
#include <fstream>
#include <iostream>
#include <string>
#include "cmdargs.h"
#include "object.h"
#include "parser.h"
#include "scanner.h"
using namespace std;
CmdArgs* options;
int run(const string& s) {
Scanner scanner(s);
auto tokens = scanner.scanTokens();
if (options->printLex())
for (auto t : tokens) cerr << t << endl;
Parser parser;
auto stmts = parser.parse(tokens);
Scope scope;
llvmWrapper l;
CodeGenVisitor v(scope, l);
for (auto s : stmts) {
v.visit(s);
cout << endl;
}
if (options->printIR()) l.mod->print(llvm::outs(), nullptr);
compile(v);
GraphGenVisitor gv;
gv.visitProgram(stmts);
gv.output();
return 0;
}
int runFile(const string& file) {
ifstream fin(file);
if (!fin.good()) {
cerr << "Cannot open script " << file << endl;
return -1;
}
string file_content, s;
while (getline(fin, s)) {
file_content += s;
file_content += "\n";
}
return run(file_content);
}
int main(int argc, char** argv) {
options = new CmdArgs(argc, argv);
return runFile(string(argv[1]));
}