Added getArchNameForAssembler method to the Triple class for which returns OS and...
authorViktor Kutuzov <vkutuzov@accesssoftek.com>
Tue, 17 Nov 2009 18:48:27 +0000 (18:48 +0000)
committerViktor Kutuzov <vkutuzov@accesssoftek.com>
Tue, 17 Nov 2009 18:48:27 +0000 (18:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89122 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/Triple.h
lib/Support/Triple.cpp
tools/lto/LTOCodeGenerator.cpp

index c59f79e17b06fdea56c12b96da195d65d7b5231e..a9e3e53d1d7d88fbead4911790dd389aeb48196a 100644 (file)
@@ -239,6 +239,10 @@ public:
   /// environment components with a single string.
   void setOSAndEnvironmentName(StringRef Str);
 
+  /// getArchNameForAssembler - Get an architecture name that is understood by the
+  /// target assembler.
+  const char *getArchNameForAssembler();
+
   /// @}
   /// @name Static helpers for IDs.
   /// @{
index 40f055f462326a087c1a1313fa344d57801db4c8..840fb98fe9f97883329a8d934a942b3369ac7604 100644 (file)
@@ -179,6 +179,33 @@ Triple::ArchType Triple::getArchTypeForDarwinArchName(StringRef Str) {
   return Triple::UnknownArch;
 }
 
+// Returns architecture name that is unsderstood by the target assembler.
+const char *Triple::getArchNameForAssembler() {
+  if (getOS() != Triple::Darwin && getVendor() != Triple::Apple)
+    return NULL;
+
+  StringRef Str = getArchName();
+  if (Str == "i386")
+    return "i386";
+  if (Str == "x86_64")
+    return "x86_64";
+  if (Str == "powerpc")
+    return "ppc";
+  if (Str == "powerpc64")
+    return "ppc64";
+  if (Str == "arm")
+    return "arm";
+  if (Str == "armv4t" || Str == "thumbv4t")
+    return "armv4t";
+  if (Str == "armv5" || Str == "armv5e" || Str == "thumbv5" || Str == "thumbv5e")
+    return "armv5";
+  if (Str == "armv6" || Str == "thumbv6")
+    return "armv6";
+  if (Str == "armv7" || Str == "thumbv7")
+    return "armv7";
+  return NULL;
+}
+
 //
 
 void Triple::Parse() const {
index c6217214b4086adbf09c905d517799f007be4130..eb82f984d7bd811235da3ee4a57830d05381cd8f 100644 (file)
@@ -24,6 +24,7 @@
 #include "llvm/ModuleProvider.h"
 #include "llvm/PassManager.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/LoopPass.h"
 #include "llvm/Analysis/Verifier.h"
@@ -242,51 +243,16 @@ bool LTOCodeGenerator::assemble(const std::string& asmPath,
 
     // build argument list
     std::vector<const char*> args;
-    std::string targetTriple = _linker.getModule()->getTargetTriple();
+    llvm::Triple targetTriple(_linker.getModule()->getTargetTriple());
+    const char *arch = targetTriple.getArchNameForAssembler();
+
     args.push_back(tool.c_str());
-    if ( targetTriple.find("darwin") != std::string::npos ) {
+
+    if (targetTriple.getOS() == Triple::Darwin) {
         // darwin specific command line options
-        if (strncmp(targetTriple.c_str(), "i386-apple-", 11) == 0) {
-            args.push_back("-arch");
-            args.push_back("i386");
-        }
-        else if (strncmp(targetTriple.c_str(), "x86_64-apple-", 13) == 0) {
-            args.push_back("-arch");
-            args.push_back("x86_64");
-        }
-        else if (strncmp(targetTriple.c_str(), "powerpc-apple-", 14) == 0) {
-            args.push_back("-arch");
-            args.push_back("ppc");
-        }
-        else if (strncmp(targetTriple.c_str(), "powerpc64-apple-", 16) == 0) {
-            args.push_back("-arch");
-            args.push_back("ppc64");
-        }
-        else if (strncmp(targetTriple.c_str(), "arm-apple-", 10) == 0) {
-            args.push_back("-arch");
-            args.push_back("arm");
-        }
-        else if ((strncmp(targetTriple.c_str(), "armv4t-apple-", 13) == 0) ||
-                 (strncmp(targetTriple.c_str(), "thumbv4t-apple-", 15) == 0)) {
-            args.push_back("-arch");
-            args.push_back("armv4t");
-        }
-        else if ((strncmp(targetTriple.c_str(), "armv5-apple-", 12) == 0) ||
-                 (strncmp(targetTriple.c_str(), "armv5e-apple-", 13) == 0) ||
-                 (strncmp(targetTriple.c_str(), "thumbv5-apple-", 14) == 0) ||
-                 (strncmp(targetTriple.c_str(), "thumbv5e-apple-", 15) == 0)) {
-            args.push_back("-arch");
-            args.push_back("armv5");
-        }
-        else if ((strncmp(targetTriple.c_str(), "armv6-apple-", 12) == 0) ||
-                 (strncmp(targetTriple.c_str(), "thumbv6-apple-", 14) == 0)) {
-            args.push_back("-arch");
-            args.push_back("armv6");
-        }
-        else if ((strncmp(targetTriple.c_str(), "armv7-apple-", 12) == 0) ||
-                 (strncmp(targetTriple.c_str(), "thumbv7-apple-", 14) == 0)) {
+        if (arch != NULL) {
             args.push_back("-arch");
-            args.push_back("armv7");
+            args.push_back(arch);
         }
         // add -static to assembler command line when code model requires
         if ( (_assemblerPath != NULL) && (_codeModel == LTO_CODEGEN_PIC_MODEL_STATIC) )