std::pair<uint64_t, unsigned>
ASTContext::getTypeInfo(QualType T) {
T = T.getCanonicalType();
- uint64_t Size;
+ uint64_t Width;
unsigned Align;
switch (T->getTypeClass()) {
case Type::TypeName: assert(0 && "Not a canonical type!");
ConstantArrayType *CAT = cast<ConstantArrayType>(T);
std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(CAT->getElementType());
- Size = EltInfo.first*CAT->getSize().getZExtValue();
+ Width = EltInfo.first*CAT->getSize().getZExtValue();
Align = EltInfo.second;
break;
}
case Type::Vector: {
std::pair<uint64_t, unsigned> EltInfo =
getTypeInfo(cast<VectorType>(T)->getElementType());
- Size = EltInfo.first*cast<VectorType>(T)->getNumElements();
+ Width = EltInfo.first*cast<VectorType>(T)->getNumElements();
// FIXME: Vector alignment is not the alignment of its elements.
Align = EltInfo.second;
break;
}
- case Type::Builtin: {
+ case Type::Builtin:
// FIXME: need to use TargetInfo to derive the target specific sizes. This
// implementation will suffice for play with vector support.
- const llvm::fltSemantics *F;
switch (cast<BuiltinType>(T)->getKind()) {
default: assert(0 && "Unknown builtin type!");
case BuiltinType::Void:
assert(0 && "Incomplete types have no size!");
case BuiltinType::Bool:
- Target.getBoolInfo(Size, Align);
+ Width = Target.getBoolWidth();
+ Align = Target.getBoolAlign();
break;
case BuiltinType::Char_S:
case BuiltinType::Char_U:
case BuiltinType::UChar:
case BuiltinType::SChar:
- Target.getCharInfo(Size, Align);
+ Width = Target.getCharWidth();
+ Align = Target.getCharAlign();
break;
case BuiltinType::UShort:
case BuiltinType::Short:
- Target.getShortInfo(Size, Align);
+ Width = Target.getShortWidth();
+ Align = Target.getShortAlign();
break;
case BuiltinType::UInt:
case BuiltinType::Int:
- Target.getIntInfo(Size, Align);
+ Width = Target.getIntWidth();
+ Align = Target.getIntAlign();
break;
case BuiltinType::ULong:
case BuiltinType::Long:
- Target.getLongInfo(Size, Align);
+ Width = Target.getLongWidth();
+ Align = Target.getLongAlign();
break;
case BuiltinType::ULongLong:
case BuiltinType::LongLong:
- Target.getLongLongInfo(Size, Align);
+ Width = Target.getLongLongWidth();
+ Align = Target.getLongLongAlign();
break;
case BuiltinType::Float:
- Target.getFloatInfo(Size, Align, F);
+ Width = Target.getFloatWidth();
+ Align = Target.getFloatAlign();
break;
case BuiltinType::Double:
- Target.getDoubleInfo(Size, Align, F);
+ Width = Target.getDoubleWidth();
+ Align = Target.getDoubleAlign();
break;
case BuiltinType::LongDouble:
- Target.getLongDoubleInfo(Size, Align, F);
+ Width = Target.getLongDoubleWidth();
+ Align = Target.getLongDoubleAlign();
break;
}
break;
- }
case Type::ASQual:
// FIXME: Pointers into different addr spaces could have different sizes and
// alignment requirements: getPointerInfo should take an AddrSpace.
return getTypeInfo(QualType(cast<ASQualType>(T)->getBaseType(), 0));
case Type::ObjCQualifiedId:
- Size = Target.getPointerWidth(0);
+ Width = Target.getPointerWidth(0);
Align = Target.getPointerAlign(0);
break;
case Type::Pointer: {
unsigned AS = cast<PointerType>(T)->getPointeeType().getAddressSpace();
- Size = Target.getPointerWidth(AS);
+ Width = Target.getPointerWidth(AS);
Align = Target.getPointerAlign(AS);
break;
}
// size.
std::pair<uint64_t, unsigned> EltInfo =
getTypeInfo(cast<ComplexType>(T)->getElementType());
- Size = EltInfo.first*2;
+ Width = EltInfo.first*2;
Align = EltInfo.second;
break;
}
TagType *TT = cast<TagType>(T);
if (RecordType *RT = dyn_cast<RecordType>(TT)) {
const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl());
- Size = Layout.getSize();
+ Width = Layout.getSize();
Align = Layout.getAlignment();
} else if (EnumDecl *ED = dyn_cast<EnumDecl>(TT->getDecl())) {
return getTypeInfo(ED->getIntegerType());
}
assert(Align && (Align & (Align-1)) == 0 && "Alignment must be power of 2");
- return std::make_pair(Size, Align);
+ return std::make_pair(Width, Align);
}
/// getASTRecordLayout - Get or compute information about the layout of the
std::string Triple;
protected:
/// These are all caches for target values.
+ bool CharIsSigned;
unsigned WCharWidth, WCharAlign;
- //==----------------------------------------------------------------==/
- // TargetInfo Construction.
- //==----------------------------------------------------------------==/
+ // TargetInfo Constructor.
TargetInfo(const std::string &T) : Triple(T) {
- // Set defaults.
+ // Set defaults. These should be overridden by concrete targets as needed.
+ CharIsSigned = true;
WCharWidth = WCharAlign = 32;
}
/// isCharSigned - Return true if 'char' is 'signed char' or false if it is
/// treated as 'unsigned char'. This is implementation defined according to
/// C99 6.2.5p15. In our implementation, this is target-specific.
- bool isCharSigned() const {
- // FIXME: implement correctly.
- return true;
- }
+ bool isCharSigned() const { return CharIsSigned; }
/// getPointerWidth - Return the width of pointers on this target, for the
/// specified address space. FIXME: implement correctly.
uint64_t getPointerWidth(unsigned AddrSpace) const { return 32; }
uint64_t getPointerAlign(unsigned AddrSpace) const { return 32; }
- /// getBoolInfo - Return the size of '_Bool' and C++ 'bool' for this target,
- /// in bits.
- void getBoolInfo(uint64_t &Size, unsigned &Align) const {
- Size = Align = 8; // FIXME: implement correctly: wrong for ppc32.
- }
+ /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this
+ /// target, in bits.
+ unsigned getBoolWidth(bool isWide = false) const { return 8; } // FIXME
+ unsigned getBoolAlign(bool isWide = false) const { return 8; } // FIXME
- /// getCharInfo - Return the size of 'char', 'signed char' and
- /// 'unsigned char' for this target, in bits.
- void getCharInfo(uint64_t &Size, unsigned &Align) const {
- Size = Align = 8; // FIXME: implement correctly.
+ unsigned getCharWidth(bool isWide = false) const {
+ return isWide ? getWCharWidth() : 8; // FIXME
}
-
- /// getShortInfo - Return the size of 'signed short' and 'unsigned short' for
- /// this target, in bits.
- void getShortInfo(uint64_t &Size, unsigned &Align) const {
- Size = Align = 16; // FIXME: implement correctly.
+ unsigned getCharAlign(bool isWide = false) const {
+ return isWide ? getWCharAlign() : 8; // FIXME
}
- /// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this
- /// target, in bits.
- void getIntInfo(uint64_t &Size, unsigned &Align) const {
- Size = Align = 32; // FIXME: implement correctly.
- }
+ /// getShortWidth/Align - Return the size of 'signed short' and
+ /// 'unsigned short' for this target, in bits.
+ unsigned getShortWidth() const { return 16; } // FIXME
+ unsigned getShortAlign() const { return 16; } // FIXME
- /// getLongInfo - Return the size of 'signed long' and 'unsigned long' for
- /// this target, in bits.
- void getLongInfo(uint64_t &Size, unsigned &Align) const {
- Size = Align = 32; // FIXME: implement correctly: wrong for ppc64/x86-64
- }
-
- /// getLongLongInfo - Return the size of 'signed long long' and
- /// 'unsigned long long' for this target, in bits.
- void getLongLongInfo(uint64_t &Size, unsigned &Align) const {
- Size = Align = 64; // FIXME: implement correctly.
- }
+ /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
+ /// this target, in bits.
+ unsigned getIntWidth() const { return 32; } // FIXME
+ unsigned getIntAlign() const { return 32; } // FIXME
- /// getFloatInfo - Characterize 'float' for this target.
- void getFloatInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format) const;
-
- /// getDoubleInfo - Characterize 'double' for this target.
- void getDoubleInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format) const;
-
- /// getLongDoubleInfo - Characterize 'long double' for this target.
- void getLongDoubleInfo(uint64_t &Size, unsigned &Align,
- const llvm::fltSemantics *&Format) const;
+ /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
+ /// for this target, in bits.
+ unsigned getLongWidth() const { return 32; } // FIXME
+ unsigned getLongAlign() const { return 32; } // FIXME
+ /// getLongLongWidth/Align - Return the size of 'signed long long' and
+ /// 'unsigned long long' for this target, in bits.
+ unsigned getLongLongWidth() const { return 64; } // FIXME
+ unsigned getLongLongAlign() const { return 64; } // FIXME
+
+ /// getWcharWidth/Align - Return the size of 'wchar_t' for this target, in
+ /// bits.
unsigned getWCharWidth() const { return WCharWidth; }
unsigned getWCharAlign() const { return WCharAlign; }
+ /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
+ unsigned getFloatWidth() const { return 32; } // FIXME
+ unsigned getFloatAlign() const { return 32; } // FIXME
+ const llvm::fltSemantics *getFloatFormat() const;
+
+ /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
+ unsigned getDoubleWidth() const { return 64; } // FIXME
+ unsigned getDoubleAlign() const { return 32; } // FIXME
+ const llvm::fltSemantics *getDoubleFormat() const;
+
+ /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
+ /// double'.
+ unsigned getLongDoubleWidth() const { return 64; } // FIXME
+ unsigned getLongDoubleAlign() const { return 64; } // FIXME
+ const llvm::fltSemantics *getLongDoubleFormat() const;
+
+
/// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
/// target, in bits.
unsigned getIntMaxTWidth() const {
// Returns a string of target-specific clobbers, in LLVM format.
virtual const char *getClobbers() const = 0;
- ///===---- Some helper methods ------------------------------------------===//
-
- unsigned getBoolWidth() const {
- uint64_t Size; unsigned Align;
- getBoolInfo(Size, Align);
- return static_cast<unsigned>(Size);
- }
-
- unsigned getCharWidth(bool isWide = false) const {
- if (isWide)
- return WCharWidth;
- uint64_t Size; unsigned Align;
- getCharInfo(Size, Align);
- return static_cast<unsigned>(Size);
- }
-
-
- unsigned getIntWidth() const {
- uint64_t Size; unsigned Align;
- getIntInfo(Size, Align);
- return static_cast<unsigned>(Size);
- }
-
- unsigned getLongWidth() const {
- uint64_t Size; unsigned Align;
- getLongInfo(Size, Align);
- return static_cast<unsigned>(Size);
- }
-
- unsigned getLongLongWidth() const {
- uint64_t Size; unsigned Align;
- getLongLongInfo(Size, Align);
- return static_cast<unsigned>(Size);
- }
/// getTargetPrefix - Return the target prefix used for identifying
/// llvm intrinsics.
virtual const char *getTargetPrefix() const = 0;
/// getTargetTriple - Return the target triple of the primary target.
- virtual const char *getTargetTriple() const {
+ const char *getTargetTriple() const {
return Triple.c_str();
}