aboutsummaryrefslogtreecommitdiff
path: root/include/cps/CodeGen.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/cps/CodeGen.h')
-rw-r--r--include/cps/CodeGen.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h
new file mode 100644
index 0000000..2621795
--- /dev/null
+++ b/include/cps/CodeGen.h
@@ -0,0 +1,32 @@
+#pragma once
+#include "cps/AST.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include <map>
+
+namespace cps {
+
+class CodeGen {
+ std::unique_ptr<llvm::LLVMContext> TheContext;
+ std::unique_ptr<llvm::Module> TheModule;
+ std::unique_ptr<llvm::IRBuilder<>> Builder;
+ std::map<std::string, llvm::AllocaInst*> NamedValues;
+
+ llvm::AllocaInst *CreateEntryBlockAlloca(llvm::Function *TheFunction,
+ const std::string &VarName);
+
+ llvm::FunctionCallee PrintfFunc;
+ llvm::FunctionCallee ScanfFunc;
+ llvm::Value *PrintfFormatStr;
+ llvm::Value *ScanfFormatStr;
+
+ void SetupExternalFunctions();
+
+public:
+ CodeGen();
+ void compile(const std::vector<std::unique_ptr<StmtAST>> &Statements);
+ void print();
+};
+
+} // namespace cps