]> granicus.if.org Git - clang/commitdiff
De-templatize non-dependent VS macro logic, NFC
authorReid Kleckner <rnk@google.com>
Tue, 9 Jul 2019 20:57:28 +0000 (20:57 +0000)
committerReid Kleckner <rnk@google.com>
Tue, 9 Jul 2019 20:57:28 +0000 (20:57 +0000)
These macro definitions don't depend on the template parameter, so they
don't need to be part of the template. Move them to a .cpp file.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365556 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/Targets.cpp
lib/Basic/Targets.h
lib/Basic/Targets/AArch64.cpp
lib/Basic/Targets/AArch64.h
lib/Basic/Targets/ARM.cpp
lib/Basic/Targets/OSTargets.cpp
lib/Basic/Targets/OSTargets.h
lib/Basic/Targets/X86.h

index e9af3713dfbcff1c955a730ea3068f4d70941328..a08e399e72700d47a5a5c38c9d5d9b1da922b86c 100644 (file)
@@ -98,19 +98,6 @@ void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder) {
   }
 }
 
-void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts,
-                     MacroBuilder &Builder) {
-  DefineStd(Builder, "WIN32", Opts);
-  DefineStd(Builder, "WINNT", Opts);
-  if (Triple.isArch64Bit()) {
-    DefineStd(Builder, "WIN64", Opts);
-    Builder.defineMacro("__MINGW64__");
-  }
-  Builder.defineMacro("__MSVCRT__");
-  Builder.defineMacro("__MINGW32__");
-  addCygMingDefines(Opts, Builder);
-}
-
 //===----------------------------------------------------------------------===//
 // Driver code
 //===----------------------------------------------------------------------===//
index 6172bd96d09890c463f9ae17cdb006245aa404cc..a063204e69e67fcbb9f9635edbab2a2c3af59310 100644 (file)
@@ -38,10 +38,6 @@ LLVM_LIBRARY_VISIBILITY
 void defineCPUMacros(clang::MacroBuilder &Builder, llvm::StringRef CPUName,
                      bool Tuning = true);
 
-LLVM_LIBRARY_VISIBILITY
-void addMinGWDefines(const llvm::Triple &Triple, const clang::LangOptions &Opts,
-                     clang::MacroBuilder &Builder);
-
 LLVM_LIBRARY_VISIBILITY
 void addCygMingDefines(const clang::LangOptions &Opts,
                        clang::MacroBuilder &Builder);
index 120a0e2d4e8849b58c685090d98ea0e4fd47fe6b..6011ae17b78eae084a2d33b32eccee7b32a8c37c 100644 (file)
@@ -534,16 +534,10 @@ MicrosoftARM64TargetInfo::MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
   TheCXXABI.set(TargetCXXABI::Microsoft);
 }
 
-void MicrosoftARM64TargetInfo::getVisualStudioDefines(
-    const LangOptions &Opts, MacroBuilder &Builder) const {
-  WindowsTargetInfo<AArch64leTargetInfo>::getVisualStudioDefines(Opts, Builder);
-  Builder.defineMacro("_M_ARM64", "1");
-}
-
 void MicrosoftARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
                                                 MacroBuilder &Builder) const {
-  WindowsTargetInfo::getTargetDefines(Opts, Builder);
-  getVisualStudioDefines(Opts, Builder);
+  WindowsARM64TargetInfo::getTargetDefines(Opts, Builder);
+  Builder.defineMacro("_M_ARM64", "1");
 }
 
 TargetInfo::CallingConvKind
index 73fd3bde5adcff138c3baf9b65108120f99ca494..0241b585c4d13dcb616615cf826e42cccaec0489 100644 (file)
@@ -123,8 +123,6 @@ public:
   MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
                            const TargetOptions &Opts);
 
-  void getVisualStudioDefines(const LangOptions &Opts,
-                              MacroBuilder &Builder) const;
   void getTargetDefines(const LangOptions &Opts,
                         MacroBuilder &Builder) const override;
   TargetInfo::CallingConvKind
