From 6cbeccf2ca0df91e5b71ccdbfcf412535f0c1179 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 14 May 2011 06:51:51 +0000 Subject: Use recursive types in IR rather than fugly __REC kludge. git-svn-id: http://svn.drobilla.net/resp/trunk@420 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/llvm.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/llvm.cpp') diff --git a/src/llvm.cpp b/src/llvm.cpp index 68a2a83..a0b635b 100644 --- a/src/llvm.cpp +++ b/src/llvm.cpp @@ -121,6 +121,7 @@ private: CType objectT; PATypeHolder* opaqueT; + std::string opaqueName; typedef std::map CTypes; CTypes compiledTypes; @@ -186,7 +187,10 @@ LLVMEngine::llType(const AST* t, const char* name) if (sym == "String") return PointerType::get(Type::getInt8Ty(context), 0); if (sym == "Symbol") return PointerType::get(Type::getInt8Ty(context), 0); if (sym == "Expr") return PointerType::get(Type::getInt8Ty(context), 0); - if (sym == "__REC") { if (!opaqueT) throw; return *opaqueT;} + if (sym == opaqueName) { + THROW_IF(!opaqueT, t->loc, "Broken recursive type"); + return *opaqueT; + } CTypes::const_iterator i = compiledTypes.find(sym); if (i != compiledTypes.end()) @@ -199,7 +203,8 @@ LLVMEngine::llType(const AST* t, const char* name) // Define opaque type to stand for name in recursive type body if (name) { THROW_IF(opaqueT, t->loc, "Nested recursive types"); - opaqueT = new PATypeHolder(OpaqueType::get(context)); + opaqueT = new PATypeHolder(OpaqueType::get(context)); + opaqueName = name; } const Type* ret; @@ -247,6 +252,7 @@ LLVMEngine::llType(const AST* t, const char* name) ((OpaqueType*)opaqueT->get())->refineAbstractTypeTo(ptrT); ptrT = cast(opaqueT->get()); // update potentially invalidated type opaqueT = NULL; + opaqueName = ""; module->addTypeName(name, retT.get()); } -- cgit v1.2.1