aboutsummaryrefslogtreecommitdiffstats
path: root/llvm.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-06-28 03:06:22 +0000
committerDavid Robillard <d@drobilla.net>2009-06-28 03:06:22 +0000
commit87778a3526c38e0570a9462bf28ae87d38cf8ad1 (patch)
treeba8b3b95d398b889e6009c6cfa84e9990e7bc726 /llvm.cpp
parent7ee03dcd4fa9bdbd94678f044133ba852c152532 (diff)
downloadresp-87778a3526c38e0570a9462bf28ae87d38cf8ad1.tar.gz
resp-87778a3526c38e0570a9462bf28ae87d38cf8ad1.tar.bz2
resp-87778a3526c38e0570a9462bf28ae87d38cf8ad1.zip
Fix type substitution.
git-svn-id: http://svn.drobilla.net/resp/tuplr@158 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'llvm.cpp')
-rw-r--r--llvm.cpp39
1 files changed, 31 insertions, 8 deletions
diff --git a/llvm.cpp b/llvm.cpp
index 053e2e2..b5e397e 100644
--- a/llvm.cpp
+++ b/llvm.cpp
@@ -47,6 +47,25 @@ llType(const AType* t)
if (t->at(0)->str() == "Int") return Type::Int32Ty;
if (t->at(0)->str() == "Float") return Type::FloatTy;
throw Error(t->loc, string("Unknown primitive type `") + t->str() + "'");
+ /*} else if (t->kind == AType::EXPR && t->at(0)->str() == "Fn") {
+ AType* retT = t->at(2)->as<AType*>();
+ if (!llType(retT))
+ return NULL;
+
+ vector<const Type*> cprot;
+ const ATuple* prot = t->at(1)->to<ATuple*>();
+ for (size_t i = 0; i < prot->size(); ++i) {
+ AType* at = prot->at(i)->to<AType*>();
+ const Type* lt = llType(at);
+ if (lt)
+ cprot.push_back(lt);
+ else
+ return NULL;
+ }
+
+ FunctionType* fT = FunctionType::get(llType(retT), cprot, false);
+ return PointerType::get(fT, 0);
+ */
}
return NULL; // non-primitive type
}
@@ -120,6 +139,9 @@ struct LLVMEngine : public Engine {
builder.CreateRetVoid();
}
+ /*std::cerr << "MODULE {" << endl;
+ module->dump();
+ std::cerr << "}" << endl;*/
verifyFunction(*static_cast<Function*>(f));
if (cenv.args.find("-g") == cenv.args.end())
opt.run(*static_cast<Function*>(f));
@@ -230,10 +252,11 @@ AFn::liftCall(CEnv& cenv, const AType& argsT)
{
TEnv::GenericTypes::const_iterator gt = cenv.tenv.genericTypes.find(this);
assert(gt != cenv.tenv.genericTypes.end());
- AType* thisType = new AType(*gt->second);
+ AType* genericType = new AType(*gt->second);
+ AType* thisType = genericType;
Subst argsSubst;
- if (!thisType->concrete()) {
+ if (!genericType->concrete()) {
// Build substitution to apply to generic type
assert(argsT.size() == prot()->size());
ATuple* genericProtT = gt->second->at(1)->as<ATuple*>();
@@ -249,18 +272,18 @@ AFn::liftCall(CEnv& cenv, const AType& argsT)
AType* gT = genericArgT->at(i)->to<AType*>();
AType* aT = callArgT->at(i)->to<AType*>();
if (gT && aT)
- argsSubst[gT] = aT;
+ argsSubst.add(gT, aT);
}
} else {
- argsSubst[genericArgT] = callArgT;
+ argsSubst.add(genericArgT, callArgT);
}
}
// Apply substitution to get concrete type for this call
- thisType = argsSubst.apply(thisType)->as<AType*>();
- if (!thisType->concrete())
- throw Error(loc, string("unable to resolve concrete type for function :: ")
- + thisType->str() + "\n" + this->str());
+ thisType = argsSubst.apply(genericType)->as<AType*>();
+ THROW_IF(!thisType->concrete(), loc,
+ string("unable to resolve concrete type for function :: ")
+ + thisType->str() + "\n" + this->str());
}
Object::pool.addRoot(thisType);