mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-03-17 17:41:49 +01:00
First merge of 2.064 beta.
This corresponds to DMD commit a913ce4bc59a94a022a27e390fc841f4aededffb. Doesn't build Phobos yet.
This commit is contained in:
committed by
Kai Nacke
parent
c400d180d2
commit
cb341586e3
@@ -127,68 +127,6 @@ size_t add_zeros(llvm::SmallVectorImpl<llvm::Constant*>& constants, size_t diff)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LLConstant * IrAggr::createStructInitializer(StructInitializer * si)
|
||||
{
|
||||
IF_LOG Logger::println("Building StructInitializer of type %s", si->ad->toPrettyChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
// sanity check
|
||||
assert(si->ad == aggrdecl && "struct type mismatch");
|
||||
assert(si->vars.dim == si->value.dim && "inconsistent StructInitializer");
|
||||
|
||||
// array of things to build
|
||||
VarInitMap initConsts;
|
||||
|
||||
// fill in explicit initializers
|
||||
const size_t n = si->vars.dim;
|
||||
for (size_t i = 0; i < n; i++)
|
||||
{
|
||||
VarDeclaration* vd = si->vars[i];
|
||||
Initializer* ini = si->value[i];
|
||||
if (!ini)
|
||||
{
|
||||
// Unclear when this occurs - createInitializerConstant will just
|
||||
// fill in default initializer.
|
||||
continue;
|
||||
}
|
||||
|
||||
VarInitMap::iterator it, end = initConsts.end();
|
||||
for (it = initConsts.begin(); it != end; ++it)
|
||||
{
|
||||
if (it->first == vd)
|
||||
{
|
||||
error(ini->loc, "duplicate initialization of %s", vd->toChars());
|
||||
continue;
|
||||
}
|
||||
|
||||
const unsigned f_begin = it->first->offset;
|
||||
const unsigned f_end = f_begin + it->first->type->size();
|
||||
|
||||
if (vd->offset < f_end && (vd->offset + vd->type->size()) > f_begin)
|
||||
{
|
||||
error(ini->loc, "initializer for %s overlaps previous initialization of %s",
|
||||
vd->toChars(), it->first->toChars());
|
||||
}
|
||||
}
|
||||
|
||||
IF_LOG Logger::println("Explicit initializer: %s @+%u", vd->toChars(), vd->offset);
|
||||
LOG_SCOPE;
|
||||
|
||||
initConsts[vd] = DtoConstInitializer(ini->loc, vd->type, ini);
|
||||
}
|
||||
// stop if there were errors
|
||||
if (global.errors)
|
||||
{
|
||||
fatal();
|
||||
}
|
||||
|
||||
llvm::Constant* init = createInitializerConstant(initConsts, si->ltype);
|
||||
si->ltype = static_cast<llvm::StructType*>(init->getType());
|
||||
return init;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef std::pair<VarDeclaration*, llvm::Constant*> VarInitConst;
|
||||
|
||||
static bool struct_init_data_sort(const VarInitConst& a, const VarInitConst& b)
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <vector>
|
||||
|
||||
// DMD forward declarations
|
||||
struct StructInitializer;
|
||||
class StructInitializer;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -64,9 +64,6 @@ struct IrAggr
|
||||
/// Create the __interfaceInfos symbol lazily.
|
||||
LLGlobalVariable* getInterfaceArraySymbol();
|
||||
|
||||
/// Creates a StructInitializer constant.
|
||||
LLConstant* createStructInitializer(StructInitializer* si);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// Initialize interface.
|
||||
|
||||
@@ -80,7 +80,7 @@ LLGlobalVariable * IrAggr::getClassInfoSymbol()
|
||||
// The type is also ClassInfo for interfaces – the actual TypeInfo for them
|
||||
// is a TypeInfo_Interface instance that references __ClassZ in its "base"
|
||||
// member.
|
||||
ClassDeclaration* cinfo = ClassDeclaration::classinfo;
|
||||
ClassDeclaration* cinfo = Type::typeinfoclass;
|
||||
DtoType(cinfo->type);
|
||||
IrTypeClass* tc = stripModifiers(cinfo->type)->irtype->isClass();
|
||||
assert(tc && "invalid ClassInfo type");
|
||||
@@ -127,7 +127,7 @@ LLGlobalVariable * IrAggr::getInterfaceArraySymbol()
|
||||
assert(n > 0 && "getting ClassInfo.interfaces storage symbol, but we "
|
||||
"don't implement any interfaces");
|
||||
|
||||
VarDeclarationIter idx(ClassDeclaration::classinfo->fields, 3);
|
||||
VarDeclarationIter idx(Type::typeinfoclass->fields, 3);
|
||||
LLType* InterfaceTy = DtoType(idx->type->nextOf());
|
||||
|
||||
// create Interface[N]
|
||||
@@ -162,7 +162,7 @@ LLConstant * IrAggr::getVtblInit()
|
||||
|
||||
// start with the classinfo
|
||||
llvm::Constant* c = getClassInfoSymbol();
|
||||
c = DtoBitCast(c, DtoType(ClassDeclaration::classinfo->type));
|
||||
c = DtoBitCast(c, DtoType(Type::typeinfoclass->type));
|
||||
constants.push_back(c);
|
||||
|
||||
// add virtual function pointers
|
||||
@@ -285,7 +285,7 @@ llvm::GlobalVariable * IrAggr::getInterfaceVtbl(BaseClass * b, bool new_instance
|
||||
|
||||
if (!b->base->isCPPinterface()) { // skip interface info for CPP interfaces
|
||||
// start with the interface info
|
||||
VarDeclarationIter interfaces_idx(ClassDeclaration::classinfo->fields, 3);
|
||||
VarDeclarationIter interfaces_idx(Type::typeinfoclass->fields, 3);
|
||||
|
||||
// index into the interfaces array
|
||||
llvm::Constant* idxs[2] = {
|
||||
@@ -335,7 +335,7 @@ llvm::GlobalVariable * IrAggr::getInterfaceVtbl(BaseClass * b, bool new_instance
|
||||
OutBuffer name;
|
||||
name.writestring("Th");
|
||||
name.printf("%i", b->offset);
|
||||
name.writestring(fd->mangle());
|
||||
name.writestring(fd->mangleExact());
|
||||
LLFunction *thunk = LLFunction::Create(isaFunction(fn->getType()->getContainedType(0)),
|
||||
DtoLinkage(fd), name.toChars(), gIR->module);
|
||||
|
||||
@@ -414,7 +414,7 @@ LLConstant * IrAggr::getClassInfoInterfaces()
|
||||
assert(stripModifiers(type)->irtype->isClass()->getNumInterfaceVtbls() == n &&
|
||||
"inconsistent number of interface vtables in this class");
|
||||
|
||||
VarDeclarationIter interfaces_idx(ClassDeclaration::classinfo->fields, 3);
|
||||
VarDeclarationIter interfaces_idx(Type::typeinfoclass->fields, 3);
|
||||
|
||||
if (n == 0)
|
||||
return getNullValue(DtoType(interfaces_idx->type));
|
||||
@@ -431,10 +431,10 @@ LLConstant * IrAggr::getClassInfoInterfaces()
|
||||
LLSmallVector<LLConstant*, 6> constants;
|
||||
constants.reserve(cd->vtblInterfaces->dim);
|
||||
|
||||
LLType* classinfo_type = DtoType(ClassDeclaration::classinfo->type);
|
||||
LLType* classinfo_type = DtoType(Type::typeinfoclass->type);
|
||||
LLType* voidptrptr_type = DtoType(
|
||||
Type::tvoid->pointerTo()->pointerTo());
|
||||
VarDeclarationIter idx(ClassDeclaration::classinfo->fields, 3);
|
||||
VarDeclarationIter idx(Type::typeinfoclass->fields, 3);
|
||||
LLStructType* interface_type = isaStruct(DtoType(idx->type->nextOf()));
|
||||
assert(interface_type);
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ struct IrLocal;
|
||||
struct IrParameter;
|
||||
struct IrField;
|
||||
struct IrVar;
|
||||
struct Dsymbol;
|
||||
struct Module;
|
||||
class Dsymbol;
|
||||
class Module;
|
||||
|
||||
namespace llvm {
|
||||
class Value;
|
||||
|
||||
20
ir/irforw.h
20
ir/irforw.h
@@ -16,26 +16,26 @@
|
||||
#define LDC_IR_IRFORW_H
|
||||
|
||||
// dmd forward declarations
|
||||
struct Module;
|
||||
struct Dsymbol;
|
||||
class Module;
|
||||
class Dsymbol;
|
||||
struct Declaration;
|
||||
struct VarDeclaration;
|
||||
struct FuncDeclaration;
|
||||
class VarDeclaration;
|
||||
class FuncDeclaration;
|
||||
struct AggregateDeclaration;
|
||||
struct StructDeclaration;
|
||||
struct ClassDeclaration;
|
||||
class StructDeclaration;
|
||||
class ClassDeclaration;
|
||||
struct InterfaceDeclaration;
|
||||
struct Expression;
|
||||
struct BaseClass;
|
||||
struct Array;
|
||||
struct Argument;
|
||||
|
||||
struct Type;
|
||||
struct TypeStruct;
|
||||
struct TypeClass;
|
||||
class Type;
|
||||
class TypeStruct;
|
||||
class TypeClass;
|
||||
struct TypeEnum;
|
||||
struct TypeArray;
|
||||
struct TypeFunction;
|
||||
class TypeFunction;
|
||||
|
||||
// llvm forward declarations
|
||||
namespace llvm
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
struct Statement;
|
||||
class Statement;
|
||||
struct EnclosingHandler;
|
||||
|
||||
// scope statements that can be target of jumps
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <vector>
|
||||
|
||||
class DValue;
|
||||
struct Type;
|
||||
class Type;
|
||||
struct ABIRewrite;
|
||||
namespace llvm {
|
||||
class Type;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#ifndef LDC_IR_IRMODULE_H
|
||||
#define LDC_IR_IRMODULE_H
|
||||
|
||||
struct Module;
|
||||
class Module;
|
||||
namespace llvm
|
||||
{
|
||||
class GlobalVariable;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace llvm
|
||||
class Type;
|
||||
}
|
||||
|
||||
struct Type;
|
||||
class Type;
|
||||
|
||||
class IrTypeAggr;
|
||||
class IrTypeArray;
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace llvm {
|
||||
class StructType;
|
||||
}
|
||||
|
||||
struct AggregateDeclaration;
|
||||
struct VarDeclaration;
|
||||
class AggregateDeclaration;
|
||||
class VarDeclaration;
|
||||
|
||||
/// Base class of IrTypes for aggregate types.
|
||||
class IrTypeAggr : public IrType
|
||||
|
||||
@@ -188,7 +188,7 @@ void IrTypeClass::addBaseClassData(
|
||||
|
||||
ArrayIter<BaseClass> it2(*base->vtblInterfaces);
|
||||
|
||||
VarDeclarationIter interfaces_idx(ClassDeclaration::classinfo->fields, 3);
|
||||
VarDeclarationIter interfaces_idx(Type::typeinfoclass->fields, 3);
|
||||
Type* first = interfaces_idx->type->nextOf()->pointerTo();
|
||||
|
||||
// align offset
|
||||
@@ -284,7 +284,16 @@ IrTypeClass* IrTypeClass::get(ClassDeclaration* cd)
|
||||
// VTBL
|
||||
|
||||
// set vtbl type body
|
||||
t->vtbl_type->setBody(t->buildVtblType(ClassDeclaration::classinfo->type, &cd->vtbl));
|
||||
FuncDeclarations vtbl;
|
||||
vtbl.reserve(cd->vtbl.dim);
|
||||
vtbl.push(0);
|
||||
for (size_t i = 1; i < cd->vtbl.dim; ++i)
|
||||
{
|
||||
FuncDeclaration *fd = cd->vtbl[i]->isFuncDeclaration();
|
||||
assert(fd);
|
||||
vtbl.push(fd);
|
||||
}
|
||||
t->vtbl_type->setBody(t->buildVtblType(Type::typeinfoclass->type, &vtbl));
|
||||
|
||||
IF_LOG Logger::cout() << "class type: " << *t->type << std::endl;
|
||||
|
||||
@@ -293,7 +302,7 @@ IrTypeClass* IrTypeClass::get(ClassDeclaration* cd)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::vector<llvm::Type*> IrTypeClass::buildVtblType(Type* first, Array* vtbl_array)
|
||||
std::vector<llvm::Type*> IrTypeClass::buildVtblType(Type* first, FuncDeclarations* vtbl_array)
|
||||
{
|
||||
IF_LOG Logger::println("Building vtbl type for class %s", cd->toPrettyChars());
|
||||
LOG_SCOPE;
|
||||
@@ -305,13 +314,13 @@ std::vector<llvm::Type*> IrTypeClass::buildVtblType(Type* first, Array* vtbl_arr
|
||||
types.push_back(DtoType(first));
|
||||
|
||||
// then come the functions
|
||||
ArrayIter<Dsymbol> it(*vtbl_array);
|
||||
ArrayIter<FuncDeclaration> it(*vtbl_array);
|
||||
it.index = 1;
|
||||
|
||||
for (; !it.done(); it.next())
|
||||
{
|
||||
Dsymbol* dsym = it.get();
|
||||
if (dsym == NULL)
|
||||
FuncDeclaration* fd = it.get();
|
||||
if (fd == NULL)
|
||||
{
|
||||
// FIXME
|
||||
// why is this null?
|
||||
@@ -320,9 +329,6 @@ std::vector<llvm::Type*> IrTypeClass::buildVtblType(Type* first, Array* vtbl_arr
|
||||
continue;
|
||||
}
|
||||
|
||||
FuncDeclaration* fd = dsym->isFuncDeclaration();
|
||||
assert(fd && "invalid vtbl entry");
|
||||
|
||||
IF_LOG Logger::println("Adding type of %s", fd->toPrettyChars());
|
||||
|
||||
// If inferring return type and semantic3 has not been run, do it now.
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#endif
|
||||
|
||||
template <typename TYPE> struct Array;
|
||||
typedef Array<class FuncDeclaration> FuncDeclarations;
|
||||
|
||||
///
|
||||
class IrTypeClass : public IrTypeAggr
|
||||
{
|
||||
@@ -82,7 +85,7 @@ protected:
|
||||
|
||||
/// Builds a vtable type given the type of the first entry and an array
|
||||
/// of all entries.
|
||||
std::vector<llvm::Type*> buildVtblType(Type* first, Array* vtbl_array);
|
||||
std::vector<llvm::Type*> buildVtblType(Type* first, FuncDeclarations* vtbl_array);
|
||||
|
||||
///
|
||||
void addBaseClassData(
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
#include "ir/irtypeaggr.h"
|
||||
|
||||
struct StructDeclaration;
|
||||
struct TypeStruct;
|
||||
class StructDeclaration;
|
||||
class TypeStruct;
|
||||
|
||||
/// IrType for struct/union types.
|
||||
class IrTypeStruct : public IrTypeAggr
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#endif
|
||||
|
||||
struct IrFuncTyArg;
|
||||
struct VarDeclaration;
|
||||
class VarDeclaration;
|
||||
|
||||
struct IrVar
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user