aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/InitPreprocessor.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-11-12 08:08:27 +0000
committerChris Lattner <sabre@nondot.org>2009-11-12 08:08:27 +0000
commitdcdd2a064a6d3ea7712169629328ef80d6cb28ec (patch)
treed3048cd318f7c10120ab67bb3448bd2c50c6b01f /lib/Frontend/InitPreprocessor.cpp
parent9184646509d015ea66e796113a8c68598681374b (diff)
Generalize stdint.h for non-8-bit-multiple types, patch by
Ken Dyck! "This adds definitions for types of 8-bit multiples from 8 to 64 to stdint.h and rationalizes the selection of types for the exact-width definitions in InitPreprocessor.cpp." git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86977 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/InitPreprocessor.cpp')
-rw-r--r--lib/Frontend/InitPreprocessor.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
index f6e6058908..6968049131 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -237,6 +237,12 @@ static void DefineType(const char *MacroName, TargetInfo::IntType Ty,
DefineBuiltinMacro(Buf, MacroBuf);
}
+static void DefineExactWidthIntType(TargetInfo::IntType Ty,
+ const TargetInfo &TI, std::vector<char> &Buf) {
+ char MacroBuf[60];
+ sprintf(MacroBuf, "__INT%d_TYPE__", TI.getTypeWidth(Ty));
+ DefineType(MacroBuf, Ty, Buf);
+}
static void InitializePredefinedMacros(const TargetInfo &TI,
const LangOptions &LangOpts,
@@ -386,25 +392,22 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
if (!LangOpts.CharIsSigned)
DefineBuiltinMacro(Buf, "__CHAR_UNSIGNED__");
- // Define fixed-sized integer types for stdint.h
- assert(TI.getCharWidth() == 8 && "unsupported target types");
- assert(TI.getShortWidth() == 16 && "unsupported target types");
- DefineBuiltinMacro(Buf, "__INT8_TYPE__=char");
- DefineType("__INT16_TYPE__", TargetInfo::SignedShort, Buf);
-
- TargetInfo::IntType Int32Type;
- if (TI.getIntWidth() == 32)
- Int32Type = TargetInfo::SignedInt;
- else {
- assert(TI.getLongLongWidth() == 32 && "unsupported target types");
- Int32Type = TargetInfo::SignedLongLong;
- }
- DefineType("__INT32_TYPE__", Int32Type, Buf);
-
- // 16-bit targets doesn't necessarily have a 64-bit type.
- if (TI.getLongLongWidth() == 64)
- DefineType("__INT64_TYPE__", TI.getInt64Type(), Buf);
+ // Define exact-width integer types for stdint.h
+ sprintf(MacroBuf, "__INT%d_TYPE__=char", TI.getCharWidth());
+ DefineBuiltinMacro(Buf, MacroBuf);
+ if (TI.getShortWidth() > TI.getCharWidth())
+ DefineExactWidthIntType(TargetInfo::SignedShort, TI, Buf);
+
+ if (TI.getIntWidth() > TI.getShortWidth())
+ DefineExactWidthIntType(TargetInfo::SignedInt, TI, Buf);
+
+ if (TI.getLongWidth() > TI.getIntWidth())
+ DefineExactWidthIntType(TargetInfo::SignedLong, TI, Buf);
+
+ if (TI.getLongLongWidth() > TI.getLongWidth())
+ DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Buf);
+
// Add __builtin_va_list typedef.
{
const char *VAList = TI.getVAListDeclaration();