-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
49 lines (41 loc) · 1.4 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
#include <antlr4-runtime.h>
#include <iostream>
#include <typeinfo>
#include "LuaBaseListener.h"
#include "LuaLexer.h"
#include "LuaParser.h"
#include "context.h"
#include "mlir_generator.h"
#include "ast.h"
#include "sema.h"
int main(int argc, char* argv[]) {
auto context = luac::makeContext();
std::ifstream stream;
stream.open(argv[1]);
antlr4::ANTLRInputStream input(stream);
luac::LuaLexer lexer(&input);
antlr4::CommonTokenStream tokens(&lexer);
luac::LuaParser parser(&tokens);
//luac::MLIRGenerator generator(luac::Context::genMLIRContext().release());
//parser.addParseListener(&generator);
auto chunk = parser.chunk();
std::cout << chunk->toStringTree(&parser, true) << std::endl;
//generator.dumpMLIR();
//generator.dumpIR();
//std::cout << doc->toStringTree() << std::endl << std::endl;
// antlr4::tree::ParseTree *tree = parser.keyedSimpleFieldName();
// TreeShapeListener listener;
// antlr4::tree::ParseTreeWalker::DEFAULT.walk(&listener, tree);
//luac::MLIRGenerator generator(luac::Context::genMLIRContext().release());
//generator.visitChunk(ast);
//generator.dumpMLIR();
//generator.dumpIR();
luac::Sema sema;
sema.visitChunk(chunk);
std::unique_ptr<luac::AstContext> ast = sema.Ast();
luac::MLIRGenerator generator(luac::Context::genMLIRContext().release(), ast.get());
generator.gen();
generator.dumpMLIR();
generator.dumpIR();
return 0;
}