start moving fp macros over
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57134 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index 451c67f..f5b9367 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -119,12 +119,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 9758a58..f00f1ea 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 @@
Buf.push_back('\n');
}
+/// PickFP - This is used to pick a value based on the FP semantics of the
+/// specified FP model.
+template <typename T>
+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<char> &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<char> &Buf) {
@@ -472,9 +500,13 @@
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 @@
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 @@
"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 @@
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.