ldc/ir/irtypefunction.cpp
2011-10-25 15:43:39 +04:00

53 lines
1.1 KiB
C++

#include "llvm/DerivedTypes.h"
#include "mtype.h"
#include "gen/irstate.h"
#include "gen/tollvm.h"
#include "gen/functions.h"
#include "ir/irtypefunction.h"
IrTypeFunction::IrTypeFunction(Type* dt)
: IrType(dt, func2llvm(dt))
{
irfty = NULL;
}
llvm::Type * IrTypeFunction::buildType()
{
return type;
}
llvm::Type* IrTypeFunction::func2llvm(Type* dt)
{
llvm::Type* T;
TypeFunction* tf = (TypeFunction*)dt;
if (tf->funcdecl)
T = DtoFunctionType(tf->funcdecl);
else
T = DtoFunctionType(tf,NULL,NULL);
return T;
}
//////////////////////////////////////////////////////////////////////////////
IrTypeDelegate::IrTypeDelegate(Type * dt)
: IrType(dt, delegate2llvm(dt))
{
}
llvm::Type* IrTypeDelegate::buildType()
{
return type;
}
llvm::Type* IrTypeDelegate::delegate2llvm(Type* dt)
{
assert(dt->ty == Tdelegate);
LLType* func = DtoFunctionType(dt->nextOf(), NULL, Type::tvoid->pointerTo());
llvm::SmallVector<LLType*, 2> types;
types.push_back(getVoidPtrType());
types.push_back(getPtrToType(func));
LLStructType* dgtype = LLStructType::get(gIR->context(), types);
return dgtype;
}