From: Chris Bieneman Date: Thu, 12 Jan 2017 21:35:21 +0000 (+0000) Subject: [ObjectYAML] Pull yaml2dwarf out of yaml2obj for reuse X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15135b3b8a902f25418958ad9915e6962203bfe8;p=llvm [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291828 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ObjectYAML/DWARFEmitter.h b/include/llvm/ObjectYAML/DWARFEmitter.h new file mode 100644 index 00000000000..7d47690e938 --- /dev/null +++ b/include/llvm/ObjectYAML/DWARFEmitter.h @@ -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 diff --git a/lib/ObjectYAML/CMakeLists.txt b/lib/ObjectYAML/CMakeLists.txt index 2eee95b318d..ab3939e17d7 100644 --- a/lib/ObjectYAML/CMakeLists.txt +++ b/lib/ObjectYAML/CMakeLists.txt @@ -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 ) diff --git a/tools/yaml2obj/yaml2dwarf.cpp b/lib/ObjectYAML/DWARFEmitter.cpp similarity index 92% rename from tools/yaml2obj/yaml2dwarf.cpp rename to lib/ObjectYAML/DWARFEmitter.cpp index 3ceb7772b96..7282384e8ff 100644 --- a/tools/yaml2obj/yaml2dwarf.cpp +++ b/lib/ObjectYAML/DWARFEmitter.cpp @@ -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(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; diff --git a/tools/yaml2obj/CMakeLists.txt b/tools/yaml2obj/CMakeLists.txt index 5e726496003..885a69f5d3c 100644 --- a/tools/yaml2obj/CMakeLists.txt +++ b/tools/yaml2obj/CMakeLists.txt @@ -8,7 +8,6 @@ set(LLVM_LINK_COMPONENTS add_llvm_tool(yaml2obj yaml2obj.cpp yaml2coff.cpp - yaml2dwarf.cpp yaml2elf.cpp yaml2macho.cpp ) diff --git a/tools/yaml2obj/yaml2macho.cpp b/tools/yaml2obj/yaml2macho.cpp index cbc4d7ff50d..6a27a7f64c0 100644 --- a/tools/yaml2obj/yaml2macho.cpp +++ b/tools/yaml2obj/yaml2macho.cpp @@ -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 diff --git a/tools/yaml2obj/yaml2obj.h b/tools/yaml2obj/yaml2obj.h index 4a637366e1a..b5025e860bd 100644 --- a/tools/yaml2obj/yaml2obj.h +++ b/tools/yaml2obj/yaml2obj.h @@ -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