1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00

[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.

llvm-svn: 291828
This commit is contained in:
Chris Bieneman 2017-01-12 21:35:21 +00:00
parent cfdc41713e
commit 5b0273a893
6 changed files with 63 additions and 37 deletions

View File

@ -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

View 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
)

View 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;

View File

@ -8,7 +8,6 @@ set(LLVM_LINK_COMPONENTS
add_llvm_tool(yaml2obj
yaml2obj.cpp
yaml2coff.cpp
yaml2dwarf.cpp
yaml2elf.cpp
yaml2macho.cpp
)

View 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

View 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