]> granicus.if.org Git - llvm/commitdiff
[ObjectYAML] Pull yaml2dwarf out of yaml2obj for reuse
authorChris Bieneman <beanz@apple.com>
Thu, 12 Jan 2017 21:35:21 +0000 (21:35 +0000)
committerChris Bieneman <beanz@apple.com>
Thu, 12 Jan 2017 21:35:21 +0000 (21:35 +0000)
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.

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

include/llvm/ObjectYAML/DWARFEmitter.h [new file with mode: 0644]
lib/ObjectYAML/CMakeLists.txt
lib/ObjectYAML/DWARFEmitter.cpp [moved from tools/yaml2obj/yaml2dwarf.cpp with 92% similarity]
tools/yaml2obj/CMakeLists.txt
tools/yaml2obj/yaml2macho.cpp
tools/yaml2obj/yaml2obj.h

diff --git a/include/llvm/ObjectYAML/DWARFEmitter.h b/include/llvm/ObjectYAML/DWARFEmitter.h
new file mode 100644 (file)
index 0000000..7d47690
--- /dev/null
@@ -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
index 2eee95b318dbc66ac73604cf2a01ca5d148afbef..ab3939e17d758c794886a226e923840f1a2f4775 100644 (file)
@@ -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
   )
similarity index 92%
rename from tools/yaml2obj/yaml2dwarf.cpp
rename to lib/ObjectYAML/DWARFEmitter.cpp
index 3ceb7772b9691c7c6ba0d2db14796ef88a068af4..7282384e8ffdef38602fcfb31250b49dc05b4b34 100644 (file)
@@ -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_t 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, const DWARFYAML::Data &DI) {
   }
 }
 
-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, const DWARFYAML::Data &DI) {
   }
 }
 
-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, const DWARFYAML::PubSection &Sect,
   }
 }
 
-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, const DWARFYAML::Data &DI) {
   }
 }
 
-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, const DWARFYAML::File &File) {
   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, const DWARFYAML::Data &DI) {
     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, const DWARFYAML::Data &DI) {
                                     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;
index 5e726496003f7320369e3ebd037c541a324ff313..885a69f5d3c36b810185f45daee7f630a0b52149 100644 (file)
@@ -8,7 +8,6 @@ set(LLVM_LINK_COMPONENTS
 add_llvm_tool(yaml2obj
   yaml2obj.cpp
   yaml2coff.cpp
-  yaml2dwarf.cpp
   yaml2elf.cpp
   yaml2macho.cpp
   )
index cbc4d7ff50d5ebec56fd74ae7d0ce3c27a8905c9..6a27a7f64c053fac69935f49f8405475e46b4e74 100644 (file)
@@ -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_ostream &OS) {
                "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
index 4a637366e1a16330529e671b6d352ecee179b763..b5025e860bd751281be43b9daf83b5e6af8b8bba 100644 (file)
@@ -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 &Doc, llvm::raw_ostream &Out);
 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