-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
54 lines (40 loc) · 1.37 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include "antlr4-runtime.h"
#include "../grammar/CACTLexer.h"
#include "../grammar/CACTParser.h"
#include "../grammar/CACTBaseListener.h"
#include "postGrammarAnalysis.h"
#include "symbolTable.h"
#include "semanticAnalysis.h"
#include "intermediateRepresentation.h"
#include "dataFlowAnalysis.h"
#include "codeGenerate.h"
using namespace antlr4;
SymbolTable symbol_table;
PostGrammarAnalysis post_grammar_stage;
SemanticAnalysis semantic_stage;
IntermediateRepr intermediate_stage;
DataFlow dataflow_stage;
CodeGenerate codegen_stage;
int main(int argc, const char* argv[]) {
std::ifstream stream;
stream.open(argv[1]);
ANTLRInputStream input(stream);
CACTLexer lexer(&input);
CommonTokenStream tokens(&lexer);
CACTParser parser(&tokens);
tree::ParseTree *tree = parser.compUnit();
// Post grammar stage
// Semantic analysis
tree::ParseTreeWalker::DEFAULT.walk(&semantic_stage, tree);
// Intermediate generation
tree::ParseTreeWalker::DEFAULT.walk(&intermediate_stage, tree);
// Dataflow analysis
dataflow_stage.genFlow();
// Code generation
codegen_stage.genAsm();
codegen_stage.outputToFile(argv[1]);
std::cout << "debug: hello" << std::endl;
std::cout << "-------------------------Print AST:--------------------------" << std::endl;
std::cout << tree->toStringTree(&parser) << std::endl;
}