[cfe-commits] r86177 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/Basic/TargetInfo.cpp lib/Frontend/InitPreprocessor.cpp test/Preprocessor/stdint.c
Chris Lattner
sabre at nondot.org
Thu Nov 5 13:21:32 PST 2009
Author: lattner
Date: Thu Nov 5 15:21:32 2009
New Revision: 86177
URL: http://llvm.org/viewvc/llvm-project?rev=86177&view=rev
Log:
clean up integer preprocessor type definitions, patch by Ken Dyck!
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/Preprocessor/stdint.c
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=86177&r1=86176&r2=86177&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Nov 5 15:21:32 2009
@@ -103,6 +103,10 @@
/// enum. For example, SignedInt -> getIntWidth().
unsigned getTypeWidth(IntType T) const;
+ /// getTypeAlign - Return the alignment (in bits) of the specified integer
+ /// type enum. For example, SignedInt -> getIntAlign().
+ unsigned getTypeAlign(IntType T) const;
+
/// isTypeSigned - Return whether an integer types is signed. Returns true if
/// the type is signed; false otherwise.
bool isTypeSigned(IntType T) const;
Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=86177&r1=86176&r2=86177&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Thu Nov 5 15:21:32 2009
@@ -96,17 +96,33 @@
unsigned TargetInfo::getTypeWidth(IntType T) const {
switch (T) {
default: assert(0 && "not an integer!");
- case SignedShort: return getShortWidth();
+ case SignedShort:
case UnsignedShort: return getShortWidth();
- case SignedInt: return getIntWidth();
+ case SignedInt:
case UnsignedInt: return getIntWidth();
- case SignedLong: return getLongWidth();
+ case SignedLong:
case UnsignedLong: return getLongWidth();
- case SignedLongLong: return getLongLongWidth();
+ case SignedLongLong:
case UnsignedLongLong: return getLongLongWidth();
};
}
+/// getTypeAlign - Return the alignment (in bits) of the specified integer type
+/// enum. For example, SignedInt -> getIntAlign().
+unsigned TargetInfo::getTypeAlign(IntType T) const {
+ switch (T) {
+ default: assert(0 && "not an integer!");
+ case SignedShort:
+ case UnsignedShort: return getShortAlign();
+ case SignedInt:
+ case UnsignedInt: return getIntAlign();
+ case SignedLong:
+ case UnsignedLong: return getLongAlign();
+ case SignedLongLong:
+ case UnsignedLongLong: return getLongLongAlign();
+ };
+}
+
/// isTypeSigned - Return whether an integer types is signed. Returns true if
/// the type is signed; false otherwise.
bool TargetInfo::isTypeSigned(IntType T) const {
Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=86177&r1=86176&r2=86177&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu Nov 5 15:21:32 2009
@@ -216,6 +216,14 @@
DefineBuiltinMacro(Buf, MacroBuf);
}
+/// DefineTypeSize - An overloaded helper that uses TargetInfo to determine
+/// the width, suffix, and signedness of the given type
+static void DefineTypeSize(const char *MacroName, TargetInfo::IntType Ty,
+ const TargetInfo &TI, std::vector<char> &Buf) {
+ DefineTypeSize(MacroName, TI.getTypeWidth(Ty), TI.getTypeConstantSuffix(Ty),
+ TI.isTypeSigned(Ty), Buf);
+}
+
static void DefineType(const char *MacroName, TargetInfo::IntType Ty,
std::vector<char> &Buf) {
char MacroBuf[60];
@@ -346,14 +354,16 @@
DefineBuiltinMacro(Buf, "__CHAR_BIT__=8");
DefineTypeSize("__SCHAR_MAX__", TI.getCharWidth(), "", true, Buf);
- DefineTypeSize("__SHRT_MAX__", TI.getShortWidth(), "", true, Buf);
- DefineTypeSize("__INT_MAX__", TI.getIntWidth(), "", true, Buf);
- DefineTypeSize("__LONG_MAX__", TI.getLongWidth(), "L", true, Buf);
- DefineTypeSize("__LONG_LONG_MAX__", TI.getLongLongWidth(), "LL", true, Buf);
+ DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Buf);
+ DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Buf);
+ DefineTypeSize("__LONG_MAX__", TargetInfo::SignedLong, TI, Buf);
+ DefineTypeSize("__LONG_LONG_MAX__", TargetInfo::SignedLongLong, TI, Buf);
+ // FIXME: TI.getWCharWidth() and TI.getTypeWidth(TI.getWCharType()) return
+ // different values on PIC16 and MSP430. TargetInfo needs to be corrected
+ // and the following line substituted for the one below it.
+ // DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Buf);
DefineTypeSize("__WCHAR_MAX__", TI.getWCharWidth(), "", true, Buf);
- TargetInfo::IntType IntMaxType = TI.getIntMaxType();
- DefineTypeSize("__INTMAX_MAX__", TI.getTypeWidth(IntMaxType),
- TI.getTypeConstantSuffix(IntMaxType), true, Buf);
+ DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Buf);
DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Buf);
DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Buf);
@@ -378,14 +388,16 @@
assert(TI.getCharWidth() == 8 && "unsupported target types");
assert(TI.getShortWidth() == 16 && "unsupported target types");
DefineBuiltinMacro(Buf, "__INT8_TYPE__=char");
- DefineBuiltinMacro(Buf, "__INT16_TYPE__=short");
+ DefineType("__INT16_TYPE__", TargetInfo::SignedShort, Buf);
+ TargetInfo::IntType Int32Type;
if (TI.getIntWidth() == 32)
- DefineBuiltinMacro(Buf, "__INT32_TYPE__=int");
+ Int32Type = TargetInfo::SignedInt;
else {
assert(TI.getLongLongWidth() == 32 && "unsupported target types");
- DefineBuiltinMacro(Buf, "__INT32_TYPE__=long long");
+ Int32Type = TargetInfo::SignedLongLong;
}
+ DefineType("__INT32_TYPE__", Int32Type, Buf);
// 16-bit targets doesn't necessarily have a 64-bit type.
if (TI.getLongLongWidth() == 64)
Modified: cfe/trunk/test/Preprocessor/stdint.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/stdint.c?rev=86177&r1=86176&r2=86177&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/stdint.c (original)
+++ cfe/trunk/test/Preprocessor/stdint.c Thu Nov 5 15:21:32 2009
@@ -323,8 +323,8 @@
//
// RUN: clang-cc -E -ffreestanding -triple=msp430-none-none %s | FileCheck -check-prefix MSP430 %s &&
//
-// MSP430:typedef long long int32_t;
-// MSP430:typedef unsigned long long uint32_t;
+// MSP430:typedef long long int int32_t;
+// MSP430:typedef unsigned long long int uint32_t;
// MSP430:typedef int32_t int_least32_t;
// MSP430:typedef uint32_t uint_least32_t;
// MSP430:typedef int32_t int_fast32_t;
@@ -423,8 +423,8 @@
//
// RUN: clang-cc -E -ffreestanding -triple=pic16-none-none %s | FileCheck -check-prefix PIC16 %s &&
//
-// PIC16:typedef long long int32_t;
-// PIC16:typedef unsigned long long uint32_t;
+// PIC16:typedef long long int int32_t;
+// PIC16:typedef unsigned long long int uint32_t;
// PIC16:typedef int32_t int_least32_t;
// PIC16:typedef uint32_t uint_least32_t;
// PIC16:typedef int32_t int_fast32_t;
More information about the cfe-commits
mailing list