aboutsummaryrefslogtreecommitdiffstats
path: root/src/llvm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/llvm.cpp')
-rw-r--r--src/llvm.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/llvm.cpp b/src/llvm.cpp
index 532051e..3391cb7 100644
--- a/src/llvm.cpp
+++ b/src/llvm.cpp
@@ -80,6 +80,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, CVal ret, const AST* retT);
+ CFunc getFn(CEnv& cenv, const std::string& name);
void eraseFn(CEnv& cenv, CFunc f);
CVal compileCall(CEnv& cenv, CFunc f, const ATuple* funcT, const vector<CVal>& args);
@@ -392,9 +393,11 @@ LLVMEngine::startFn(
// however LLVM chooses to mangle is fine, we keep a pointer
// Set argument names in generated code
- Function::arg_iterator a = f->arg_begin();
- for (ATuple::const_iterator i = args->begin(); i != args->end(); ++a, ++i)
- a->setName((*i)->as_symbol()->sym());
+ if (args) {
+ Function::arg_iterator a = f->arg_begin();
+ for (ATuple::const_iterator i = args->begin(); i != args->end(); ++a, ++i)
+ a->setName((*i)->as_symbol()->sym());
+ }
BasicBlock* bb = BasicBlock::Create(context, "entry", f);
builder.SetInsertPoint(bb);
@@ -408,6 +411,9 @@ LLVMEngine::pushFnArgs(CEnv& cenv, const ATuple* prot, const ATuple* type, CFunc
{
cenv.push();
+ if (!prot)
+ return;
+
const ATuple* argsT = type->prot();
Function* f = llFunc(cfunc);
@@ -443,6 +449,12 @@ LLVMEngine::finishFn(CEnv& cenv, CVal ret, const AST* retT)
currentFn = NULL;
}
+CFunc
+LLVMEngine::getFn(CEnv& cenv, const std::string& name)
+{
+ return module->getFunction(name);
+}
+
void
LLVMEngine::eraseFn(CEnv& cenv, CFunc f)
{