diff options
Diffstat (limited to 'src/llvm.cpp')
-rw-r--r-- | src/llvm.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/llvm.cpp b/src/llvm.cpp index a0b635b..4bb21ec 100644 --- a/src/llvm.cpp +++ b/src/llvm.cpp @@ -79,7 +79,7 @@ struct LLVMEngine : public Engine { CFunc startFn(CEnv& cenv, const string& name, const ATuple* args, const ATuple* type); void pushFnArgs(CEnv& cenv, const ATuple* prot, const ATuple* type, CFunc f); - void finishFn(CEnv& cenv, CFunc f, CVal ret, const AST* retT); + void finishFn(CEnv& cenv, CVal ret, const AST* retT); void eraseFn(CEnv& cenv, CFunc f); CVal compileCall(CEnv& cenv, CFunc f, const ATuple* funcT, const vector<CVal>& args); @@ -129,12 +129,15 @@ private: typedef std::stack<IfRecord*> IfStack; IfStack if_stack; + CFunc currentFn; + unsigned labelIndex; }; LLVMEngine::LLVMEngine() : builder(context) , opaqueT(NULL) + , currentFn(NULL) , labelIndex(1) { InitializeNativeTarget(); @@ -396,6 +399,7 @@ LLVMEngine::startFn( BasicBlock* bb = BasicBlock::Create(context, "entry", f); builder.SetInsertPoint(bb); + currentFn = f; return f; } @@ -420,8 +424,10 @@ LLVMEngine::pushFnArgs(CEnv& cenv, const ATuple* prot, const ATuple* type, CFunc } void -LLVMEngine::finishFn(CEnv& cenv, CFunc f, CVal ret, const AST* retT) +LLVMEngine::finishFn(CEnv& cenv, CVal ret, const AST* retT) { + CFunc f = currentFn; + if (retT->str() == "Nothing") builder.CreateRetVoid(); else @@ -433,6 +439,8 @@ LLVMEngine::finishFn(CEnv& cenv, CFunc f, CVal ret, const AST* retT) } if (cenv.args.find("-g") == cenv.args.end()) fnOpt->run(*static_cast<Function*>(f)); + + currentFn = NULL; } void |