34 MLIRGenImpl(mlir::MLIRContext &context,
const std::string &moduleName,
35 const std::string &fileName,
const std::string &sourceText,
37 : builder(&context), moduleName(moduleName), fileName(fileName),
39 sammine_util::Reporter::get_diagnostic_data(sourceText)),
46 mlir::ModuleOp theModule;
47 mlir::OpBuilder builder;
48 std::string moduleName;
50 sammine_util::Reporter::DiagnosticData diagnosticData;
56 std::map<std::string, mlir::LLVM::LLVMStructType> structTypes;
57 std::map<std::string, mlir::LLVM::LLVMStructType> enumTypes;
59 mlir::LLVM::LLVMStructType closureType;
60 std::map<std::string, std::string> closureWrappers;
61 int partialCounter = 0;
63 mlir::Value currentSretBuffer =
nullptr;
68 mlir::LLVM::LLVMPointerType llvmPtrTy() {
69 return mlir::LLVM::LLVMPointerType::get(builder.getContext());
71 mlir::LLVM::LLVMVoidType llvmVoidTy() {
72 return mlir::LLVM::LLVMVoidType::get(builder.getContext());
79 void declareRuntimeFunctions();
82 mlir::Type convertType(
const Type &type);
83 bool isIntegerType(
const Type &type);
84 bool isUnsignedIntegerType(
const Type &type);
85 bool isFloatType(
const Type &type);
86 bool isBoolType(
const Type &type);
87 mlir::Type getEnumBackingMLIRType(
const EnumType &et);
103 mlir::Value buildClosure(mlir::Value codePtr, mlir::Value envPtr,
105 mlir::LLVM::LLVMFunctionType getClosureFuncType(
const FunctionType &ft);
106 std::string getOrCreateClosureWrapper(
const std::string &funcName,
110 const std::string &calleeName,
111 llvm::ArrayRef<mlir::Value> boundArgs);
113 llvm::ArrayRef<mlir::Value> operands);
114 void emitFuncCallAndLLVMReturn(llvm::StringRef callee,
const Type &retType,
115 mlir::ValueRange args, mlir::Location loc);
131 mlir::Value emitPtrArrayGEP(mlir::Value ptr, mlir::Value idx,
133 mlir::Location location);
134 mlir::Value emitPtrArrayLoad(mlir::Value ptr, mlir::Value idx,
136 mlir::Location location);
137 void emitPtrArrayStore(mlir::Value ptr, mlir::Value idx, mlir::Value val,
138 const ArrayType &arrType, mlir::Location location);
150 mlir::Value scrutineeVal,
152 void emitBoundsCheck(mlir::Value idx,
size_t arrSize,
153 mlir::Location location);
154 mlir::Value emitArrayComparison(mlir::Value lhs, mlir::Value rhs,
155 const Type &arrType, TokenType tok,
156 mlir::Location location);
159 mlir::Value emitAllocaOne(mlir::Type elemType, mlir::Location loc);
160 int64_t getTypeSize(
const Type &type);
161 mlir::Value getOrCreateGlobalString(llvm::StringRef name,
162 llvm::StringRef value,
163 mlir::Location location);