aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/Preprocessor.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-06 22:59:26 +0000
committerChris Lattner <sabre@nondot.org>2009-02-06 22:59:26 +0000
commit03c972767e6f1a9be8540f29edd110b27fbb6b59 (patch)
tree0bf5694fedd7865872f7d755c136b16011b0be89 /lib/Lex/Preprocessor.cpp
parent4b99bae3bf2395f732eaadb9edc07690ae177f54 (diff)
Export __INT8_TYPE__ / __INT16_TYPE__ / __INT32_TYPE__ / __INT64_TYPE__
in a gcc 4.5 compatible way so that stdint.h can follow the compiler's notion of types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63976 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Preprocessor.cpp')
-rw-r--r--lib/Lex/Preprocessor.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index f4f3a0bfb6..db5ca2bd7f 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -438,6 +438,7 @@ static void DefineType(const char *MacroName, TargetInfo::IntType Ty,
static void InitializePredefinedMacros(Preprocessor &PP,
std::vector<char> &Buf) {
+ char MacroBuf[60];
// Compiler version introspection macros.
DefineBuiltinMacro(Buf, "__llvm__=1"); // LLVM Backend
DefineBuiltinMacro(Buf, "__clang__=1"); // Clang Frontend
@@ -512,10 +513,10 @@ static void InitializePredefinedMacros(Preprocessor &PP,
// mode.
if (PP.getLangOptions().Microsoft) {
DefineBuiltinMacro(Buf, "_cdecl=__cdecl");
- DefineBuiltinMacro(Buf, "__int8=char");
- DefineBuiltinMacro(Buf, "__int16=short");
- DefineBuiltinMacro(Buf, "__int32=int");
- DefineBuiltinMacro(Buf, "__int64=long long");
+ DefineBuiltinMacro(Buf, "__int8=__INT8_TYPE__");
+ DefineBuiltinMacro(Buf, "__int16=__INT16_TYPE__");
+ DefineBuiltinMacro(Buf, "__int32=__INT32_TYPE__");
+ DefineBuiltinMacro(Buf, "__int64=__INT64_TYPE__");
}
// Initialize target-specific preprocessor defines.
@@ -558,6 +559,30 @@ static void InitializePredefinedMacros(Preprocessor &PP,
DefineFloatMacros(Buf, "FLT", &TI.getFloatFormat());
DefineFloatMacros(Buf, "DBL", &TI.getDoubleFormat());
DefineFloatMacros(Buf, "LDBL", &TI.getLongDoubleFormat());
+
+ // Define a __POINTER_WIDTH__ macro for stdint.h.
+ sprintf(MacroBuf, "__POINTER_WIDTH__=%d", (int)TI.getPointerWidth(0));
+ DefineBuiltinMacro(Buf, MacroBuf);
+
+ if (!TI.isCharSigned())
+ 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");
+ DefineBuiltinMacro(Buf, "__INT16_TYPE__=short");
+
+ if (TI.getIntWidth() == 32)
+ DefineBuiltinMacro(Buf, "__INT32_TYPE__=int");
+ else {
+ assert(TI.getLongLongWidth() == 32 && "unsupported target types");
+ DefineBuiltinMacro(Buf, "__INT32_TYPE__=long long");
+ }
+
+ // 16-bit targets doesn't necessarily have a 64-bit type.
+ if (TI.getLongLongWidth() == 64)
+ DefineBuiltinMacro(Buf, "__INT64_TYPE__=long long");
// Add __builtin_va_list typedef.
{
@@ -566,15 +591,11 @@ static void InitializePredefinedMacros(Preprocessor &PP,
Buf.push_back('\n');
}
- char MacroBuf[60];
if (const char *Prefix = TI.getUserLabelPrefix()) {
sprintf(MacroBuf, "__USER_LABEL_PREFIX__=%s", Prefix);
DefineBuiltinMacro(Buf, MacroBuf);
}
- if (!TI.isCharSigned())
- DefineBuiltinMacro(Buf, "__CHAR_UNSIGNED__");
-
// Build configuration options. FIXME: these should be controlled by
// command line options or something.
DefineBuiltinMacro(Buf, "__DYNAMIC__=1");