simplify and refactor a bunch of type definition code in Preprocessor
predefines buffer initialization. llvm-svn: 63919
This commit is contained in:
parent
61898606dc
commit
a91c30fdb0
|
@ -61,7 +61,7 @@ public:
|
||||||
|
|
||||||
///===---- Target Data Type Query Methods -------------------------------===//
|
///===---- Target Data Type Query Methods -------------------------------===//
|
||||||
enum IntType {
|
enum IntType {
|
||||||
NoInt = 0x0,
|
NoInt = 0,
|
||||||
SignedShort,
|
SignedShort,
|
||||||
UnsignedShort,
|
UnsignedShort,
|
||||||
SignedInt,
|
SignedInt,
|
||||||
|
@ -165,6 +165,10 @@ public:
|
||||||
return UserLabelPrefix;
|
return UserLabelPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// getTypeName - Return the user string for the specified integer type enum.
|
||||||
|
/// For example, SignedShort -> "short".
|
||||||
|
static const char *getTypeName(IntType T);
|
||||||
|
|
||||||
///===---- Other target property query methods --------------------------===//
|
///===---- Other target property query methods --------------------------===//
|
||||||
|
|
||||||
/// getTargetDefines - Appends the target-specific #define values for this
|
/// getTargetDefines - Appends the target-specific #define values for this
|
||||||
|
|
|
@ -51,6 +51,22 @@ TargetInfo::TargetInfo(const std::string &T) : Triple(T) {
|
||||||
// Out of line virtual dtor for TargetInfo.
|
// Out of line virtual dtor for TargetInfo.
|
||||||
TargetInfo::~TargetInfo() {}
|
TargetInfo::~TargetInfo() {}
|
||||||
|
|
||||||
|
/// getTypeName - Return the user string for the specified integer type enum.
|
||||||
|
/// For example, SignedShort -> "short".
|
||||||
|
const char *TargetInfo::getTypeName(IntType T) {
|
||||||
|
switch (T) {
|
||||||
|
default: assert(0 && "not an integer!");
|
||||||
|
case SignedShort: return "short";
|
||||||
|
case UnsignedShort: return "unsigned short";
|
||||||
|
case SignedInt: return "int";
|
||||||
|
case UnsignedInt: return "unsigned int";
|
||||||
|
case SignedLong: return "long int";
|
||||||
|
case UnsignedLong: return "long unsigned int";
|
||||||
|
case SignedLongLong: return "long long int";
|
||||||
|
case UnsignedLongLong: return "long long unsigned int";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -428,6 +428,14 @@ static void DefineTypeSize(const char *MacroName, unsigned TypeWidth,
|
||||||
DefineBuiltinMacro(Buf, MacroBuf);
|
DefineBuiltinMacro(Buf, MacroBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void DefineType(const char *MacroName, TargetInfo::IntType Ty,
|
||||||
|
std::vector<char> &Buf) {
|
||||||
|
char MacroBuf[60];
|
||||||
|
sprintf(MacroBuf, "%s=%s", MacroName, TargetInfo::getTypeName(Ty));
|
||||||
|
DefineBuiltinMacro(Buf, MacroBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void InitializePredefinedMacros(Preprocessor &PP,
|
static void InitializePredefinedMacros(Preprocessor &PP,
|
||||||
std::vector<char> &Buf) {
|
std::vector<char> &Buf) {
|
||||||
// Compiler version introspection macros.
|
// Compiler version introspection macros.
|
||||||
|
@ -520,8 +528,6 @@ static void InitializePredefinedMacros(Preprocessor &PP,
|
||||||
DefineBuiltinMacro(Buf, "__WCHAR_TYPE__=int");
|
DefineBuiltinMacro(Buf, "__WCHAR_TYPE__=int");
|
||||||
DefineBuiltinMacro(Buf, "__WINT_TYPE__=int");
|
DefineBuiltinMacro(Buf, "__WINT_TYPE__=int");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned IntMaxWidth;
|
unsigned IntMaxWidth;
|
||||||
const char *IntMaxSuffix;
|
const char *IntMaxSuffix;
|
||||||
if (TI.getIntMaxType() == TargetInfo::SignedLongLong) {
|
if (TI.getIntMaxType() == TargetInfo::SignedLongLong) {
|
||||||
|
@ -544,64 +550,11 @@ static void InitializePredefinedMacros(Preprocessor &PP,
|
||||||
DefineTypeSize("__WCHAR_MAX__", TI.getWCharWidth(), "", true, Buf);
|
DefineTypeSize("__WCHAR_MAX__", TI.getWCharWidth(), "", true, Buf);
|
||||||
DefineTypeSize("__INTMAX_MAX__", IntMaxWidth, IntMaxSuffix, true, Buf);
|
DefineTypeSize("__INTMAX_MAX__", IntMaxWidth, IntMaxSuffix, true, Buf);
|
||||||
|
|
||||||
if (TI.getIntMaxType() == TargetInfo::UnsignedLongLong)
|
DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Buf);
|
||||||
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=unsigned long long int");
|
DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Buf);
|
||||||
else if (TI.getIntMaxType() == TargetInfo::SignedLongLong)
|
DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Buf);
|
||||||
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long long int");
|
DefineType("__SIZE_TYPE__", TI.getSizeType(), Buf);
|
||||||
else if (TI.getIntMaxType() == TargetInfo::UnsignedLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=unsigned long int");
|
|
||||||
else if (TI.getIntMaxType() == TargetInfo::SignedLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long int");
|
|
||||||
else if (TI.getIntMaxType() == TargetInfo::UnsignedInt)
|
|
||||||
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=unsigned int");
|
|
||||||
else
|
|
||||||
DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=int");
|
|
||||||
|
|
||||||
if (TI.getUIntMaxType() == TargetInfo::UnsignedLongLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=unsigned long long int");
|
|
||||||
else if (TI.getUIntMaxType() == TargetInfo::SignedLongLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=long long int");
|
|
||||||
else if (TI.getUIntMaxType() == TargetInfo::UnsignedLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=unsigned long int");
|
|
||||||
else if (TI.getUIntMaxType() == TargetInfo::SignedLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=long int");
|
|
||||||
else if (TI.getUIntMaxType() == TargetInfo::UnsignedInt)
|
|
||||||
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=unsigned int");
|
|
||||||
else
|
|
||||||
DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=int");
|
|
||||||
|
|
||||||
if (TI.getPtrDiffType(0) == TargetInfo::UnsignedLongLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=unsigned long long int");
|
|
||||||
else if (TI.getPtrDiffType(0) == TargetInfo::SignedLongLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=long long int");
|
|
||||||
else if (TI.getPtrDiffType(0) == TargetInfo::UnsignedLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=unsigned long int");
|
|
||||||
else if (TI.getPtrDiffType(0) == TargetInfo::SignedLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=long int");
|
|
||||||
else if (TI.getPtrDiffType(0) == TargetInfo::UnsignedInt)
|
|
||||||
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=unsigned int");
|
|
||||||
else {
|
|
||||||
assert(TI.getPtrDiffType(0) == TargetInfo::SignedInt);
|
|
||||||
DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=int");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TI.getSizeType() == TargetInfo::UnsignedLongLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned long long int");
|
|
||||||
else if (TI.getSizeType() == TargetInfo::SignedLongLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=long long int");
|
|
||||||
else if (TI.getSizeType() == TargetInfo::UnsignedLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned long int");
|
|
||||||
else if (TI.getSizeType() == TargetInfo::SignedLong)
|
|
||||||
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=long int");
|
|
||||||
else if (TI.getSizeType() == TargetInfo::UnsignedInt)
|
|
||||||
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned int");
|
|
||||||
else if (TI.getSizeType() == TargetInfo::SignedInt)
|
|
||||||
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=int");
|
|
||||||
else {
|
|
||||||
assert(TI.getPtrDiffType(0) == TargetInfo::UnsignedShort);
|
|
||||||
DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned short");
|
|
||||||
}
|
|
||||||
|
|
||||||
DefineFloatMacros(Buf, "FLT", &TI.getFloatFormat());
|
DefineFloatMacros(Buf, "FLT", &TI.getFloatFormat());
|
||||||
DefineFloatMacros(Buf, "DBL", &TI.getDoubleFormat());
|
DefineFloatMacros(Buf, "DBL", &TI.getDoubleFormat());
|
||||||
DefineFloatMacros(Buf, "LDBL", &TI.getLongDoubleFormat());
|
DefineFloatMacros(Buf, "LDBL", &TI.getLongDoubleFormat());
|
||||||
|
|
Loading…
Reference in New Issue