-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompiler.cpp
More file actions
35 lines (28 loc) · 760 Bytes
/
compiler.cpp
File metadata and controls
35 lines (28 loc) · 760 Bytes
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
#include <iostream>
#include <vector>
#include "ir/ir.h"
#include "lexer/lexer.h"
#include "parser/parser.h"
#include "shared/allincludes.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
error("COMPILER", "No file to compile.");
}
// Lexer
string fileName = argv[1];
vector<token> tokens;
tokens = getTokens(fileName);
// Parser
lr0_automaton automaton = getAutomaton();
parsing_table parsingTable = getParsingTable(automaton);
shared_ptr<S> AST = getAST(parsingTable, tokens);
// IR Generation
compileToIR(move(AST));
// Save module
string outputFileName = "calvo.ll";
if (argc == 3) {
outputFileName = argv[2];
}
saveModuleToFile(outputFileName);
return 0;
}