[llvm] r291828 - [ObjectYAML] Pull yaml2dwarf out of yaml2obj for reuse

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 12 13:35:21 PST 2017


Author: cbieneman
Date: Thu Jan 12 15:35:21 2017
New Revision: 291828

URL: http://llvm.org/viewvc/llvm-project?rev=291828&view=rev
Log:
[ObjectYAML] Pull yaml2dwarf out of yaml2obj for reuse

This patch pulls the yaml2dwarf code out of yaml2obj into a new set of DWARF emitter functions in the DWARFYAML namespace. This will enable the YAML->DWARF code to be used inside DWARF tests by populating the DWARFYAML structs and calling the Emitter functions.

Added:
    llvm/trunk/include/llvm/ObjectYAML/DWARFEmitter.h
    llvm/trunk/lib/ObjectYAML/DWARFEmitter.cpp
      - copied, changed from r291815, llvm/trunk/tools/yaml2obj/yaml2dwarf.cpp
Removed:
    llvm/trunk/tools/yaml2obj/yaml2dwarf.cpp
Modified:
    llvm/trunk/lib/ObjectYAML/CMakeLists.txt
    llvm/trunk/tools/yaml2obj/CMakeLists.txt
    llvm/trunk/tools/yaml2obj/yaml2macho.cpp
    llvm/trunk/tools/yaml2obj/yaml2obj.h

