forked from eg0rmeister/testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.cpp
37 lines (32 loc) · 916 Bytes
/
driver.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
#include <iostream>
#include "ExprLexer.h"
#include "ExprParser.h"
#include "IRVisitor.h"
#include "InterpreterVisitor.h"
#include "PrintVisitor.h"
#include "antlr4-runtime.h"
int main(int argc, const char* argv[]) {
std::ifstream stream;
std::string filename = "../input.txt";
if (argc == 2) { // custom program file
filename = argv[1];
}
stream.open(filename);
antlr4::ANTLRInputStream input(stream);
ExprLexer lexer(&input);
antlr4::CommonTokenStream tokens(&lexer);
ExprParser parser(&tokens);
ExprParser::FileContext* tree = parser.file();
InterpreterVisitor visitor;
PrintVisitor print_visitor;
IRVisitor ir_visitor;
try {
ir_visitor.visitFile(tree);
ir_visitor.printIR();
ir_visitor.printIR("program.ll");
} catch (const std::exception& ex) {
std::cout << "Error occured in translation pass!\n"
<< ex.what() << std::endl;
}
return 0;
}