diff options
| author | _ov4 <hausemasterstream@gmail.com> | 2026-01-30 13:11:20 +0000 |
|---|---|---|
| committer | _ov4 <hausemasterstream@gmail.com> | 2026-01-30 13:11:20 +0000 |
| commit | bd799e42b40613983c6e3cb9aedf58866ac68605 (patch) | |
| tree | 03fdd0dffba45fa2a1d9b8d4b0e78f49140c07e5 /include/cps/FunctionGen.h | |
| parent | 80420b0f92f42edc0a3cac4490a08adb8b2457dc (diff) | |
Added FUNCTION and PROCEDURE
Diffstat (limited to 'include/cps/FunctionGen.h')
| -rw-r--r-- | include/cps/FunctionGen.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/include/cps/FunctionGen.h b/include/cps/FunctionGen.h new file mode 100644 index 0000000..c1a6ebd --- /dev/null +++ b/include/cps/FunctionGen.h @@ -0,0 +1,39 @@ +#pragma once +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Module.h" +#include "cps/FunctionAST.h" +#include <map> +#include <vector> +#include <functional> +#include <string> + +namespace cps { + +class FunctionGen { + llvm::LLVMContext &Context; + llvm::Module &Module; + llvm::IRBuilder<> &Builder; + + std::map<std::string, llvm::AllocaInst*> &NamedValues; + + void createArgumentAllocas(llvm::Function *F, const std::vector<std::pair<std::string, std::string>> &Args); + +public: + FunctionGen(llvm::LLVMContext &C, llvm::Module &M, llvm::IRBuilder<> &B, + std::map<std::string, llvm::AllocaInst*> &NV) + : Context(C), Module(M), Builder(B), NamedValues(NV) {} + + llvm::Type *getLLVMType(const std::string &TypeName); + + llvm::Function *emitPrototype(PrototypeAST *Proto); + + llvm::Function *emitFunctionDef(FunctionDefAST *FuncAST, const std::function<void(StmtAST*)> &StmtEmitter); + + llvm::Value *emitCallExpr(CallExprAST *Call, const std::vector<llvm::Value*> &Args); + + void emitCallStmt(CallStmtAST *Call, const std::vector<llvm::Value*> &Args); + + void emitReturn(ReturnStmtAST *Ret, llvm::Value *RetVal); +}; + +} |