Added: llvm/trunk/include/llvm/ObjectYAML/DWARFEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/DWARFEmitter.h?rev=291828&view=auto
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/DWARFEmitter.h (added)
+++ llvm/trunk/include/llvm/ObjectYAML/DWARFEmitter.h Thu Jan 12 15:35:21 2017
@@ -0,0 +1,36 @@
+//===--- DWARFEmitter.h - -------------------------------------------*- C++
+//-*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+/// \file
+/// \brief Common declarations for yaml2obj
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_OBJECTYAML_DWARFEMITTER_H
+#define LLVM_OBJECTYAML_DWARFEMITTER_H
+
+namespace llvm {
+class raw_ostream;
+
+namespace DWARFYAML {
+struct Data;
+struct PubSection;
+
+void EmitDebugAbbrev(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
+void EmitDebugStr(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
+
+void EmitDebugAranges(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
+void EmitPubSection(llvm::raw_ostream &OS,
+                    const llvm::DWARFYAML::PubSection &Sect,
+                    bool IsLittleEndian);
+void EmitDebugInfo(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
+void EmitDebugLine(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
+
+} // namespace DWARFYAML
+} // namespace llvm
+
+#endif

Modified: llvm/trunk/lib/ObjectYAML/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/CMakeLists.txt?rev=291828&r1=291827&r2=291828&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/CMakeLists.txt (original)
+++ llvm/trunk/lib/ObjectYAML/CMakeLists.txt Thu Jan 12 15:35:21 2017
@@ -1,8 +1,9 @@
 add_llvm_library(LLVMObjectYAML
-  YAML.cpp
   COFFYAML.cpp
+  DWARFEmitter.cpp
+  DWARFYAML.cpp
   ELFYAML.cpp
   MachOYAML.cpp
   ObjectYAML.cpp
-  DWARFYAML.cpp
+  YAML.cpp
   )

Copied: llvm/trunk/lib/ObjectYAML/DWARFEmitter.cpp (from r291815, llvm/trunk/tools/yaml2obj/yaml2dwarf.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/DWARFEmitter.cpp?p2=llvm/trunk/lib/ObjectYAML/DWARFEmitter.cpp&p1=llvm/trunk/tools/yaml2obj/yaml2dwarf.cpp&r1=291815&r2=291828&rev=291828&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2dwarf.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/DWARFEmitter.cpp Thu Jan 12 15:35:21 2017
@@ -1,4 +1,4 @@
-//===- yaml2dwarf - Convert YAML to DWARF binary data ---------------------===//
+//===- DWARFEmitter - Convert YAML to DWARF binary data -------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -8,10 +8,11 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief The DWARF component of yaml2obj.
+/// \brief The DWARF component of yaml2obj. Provided as library code for tests.
 ///
 //===----------------------------------------------------------------------===//
 
+#include "llvm/ObjectYAML/DWARFEmitter.h"
 #include "llvm/ObjectYAML/DWARFYAML.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/LEB128.h"
@@ -49,14 +50,14 @@ void ZeroFillBytes(raw_ostream &OS, size
   OS.write(reinterpret_cast<char *>(FillData.data()), Size);
 }
 
-void yaml2debug_str(raw_ostream &OS, const DWARFYAML::Data &DI) {
+void DWARFYAML::EmitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) {
   for (auto Str : DI.DebugStrings) {
     OS.write(Str.data(), Str.size());
     OS.write('\0');
   }
 }
 
-void yaml2debug_abbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {
+void DWARFYAML::EmitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {
   for (auto AbbrevDecl : DI.AbbrevDecls) {
     encodeULEB128(AbbrevDecl.Code, OS);
     encodeULEB128(AbbrevDecl.Tag, OS);
@@ -70,7 +71,7 @@ void yaml2debug_abbrev(raw_ostream &OS,
   }
 }
 
-void yaml2debug_aranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
+void DWARFYAML::EmitDebugAranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
   for (auto Range : DI.ARanges) {
     auto HeaderStart = OS.tell();
     writeInteger((uint32_t)Range.Length, OS, DI.IsLittleEndian);
@@ -93,8 +94,9 @@ void yaml2debug_aranges(raw_ostream &OS,
   }
 }
 
-void yaml2pubsection(raw_ostream &OS, const DWARFYAML::PubSection &Sect,
-                     bool IsLittleEndian) {
+void DWARFYAML::EmitPubSection(raw_ostream &OS,
+                               const DWARFYAML::PubSection &Sect,
+                               bool IsLittleEndian) {
   writeInteger((uint32_t)Sect.Length, OS, IsLittleEndian);
   writeInteger((uint16_t)Sect.Version, OS, IsLittleEndian);
   writeInteger((uint32_t)Sect.UnitOffset, OS, IsLittleEndian);
@@ -108,7 +110,7 @@ void yaml2pubsection(raw_ostream &OS, co
   }
 }
 
-void yaml2debug_info(raw_ostream &OS, const DWARFYAML::Data &DI) {
+void DWARFYAML::EmitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
 
   for (auto CU : DI.CompileUnits) {
     writeInteger((uint32_t)CU.Length, OS, DI.IsLittleEndian);
@@ -234,7 +236,7 @@ void yaml2debug_info(raw_ostream &OS, co
   }
 }
 
-void yaml2FileEntry(raw_ostream &OS, const DWARFYAML::File &File) {
+void EmitFileEntry(raw_ostream &OS, const DWARFYAML::File &File) {
   OS.write(File.Name.data(), File.Name.size());
   OS.write('\0');
   encodeULEB128(File.DirIdx, OS);
@@ -242,7 +244,7 @@ void yaml2FileEntry(raw_ostream &OS, con
   encodeULEB128(File.Length, OS);
 }
 
-void yaml2debug_line(raw_ostream &OS, const DWARFYAML::Data &DI) {
+void DWARFYAML::EmitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
   for (const auto LineTable : DI.DebugLines) {
     writeInteger((uint32_t)LineTable.TotalLength, OS, DI.IsLittleEndian);
     uint64_t SizeOfPrologueLength = 4;
@@ -271,7 +273,7 @@ void yaml2debug_line(raw_ostream &OS, co
     OS.write('\0');
 
     for (auto File : LineTable.Files)
-      yaml2FileEntry(OS, File);
+      EmitFileEntry(OS, File);
     OS.write('\0');
 
     for (auto Op : LineTable.Opcodes) {
@@ -286,7 +288,7 @@ void yaml2debug_line(raw_ostream &OS, co
                                     DI.IsLittleEndian);
           break;
         case dwarf::DW_LNE_define_file:
-          yaml2FileEntry(OS, Op.FileEntry);
+          EmitFileEntry(OS, Op.FileEntry);
           break;
         case dwarf::DW_LNE_end_sequence:
           break;

Modified: llvm/trunk/tools/yaml2obj/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/CMakeLists.txt?rev=291828&r1=291827&r2=291828&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/CMakeLists.txt (original)
+++ llvm/trunk/tools/yaml2obj/CMakeLists.txt Thu Jan 12 15:35:21 2017
@@ -8,7 +8,6 @@ set(LLVM_LINK_COMPONENTS
 add_llvm_tool(yaml2obj
   yaml2obj.cpp
   yaml2coff.cpp
-  yaml2dwarf.cpp
   yaml2elf.cpp
   yaml2macho.cpp
   )

Removed: llvm/trunk/tools/yaml2obj/yaml2dwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2dwarf.cpp?rev=291827&view=auto
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2dwarf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2dwarf.cpp (removed)
@@ -1,330 +0,0 @@
-//===- yaml2dwarf - Convert YAML to DWARF binary data ---------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief The DWARF component of yaml2obj.
-///
-//===----------------------------------------------------------------------===//
-
-#include "llvm/ObjectYAML/DWARFYAML.h"
-#include "llvm/Support/Error.h"
-#include "llvm/Support/LEB128.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/SwapByteOrder.h"
-
-#include <algorithm>
-
-using namespace llvm;
-
-template <typename T>
-void writeInteger(T Integer, raw_ostream &OS, bool IsLittleEndian) {
-  if (IsLittleEndian != sys::IsLittleEndianHost)
-    sys::swapByteOrder(Integer);
-  OS.write(reinterpret_cast<char *>(&Integer), sizeof(T));
-}
-
-void writeVariableSizedInteger(uint64_t Integer, size_t Size, raw_ostream &OS,
-                               bool IsLittleEndian) {
-  if (8 == Size)
-    writeInteger((uint64_t)Integer, OS, IsLittleEndian);
-  else if (4 == Size)
-    writeInteger((uint32_t)Integer, OS, IsLittleEndian);
-  else if (2 == Size)
-    writeInteger((uint16_t)Integer, OS, IsLittleEndian);
-  else if (1 == Size)
-    writeInteger((uint8_t)Integer, OS, IsLittleEndian);
-  else
-    assert(false && "Invalid integer write size.");
-}
-
-void ZeroFillBytes(raw_ostream &OS, size_t Size) {
-  std::vector<uint8_t> FillData;
-  FillData.insert(FillData.begin(), Size, 0);
-  OS.write(reinterpret_cast<char *>(FillData.data()), Size);
-}
-
-void yaml2debug_str(raw_ostream &OS, const DWARFYAML::Data &DI) {
-  for (auto Str : DI.DebugStrings) {
-    OS.write(Str.data(), Str.size());
-    OS.write('\0');
-  }
-}
-
-void yaml2debug_abbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {
-  for (auto AbbrevDecl : DI.AbbrevDecls) {
-    encodeULEB128(AbbrevDecl.Code, OS);
-    encodeULEB128(AbbrevDecl.Tag, OS);
-    OS.write(AbbrevDecl.Children);
-    for (auto Attr : AbbrevDecl.Attributes) {
-      encodeULEB128(Attr.Attribute, OS);
-      encodeULEB128(Attr.Form, OS);
-    }
-    encodeULEB128(0, OS);
-    encodeULEB128(0, OS);
-  }
-}
-
-void yaml2debug_aranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
-  for (auto Range : DI.ARanges) {
-    auto HeaderStart = OS.tell();
-    writeInteger((uint32_t)Range.Length, OS, DI.IsLittleEndian);
-    writeInteger((uint16_t)Range.Version, OS, DI.IsLittleEndian);
-    writeInteger((uint32_t)Range.CuOffset, OS, DI.IsLittleEndian);
-    writeInteger((uint8_t)Range.AddrSize, OS, DI.IsLittleEndian);
-    writeInteger((uint8_t)Range.SegSize, OS, DI.IsLittleEndian);
-
-    auto HeaderSize = OS.tell() - HeaderStart;
-    auto FirstDescriptor = alignTo(HeaderSize, Range.AddrSize * 2);
-    ZeroFillBytes(OS, FirstDescriptor - HeaderSize);
-
-    for (auto Descriptor : Range.Descriptors) {
-      writeVariableSizedInteger(Descriptor.Address, Range.AddrSize, OS,
-                                DI.IsLittleEndian);
-      writeVariableSizedInteger(Descriptor.Length, Range.AddrSize, OS,
-                                DI.IsLittleEndian);
-    }
-    ZeroFillBytes(OS, Range.AddrSize * 2);
-  }
-}
-
-void yaml2pubsection(raw_ostream &OS, const DWARFYAML::PubSection &Sect,
-                     bool IsLittleEndian) {
-  writeInteger((uint32_t)Sect.Length, OS, IsLittleEndian);
-  writeInteger((uint16_t)Sect.Version, OS, IsLittleEndian);
-  writeInteger((uint32_t)Sect.UnitOffset, OS, IsLittleEndian);
-  writeInteger((uint32_t)Sect.UnitSize, OS, IsLittleEndian);
-  for (auto Entry : Sect.Entries) {
-    writeInteger((uint32_t)Entry.DieOffset, OS, IsLittleEndian);
-    if (Sect.IsGNUStyle)
-      writeInteger((uint32_t)Entry.Descriptor, OS, IsLittleEndian);
-    OS.write(Entry.Name.data(), Entry.Name.size());
-    OS.write('\0');
-  }
-}
-
-void yaml2debug_info(raw_ostream &OS, const DWARFYAML::Data &DI) {
-
-  for (auto CU : DI.CompileUnits) {
-    writeInteger((uint32_t)CU.Length, OS, DI.IsLittleEndian);
-    writeInteger((uint16_t)CU.Version, OS, DI.IsLittleEndian);
-    writeInteger((uint32_t)CU.AbbrOffset, OS, DI.IsLittleEndian);
-    writeInteger((uint8_t)CU.AddrSize, OS, DI.IsLittleEndian);
-
-    auto FirstAbbrevCode = CU.Entries[0].AbbrCode;
-
-    for (auto Entry : CU.Entries) {
-      encodeULEB128(Entry.AbbrCode, OS);
-      if (Entry.AbbrCode == 0u)
-        continue;
-      bool Indirect = false;
-      assert(Entry.AbbrCode - FirstAbbrevCode < DI.AbbrevDecls.size() &&
-             "Out of range AbbCode");
-      auto &Abbrev = DI.AbbrevDecls[Entry.AbbrCode - FirstAbbrevCode];
-
-      auto FormVal = Entry.Values.begin();
-      auto AbbrForm = Abbrev.Attributes.begin();
-      for (;
-           FormVal != Entry.Values.end() && AbbrForm != Abbrev.Attributes.end();
-           ++FormVal, ++AbbrForm) {
-        dwarf::Form Form = AbbrForm->Form;
-        do {
-          Indirect = false;
-          switch (Form) {
-          case dwarf::DW_FORM_addr:
-            writeVariableSizedInteger(FormVal->Value, CU.AddrSize, OS,
-                                      DI.IsLittleEndian);
-            break;
-          case dwarf::DW_FORM_ref_addr: {
-            // TODO: Handle DWARF32/DWARF64 after Line Table data is done
-            auto writeSize = CU.Version == 2 ? CU.AddrSize : 4;
-            writeVariableSizedInteger(FormVal->Value, writeSize, OS,
-                                      DI.IsLittleEndian);
-            break;
-          }
-          case dwarf::DW_FORM_exprloc:
-          case dwarf::DW_FORM_block:
-            encodeULEB128(FormVal->BlockData.size(), OS);
-            OS.write(reinterpret_cast<char *>(&FormVal->BlockData[0]),
-                     FormVal->BlockData.size());
-            break;
-          case dwarf::DW_FORM_block1: {
-            auto writeSize = FormVal->BlockData.size();
-            writeInteger((uint8_t)writeSize, OS, DI.IsLittleEndian);
-            OS.write(reinterpret_cast<char *>(&FormVal->BlockData[0]),
-                     FormVal->BlockData.size());
-            break;
-          }
-          case dwarf::DW_FORM_block2: {
-            auto writeSize = FormVal->BlockData.size();
-            writeInteger((uint16_t)writeSize, OS, DI.IsLittleEndian);
-            OS.write(reinterpret_cast<char *>(&FormVal->BlockData[0]),
-                     FormVal->BlockData.size());
-            break;
-          }
-          case dwarf::DW_FORM_block4: {
-            auto writeSize = FormVal->BlockData.size();
-            writeInteger((uint32_t)writeSize, OS, DI.IsLittleEndian);
-            OS.write(reinterpret_cast<char *>(&FormVal->BlockData[0]),
-                     FormVal->BlockData.size());
-            break;
-          }
-          case dwarf::DW_FORM_data1:
-          case dwarf::DW_FORM_ref1:
-          case dwarf::DW_FORM_flag:
-            writeInteger((uint8_t)FormVal->Value, OS, DI.IsLittleEndian);
-            break;
-          case dwarf::DW_FORM_data2:
-          case dwarf::DW_FORM_ref2:
-            writeInteger((uint16_t)FormVal->Value, OS, DI.IsLittleEndian);
-            break;
-          case dwarf::DW_FORM_data4:
-          case dwarf::DW_FORM_ref4:
-            writeInteger((uint32_t)FormVal->Value, OS, DI.IsLittleEndian);
-            break;
-          case dwarf::DW_FORM_data8:
-          case dwarf::DW_FORM_ref8:
-            writeInteger((uint64_t)FormVal->Value, OS, DI.IsLittleEndian);
-            break;
-          case dwarf::DW_FORM_sdata:
-            encodeSLEB128(FormVal->Value, OS);
-            break;
-          case dwarf::DW_FORM_udata:
-          case dwarf::DW_FORM_ref_udata:
-            encodeULEB128(FormVal->Value, OS);
-            break;
-          case dwarf::DW_FORM_string:
-            OS.write(FormVal->CStr.data(), FormVal->CStr.size());
-            OS.write('\0');
-            break;
-          case dwarf::DW_FORM_indirect:
-            encodeULEB128(FormVal->Value, OS);
-            Indirect = true;
-            Form = static_cast<dwarf::Form>((uint64_t)FormVal->Value);
-            ++FormVal;
-            break;
-          case dwarf::DW_FORM_strp:
-          case dwarf::DW_FORM_sec_offset:
-          case dwarf::DW_FORM_GNU_ref_alt:
-          case dwarf::DW_FORM_GNU_strp_alt:
-          case dwarf::DW_FORM_line_strp:
-          case dwarf::DW_FORM_strp_sup:
-          case dwarf::DW_FORM_ref_sup:
-            // TODO: Handle DWARF32/64
-            writeInteger((uint32_t)FormVal->Value, OS, DI.IsLittleEndian);
-            break;
-          case dwarf::DW_FORM_ref_sig8:
-            writeInteger((uint64_t)FormVal->Value, OS, DI.IsLittleEndian);
-            break;
-          case dwarf::DW_FORM_GNU_addr_index:
-          case dwarf::DW_FORM_GNU_str_index:
-            encodeULEB128(FormVal->Value, OS);
-            break;
-          default:
-            break;
-          }
-        } while (Indirect);
-      }
-    }
-  }
-}
-
-void yaml2FileEntry(raw_ostream &OS, const DWARFYAML::File &File) {
-  OS.write(File.Name.data(), File.Name.size());
-  OS.write('\0');
-  encodeULEB128(File.DirIdx, OS);
-  encodeULEB128(File.ModTime, OS);
-  encodeULEB128(File.Length, OS);
-}
-
-void yaml2debug_line(raw_ostream &OS, const DWARFYAML::Data &DI) {
-  for (const auto LineTable : DI.DebugLines) {
-    writeInteger((uint32_t)LineTable.TotalLength, OS, DI.IsLittleEndian);
-    uint64_t SizeOfPrologueLength = 4;
-    if (LineTable.TotalLength == UINT32_MAX) {
-      writeInteger((uint64_t)LineTable.TotalLength64, OS, DI.IsLittleEndian);
-      SizeOfPrologueLength = 8;
-    }
-    writeInteger((uint16_t)LineTable.Version, OS, DI.IsLittleEndian);
-    writeVariableSizedInteger(LineTable.PrologueLength, SizeOfPrologueLength,
-                              OS, DI.IsLittleEndian);
-    writeInteger((uint8_t)LineTable.MinInstLength, OS, DI.IsLittleEndian);
-    if (LineTable.Version >= 4)
-      writeInteger((uint8_t)LineTable.MaxOpsPerInst, OS, DI.IsLittleEndian);
-    writeInteger((uint8_t)LineTable.DefaultIsStmt, OS, DI.IsLittleEndian);
-    writeInteger((uint8_t)LineTable.LineBase, OS, DI.IsLittleEndian);
-    writeInteger((uint8_t)LineTable.LineRange, OS, DI.IsLittleEndian);
-    writeInteger((uint8_t)LineTable.OpcodeBase, OS, DI.IsLittleEndian);
-
-    for (auto OpcodeLength : LineTable.StandardOpcodeLengths)
-      writeInteger((uint8_t)OpcodeLength, OS, DI.IsLittleEndian);
-
-    for (auto IncludeDir : LineTable.IncludeDirs) {
-      OS.write(IncludeDir.data(), IncludeDir.size());
-      OS.write('\0');
-    }
-    OS.write('\0');
-
-    for (auto File : LineTable.Files)
-      yaml2FileEntry(OS, File);
-    OS.write('\0');
-
-    for (auto Op : LineTable.Opcodes) {
-      writeInteger((uint8_t)Op.Opcode, OS, DI.IsLittleEndian);
-      if (Op.Opcode == 0) {
-        encodeULEB128(Op.ExtLen, OS);
-        writeInteger((uint8_t)Op.SubOpcode, OS, DI.IsLittleEndian);
-        switch (Op.SubOpcode) {
-        case dwarf::DW_LNE_set_address:
-        case dwarf::DW_LNE_set_discriminator:
-          writeVariableSizedInteger(Op.Data, DI.CompileUnits[0].AddrSize, OS,
-                                    DI.IsLittleEndian);
-          break;
-        case dwarf::DW_LNE_define_file:
-          yaml2FileEntry(OS, Op.FileEntry);
-          break;
-        case dwarf::DW_LNE_end_sequence:
-          break;
-        default:
-          for (auto OpByte : Op.UnknownOpcodeData)
-            writeInteger((uint8_t)OpByte, OS, DI.IsLittleEndian);
-        }
-      } else if (Op.Opcode < LineTable.OpcodeBase) {
-        switch (Op.Opcode) {
-        case dwarf::DW_LNS_copy:
-        case dwarf::DW_LNS_negate_stmt:
-        case dwarf::DW_LNS_set_basic_block:
-        case dwarf::DW_LNS_const_add_pc:
-        case dwarf::DW_LNS_set_prologue_end:
-        case dwarf::DW_LNS_set_epilogue_begin:
-          break;
-
-        case dwarf::DW_LNS_advance_pc:
-        case dwarf::DW_LNS_set_file:
-        case dwarf::DW_LNS_set_column:
-        case dwarf::DW_LNS_set_isa:
-          encodeULEB128(Op.Data, OS);
-          break;
-
-        case dwarf::DW_LNS_advance_line:
-          encodeSLEB128(Op.SData, OS);
-          break;
-
-        case dwarf::DW_LNS_fixed_advance_pc:
-          writeInteger((uint16_t)Op.Data, OS, DI.IsLittleEndian);
-          break;
-
-        default:
-          for (auto OpData : Op.StandardOpcodeData) {
-            encodeULEB128(OpData, OS);
-          }
-        }
-      }
-    }
-  }
-}

Modified: llvm/trunk/tools/yaml2obj/yaml2macho.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2macho.cpp?rev=291828&r1=291827&r2=291828&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2macho.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2macho.cpp Thu Jan 12 15:35:21 2017
@@ -14,6 +14,7 @@
 
 #include "yaml2obj.h"
 #include "llvm/ObjectYAML/ObjectYAML.h"
+#include "llvm/ObjectYAML/DWARFEmitter.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/LEB128.h"
 #include "llvm/Support/MachO.h"
@@ -269,19 +270,21 @@ Error MachOWriter::writeSectionData(raw_
                "Wrote too much data somewhere, section offsets don't line up.");
         if (0 == strncmp(&Sec.segname[0], "__DWARF", 16)) {
           if (0 == strncmp(&Sec.sectname[0], "__debug_str", 16)) {
-            yaml2debug_str(OS, Obj.DWARF);
+            DWARFYAML::EmitDebugStr(OS, Obj.DWARF);
           } else if (0 == strncmp(&Sec.sectname[0], "__debug_abbrev", 16)) {
-            yaml2debug_abbrev(OS, Obj.DWARF);
+            DWARFYAML::EmitDebugAbbrev(OS, Obj.DWARF);
           } else if (0 == strncmp(&Sec.sectname[0], "__debug_aranges", 16)) {
-            yaml2debug_aranges(OS, Obj.DWARF);
+            DWARFYAML::EmitDebugAranges(OS, Obj.DWARF);
           } else if (0 == strncmp(&Sec.sectname[0], "__debug_pubnames", 16)) {
-            yaml2pubsection(OS, Obj.DWARF.PubNames, Obj.IsLittleEndian);
+            DWARFYAML::EmitPubSection(OS, Obj.DWARF.PubNames,
+                                      Obj.IsLittleEndian);
           } else if (0 == strncmp(&Sec.sectname[0], "__debug_pubtypes", 16)) {
-            yaml2pubsection(OS, Obj.DWARF.PubTypes, Obj.IsLittleEndian);
+            DWARFYAML::EmitPubSection(OS, Obj.DWARF.PubTypes,
+                                      Obj.IsLittleEndian);
           } else if (0 == strncmp(&Sec.sectname[0], "__debug_info", 16)) {
-            yaml2debug_info(OS, Obj.DWARF);
+            DWARFYAML::EmitDebugInfo(OS, Obj.DWARF);
           } else if (0 == strncmp(&Sec.sectname[0], "__debug_line", 16)) {
-            yaml2debug_line(OS, Obj.DWARF);
+            DWARFYAML::EmitDebugLine(OS, Obj.DWARF);
           }
         } else {
           // Fills section data with 0xDEADBEEF

Modified: llvm/trunk/tools/yaml2obj/yaml2obj.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2obj.h?rev=291828&r1=291827&r2=291828&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2obj.h (original)
+++ llvm/trunk/tools/yaml2obj/yaml2obj.h Thu Jan 12 15:35:21 2017
@@ -23,11 +23,6 @@ namespace ELFYAML {
 struct Object;
 }
 
-namespace DWARFYAML {
-struct Data;
-struct PubSection;
-}
-
 namespace yaml {
 class Input;
 struct YamlObjectFile;
@@ -38,14 +33,4 @@ int yaml2coff(llvm::COFFYAML::Object &Do
 int yaml2elf(llvm::ELFYAML::Object &Doc, llvm::raw_ostream &Out);
 int yaml2macho(llvm::yaml::YamlObjectFile &Doc, llvm::raw_ostream &Out);
 
-void yaml2debug_abbrev(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
-void yaml2debug_str(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
-
-void yaml2debug_aranges(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
-void yaml2pubsection(llvm::raw_ostream &OS,
-                     const llvm::DWARFYAML::PubSection &Sect,
-                     bool IsLittleEndian);
-void yaml2debug_info(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
-void yaml2debug_line(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
-
 #endif




More information about the llvm-commits mailing list