Eliminate the need for TypeFunction::funcdecl

This commit is contained in:
Alexey Prokhin
2013-10-05 19:03:03 +04:00
parent ca82589e25
commit b819975c84
22 changed files with 187 additions and 160 deletions
+4 -4
View File
@@ -29,6 +29,7 @@
#include "gen/arrays.h"
#include "gen/metadata.h"
#include "gen/runtime.h"
#include "gen/functions.h"
#include "ir/iraggr.h"
#include "ir/irtypeclass.h"
@@ -177,7 +178,7 @@ LLConstant * IrAggr::getVtblInit()
if (cd->isAbstract() || (fd->isAbstract() && !fd->fbody))
{
c = getNullValue(DtoType(fd->type->pointerTo()));
c = getNullValue(getPtrToType(DtoFunctionType(fd)));
}
else
{
@@ -329,8 +330,7 @@ llvm::GlobalVariable * IrAggr::getInterfaceVtbl(BaseClass * b, bool new_instance
// the function, we place into the vtable a small wrapper, called thunk,
// that casts 'this' to the object and then pass it to the real function.
if (b->base->isCPPinterface()) {
TypeFunction *f = (TypeFunction*)fd->type->toBasetype();
assert(f->fty.arg_this);
assert(fd->irFty.arg_this);
// create the thunk function
OutBuffer name;
@@ -352,7 +352,7 @@ llvm::GlobalVariable * IrAggr::getInterfaceVtbl(BaseClass * b, bool new_instance
args.push_back(iarg);
// cast 'this' to Object
LLValue* &thisArg = args[(f->fty.arg_sret == 0) ? 0 : 1];
LLValue* &thisArg = args[(fd->irFty.arg_sret == 0) ? 0 : 1];
LLType* thisType = thisArg->getType();
thisArg = DtoBitCast(thisArg, getVoidPtrType());
thisArg = DtoGEP1(thisArg, DtoConstInt(-b->offset));
+2 -1
View File
@@ -25,6 +25,7 @@
#include "gen/tollvm.h"
#include "gen/utils.h"
#include "gen/llvmhelpers.h"
#include "gen/functions.h"
#include "ir/irtypeclass.h"
//////////////////////////////////////////////////////////////////////////////
@@ -346,7 +347,7 @@ std::vector<llvm::Type*> IrTypeClass::buildVtblType(Type* first, Array* vtbl_arr
continue;
}
types.push_back(DtoType(fd->type->pointerTo()));
types.push_back(getPtrToType(DtoFunctionType(fd)));
}
+10 -24
View File
@@ -30,14 +30,8 @@ IrTypeFunction* IrTypeFunction::get(Type* dt, Type* nestedContextOverride)
assert(!dt->irtype);
assert(dt->ty == Tfunction);
// We can't get cycles here, but we can end up building the type as part of
// a class vtbl, ...
llvm::Type* lt;
TypeFunction* tf = static_cast<TypeFunction*>(dt);
if (tf->funcdecl)
lt = DtoFunctionType(tf->funcdecl);
else
lt = DtoFunctionType(tf, NULL, nestedContextOverride);
llvm::Type* lt = DtoFunctionType(tf, tf->irFty, NULL, nestedContextOverride);
if (!dt->irtype)
dt->irtype = new IrTypeFunction(dt, lt);
@@ -51,29 +45,21 @@ IrTypeDelegate::IrTypeDelegate(Type * dt, LLType* lt)
{
}
IrTypeDelegate* IrTypeDelegate::get(Type* dt)
IrTypeDelegate* IrTypeDelegate::get(Type* t)
{
assert(!dt->irtype);
assert(dt->ty == Tdelegate);
assert(!t->irtype);
assert(t->ty == Tdelegate);
assert(t->nextOf()->ty == Tfunction);
TypeDelegate *dt = (TypeDelegate*)t;
// We can't get cycles here, but we could end up building the type as part
// of a class vtbl, ...
if (!dt->nextOf()->irtype)
{
// Build the underlying function type. Be sure to set irtype here, so
// the nested context arg doesn't disappear if DtoType is ever called
// on dt->nextOf().
IrTypeFunction::get(dt->nextOf(), Type::tvoid->pointerTo());
}
if (!dt->irtype)
{
assert(static_cast<TypeFunction*>(dt->nextOf())->fty.arg_nest &&
"Underlying function type should have nested context arg, "
"picked up random pre-existing type?"
);
TypeFunction* tf = static_cast<TypeFunction*>(dt->nextOf());
llvm::Type* ltf = DtoFunctionType(tf, dt->irFty, NULL, Type::tvoid->pointerTo());
llvm::Type *types[] = { getVoidPtrType(),
getPtrToType(dt->nextOf()->irtype->getLLType()) };
getPtrToType(ltf) };
LLStructType* lt = LLStructType::get(gIR->context(), types, false);
dt->irtype = new IrTypeDelegate(dt, lt);
}