mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-02 16:11:08 +03:00
Refactored IrType construction to use static get() method.
This also allows us to enable the assert in IrType::IrType. Unfortunately, this is mostly a "peace of mind" commit, there doesn't seem to have been a bug actually caused by the transitory duplicate IrTypePointer/IrTypeStruct instances. The remaining xyz2llvm static methods are not exactly pretty, they should probably just be folded into get.
This commit is contained in:
parent
464c695814
commit
a3a511ca55
9 changed files with 170 additions and 156 deletions
|
@ -16,47 +16,51 @@
|
|||
|
||||
#include "ir/irtypefunction.h"
|
||||
|
||||
IrTypeFunction::IrTypeFunction(Type* dt)
|
||||
: IrType(dt, func2llvm(dt))
|
||||
IrTypeFunction::IrTypeFunction(Type* dt, LLType* lt)
|
||||
: IrType(dt, lt)
|
||||
{
|
||||
irfty = NULL;
|
||||
}
|
||||
|
||||
llvm::Type * IrTypeFunction::buildType()
|
||||
IrTypeFunction* IrTypeFunction::get(Type* dt)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
assert(dt->ty == Tfunction);
|
||||
|
||||
llvm::Type* IrTypeFunction::func2llvm(Type* dt)
|
||||
{
|
||||
llvm::Type* T;
|
||||
// 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)
|
||||
T = DtoFunctionType(tf->funcdecl);
|
||||
lt = DtoFunctionType(tf->funcdecl);
|
||||
else
|
||||
T = DtoFunctionType(tf,NULL,NULL);
|
||||
return T;
|
||||
lt = DtoFunctionType(tf,NULL,NULL);
|
||||
|
||||
if (!dt->irtype)
|
||||
dt->irtype = new IrTypeFunction(dt, lt);
|
||||
return dt->irtype->isFunction();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IrTypeDelegate::IrTypeDelegate(Type * dt)
|
||||
: IrType(dt, delegate2llvm(dt))
|
||||
IrTypeDelegate::IrTypeDelegate(Type * dt, LLType* lt)
|
||||
: IrType(dt, lt)
|
||||
{
|
||||
}
|
||||
|
||||
llvm::Type* IrTypeDelegate::buildType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
llvm::Type* IrTypeDelegate::delegate2llvm(Type* dt)
|
||||
IrTypeDelegate* IrTypeDelegate::get(Type* dt)
|
||||
{
|
||||
assert(dt->ty == Tdelegate);
|
||||
|
||||
// We can't get cycles here, but we can end up building the type as part of
|
||||
// a class vtbl, ...
|
||||
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;
|
||||
if (!dt->irtype)
|
||||
{
|
||||
llvm::SmallVector<LLType*, 2> types;
|
||||
types.push_back(getVoidPtrType());
|
||||
types.push_back(getPtrToType(func));
|
||||
LLStructType* lt = LLStructType::get(gIR->context(), types);
|
||||
dt->irtype = new IrTypeDelegate(dt, lt);
|
||||
}
|
||||
|
||||
return dt->irtype->isDelegate();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue