diff options
Diffstat (limited to 'include/cps/CodeGen.h')
| -rw-r--r-- | include/cps/CodeGen.h | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h index 9be6cc7..8bf5819 100644 --- a/include/cps/CodeGen.h +++ b/include/cps/CodeGen.h @@ -1,40 +1,46 @@ #pragma once -#include "cps/AST.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" +#include "cps/AST.h" #include <map> +#include <memory> namespace cps { +class ArrayHandler; + 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); + + std::unique_ptr<ArrayHandler> Arrays; llvm::FunctionCallee PrintfFunc; llvm::FunctionCallee ScanfFunc; llvm::Value *PrintfFormatStr; llvm::Value *ScanfFormatStr; - - llvm::Value *emitExpr(ExprAST *Expr); - void emitStmt(StmtAST *Stmt); - + + void SetupExternalFunctions(); + llvm::AllocaInst *CreateEntryBlockAlloca(llvm::Function *TheFunction, const std::string &VarName); + void emitIfStmt(IfStmtAST *Stmt); void emitWhileStmt(WhileStmtAST *Stmt); void emitRepeatStmt(RepeatStmtAST *Stmt); void emitForStmt(ForStmtAST *Stmt); - void SetupExternalFunctions(); - public: CodeGen(); + ~CodeGen(); void compile(const std::vector<std::unique_ptr<StmtAST>> &Statements); void print(); + + llvm::Value *emitExpr(ExprAST *Expr); + void emitStmt(StmtAST *Stmt); + + friend class ArrayHandler; }; -} // namespace cps +} |
