Renamed IrStruct to IrAggr, as it is also used for classes.

The class-specific parts should probably be factored out.
This commit is contained in:
David Nadlinger
2013-06-12 11:40:30 +02:00
parent 28f39cbdad
commit f2f3c751b3
13 changed files with 52 additions and 52 deletions

View File

@@ -25,7 +25,7 @@
#include "gen/structs.h"
#include "gen/tollvm.h"
#include "gen/utils.h"
#include "ir/irstruct.h"
#include "ir/iraggr.h"
#include "ir/irtypeclass.h"
//////////////////////////////////////////////////////////////////////////////////////////
@@ -55,10 +55,10 @@ void DtoResolveClass(ClassDeclaration* cd)
// make sure type exists
DtoType(cd->type);
// create IrStruct
// create IrAggr
assert(cd->ir.irStruct == NULL);
IrStruct* irstruct = new IrStruct(cd);
cd->ir.irStruct = irstruct;
IrAggr* irAggr = new IrAggr(cd);
cd->ir.irStruct = irAggr;
// make sure all fields really get their ir field
ArrayIter<VarDeclaration> it(cd->fields);
@@ -75,30 +75,30 @@ void DtoResolveClass(ClassDeclaration* cd)
bool needs_def = mustDefineSymbol(cd);
// emit the ClassZ symbol
LLGlobalVariable* ClassZ = irstruct->getClassInfoSymbol();
LLGlobalVariable* ClassZ = irAggr->getClassInfoSymbol();
// emit the interfaceInfosZ symbol if necessary
if (cd->vtblInterfaces && cd->vtblInterfaces->dim > 0)
irstruct->getInterfaceArraySymbol(); // initializer is applied when it's built
irAggr->getInterfaceArraySymbol(); // initializer is applied when it's built
// interface only emit typeinfo and classinfo
if (cd->isInterfaceDeclaration())
{
irstruct->initializeInterface();
irAggr->initializeInterface();
}
else
{
// emit the initZ symbol
LLGlobalVariable* initZ = irstruct->getInitSymbol();
LLGlobalVariable* initZ = irAggr->getInitSymbol();
// emit the vtblZ symbol
LLGlobalVariable* vtblZ = irstruct->getVtblSymbol();
LLGlobalVariable* vtblZ = irAggr->getVtblSymbol();
// perform definition
if (needs_def)
{
// set symbol initializers
initZ->setInitializer(irstruct->getDefaultInit());
vtblZ->setInitializer(irstruct->getVtblInit());
initZ->setInitializer(irAggr->getDefaultInit());
vtblZ->setInitializer(irAggr->getVtblInit());
}
}
@@ -121,7 +121,7 @@ void DtoResolveClass(ClassDeclaration* cd)
DtoTypeInfoOf(cd->type);
// define classinfo
ClassZ->setInitializer(irstruct->getClassInfoInit());
ClassZ->setInitializer(irAggr->getClassInfoInit());
}
}
@@ -689,7 +689,7 @@ LLConstant* DtoDefineClassInfo(ClassDeclaration* cd)
assert(cd->type->ty == Tclass);
TypeClass* cdty = static_cast<TypeClass*>(cd->type);
IrStruct* ir = cd->ir.irStruct;
IrAggr* ir = cd->ir.irStruct;
assert(ir);
ClassDeclaration* cinfo = ClassDeclaration::classinfo;

View File

@@ -105,7 +105,7 @@ llvm::Instruction* IRState::topallocapoint()
return functions.back()->allocapoint;
}
IrStruct* IRState::topstruct()
IrAggr* IRState::topstruct()
{
assert(!structs.empty() && "Struct vector is empty!");
return structs.back();

View File

@@ -18,7 +18,7 @@
#include "aggregate.h"
#include "root.h"
#include "ir/irfunction.h"
#include "ir/irstruct.h"
#include "ir/iraggr.h"
#include "ir/irvar.h"
#include <deque>
#include <list>
@@ -146,9 +146,9 @@ struct IRState
llvm::Instruction* topallocapoint();
// structs
typedef std::vector<IrStruct*> StructVector;
typedef std::vector<IrAggr*> StructVector;
StructVector structs;
IrStruct* topstruct();
IrAggr* topstruct();
// D main function
bool emitMain;

View File

@@ -16,7 +16,7 @@
#include "gen/llvm.h"
#include "gen/llvmhelpers.h"
#include "gen/tollvm.h"
#include "ir/irstruct.h"
#include "ir/iraggr.h"
RTTIBuilder::RTTIBuilder(AggregateDeclaration* base_class)
{

View File

@@ -27,7 +27,7 @@ struct ClassDeclaration;
struct Dsymbol;
struct FuncDeclaration;
struct IrGlobal;
struct IrStruct;
struct IrAggr;
struct Type;
struct TypeClass;
namespace llvm { class StructType; }
@@ -36,7 +36,7 @@ struct RTTIBuilder
{
AggregateDeclaration* base;
TypeClass* basetype;
IrStruct* baseir;
IrAggr* baseir;
// 10 is enough for any D1 TypeInfo
// 14 is enough for any D1 ClassInfo

View File

@@ -21,7 +21,7 @@
#include "gen/structs.h"
#include "gen/tollvm.h"
#include "gen/utils.h"
#include "ir/irstruct.h"
#include "ir/iraggr.h"
#include "ir/irtypestruct.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/ManagedStatic.h"
@@ -45,8 +45,8 @@ void DtoResolveStruct(StructDeclaration* sd)
if (sd->sizeok != 1)
return;
// create the IrStruct
IrStruct* irstruct = new IrStruct(sd);
// create the IrAggr
IrAggr* irstruct = new IrAggr(sd);
sd->ir.irStruct = irstruct;
// Set up our field metadata.

View File

@@ -280,7 +280,7 @@ static llvm::DIType dwarfCompositeType(Type* type)
if (sd->sizeok == 0)
return llvm::DICompositeType(NULL);
IrStruct* ir = sd->ir.irStruct;
IrAggr* ir = sd->ir.irStruct;
assert(ir);
if (static_cast<llvm::MDNode*>(ir->diCompositeType) != 0)
return ir->diCompositeType;

View File

@@ -607,7 +607,7 @@ void TypeInfoStructDeclaration::llvmDefine()
}
sd->codegen(Type::sir);
IrStruct* irstruct = sd->ir.irStruct;
IrAggr* irstruct = sd->ir.irStruct;
RTTIBuilder b(Type::typeinfostruct);

View File

@@ -1,4 +1,4 @@
//===-- irstruct.cpp ------------------------------------------------------===//
//===-- iraggr.cpp --------------------------------------------------------===//
//
// LDC the LLVM D compiler
//
@@ -17,13 +17,13 @@
#include "gen/logger.h"
#include "gen/tollvm.h"
#include "gen/utils.h"
#include "ir/irstruct.h"
#include "ir/iraggr.h"
#include "ir/irtypeclass.h"
#include <algorithm>
//////////////////////////////////////////////////////////////////////////////
IrStruct::IrStruct(AggregateDeclaration* aggr)
IrAggr::IrAggr(AggregateDeclaration* aggr)
: diCompositeType(NULL),
init_type(LLStructType::create(gIR->context(), std::string(aggr->toPrettyChars()) + "_init"))
{
@@ -50,7 +50,7 @@ IrStruct::IrStruct(AggregateDeclaration* aggr)
//////////////////////////////////////////////////////////////////////////////
LLGlobalVariable * IrStruct::getInitSymbol()
LLGlobalVariable * IrAggr::getInitSymbol()
{
if (init)
return init;
@@ -76,7 +76,7 @@ LLGlobalVariable * IrStruct::getInitSymbol()
//////////////////////////////////////////////////////////////////////////////
llvm::Constant * IrStruct::getDefaultInit()
llvm::Constant * IrAggr::getDefaultInit()
{
if (constInit)
return constInit;
@@ -158,7 +158,7 @@ size_t add_zeros(std::vector<llvm::Constant*>& constants, size_t diff)
// Matches the way the type is built in IrTypeStruct
// maybe look at unifying the interface.
std::vector<llvm::Constant*> IrStruct::createStructDefaultInitializer()
std::vector<llvm::Constant*> IrAggr::createStructDefaultInitializer()
{
IF_LOG Logger::println("Building default initializer for %s", aggrdecl->toPrettyChars());
LOG_SCOPE;
@@ -218,7 +218,7 @@ std::vector<llvm::Constant*> IrStruct::createStructDefaultInitializer()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
LLConstant * IrStruct::createStructInitializer(StructInitializer * si)
LLConstant * IrAggr::createStructInitializer(StructInitializer * si)
{
IF_LOG Logger::println("Building StructInitializer of type %s", si->ad->toPrettyChars());
LOG_SCOPE;

View File

@@ -1,4 +1,4 @@
//===-- ir/irstruct.h - Codegen state for D aggregates ----------*- C++ -*-===//
//===-- ir/iraggr.h - Codegen state for D aggregates ------------*- C++ -*-===//
//
// LDC the LLVM D compiler
//
@@ -12,8 +12,8 @@
//
//===----------------------------------------------------------------------===//
#ifndef LDC_IR_IRSTRUCT_H
#define LDC_IR_IRSTRUCT_H
#ifndef LDC_IR_IRAGGR_H
#define LDC_IR_IRAGGR_H
#include "ir/ir.h"
#include <map>
@@ -26,10 +26,10 @@ struct StructInitializer;
// represents a struct or class
// it is used during codegen to hold all the vital info we need
struct IrStruct
struct IrAggr
{
/// Constructor.
IrStruct(AggregateDeclaration* agg);
IrAggr(AggregateDeclaration* agg);
//////////////////////////////////////////////////////////////////////////
// public fields,

View File

@@ -29,7 +29,7 @@
#include "gen/metadata.h"
#include "gen/runtime.h"
#include "ir/irstruct.h"
#include "ir/iraggr.h"
#include "ir/irtypeclass.h"
//////////////////////////////////////////////////////////////////////////////
@@ -41,7 +41,7 @@ extern LLConstant* DtoDefineClassInfo(ClassDeclaration* cd);
//////////////////////////////////////////////////////////////////////////////
LLGlobalVariable * IrStruct::getVtblSymbol()
LLGlobalVariable * IrAggr::getVtblSymbol()
{
if (vtbl)
return vtbl;
@@ -63,7 +63,7 @@ LLGlobalVariable * IrStruct::getVtblSymbol()
//////////////////////////////////////////////////////////////////////////////
LLGlobalVariable * IrStruct::getClassInfoSymbol()
LLGlobalVariable * IrAggr::getClassInfoSymbol()
{
if (classInfo)
return classInfo;
@@ -114,7 +114,7 @@ LLGlobalVariable * IrStruct::getClassInfoSymbol()
//////////////////////////////////////////////////////////////////////////////
LLGlobalVariable * IrStruct::getInterfaceArraySymbol()
LLGlobalVariable * IrAggr::getInterfaceArraySymbol()
{
if (classInterfacesArray)
return classInterfacesArray;
@@ -145,7 +145,7 @@ LLGlobalVariable * IrStruct::getInterfaceArraySymbol()
//////////////////////////////////////////////////////////////////////////////
LLConstant * IrStruct::getVtblInit()
LLConstant * IrAggr::getVtblInit()
{
if (constVtbl)
return constVtbl;
@@ -253,7 +253,7 @@ LLConstant * IrStruct::getVtblInit()
//////////////////////////////////////////////////////////////////////////////
LLConstant * IrStruct::getClassInfoInit()
LLConstant * IrAggr::getClassInfoInit()
{
if (constClassInfo)
return constClassInfo;
@@ -263,7 +263,7 @@ LLConstant * IrStruct::getClassInfoInit()
//////////////////////////////////////////////////////////////////////////////
void IrStruct::addBaseClassInits(
void IrAggr::addBaseClassInits(
std::vector<llvm::Constant*>& constants,
ClassDeclaration* base,
size_t& offset,
@@ -330,7 +330,7 @@ void IrStruct::addBaseClassInits(
//////////////////////////////////////////////////////////////////////////////
std::vector<llvm::Constant*> IrStruct::createClassDefaultInitializer()
std::vector<llvm::Constant*> IrAggr::createClassDefaultInitializer()
{
ClassDeclaration* cd = aggrdecl->isClassDeclaration();
assert(cd && "invalid class aggregate");
@@ -366,7 +366,7 @@ std::vector<llvm::Constant*> IrStruct::createClassDefaultInitializer()
//////////////////////////////////////////////////////////////////////////////
llvm::GlobalVariable * IrStruct::getInterfaceVtbl(BaseClass * b, bool new_instance, size_t interfaces_index)
llvm::GlobalVariable * IrAggr::getInterfaceVtbl(BaseClass * b, bool new_instance, size_t interfaces_index)
{
ClassGlobalMap::iterator it = interfaceVtblMap.find(b->base);
if (it != interfaceVtblMap.end())
@@ -454,7 +454,7 @@ llvm::GlobalVariable * IrStruct::getInterfaceVtbl(BaseClass * b, bool new_instan
//////////////////////////////////////////////////////////////////////////////
LLConstant * IrStruct::getClassInfoInterfaces()
LLConstant * IrAggr::getClassInfoInterfaces()
{
IF_LOG Logger::println("Building ClassInfo.interfaces");
LOG_SCOPE;
@@ -496,7 +496,7 @@ LLConstant * IrStruct::getClassInfoInterfaces()
IF_LOG Logger::println("Adding interface %s", it->base->toPrettyChars());
IrStruct* irinter = it->base->ir.irStruct;
IrAggr* irinter = it->base->ir.irStruct;
assert(irinter && "interface has null IrStruct");
IrTypeClass* itc = stripModifiers(irinter->type)->irtype->isClass();
assert(itc && "null interface IrTypeClass");
@@ -559,7 +559,7 @@ LLConstant * IrStruct::getClassInfoInterfaces()
//////////////////////////////////////////////////////////////////////////////
void IrStruct::initializeInterface()
void IrAggr::initializeInterface()
{
InterfaceDeclaration* base = aggrdecl->isInterfaceDeclaration();
assert(base && "not interface");

View File

@@ -18,7 +18,7 @@
struct IrModule;
struct IrFunction;
struct IrStruct;
struct IrAggr;
struct IrGlobal;
struct IrLocal;
struct IrParameter;
@@ -52,7 +52,7 @@ struct IrDsymbol
IrModule* irModule;
IrStruct* irStruct;
IrAggr* irStruct;
IrFunction* irFunc;

View File

@@ -56,7 +56,7 @@ class IrTypeVector;
/// easily check for uniqueness violations in the face of forward references.
/// TODO: Implement the described changes (now that the forward reference
/// handling logic seems to work correctly) and get rid of the "no-op" DtoType
/// calls in IrStruct, ... that only exist for their side effect.
/// calls in IrAggr, ... that only exist for their side effect.
class IrType
{
public: