From 667423a545c1f62efc32b48e5ce19c1c90181d4a Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 25 Mar 2009 22:36:49 +0000 Subject: [PATCH] More for for objc2's ivar layout map (currently is not in use). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67713 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCMac.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 2e059ad52e..f839374242 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -1516,7 +1516,8 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) { Values[ 8] = llvm::Constant::getNullValue(ObjCTypes.CachePtrTy); Values[ 9] = Protocols; // FIXME: Set ivar_layout - Values[10] = GetIvarLayoutName(0, ObjCTypes); + // Values[10] = BuildIvarLayout(ID, true); + Values[10] = GetIvarLayoutName(0, ObjCTypes); Values[11] = EmitClassExtension(ID); llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.ClassTy, Values); @@ -1640,6 +1641,7 @@ CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID) { std::vector Values(3); Values[0] = llvm::ConstantInt::get(ObjCTypes.IntTy, Size); // FIXME: Output weak_ivar_layout string. + // Values[1] = BuildIvarLayout(ID, false); Values[1] = GetIvarLayoutName(0, ObjCTypes); Values[2] = EmitPropertyList("\01L_OBJC_$_PROP_LIST_" + ID->getNameAsString(), ID, ID->getClassInterface(), ObjCTypes); @@ -2553,7 +2555,7 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI, if (!Field->getIdentifier() || Field->isBitField()) continue; QualType FQT = Field->getType(); - if (FQT->isAggregateType()) { + if (FQT->isRecordType() || FQT->isUnionType()) { std::vector NestedRecFields; if (FQT->isUnionType()) HasUnion = true; @@ -2580,6 +2582,12 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI, dyn_cast_or_null(Array); assert(CArray && "only array with know element size is supported"); FQT = CArray->getElementType(); + while (const ArrayType *Array = CGM.getContext().getAsArrayType(FQT)) { + const ConstantArrayType *CArray = + dyn_cast_or_null(Array); + FQT = CArray->getElementType(); + } + assert(!FQT->isUnionType() && "layout for array of unions not supported"); if (FQT->isRecordType()) { @@ -2893,7 +2901,8 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout( } } // null terminate string. - // BitMap += (unsigned char)0; + unsigned char zero = 0; + BitMap += zero; // if ivar_layout bitmap is all 1 bits (nothing skipped) then use NULL as // final layout. if (ForStrongLayout && !BytesSkipped) @@ -2902,6 +2911,16 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout( llvm::ConstantArray::get(BitMap.c_str()), "__TEXT,__cstring,cstring_literals", 0, true); + // FIXME. Need a commomand-line option for this eventually. + if (ForStrongLayout) + printf("\nstrong ivar layout: "); + else + printf("\nweak ivar layout: "); + const unsigned char *s = (unsigned char*)BitMap.c_str(); + for (unsigned i = 0; i < BitMap.size(); i++) + printf("0x%x ", s[i]); + printf("\n"); + return getConstantGEP(Entry, 0, 0); } -- 2.40.0