summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2016-12-07 22:30:15 +0000
committerChris Bieneman <beanz@apple.com>2016-12-07 22:30:15 +0000
commit7d7364ab4fecfd8cdf6f129df518922dacb53047 (patch)
tree1dde94cac23d7339dd89a84158f4b0e8e61375f7
parent9408c6183054d824780fa4eaf5e67b9f640b78fd (diff)
downloadbcm5719-llvm-7d7364ab4fecfd8cdf6f129df518922dacb53047.tar.gz
bcm5719-llvm-7d7364ab4fecfd8cdf6f129df518922dacb53047.zip
[yaml2obj] Refactor and abstract yaml2dwarf functions
This abstracts the code for emitting DWARF binary from the DWARFYAML types into reusable interfaces that could be used by ELF and COFF. llvm-svn: 288990
-rw-r--r--llvm/tools/yaml2obj/CMakeLists.txt1
-rw-r--r--llvm/tools/yaml2obj/yaml2dwarf.cpp41
-rw-r--r--llvm/tools/yaml2obj/yaml2macho.cpp17
-rw-r--r--llvm/tools/yaml2obj/yaml2obj.h9
4 files changed, 53 insertions, 15 deletions
diff --git a/llvm/tools/yaml2obj/CMakeLists.txt b/llvm/tools/yaml2obj/CMakeLists.txt
index 885a69f5d3c..5e726496003 100644
--- a/llvm/tools/yaml2obj/CMakeLists.txt
+++ b/llvm/tools/yaml2obj/CMakeLists.txt
@@ -8,6 +8,7 @@ set(LLVM_LINK_COMPONENTS
add_llvm_tool(yaml2obj
yaml2obj.cpp
yaml2coff.cpp
+ yaml2dwarf.cpp
yaml2elf.cpp
yaml2macho.cpp
)
diff --git a/llvm/tools/yaml2obj/yaml2dwarf.cpp b/llvm/tools/yaml2obj/yaml2dwarf.cpp
new file mode 100644
index 00000000000..9e869996367
--- /dev/null
+++ b/llvm/tools/yaml2obj/yaml2dwarf.cpp
@@ -0,0 +1,41 @@
+//===- 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"
+
+using namespace llvm;
+
+void yaml2debug_str(raw_ostream &OS, const DWARFYAML::DWARFData &DI) {
+ for (auto Str : DI.DebugStrings) {
+ OS.write(Str.data(), Str.size());
+ OS.write('\0');
+ }
+}
+
+void yaml2debug_abbrev(raw_ostream &OS, const DWARFYAML::DWARFData &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);
+ }
+}
diff --git a/llvm/tools/yaml2obj/yaml2macho.cpp b/llvm/tools/yaml2obj/yaml2macho.cpp
index 48bd9e83ad3..a6d56ef8501 100644
--- a/llvm/tools/yaml2obj/yaml2macho.cpp
+++ b/llvm/tools/yaml2obj/yaml2macho.cpp
@@ -389,22 +389,9 @@ Error MachOWriter::writeDWARFData(raw_ostream &OS,
for(auto Section : Sections) {
ZeroToOffset(OS, Section.offset);
if (0 == strncmp(&Section.sectname[0], "__debug_str", 16)) {
- for (auto Str : Obj.DWARF.DebugStrings) {
- OS.write(Str.data(), Str.size());
- OS.write('\0');
- }
+ yaml2debug_str(OS, Obj.DWARF);
} else if (0 == strncmp(&Section.sectname[0], "__debug_abbrev", 16)) {
- for (auto AbbrevDecl : Obj.DWARF.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);
- }
+ yaml2debug_abbrev(OS, Obj.DWARF);
}
}
return Error::success();
diff --git a/llvm/tools/yaml2obj/yaml2obj.h b/llvm/tools/yaml2obj/yaml2obj.h
index b5025e860bd..55edf33a2be 100644
--- a/llvm/tools/yaml2obj/yaml2obj.h
+++ b/llvm/tools/yaml2obj/yaml2obj.h
@@ -23,6 +23,10 @@ namespace ELFYAML {
struct Object;
}
+namespace DWARFYAML {
+struct DWARFData;
+}
+
namespace yaml {
class Input;
struct YamlObjectFile;
@@ -33,4 +37,9 @@ 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::DWARFData &DI);
+void yaml2debug_str(llvm::raw_ostream &OS,
+ const llvm::DWARFYAML::DWARFData &DI);
+
#endif
OpenPOWER on IntegriCloud