-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmlir_generator.h
63 lines (43 loc) · 1.47 KB
/
mlir_generator.h
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
55
56
57
58
59
60
61
62
63
#pragma once
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Verifier.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopedHashTable.h"
#include "llvm/Support/raw_ostream.h"
#include "LuaBaseVisitor.h"
#include "ast.h"
namespace luac {
class MLIRGenerator {
public:
MLIRGenerator(mlir::MLIRContext* context, AstContext* ast);
void gen();
void dumpMLIR();
void dumpIR();
private:
std::any visitBlock(LuaParser::BlockContext *ctx);
std::any genFunctioncall(FunctionCall* funcCall);
std::any visitNameAndArgs(LuaParser::NameAndArgsContext* ctx);
mlir::Location loc(unsigned int line, unsigned int column) {
return mlir::FileLineColLoc::get(builder.getStringAttr(""), line, column);
}
void addLuacBaseType();
void createLuaVarSturct();
void createLuaStringSturct();
mlir::LLVM::LLVMStructType getLuaStringSturct();
mlir::Value getOrCreateGlobalString(llvm::StringRef name, llvm::StringRef value);
void createMainFunction();
void endMainFunction();
mlir::LLVM::LLVMFuncOp getFunction(llvm::StringRef name);
private:
mlir::OpBuilder builder;
mlir::ModuleOp module;
AstContext* ast;
llvm::ScopedHashTable<llvm::StringRef, mlir::Value> symbolTable;
llvm::StringMap<mlir::LLVM::LLVMFuncOp> functionMap;
};
}