diff options
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); +}; + +} |
