Renamed IrType::get/IrType::getD, treat classes as the special case they are.

This commit is contained in:
David Nadlinger
2012-12-20 06:23:27 +01:00
parent aa4543465d
commit 464c695814
8 changed files with 35 additions and 17 deletions

View File

@@ -722,7 +722,7 @@ LLConstant* DtoDefineClassInfo(ClassDeclaration* cd)
}
else
{
LLType* cd_type = stripModifiers(cdty)->irtype->getType();
LLType* cd_type = cdty->irtype->isClass()->getMemoryLLType();
size_t initsz = getTypePaddedSize(cd_type);
b.push_void_array(initsz, ir->getInitSymbol());
}

View File

@@ -50,6 +50,10 @@
#include "ir/irmodule.h"
#include "ir/irtype.h"
#if !MODULEINFO_IS_STRUCT
#include "ir/irtypeclass.h"
#endif
#if DMDV2
#define NEW_MODULEINFO_LAYOUT 1
#endif
@@ -379,8 +383,12 @@ void Module::genmoduleinfo()
RTTIBuilder b(moduleinfo);
// some types
LLType* moduleinfoTy = moduleinfo->type->irtype->getType();
LLType* classinfoTy = ClassDeclaration::classinfo->type->irtype->getType();
#if MODULEINFO_IS_STRUCT
LLType* moduleinfoTy = moduleinfo->type->irtype->getLLType();
#else
LLType* moduleinfoTy = moduleinfo->type->irtype->isClass()->getMemoryLLType();
#endif
LLType* classinfoTy = ClassDeclaration::classinfo->type->irtype->getLLType();
// importedModules[]
std::vector<LLConstant*> importInits;
@@ -438,13 +446,13 @@ void Module::genmoduleinfo()
continue;
}
Logger::println("class: %s", cd->toPrettyChars());
LLConstant *c = DtoBitCast(cd->ir.irStruct->getClassInfoSymbol(), getPtrToType(classinfoTy));
LLConstant *c = DtoBitCast(cd->ir.irStruct->getClassInfoSymbol(), classinfoTy);
classInits.push_back(c);
}
// has class array?
if (!classInits.empty())
{
localClassesTy = llvm::ArrayType::get(getPtrToType(classinfoTy), classInits.size());
localClassesTy = llvm::ArrayType::get(classinfoTy, classInits.size());
localClasses = LLConstantArray::get(localClassesTy, classInits);
}

View File

@@ -79,7 +79,7 @@ LLType* DtoType(Type* t)
if (t->irtype)
{
return t->irtype->get();
return t->irtype->getLLType();
}
IF_LOG Logger::println("Building type: %s", t->toChars());

View File

@@ -53,6 +53,7 @@
#include "ir/irvar.h"
#include "ir/irtype.h"
#include <ir/irtypeclass.h>
/*******************************************
* Get a canonicalized form of the TypeInfo for use with the internal
@@ -323,7 +324,7 @@ void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
if (!irg->value) {
if (tid->tinfo->builtinTypeInfo()) // this is a declaration of a builtin __initZ var
irg->type = Type::typeinfo->type->irtype->getType();
irg->type = Type::typeinfo->type->irtype->isClass()->getMemoryLLType();
else
irg->type = LLStructType::create(gIR->context(), tid->toPrettyChars());
irg->value = new llvm::GlobalVariable(*gIR->module, irg->type, true,
@@ -638,7 +639,7 @@ void TypeInfoStructDeclaration::llvmDefine()
// void[] init
// never emit a null array, even for zero initialized typeinfo
// the size() method uses this array!
size_t init_size = getTypeStoreSize(tc->irtype->getType());
size_t init_size = getTypeStoreSize(tc->irtype->getLLType());
b.push_void_array(init_size, irstruct->getInitSymbol());
// toX functions ground work

View File

@@ -78,9 +78,9 @@ LLGlobalVariable * IrStruct::getClassInfoSymbol()
IrTypeClass* tc = stripModifiers(cinfo->type)->irtype->isClass();
assert(tc && "invalid ClassInfo type");
// classinfos cannot be constants since they're used a locks for synchronized
// classinfos cannot be constants since they're used as locks for synchronized
classInfo = new llvm::GlobalVariable(
*gIR->module, tc->getType(), false, _linkage, NULL, initname);
*gIR->module, tc->getMemoryLLType(), false, _linkage, NULL, initname);
#if USE_METADATA
// Generate some metadata on this ClassInfo if it's for a class.

View File

@@ -71,11 +71,9 @@ public:
#endif
///
Type* getD() { return dtype; }
Type* getDType() { return dtype; }
///
virtual llvm::Type* get() { return type; }
///
llvm::Type* getType() { return type; }
virtual llvm::Type* getLLType() { return type; }
///
virtual llvm::Type* buildType() = 0;

View File

@@ -279,7 +279,7 @@ llvm::Type* IrTypeClass::buildType()
IF_LOG Logger::cout() << "class type: " << *type << std::endl;
return get();
return getLLType();
}
//////////////////////////////////////////////////////////////////////////////
@@ -349,13 +349,20 @@ std::vector<llvm::Type*> IrTypeClass::buildVtblType(Type* first, Array* vtbl_arr
//////////////////////////////////////////////////////////////////////////////
llvm::Type * IrTypeClass::get()
llvm::Type * IrTypeClass::getLLType()
{
return llvm::PointerType::get(type, 0);
}
//////////////////////////////////////////////////////////////////////////////
llvm::Type * IrTypeClass::getMemoryLLType()
{
return type;
}
//////////////////////////////////////////////////////////////////////////////
size_t IrTypeClass::getInterfaceIndex(ClassDeclaration * inter)
{
ClassIndexMap::iterator it = interfaceMap.find(inter);

View File

@@ -31,7 +31,11 @@ public:
llvm::Type* buildType();
///
llvm::Type* get();
llvm::Type* getLLType();
/// Returns the actual storage type, i.e. without the indirection
/// for the class reference.
llvm::Type* getMemoryLLType();
/// Returns the vtable type for this class.
llvm::Type* getVtbl() { return vtbl_type; }