From 2db78dd977fbba8fdf24cf8a4593436c031cfbcb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 5 Oct 2008 20:40:30 +0000 Subject: [PATCH] start moving fp macros over git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57134 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 20 -------------------- lib/Lex/Preprocessor.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 451c67f4e0..f5b936754b 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -119,12 +119,7 @@ static void getPowerPCDefines(std::vector &Defs, bool is64Bit) { Define(Defs, "__NATURAL_ALIGNMENT__"); Define(Defs, "__REGISTER_PREFIX__", ""); - Define(Defs, "__WCHAR_MAX__", "2147483647"); - Define(Defs, "__WCHAR_TYPE__", "int"); - Define(Defs, "__WINT_TYPE__", "int"); - // Float macros. - Define(Defs, "__FLT_DENORM_MIN__", "1.40129846e-45F"); Define(Defs, "__FLT_DIG__", "6"); Define(Defs, "__FLT_EPSILON__", "1.19209290e-7F"); Define(Defs, "__FLT_EVAL_METHOD__", "0"); @@ -140,7 +135,6 @@ static void getPowerPCDefines(std::vector &Defs, bool is64Bit) { Define(Defs, "__FLT_RADIX__", "2"); // double macros. - Define(Defs, "__DBL_DENORM_MIN__", "4.9406564584124654e-324"); Define(Defs, "__DBL_DIG__", "15"); Define(Defs, "__DBL_EPSILON__", "2.2204460492503131e-16"); Define(Defs, "__DBL_HAS_INFINITY__"); @@ -155,8 +149,6 @@ static void getPowerPCDefines(std::vector &Defs, bool is64Bit) { Define(Defs, "__DECIMAL_DIG__", "33"); // 128-bit long double macros. - Define(Defs, "__LDBL_DENORM_MIN__", - "4.94065645841246544176568792868221e-324L"); Define(Defs, "__LDBL_DIG__", "31"); Define(Defs, "__LDBL_EPSILON__", "4.94065645841246544176568792868221e-324L"); @@ -205,12 +197,8 @@ static void getX86Defines(std::vector &Defs, bool is64Bit) { Define(Defs, "__MMX__"); Define(Defs, "__REGISTER_PREFIX__", ""); - Define(Defs, "__WCHAR_MAX__", "2147483647"); - Define(Defs, "__WCHAR_TYPE__", "int"); - Define(Defs, "__WINT_TYPE__", "int"); // Float macros. - Define(Defs, "__FLT_DENORM_MIN__", "1.40129846e-45F"); Define(Defs, "__FLT_DIG__", "6"); Define(Defs, "__FLT_EPSILON__", "1.19209290e-7F"); Define(Defs, "__FLT_EVAL_METHOD__", "0"); @@ -226,7 +214,6 @@ static void getX86Defines(std::vector &Defs, bool is64Bit) { Define(Defs, "__FLT_RADIX__", "2"); // Double macros. - Define(Defs, "__DBL_DENORM_MIN__", "4.9406564584124654e-324"); Define(Defs, "__DBL_DIG__", "15"); Define(Defs, "__DBL_EPSILON__", "2.2204460492503131e-16"); Define(Defs, "__DBL_HAS_INFINITY__"); @@ -241,7 +228,6 @@ static void getX86Defines(std::vector &Defs, bool is64Bit) { Define(Defs, "__DECIMAL_DIG__", "21"); // 80-bit Long double macros. - Define(Defs, "__LDBL_DENORM_MIN__", "3.64519953188247460253e-4951L"); Define(Defs, "__LDBL_DIG__", "18"); Define(Defs, "__LDBL_EPSILON__", "1.08420217248550443401e-19L"); Define(Defs, "__LDBL_HAS_INFINITY__"); @@ -270,14 +256,10 @@ static void getARMDefines(std::vector &Defs) { Define(Defs, "__ARMEL__"); Define(Defs, "__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", "20000"); - Define(Defs, "__WCHAR_MAX__", "2147483647"); - Define(Defs, "__WCHAR_TYPE__", "int"); - Define(Defs, "__WINT_TYPE__", "int"); Define(Defs, "__DECIMAL_DIG__", "17"); Define(Defs, "__FLT_RADIX__", "2"); // Float macros. - Define(Defs, "__FLT_DENORM_MIN__", "1.40129846e-45F"); Define(Defs, "__FLT_DIG__", "6"); Define(Defs, "__FLT_EPSILON__", "1.19209290e-7F"); Define(Defs, "__FLT_EVAL_METHOD__", "0"); @@ -292,7 +274,6 @@ static void getARMDefines(std::vector &Defs) { Define(Defs, "__FLT_MIN__", "1.17549435e-38F"); // Double macros. - Define(Defs, "__DBL_DENORM_MIN__", "4.9406564584124654e-324"); Define(Defs, "__DBL_DIG__", "15"); Define(Defs, "__DBL_EPSILON__", "2.2204460492503131e-16"); Define(Defs, "__DBL_HAS_INFINITY__"); @@ -306,7 +287,6 @@ static void getARMDefines(std::vector &Defs) { Define(Defs, "__DBL_MIN__", "2.2250738585072014e-308"); // 64-bit Long double macros (same as double). - Define(Defs, "__LDBL_DENORM_MIN__", "4.9406564584124654e-324"); Define(Defs, "__LDBL_DIG__", "15"); Define(Defs, "__LDBL_EPSILON__", "2.2204460492503131e-16"); Define(Defs, "__LDBL_HAS_INFINITY__"); diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 9758a586e4..f00f1ea69c 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -33,6 +33,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" +#include "llvm/ADT/APFloat.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Streams.h" @@ -377,6 +378,33 @@ static void DefineBuiltinMacro(std::vector &Buf, const char *Macro, Buf.push_back('\n'); } +/// PickFP - This is used to pick a value based on the FP semantics of the +/// specified FP model. +template +static T PickFP(const llvm::fltSemantics *Sem, T IEEESingleVal, + T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal) { + if (Sem == &llvm::APFloat::IEEEsingle) + return IEEESingleVal; + if (Sem == &llvm::APFloat::IEEEdouble) + return IEEEDoubleVal; + if (Sem == &llvm::APFloat::x87DoubleExtended) + return X87DoubleExtendedVal; + assert(Sem == &llvm::APFloat::PPCDoubleDouble); + return PPCDoubleDoubleVal; +} + +static void DefineFloatMacros(std::vector &Buf, const char *Prefix, + const llvm::fltSemantics *Sem) { + const char *DenormMin = PickFP(Sem, "1.40129846e-45F", + "4.9406564584124654e-324", + "3.64519953188247460253e-4951L", + "4.94065645841246544176568792868221e-324L"); + + char MacroBuf[60]; + sprintf(MacroBuf, "__%s_DENORM_MIN__=%s", Prefix, DenormMin); + DefineBuiltinMacro(Buf, MacroBuf); +} + static void InitializePredefinedMacros(Preprocessor &PP, std::vector &Buf) { @@ -472,9 +500,13 @@ static void InitializePredefinedMacros(Preprocessor &PP, assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far"); DefineBuiltinMacro(Buf, "__CHAR_BIT__=8"); DefineBuiltinMacro(Buf, "__SCHAR_MAX__=127"); + + assert(TI.getWCharWidth() == 32 && "Only support 32-bit wchar so far"); + DefineBuiltinMacro(Buf, "__WCHAR_MAX__=2147483647"); + DefineBuiltinMacro(Buf, "__WCHAR_TYPE__=int"); + DefineBuiltinMacro(Buf, "__WINT_TYPE__=int"); assert(TI.getShortWidth() == 16 && "Only support 16-bit short so far"); - DefineBuiltinMacro(Buf, "__CHAR_BIT__=8"); DefineBuiltinMacro(Buf, "__SHRT_MAX__=32767"); if (TI.getIntWidth() == 32) @@ -506,6 +538,7 @@ static void InitializePredefinedMacros(Preprocessor &PP, assert(TI.getPointerWidth(0) == TI.getLongWidth() && TI.getLongWidth() == 64 && TI.getIntWidth() == 32 && "Not I32 LP64?"); + assert(TI.getIntMaxTWidth() == 64); DefineBuiltinMacro(Buf, "__INTMAX_MAX__=9223372036854775807L"); DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long int"); DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=long int"); @@ -518,6 +551,7 @@ static void InitializePredefinedMacros(Preprocessor &PP, "Unexpected target sizes"); // We currently only support targets where long is 32-bit. This can be // easily generalized in the future. + assert(TI.getIntMaxTWidth() == 64); DefineBuiltinMacro(Buf, "__INTMAX_MAX__=9223372036854775807LL"); DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long long int"); DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=int"); @@ -528,7 +562,9 @@ static void InitializePredefinedMacros(Preprocessor &PP, assert(TI.getPointerWidth(0) == TI.getLongWidth()); DefineBuiltinMacro(Buf, "__SIZE_TYPE__=long unsigned int"); - + DefineFloatMacros(Buf, "FLT", &TI.getFloatFormat()); + DefineFloatMacros(Buf, "DBL", &TI.getDoubleFormat()); + DefineFloatMacros(Buf, "LDBL", &TI.getLongDoubleFormat()); // Add __builtin_va_list typedef. -- 2.40.0