index cceed8880ffe4663c187ab6a2a4e50223cf208df..c6834b9fac15bd3bc37fa80042edd67e827c6528 100644 (file)
@@ -1030,8 +1030,6 @@ WindowsARMTargetInfo::WindowsARMTargetInfo(const llvm::Triple &Triple,
 
 void WindowsARMTargetInfo::getVisualStudioDefines(const LangOptions &Opts,
                                                   MacroBuilder &Builder) const {
-  WindowsTargetInfo<ARMleTargetInfo>::getVisualStudioDefines(Opts, Builder);
-
   // FIXME: this is invalid for WindowsCE
   Builder.defineMacro("_M_ARM_NT", "1");
   Builder.defineMacro("_M_ARMT", "_M_ARM");
index 5f4280a989e0952487a4a7e385427be590265075..72fdb0e7dde8a256f9443deb6fc9df5d67af0d43 100644 (file)
@@ -134,5 +134,84 @@ void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
 
   PlatformMinVersion = VersionTuple(Maj, Min, Rev);
 }
+
+static void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts,
+                            MacroBuilder &Builder) {
+  DefineStd(Builder, "WIN32", Opts);
+  DefineStd(Builder, "WINNT", Opts);
+  if (Triple.isArch64Bit()) {
+    DefineStd(Builder, "WIN64", Opts);
+    Builder.defineMacro("__MINGW64__");
+  }
+  Builder.defineMacro("__MSVCRT__");
+  Builder.defineMacro("__MINGW32__");
+  addCygMingDefines(Opts, Builder);
+}
+
+static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
+  if (Opts.CPlusPlus) {
+    if (Opts.RTTIData)
+      Builder.defineMacro("_CPPRTTI");
+
+    if (Opts.CXXExceptions)
+      Builder.defineMacro("_CPPUNWIND");
+  }
+
+  if (Opts.Bool)
+    Builder.defineMacro("__BOOL_DEFINED");
+
+  if (!Opts.CharIsSigned)
+    Builder.defineMacro("_CHAR_UNSIGNED");
+
+  // FIXME: POSIXThreads isn't exactly the option this should be defined for,
+  //        but it works for now.
+  if (Opts.POSIXThreads)
+    Builder.defineMacro("_MT");
+
+  if (Opts.MSCompatibilityVersion) {
+    Builder.defineMacro("_MSC_VER",
+                        Twine(Opts.MSCompatibilityVersion / 100000));
+    Builder.defineMacro("_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
+    // FIXME We cannot encode the revision information into 32-bits
+    Builder.defineMacro("_MSC_BUILD", Twine(1));
+
+    if (Opts.CPlusPlus11 && Opts.isCompatibleWithMSVC(LangOptions::MSVC2015))
+      Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
+
+    if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
+      if (Opts.CPlusPlus2a)
+        Builder.defineMacro("_MSVC_LANG", "201704L");
+      else if (Opts.CPlusPlus17)
+        Builder.defineMacro("_MSVC_LANG", "201703L");
+      else if (Opts.CPlusPlus14)
+        Builder.defineMacro("_MSVC_LANG", "201402L");
+    }
+  }
+
+  if (Opts.MicrosoftExt) {
+    Builder.defineMacro("_MSC_EXTENSIONS");
+
+    if (Opts.CPlusPlus11) {
+      Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
+      Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
+      Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
+    }
+  }
+
+  Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
+}
+
+void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
+                       MacroBuilder &Builder) {
+  Builder.defineMacro("_WIN32");
+  if (Triple.isArch64Bit())
+    Builder.defineMacro("_WIN64");
+  if (Triple.isWindowsGNUEnvironment())
+    addMinGWDefines(Triple, Opts, Builder);
+  else if (Triple.isKnownWindowsMSVCEnvironment() ||
+           (Triple.isWindowsItaniumEnvironment() && Opts.MSVCCompat))
+    addVisualCDefines(Opts, Builder);
+}
+
 } // namespace targets
 } // namespace clang
index 9bb5e7c1ca2b84a0268d82c37ca05782c74a7cf7..8542311ffa41dcc2550952baa34b19c3563ade3e 100644 (file)
@@ -711,71 +711,16 @@ public:
   bool hasInt128Type() const override { return false; }
 };
 
+void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
+                       MacroBuilder &Builder);
+
 // Windows target
 template <typename Target>
 class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo<Target> {
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                     MacroBuilder &Builder) const override {
-    Builder.defineMacro("_WIN32");
-    if (Triple.isArch64Bit())
-      Builder.defineMacro("_WIN64");
-    if (Triple.isWindowsGNUEnvironment())
-      addMinGWDefines(Triple, Opts, Builder);
-
-  }
-  void getVisualStudioDefines(const LangOptions &Opts,
-                              MacroBuilder &Builder) const {
-    if (Opts.CPlusPlus) {
-      if (Opts.RTTIData)
-        Builder.defineMacro("_CPPRTTI");
-
-      if (Opts.CXXExceptions)
-        Builder.defineMacro("_CPPUNWIND");
-    }
-
-    if (Opts.Bool)
-      Builder.defineMacro("__BOOL_DEFINED");
-
-    if (!Opts.CharIsSigned)
-      Builder.defineMacro("_CHAR_UNSIGNED");
-
-    // FIXME: POSIXThreads isn't exactly the option this should be defined for,
-    //        but it works for now.
-    if (Opts.POSIXThreads)
-      Builder.defineMacro("_MT");
-
-    if (Opts.MSCompatibilityVersion) {
-      Builder.defineMacro("_MSC_VER",
-                          Twine(Opts.MSCompatibilityVersion / 100000));
-      Builder.defineMacro("_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
-      // FIXME We cannot encode the revision information into 32-bits
-      Builder.defineMacro("_MSC_BUILD", Twine(1));
-
-      if (Opts.CPlusPlus11 && Opts.isCompatibleWithMSVC(LangOptions::MSVC2015))
-        Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
-
-      if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
-        if (Opts.CPlusPlus2a)
-          Builder.defineMacro("_MSVC_LANG", "201704L");
-        else if (Opts.CPlusPlus17)
-          Builder.defineMacro("_MSVC_LANG", "201703L");
-        else if (Opts.CPlusPlus14)
-          Builder.defineMacro("_MSVC_LANG", "201402L");
-      }
-    }
-
-    if (Opts.MicrosoftExt) {
-      Builder.defineMacro("_MSC_EXTENSIONS");
-
-      if (Opts.CPlusPlus11) {
-        Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
-        Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
-        Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
-      }
-    }
-
-    Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
+    addWindowsDefines(Triple, Opts, Builder);
   }
 
 public:
index 892a481e2a7bad508133cde24a208329de31ad19..c0dfc81f57c5ea1dcaf33f51c89e49d1325cbe61 100644 (file)
@@ -481,7 +481,6 @@ public:
   void getTargetDefines(const LangOptions &Opts,
                         MacroBuilder &Builder) const override {
     WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
-    WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder);
     // The value of the following reflects processor type.
     // 300=386, 400=486, 500=Pentium, 600=Blend (default)
     // We lost the original triple, so we use the default.
@@ -745,7 +744,6 @@ public:
   void getTargetDefines(const LangOptions &Opts,
                         MacroBuilder &Builder) const override {
     WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
-    WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder);
     Builder.defineMacro("_M_X64", "100");
     Builder.defineMacro("_M_AMD64", "100");
   }