diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-06 04:50:25 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-06 04:50:25 +0000 |
commit | 996feccdec6c865a2f9d11faac7e0970e7aebb1b (patch) | |
tree | 3a8b477a278254ea11c542f9968e50377cd1a6a2 | |
parent | db76684bcbc99d7532d1ec1a2b501cd0e2d7cf5f (diff) |
refactor some code into a DefineTypeSize function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63917 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index f6a29dbd7c..1386cc5ab7 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -411,6 +411,23 @@ static void DefineFloatMacros(std::vector<char> &Buf, const char *Prefix, } +/// DefineTypeSize - Emit a macro to the predefines buffer that declares a macro +/// named MacroName with the max value for a type with width 'TypeWidth' a +/// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL). +static void DefineTypeSize(const char *MacroName, unsigned TypeWidth, + const char *ValSuffix, bool isSigned, + std::vector<char> &Buf) { + char MacroBuf[60]; + uint64_t MaxVal; + if (isSigned) + MaxVal = (1LL << (TypeWidth - 1)) - 1; + else + MaxVal = ~0LL >> (64-TypeWidth); + + sprintf(MacroBuf, "%s=%llu%s", MacroName, MaxVal, ValSuffix); + DefineBuiltinMacro(Buf, MacroBuf); +} + static void InitializePredefinedMacros(Preprocessor &PP, std::vector<char> &Buf) { // Compiler version introspection macros. @@ -530,7 +547,7 @@ static void InitializePredefinedMacros(Preprocessor &PP, DefineBuiltinMacro(Buf, "__LONG_MAX__=32767L"); else assert(0 && "Unknown long size"); - char MacroBuf[60]; + unsigned IntMaxWidth; const char *IntMaxSuffix; if (TI.getIntMaxType() == TargetInfo::SignedLongLong) { @@ -545,10 +562,8 @@ static void InitializePredefinedMacros(Preprocessor &PP, IntMaxSuffix = ""; } - sprintf(MacroBuf, "__INTMAX_MAX__=%lld%s", (1LL << (IntMaxWidth - 1)) - 1, - IntMaxSuffix); - DefineBuiltinMacro(Buf, MacroBuf); - + DefineTypeSize("__INTMAX_MAX__", IntMaxWidth, IntMaxSuffix, true, Buf); + if (TI.getIntMaxType() == TargetInfo::UnsignedLongLong) DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=unsigned long long int"); else if (TI.getIntMaxType() == TargetInfo::SignedLongLong) @@ -611,7 +626,6 @@ static void InitializePredefinedMacros(Preprocessor &PP, DefineFloatMacros(Buf, "DBL", &TI.getDoubleFormat()); DefineFloatMacros(Buf, "LDBL", &TI.getLongDoubleFormat()); - // Add __builtin_va_list typedef. { const char *VAList = TI.getVAListDeclaration(); @@ -619,6 +633,7 @@ 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); |