From f13c5e82f5178eeac5ce1e2e2f67972258f8d4cf Mon Sep 17 00:00:00 2001 From: Robert Clipsham Date: Thu, 18 Jun 2009 15:44:04 +0100 Subject: [PATCH] Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers). Replaced a few occurances of STCinvariant with STCimmutable. --- gen/declarations.cpp | 2 +- gen/llvmhelpers.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++ gen/llvmhelpers.h | 2 ++ gen/todebug.cpp | 2 +- gen/tollvm.cpp | 4 +-- 5 files changed, 78 insertions(+), 5 deletions(-) diff --git a/gen/declarations.cpp b/gen/declarations.cpp index 4d495208..5227fbb8 100644 --- a/gen/declarations.cpp +++ b/gen/declarations.cpp @@ -96,7 +96,7 @@ void VarDeclaration::codegen(Ir* p) // global variable #if DMDV2 // taken from dmd2/structs - if (isDataseg() || (storage_class & (STCconst | STCinvariant) && init)) + if (isDataseg() || (storage_class & (STCconst | STCimmutable) && init)) #else if (isDataseg()) #endif diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index c664ee67..591669fb 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1480,3 +1480,76 @@ size_t realignOffset(size_t offset, Type* type) } ////////////////////////////////////////////////////////////////////////////////////////// + +Type * stripModifiers( Type * type ) +{ +#if DMDV2 + Type *t = type; + while (t->mod) + { + switch (t->mod) + { + case MODconst: + t = type->cto; + break; + case MODshared: + t = type->sto; + break; + case MODinvariant: + t = type->ito; + break; + case MODshared | MODconst: + t = type->scto; + break; + default: + assert(0 && "Unhandled type modifier"); + } + + if (!t) + { + unsigned sz = type->sizeTy[type->ty]; + t = (Type *)malloc(sz); + memcpy(t, type, sz); + t->mod = 0; + t->deco = NULL; + t->arrayof = NULL; + t->pto = NULL; + t->rto = NULL; + t->cto = NULL; + t->ito = NULL; + t->sto = NULL; + t->scto = NULL; + t->vtinfo = NULL; + t = t->merge(); + + t->fixTo(type); + switch (type->mod) + { + case MODconst: + t->cto = type; + break; + + case MODinvariant: + t->ito = type; + break; + + case MODshared: + t->sto = type; + break; + + case MODshared | MODconst: + t->scto = type; + break; + + default: + assert(0); + } + } + } + return t; +#else + return type; +#endif +} + +////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index b79261b5..01434e59 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -170,4 +170,6 @@ void DtoBuildDVarArgList(std::vector& args, llvm::AttrListPtr& palist, /// DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* arguments); +Type* stripModifiers(Type* type); + #endif diff --git a/gen/todebug.cpp b/gen/todebug.cpp index 0606b32c..da4c5ef8 100644 --- a/gen/todebug.cpp +++ b/gen/todebug.cpp @@ -408,7 +408,7 @@ static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit static llvm::DIGlobalVariable dwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd) { #if DMDV2 - assert(vd->isDataseg() || (vd->storage_class & (STCconst | STCinvariant) && vd->init)); + assert(vd->isDataseg() || (vd->storage_class & (STCconst | STCimmutable) && vd->init)); #else assert(vd->isDataseg()); #endif diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 1022763e..f71a7aa0 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -54,9 +54,7 @@ unsigned DtoShouldExtend(Type* type) const LLType* DtoType(Type* t) { -#if DMDV2 - t = t->mutableOf(); -#endif + t = stripModifiers( t ); if (t->irtype) {