[PATCH] D37719: Allow public Triple deduction from ObjectFiles.

Vlad Tsyrklevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 19:24:15 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL313605: Allow public Triple deduction from ObjectFiles. (authored by vlad.tsyrklevich).

Changed prior to commit:
  https://reviews.llvm.org/D37719?vs=115763&id=115776#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37719

Files:
  llvm/trunk/include/llvm/Object/ObjectFile.h
  llvm/trunk/lib/Object/ObjectFile.cpp
  llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp


Index: llvm/trunk/lib/Object/ObjectFile.cpp
===================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp
+++ llvm/trunk/lib/Object/ObjectFile.cpp
@@ -79,6 +79,31 @@
   return section_iterator(SectionRef(Sec, this));
 }
 
+Triple ObjectFile::makeTriple() const {
+  Triple TheTriple;
+  auto Arch = getArch();
+  TheTriple.setArch(Triple::ArchType(Arch));
+
+  // For ARM targets, try to use the build attributes to build determine
+  // the build target. Target features are also added, but later during
+  // disassembly.
+  if (Arch == Triple::arm || Arch == Triple::armeb)
+    setARMSubArch(TheTriple);
+
+  // TheTriple defaults to ELF, and COFF doesn't have an environment:
+  // the best we can do here is indicate that it is mach-o.
+  if (isMachO())
+    TheTriple.setObjectFormat(Triple::MachO);
+
+  if (isCOFF()) {
+    const auto COFFObj = dyn_cast<COFFObjectFile>(this);
+    if (COFFObj->getArch() == Triple::thumb)
+      TheTriple.setTriple("thumbv7-windows");
+  }
+
+  return TheTriple;
+}
+
 Expected<std::unique_ptr<ObjectFile>>
 ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type) {
   StringRef Data = Object.getBuffer();
Index: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
@@ -362,29 +362,11 @@
   llvm::Triple TheTriple("unknown-unknown-unknown");
   if (TripleName.empty()) {
     if (Obj) {
-      auto Arch = Obj->getArch();
-      TheTriple.setArch(Triple::ArchType(Arch));
-
-      // For ARM targets, try to use the build attributes to build determine
-      // the build target. Target features are also added, but later during
-      // disassembly.
-      if (Arch == Triple::arm || Arch == Triple::armeb) {
-        Obj->setARMSubArch(TheTriple);
-      }
-
-      // TheTriple defaults to ELF, and COFF doesn't have an environment:
-      // the best we can do here is indicate that it is mach-o.
-      if (Obj->isMachO())
-        TheTriple.setObjectFormat(Triple::MachO);
-
-      if (Obj->isCOFF()) {
-        const auto COFFObj = dyn_cast<COFFObjectFile>(Obj);
-        if (COFFObj->getArch() == Triple::thumb)
-          TheTriple.setTriple("thumbv7-windows");
-      }
+      TheTriple = Obj->makeTriple();
     }
   } else {
     TheTriple.setTriple(Triple::normalize(TripleName));
+
     // Use the triple, but also try to combine with ARM build attributes.
     if (Obj) {
       auto Arch = Obj->getArch();
Index: llvm/trunk/include/llvm/Object/ObjectFile.h
===================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h
+++ llvm/trunk/include/llvm/Object/ObjectFile.h
@@ -282,6 +282,9 @@
   virtual SubtargetFeatures getFeatures() const = 0;
   virtual void setARMSubArch(Triple &TheTriple) const { }
 
+  /// @brief Create a triple from the data in this object file.
+  Triple makeTriple() const;
+
   /// Returns platform-specific object flags, if any.
   virtual std::error_code getPlatformFlags(unsigned &Result) const {
     Result = 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37719.115776.patch
Type: text/x-patch
Size: 3181 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170919/bf199235/attachment.bin>


More information about the llvm-commits mailing list