aboutsummaryrefslogtreecommitdiff
path: root/include/cps/CodeGen.h
diff options
context:
space:
mode:
authorov-4 <hausemasterstream@gmail.com>2026-01-29 10:20:58 +0000
committerov-4 <hausemasterstream@gmail.com>2026-01-29 10:20:58 +0000
commitc2a3cecc1ab2d3f27dcea40a6f0f353b0306d66a (patch)
tree3adfa6ed51620adcf6b129eade1622b01527c8a9 /include/cps/CodeGen.h
parent3f48a1d3af588242cd745e344b6b0b02cfb26131 (diff)
Added INPUT, OUTPUT and DECLARE
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