diff options
author | Chris Lattner <sabre@nondot.org> | 2007-07-14 01:29:45 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-07-14 01:29:45 +0000 |
commit | d2d2a11a91d7ddf468bfb70f66362d24806ed601 (patch) | |
tree | 1920f1ccb6fc00b05bbd9d884dd821601d906626 | |
parent | 8f32f7189b12f67aa4a19bc7c3855b599980eca0 (diff) |
A significant refactoring of the type size stuff to also
compute type alignment. This info is needed for struct layout.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39850 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | AST/ASTContext.cpp | 62 | ||||
-rw-r--r-- | Basic/TargetInfo.cpp | 11 | ||||
-rw-r--r-- | CodeGen/CGExpr.cpp | 3 | ||||
-rw-r--r-- | CodeGen/CodeGenFunction.cpp | 4 | ||||
-rw-r--r-- | CodeGen/CodeGenModule.cpp | 9 | ||||
-rw-r--r-- | CodeGen/CodeGenTypes.cpp | 21 | ||||
-rw-r--r-- | CodeGen/CodeGenTypes.h | 4 | ||||
-rw-r--r-- | Driver/Targets.cpp | 1 | ||||
-rw-r--r-- | Sema/SemaDecl.cpp | 2 | ||||
-rw-r--r-- | Sema/SemaExpr.cpp | 11 | ||||
-rw-r--r-- | include/clang/AST/ASTContext.h | 19 | ||||
-rw-r--r-- | include/clang/Basic/TargetInfo.h | 102 |
12 files changed, 137 insertions, 112 deletions
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp index 6e9208bbb5..d62bf94298 100644 --- a/AST/ASTContext.cpp +++ b/AST/ASTContext.cpp @@ -140,8 +140,11 @@ void ASTContext::InitBuiltinTypes() { /// getTypeSize - Return the size of the specified type, in bits. This method /// does not work on incomplete types. -unsigned ASTContext::getTypeSize(QualType T) { +std::pair<uint64_t, unsigned> +ASTContext::getTypeInfo(QualType T, SourceLocation L) { T = T.getCanonicalType(); + uint64_t Size; + unsigned Align; switch (T->getTypeClass()) { default: case Type::Complex: @@ -158,33 +161,34 @@ unsigned ASTContext::getTypeSize(QualType T) { // implementation will suffice for play with vector support. switch (cast<BuiltinType>(T)->getKind()) { default: assert(0 && "Unknown builtin type!"); - case BuiltinType::Void: assert(0 && "Incomplete types have no size!"); - case BuiltinType::Bool: return Target.getBoolWidth(SourceLocation()); + case BuiltinType::Void: + assert(0 && "Incomplete types have no size!"); + case BuiltinType::Bool: Target.getBoolInfo(Size, Align, L); break; case BuiltinType::Char_S: case BuiltinType::Char_U: case BuiltinType::UChar: - case BuiltinType::SChar: return Target.getCharWidth(SourceLocation()); + case BuiltinType::SChar: Target.getCharInfo(Size, Align, L); break; case BuiltinType::UShort: - case BuiltinType::Short: return Target.getShortWidth(SourceLocation()); + case BuiltinType::Short: Target.getShortInfo(Size, Align, L); break; case BuiltinType::UInt: - case BuiltinType::Int: return Target.getIntWidth(SourceLocation()); + case BuiltinType::Int: Target.getIntInfo(Size, Align, L); break; case BuiltinType::ULong: - case BuiltinType::Long: return Target.getLongWidth(SourceLocation()); + case BuiltinType::Long: Target.getLongInfo(Size, Align, L); break; case BuiltinType::ULongLong: - case BuiltinType::LongLong:return Target.getLongLongWidth(SourceLocation()); - case BuiltinType::Float: return Target.getFloatWidth(SourceLocation()); - case BuiltinType::Double: return Target.getDoubleWidth(SourceLocation()); - case BuiltinType::LongDouble: - return Target.getLongDoubleWidth(SourceLocation()); + case BuiltinType::LongLong: Target.getLongLongInfo(Size, Align, L); break; + case BuiltinType::Float: Target.getFloatInfo(Size, Align, L); break; + case BuiltinType::Double: Target.getDoubleInfo(Size, Align, L); break; + case BuiltinType::LongDouble: Target.getLongDoubleInfo(Size, Align,L);break; } } - case Type::Pointer: - return Target.getPointerWidth(SourceLocation()); + case Type::Pointer: Target.getPointerInfo(Size, Align, L); break; case Type::Reference: // "When applied to a reference or a reference type, the result is the size // of the referenced type." C++98 5.3.3p2: expr.sizeof - return getTypeSize(cast<ReferenceType>(T)->getReferenceeType()); + return getTypeInfo(cast<ReferenceType>(T)->getReferenceeType(), L); } + + return std::make_pair(Size, Align); } //===----------------------------------------------------------------------===// @@ -460,34 +464,6 @@ QualType ASTContext::getPointerDiffType() const { return IntTy; } -/// getIntegerBitwidth - Return the bitwidth of the specified integer type -/// according to the target. 'Loc' specifies the source location that -/// requires evaluation of this property. -unsigned ASTContext::getIntegerBitwidth(QualType T, SourceLocation Loc) { - if (const TagType *TT = dyn_cast<TagType>(T.getCanonicalType())) { - assert(TT->getDecl()->getKind() == Decl::Enum && "not an int or enum"); - assert(0 && "FIXME: getIntegerBitwidth(enum) unimplemented!"); - } - - const BuiltinType *BT = cast<BuiltinType>(T.getCanonicalType()); - switch (BT->getKind()) { - default: assert(0 && "getIntegerBitwidth(): not a built-in integer"); - case BuiltinType::Bool: return Target.getBoolWidth(Loc); - case BuiltinType::Char_S: - case BuiltinType::Char_U: - case BuiltinType::SChar: - case BuiltinType::UChar: return Target.getCharWidth(Loc); - case BuiltinType::Short: - case BuiltinType::UShort: return Target.getShortWidth(Loc); - case BuiltinType::Int: - case BuiltinType::UInt: return Target.getIntWidth(Loc); - case BuiltinType::Long: - case BuiltinType::ULong: return Target.getLongWidth(Loc); - case BuiltinType::LongLong: - case BuiltinType::ULongLong: return Target.getLongLongWidth(Loc); - } -} - /// getIntegerRank - Return an integer conversion rank (C99 6.3.1.1p1). This /// routine will assert if passed a built-in type that isn't an integer or enum. static int getIntegerRank(QualType t) { diff --git a/Basic/TargetInfo.cpp b/Basic/TargetInfo.cpp index 008e99b914..c94038508e 100644 --- a/Basic/TargetInfo.cpp +++ b/Basic/TargetInfo.cpp @@ -157,14 +157,17 @@ void TargetInfo::getTargetDefines(std::vector<char> &Buffer) { /// ComputeWCharWidth - Determine the width of the wchar_t type for the primary /// target, diagnosing whether this is non-portable across the secondary /// targets. -void TargetInfo::ComputeWCharWidth(SourceLocation Loc) { - WCharWidth = PrimaryTarget->getWCharWidth(); +void TargetInfo::ComputeWCharInfo(SourceLocation Loc) { + PrimaryTarget->getWCharInfo(WCharWidth, WCharAlign); // Check whether this is portable across the secondary targets if the T-U is // portable so far. - for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i) - if (SecondaryTargets[i]->getWCharWidth() != WCharWidth) + for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i) { + unsigned Width, Align; + SecondaryTargets[i]->getWCharInfo(Width, Align); + if (Width != WCharWidth || Align != WCharAlign) return DiagnoseNonPortability(Loc, diag::port_wchar_t); + } } diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp index 9f535b5352..0b1ac8fc79 100644 --- a/CodeGen/CGExpr.cpp +++ b/CodeGen/CGExpr.cpp @@ -1168,7 +1168,8 @@ RValue CodeGenFunction::EmitPointerSub(RValue LHS, QualType LHSTy, QualType LHSElementType = LHSPtrType->getPointeeType(); assert(LHSElementType == RHSPtrType->getPointeeType() && "can't subtract pointers with differing element types"); - unsigned ElementSize = getContext().getTypeSize(LHSElementType) / 8; + unsigned ElementSize = getContext().getTypeSize(LHSElementType, + SourceLocation()) / 8; const llvm::Type *ResultType = ConvertType(ResTy); llvm::Value *CastLHS = Builder.CreatePtrToInt(LHSValue, ResultType, "sub.ptr.lhs.cast"); diff --git a/CodeGen/CodeGenFunction.cpp b/CodeGen/CodeGenFunction.cpp index 662c3b513c..0cdda6c77c 100644 --- a/CodeGen/CodeGenFunction.cpp +++ b/CodeGen/CodeGenFunction.cpp @@ -51,7 +51,9 @@ bool CodeGenFunction::hasAggregateLLVMType(QualType T) { void CodeGenFunction::GenerateCode(const FunctionDecl *FD) { LLVMIntTy = ConvertType(getContext().IntTy); - LLVMPointerWidth = Target.getPointerWidth(SourceLocation()); + LLVMPointerWidth = + getContext().getTypeSize(getContext().getPointerType(getContext().VoidTy), + SourceLocation()); CurFn = cast<llvm::Function>(CGM.GetAddrOfGlobalDecl(FD)); CurFuncDecl = FD; diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp index d091dd73eb..262469e34b 100644 --- a/CodeGen/CodeGenModule.cpp +++ b/CodeGen/CodeGenModule.cpp @@ -26,7 +26,7 @@ using namespace CodeGen; CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M) - : Context(C), TheModule(M), Types(C.Target) {} + : Context(C), TheModule(M), Types(C) {} llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const Decl *D) { // See if it is already in the map. @@ -68,7 +68,8 @@ void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) { if (D->getInit() == 0) { Init = llvm::Constant::getNullValue(GV->getType()->getElementType()); } else if (D->getType()->isIntegerType()) { - llvm::APSInt Value(getContext().getTypeSize(D->getInit()->getType())); + llvm::APSInt Value(getContext().getTypeSize(D->getInit()->getType(), + SourceLocation())); if (D->getInit()->isIntegerConstantExpr(Value)) Init = llvm::ConstantInt::get(Value); } @@ -103,7 +104,9 @@ void CodeGenModule::EmitGlobalVarDeclarator(const FileVarDecl *D) { llvm::Function *CodeGenModule::getMemCpyFn() { if (MemCpyFn) return MemCpyFn; llvm::Intrinsic::ID IID; - switch (Context.Target.getPointerWidth(SourceLocation())) { + uint64_t Size; unsigned Align; + Context.Target.getPointerInfo(Size, Align, SourceLocation()); + switch (Size) { default: assert(0 && "Unknown ptr width"); case 32: IID = llvm::Intrinsic::memcpy_i32; break; case 64: IID = llvm::Intrinsic::memcpy_i64; break; diff --git a/CodeGen/CodeGenTypes.cpp b/CodeGen/CodeGenTypes.cpp index a75ac4ce75..5bae791080 100644 --- a/CodeGen/CodeGenTypes.cpp +++ b/CodeGen/CodeGenTypes.cpp @@ -19,6 +19,9 @@ using namespace clang; using namespace CodeGen; +CodeGenTypes::CodeGenTypes(ASTContext &Ctx) + : Context(Ctx), Target(Ctx.Target) { +} /// ConvertType - Convert the specified type to its LLVM form. const llvm::Type *CodeGenTypes::ConvertType(QualType T) { @@ -31,32 +34,26 @@ const llvm::Type *CodeGenTypes::ConvertType(QualType T) { case BuiltinType::Void: // LLVM void type can only be used as the result of a function call. Just // map to the same as char. - case BuiltinType::Char_S: - case BuiltinType::Char_U: - case BuiltinType::SChar: - case BuiltinType::UChar: - return llvm::IntegerType::get(Target.getCharWidth(SourceLocation())); + return llvm::IntegerType::get(8); case BuiltinType::Bool: // FIXME: This is very strange. We want scalars to be i1, but in memory // they can be i1 or i32. Should the codegen handle this issue? return llvm::Type::Int1Ty; + case BuiltinType::Char_S: + case BuiltinType::Char_U: + case BuiltinType::SChar: + case BuiltinType::UChar: case BuiltinType::Short: case BuiltinType::UShort: - return llvm::IntegerType::get(Target.getShortWidth(SourceLocation())); - case BuiltinType::Int: case BuiltinType::UInt: - return llvm::IntegerType::get(Target.getIntWidth(SourceLocation())); - case BuiltinType::Long: case BuiltinType::ULong: - return llvm::IntegerType::get(Target.getLongWidth(SourceLocation())); - case BuiltinType::LongLong: case BuiltinType::ULongLong: - return llvm::IntegerType::get(Target.getLongLongWidth(SourceLocation())); + return llvm::IntegerType::get(Context.getTypeSize(T, SourceLocation())); case BuiltinType::Float: return llvm::Type::FloatTy; case BuiltinType::Double: return llvm::Type::DoubleTy; diff --git a/CodeGen/CodeGenTypes.h b/CodeGen/CodeGenTypes.h index 3d8756415b..1b49dce0c3 100644 --- a/CodeGen/CodeGenTypes.h +++ b/CodeGen/CodeGenTypes.h @@ -21,6 +21,7 @@ namespace llvm { } namespace clang { + class ASTContext; class TargetInfo; class QualType; class FunctionTypeProto; @@ -30,10 +31,11 @@ namespace CodeGen { /// CodeGenTypes - This class organizes the cross-module state that is used /// while lowering AST types to LLVM types. class CodeGenTypes { + ASTContext &Context; TargetInfo &Target; public: - CodeGenTypes(TargetInfo &target) : Target(target) {} + CodeGenTypes(ASTContext &Ctx); TargetInfo &getTarget() const { return Target; } diff --git a/Driver/Targets.cpp b/Driver/Targets.cpp index 168084dcd7..9d52a00a8b 100644 --- a/Driver/Targets.cpp +++ b/Driver/Targets.cpp @@ -378,6 +378,7 @@ public: LinuxTargetInfo() { // Note: I have no idea if this is right, just for testing. WCharWidth = 16; + WCharAlign = 16; } virtual void getTargetDefines(std::vector<std::string> &Defines) const { diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 4c2c5a5e06..aebc266970 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -1005,7 +1005,7 @@ QualType Sema::HandleVectorTypeAttribute(QualType curType, curType.getCanonicalType().getAsString()); return QualType(); } - unsigned typeSize = Context.getTypeSize(curType); + unsigned typeSize = Context.getTypeSize(curType, rawAttr->getAttributeLoc()); // vecSize is specified in bytes - convert to bits. unsigned vectorSize = vecSize.getZExtValue() * 8; diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 9260ff1fb3..60b07a7915 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -115,7 +115,7 @@ Action::ExprResult Sema::ParseNumericConstant(const LexerToken &Tok) { if (Tok.getLength() == 1) { const char *t = PP.getSourceManager().getCharacterData(Tok.getLocation()); - unsigned IntSize = Context.Target.getIntWidth(Tok.getLocation()); + unsigned IntSize = Context.getTypeSize(Context.IntTy, Tok.getLocation()); return ExprResult(new IntegerLiteral(llvm::APInt(IntSize, *t-'0'), Context.IntTy, Tok.getLocation())); @@ -141,7 +141,7 @@ Action::ExprResult Sema::ParseNumericConstant(const LexerToken &Tok) { // If this value didn't fit into uintmax_t, warn and force to ull. Diag(Tok.getLocation(), diag::warn_integer_too_large); t = Context.UnsignedLongLongTy; - assert(Context.getIntegerBitwidth(t, Tok.getLocation()) == + assert(Context.getTypeSize(t, Tok.getLocation()) == ResultVal.getBitWidth() && "long long is not intmax_t?"); } else { // If this value fits into a ULL, try to figure out what else it fits into @@ -153,7 +153,7 @@ Action::ExprResult Sema::ParseNumericConstant(const LexerToken &Tok) { // Check from smallest to largest, picking the smallest type we can. if (!Literal.isLong) { // Are int/unsigned possibilities? - unsigned IntSize = Context.Target.getIntWidth(Tok.getLocation()); + unsigned IntSize = Context.getTypeSize(Context.IntTy,Tok.getLocation()); // Does it fit in a unsigned int? if (ResultVal.isIntN(IntSize)) { // Does it fit in a signed int? @@ -169,7 +169,8 @@ Action::ExprResult Sema::ParseNumericConstant(const LexerToken &Tok) { // Are long/unsigned long possibilities? if (t.isNull() && !Literal.isLongLong) { - unsigned LongSize = Context.Target.getLongWidth(Tok.getLocation()); + unsigned LongSize = Context.getTypeSize(Context.LongTy, + Tok.getLocation()); // Does it fit in a unsigned long? if (ResultVal.isIntN(LongSize)) { @@ -186,7 +187,7 @@ Action::ExprResult Sema::ParseNumericConstant(const LexerToken &Tok) { // Finally, check long long if needed. if (t.isNull()) { unsigned LongLongSize = - Context.Target.getLongLongWidth(Tok.getLocation()); + Context.getTypeSize(Context.LongLongTy, Tok.getLocation()); // Does it fit in a unsigned long long? if (ResultVal.isIntN(LongLongSize)) { diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 5aa6a0401f..9010a85416 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -54,12 +54,23 @@ public: ~ASTContext(); void PrintStats() const; - + + /// getTypeInfo - Get the size and alignment of the specified complete type in + /// bits. + std::pair<uint64_t, unsigned> getTypeInfo(QualType T, SourceLocation L); + /// getTypeSize - Return the size of the specified type, in bits. This method /// does not work on incomplete types. - unsigned getTypeSize(QualType T); - //TODO: unsigned getTypeAlign(QualType T); - + uint64_t getTypeSize(QualType T, SourceLocation L) { + return getTypeInfo(T, L).first; + } + + /// getTypeAlign - Return the alignment of the specified type, in bits. This + /// method does not work on incomplete types. + unsigned getTypeAlign(QualType T, SourceLocation L) { + return getTypeInfo(T, L).second; + } + /// getComplexType - Return the uniqued reference to the type for a complex /// number with the specified element type. QualType getComplexType(QualType T); diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index 0fefd075ef..4b8e0d0ca3 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -55,7 +55,7 @@ class TargetInfo { bool NonPortable; /// These are all caches for target values. - unsigned WCharWidth; + unsigned WCharWidth, WCharAlign; public: TargetInfo(const TargetInfoImpl *Primary, Diagnostic *D = 0) { @@ -105,67 +105,71 @@ public: /// getPointerWidth - Return the width of pointers on this target, we /// currently assume one pointer type. - unsigned getPointerWidth(SourceLocation Loc) { - return 32; // FIXME: implement correctly. + void getPointerInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) { + Size = 32; // FIXME: implement correctly. + Align = 32; } - /// getBoolWidth - Return the size of '_Bool' and C++ 'bool' for this target, + /// getBoolInfo - Return the size of '_Bool' and C++ 'bool' for this target, /// in bits. - unsigned getBoolWidth(SourceLocation Loc) { - return 8; // FIXME: implement correctly: wrong for ppc32. + void getBoolInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) { + Size = Align = 8; // FIXME: implement correctly: wrong for ppc32. } - /// getCharWidth - Return the size of 'char', 'signed char' and + /// getCharInfo - Return the size of 'char', 'signed char' and /// 'unsigned char' for this target, in bits. - unsigned getCharWidth(SourceLocation Loc) { - return 8; // FIXME: implement correctly. + void getCharInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) { + Size = Align = 8; // FIXME: implement correctly. } - /// getShortWidth - Return the size of 'signed short' and 'unsigned short' for + /// getShortInfo - Return the size of 'signed short' and 'unsigned short' for /// this target, in bits. - unsigned getShortWidth(SourceLocation Loc) { - return 16; // FIXME: implement correctly. + void getShortInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) { + Size = Align = 16; // FIXME: implement correctly. } - /// getIntWidth - Return the size of 'signed int' and 'unsigned int' for this + /// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this /// target, in bits. - unsigned getIntWidth(SourceLocation Loc) { - return 32; // FIXME: implement correctly. + void getIntInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) { + Size = Align = 32; // FIXME: implement correctly. } - /// getLongWidth - Return the size of 'signed long' and 'unsigned long' for + /// getLongInfo - Return the size of 'signed long' and 'unsigned long' for /// this target, in bits. - unsigned getLongWidth(SourceLocation Loc) { - return 32; // FIXME: implement correctly: wrong for ppc64/x86-64 + void getLongInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) { + Size = Align = 32; // FIXME: implement correctly: wrong for ppc64/x86-64 } - /// getLongLongWidth - Return the size of 'signed long long' and + /// getLongLongInfo - Return the size of 'signed long long' and /// 'unsigned long long' for this target, in bits. - unsigned getLongLongWidth(SourceLocation Loc) { - return 64; // FIXME: implement correctly. + void getLongLongInfo(uint64_t &Size, unsigned &Align, + SourceLocation Loc) { + Size = Align = 64; // FIXME: implement correctly. } - /// getFloatWidth - Return the size of 'float' for this target, in bits. - unsigned getFloatWidth(SourceLocation Loc) { - return 32; // FIXME: implement correctly. + /// getFloatInfo - Return the size of 'float' for this target, in bits. + void getFloatInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) { + Align = Size = 32; // FIXME: implement correctly. } - /// getDoubleWidth - Return the size of 'double' for this target, in bits. - unsigned getDoubleWidth(SourceLocation Loc) { - return 64; // FIXME: implement correctly. + /// getDoubleInfo - Return the size of 'double' for this target, in bits. + void getDoubleInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) { + Size = Align = 64; // FIXME: implement correctly. } - /// getLongDoubleWidth - Return the size of 'long double' for this target, in + /// getLongDoubleInfo - Return the size of 'long double' for this target, in /// bits. - unsigned getLongDoubleWidth(SourceLocation Loc) { - return 64; // FIXME: implement correctly. + void getLongDoubleInfo(uint64_t &Size, unsigned &Align, + SourceLocation Loc) { + Size = Align = 64; // FIXME: implement correctly. } - /// getWCharWidth - Return the size of wchar_t in bits. + /// getWCharInfo - Return the size of wchar_t in bits. /// - unsigned getWCharWidth(SourceLocation Loc) { - if (!WCharWidth) ComputeWCharWidth(Loc); - return WCharWidth; + void getWCharInfo(uint64_t &Size, unsigned &Align, SourceLocation Loc) { + if (!WCharWidth) ComputeWCharInfo(Loc); + Size = WCharWidth; + Align = WCharAlign; } /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this @@ -181,8 +185,28 @@ public: void getTargetBuiltins(const Builtin::Info *&Records, unsigned &NumRecords, std::vector<const char *> &NonPortableBuiltins) const; + ///===---- Some helper methods ------------------------------------------===// + + unsigned getCharWidth(SourceLocation Loc) { + uint64_t Size; unsigned Align; + getCharInfo(Size, Align, Loc); + return Size; + } + + unsigned getWCharWidth(SourceLocation Loc) { + uint64_t Size; unsigned Align; + getWCharInfo(Size, Align, Loc); + return Size; + } + + unsigned getIntWidth(SourceLocation Loc) { + uint64_t Size; unsigned Align; + getIntInfo(Size, Align, Loc); + return Size; + } + private: - void ComputeWCharWidth(SourceLocation Loc); + void ComputeWCharInfo(SourceLocation Loc); }; @@ -195,8 +219,9 @@ private: class TargetInfoImpl { protected: unsigned WCharWidth; /// sizeof(wchar_t) in bits. Default value is 32. + unsigned WCharAlign; /// alignof(wchar_t) in bits. Default value is 32. public: - TargetInfoImpl() : WCharWidth(32) {} + TargetInfoImpl() : WCharWidth(32), WCharAlign(32) {} virtual ~TargetInfoImpl() {} /// getTargetDefines - Return a list of the target-specific #define values set @@ -206,7 +231,10 @@ public: /// getWCharWidth - Return the size of wchar_t in bits. /// - unsigned getWCharWidth() const { return WCharWidth; } + void getWCharInfo(unsigned &Size, unsigned &Align) const { + Size = WCharWidth; + Align = WCharAlign; + } /// getTargetBuiltins - Return information about target-specific builtins for /// the target. |