aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/ObjectYAML
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/ObjectYAML')
-rw-r--r--include/llvm/ObjectYAML/DWARFEmitter.h48
-rw-r--r--include/llvm/ObjectYAML/DWARFYAML.h52
-rw-r--r--include/llvm/ObjectYAML/MachOYAML.h8
-rw-r--r--include/llvm/ObjectYAML/ObjectYAML.h6
-rw-r--r--include/llvm/ObjectYAML/WasmYAML.h339
5 files changed, 441 insertions, 12 deletions
diff --git a/include/llvm/ObjectYAML/DWARFEmitter.h b/include/llvm/ObjectYAML/DWARFEmitter.h
new file mode 100644
index 000000000000..ce231cc0ce68
--- /dev/null
+++ b/include/llvm/ObjectYAML/DWARFEmitter.h
@@ -0,0 +1,48 @@
+//===--- 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
+
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include <memory>
+#include <vector>
+
+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);
+
+Expected<StringMap<std::unique_ptr<MemoryBuffer>>>
+EmitDebugSections(StringRef YAMLString,
+ bool IsLittleEndian = sys::IsLittleEndianHost);
+
+} // namespace DWARFYAML
+} // namespace llvm
+
+#endif
diff --git a/include/llvm/ObjectYAML/DWARFYAML.h b/include/llvm/ObjectYAML/DWARFYAML.h
index d031b5ac404c..ec34de1f0881 100644
--- a/include/llvm/ObjectYAML/DWARFYAML.h
+++ b/include/llvm/ObjectYAML/DWARFYAML.h
@@ -13,7 +13,6 @@
///
//===----------------------------------------------------------------------===//
-
#ifndef LLVM_OBJECTYAML_DWARFYAML_H
#define LLVM_OBJECTYAML_DWARFYAML_H
@@ -23,9 +22,30 @@
namespace llvm {
namespace DWARFYAML {
+struct InitialLength {
+ uint32_t TotalLength;
+ uint64_t TotalLength64;
+
+ bool isDWARF64() const { return TotalLength == UINT32_MAX; }
+
+ uint64_t getLength() const {
+ return isDWARF64() ? TotalLength64 : TotalLength;
+ }
+
+ void setLength(uint64_t Len) {
+ if (Len >= (uint64_t)UINT32_MAX) {
+ TotalLength64 = Len;
+ TotalLength = UINT32_MAX;
+ } else {
+ TotalLength = Len;
+ }
+ }
+};
+
struct AttributeAbbrev {
llvm::dwarf::Attribute Attribute;
llvm::dwarf::Form Form;
+ llvm::yaml::Hex64 Value; // Some DWARF5 attributes have values
};
struct Abbrev {
@@ -41,7 +61,7 @@ struct ARangeDescriptor {
};
struct ARange {
- uint32_t Length;
+ InitialLength Length;
uint16_t Version;
uint32_t CuOffset;
uint8_t AddrSize;
@@ -58,7 +78,7 @@ struct PubEntry {
struct PubSection {
PubSection() : IsGNUStyle(false) {}
- uint32_t Length;
+ InitialLength Length;
uint16_t Version;
uint32_t UnitOffset;
uint32_t UnitSize;
@@ -78,8 +98,9 @@ struct Entry {
};
struct Unit {
- uint32_t Length;
+ InitialLength Length;
uint16_t Version;
+ llvm::dwarf::UnitType Type; // Added in DWARF 5
uint32_t AbbrOffset;
uint8_t AddrSize;
std::vector<Entry> Entries;
@@ -104,8 +125,7 @@ struct LineTableOpcode {
};
struct LineTable {
- uint32_t TotalLength;
- uint64_t TotalLength64;
+ InitialLength Length;
uint16_t Version;
uint64_t PrologueLength;
uint8_t MinInstLength;
@@ -130,7 +150,7 @@ struct Data {
PubSection GNUPubNames;
PubSection GNUPubTypes;
-
+
std::vector<Unit> CompileUnits;
std::vector<LineTable> DebugLines;
@@ -141,7 +161,7 @@ struct Data {
} // namespace llvm::DWARFYAML
} // namespace llvm
-LLVM_YAML_IS_SEQUENCE_VECTOR(uint8_t)
+LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint8_t)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex64)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex8)
@@ -203,7 +223,7 @@ template <> struct MappingTraits<DWARFYAML::FormValue> {
template <> struct MappingTraits<DWARFYAML::File> {
static void mapping(IO &IO, DWARFYAML::File &File);
};
-
+
template <> struct MappingTraits<DWARFYAML::LineTableOpcode> {
static void mapping(IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode);
};
@@ -212,6 +232,10 @@ template <> struct MappingTraits<DWARFYAML::LineTable> {
static void mapping(IO &IO, DWARFYAML::LineTable &LineTable);
};
+template <> struct MappingTraits<DWARFYAML::InitialLength> {
+ static void mapping(IO &IO, DWARFYAML::InitialLength &DWARF);
+};
+
#define HANDLE_DW_TAG(unused, name) \
io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
@@ -262,6 +286,16 @@ template <> struct ScalarEnumerationTraits<dwarf::Form> {
}
};
+#define HANDLE_DW_UT(unused, name) \
+ io.enumCase(value, "DW_UT_" #name, dwarf::DW_UT_##name);
+
+template <> struct ScalarEnumerationTraits<dwarf::UnitType> {
+ static void enumeration(IO &io, dwarf::UnitType &value) {
+#include "llvm/Support/Dwarf.def"
+ io.enumFallback<Hex8>(value);
+ }
+};
+
template <> struct ScalarEnumerationTraits<dwarf::Constants> {
static void enumeration(IO &io, dwarf::Constants &value) {
io.enumCase(value, "DW_CHILDREN_no", dwarf::DW_CHILDREN_no);
diff --git a/include/llvm/ObjectYAML/MachOYAML.h b/include/llvm/ObjectYAML/MachOYAML.h
index 9ec32d265bca..ae858c8f4aaf 100644
--- a/include/llvm/ObjectYAML/MachOYAML.h
+++ b/include/llvm/ObjectYAML/MachOYAML.h
@@ -53,6 +53,7 @@ struct LoadCommand {
virtual ~LoadCommand();
llvm::MachO::macho_load_command Data;
std::vector<Section> Sections;
+ std::vector<MachO::build_tool_version> Tools;
std::vector<llvm::yaml::Hex8> PayloadBytes;
std::string PayloadString;
uint64_t ZeroPadBytes;
@@ -139,13 +140,14 @@ struct UniversalBinary {
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::LoadCommand)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::Section)
-LLVM_YAML_IS_SEQUENCE_VECTOR(int64_t)
+LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(int64_t)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::RebaseOpcode)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::BindOpcode)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::ExportEntry)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::NListEntry)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::Object)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::FatArch)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachO::build_tool_version)
namespace llvm {
namespace yaml {
@@ -198,6 +200,10 @@ template <> struct MappingTraits<MachOYAML::NListEntry> {
static void mapping(IO &IO, MachOYAML::NListEntry &NListEntry);
};
+template <> struct MappingTraits<MachO::build_tool_version> {
+ static void mapping(IO &IO, MachO::build_tool_version &tool);
+};
+
#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
io.enumCase(value, #LCName, MachO::LCName);
diff --git a/include/llvm/ObjectYAML/ObjectYAML.h b/include/llvm/ObjectYAML/ObjectYAML.h
index 1d6462347770..36d6ed5417cf 100644
--- a/include/llvm/ObjectYAML/ObjectYAML.h
+++ b/include/llvm/ObjectYAML/ObjectYAML.h
@@ -10,10 +10,11 @@
#ifndef LLVM_OBJECTYAML_OBJECTYAML_H
#define LLVM_OBJECTYAML_OBJECTYAML_H
-#include "llvm/Support/YAMLTraits.h"
-#include "llvm/ObjectYAML/ELFYAML.h"
#include "llvm/ObjectYAML/COFFYAML.h"
+#include "llvm/ObjectYAML/ELFYAML.h"
#include "llvm/ObjectYAML/MachOYAML.h"
+#include "llvm/ObjectYAML/WasmYAML.h"
+#include "llvm/Support/YAMLTraits.h"
namespace llvm {
namespace yaml {
@@ -23,6 +24,7 @@ struct YamlObjectFile {
std::unique_ptr<COFFYAML::Object> Coff;
std::unique_ptr<MachOYAML::Object> MachO;
std::unique_ptr<MachOYAML::UniversalBinary> FatMachO;
+ std::unique_ptr<WasmYAML::Object> Wasm;
};
template <> struct MappingTraits<YamlObjectFile> {
diff --git a/include/llvm/ObjectYAML/WasmYAML.h b/include/llvm/ObjectYAML/WasmYAML.h
new file mode 100644
index 000000000000..b1af8bbdfa6e
--- /dev/null
+++ b/include/llvm/ObjectYAML/WasmYAML.h
@@ -0,0 +1,339 @@
+//===- WasmYAML.h - Wasm YAMLIO implementation ------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file declares classes for handling the YAML representation
+/// of wasm binaries.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_OBJECTYAML_WASMYAML_H
+#define LLVM_OBJECTYAML_WASMYAML_H
+
+#include "llvm/ObjectYAML/YAML.h"
+#include "llvm/Support/Wasm.h"
+
+namespace llvm {
+namespace WasmYAML {
+
+LLVM_YAML_STRONG_TYPEDEF(uint32_t, SectionType)
+LLVM_YAML_STRONG_TYPEDEF(int32_t, ValueType)
+LLVM_YAML_STRONG_TYPEDEF(int32_t, TableType)
+LLVM_YAML_STRONG_TYPEDEF(int32_t, SignatureForm)
+LLVM_YAML_STRONG_TYPEDEF(uint32_t, ExportKind)
+LLVM_YAML_STRONG_TYPEDEF(uint32_t, Opcode)
+LLVM_YAML_STRONG_TYPEDEF(uint32_t, RelocType)
+
+struct FileHeader {
+ yaml::Hex32 Version;
+};
+
+struct Import {
+ StringRef Module;
+ StringRef Field;
+ ExportKind Kind;
+ union {
+ uint32_t SigIndex;
+ ValueType GlobalType;
+ };
+ bool GlobalMutable;
+};
+
+struct Limits {
+ yaml::Hex32 Flags;
+ yaml::Hex32 Initial;
+ yaml::Hex32 Maximum;
+};
+
+struct Table {
+ TableType ElemType;
+ Limits TableLimits;
+};
+
+struct Export {
+ StringRef Name;
+ ExportKind Kind;
+ uint32_t Index;
+};
+
+struct ElemSegment {
+ uint32_t TableIndex;
+ wasm::WasmInitExpr Offset;
+ std::vector<uint32_t> Functions;
+};
+
+struct Global {
+ ValueType Type;
+ bool Mutable;
+ wasm::WasmInitExpr InitExpr;
+};
+
+struct LocalDecl {
+ ValueType Type;
+ uint32_t Count;
+};
+
+struct Function {
+ std::vector<LocalDecl> Locals;
+ yaml::BinaryRef Body;
+};
+
+struct Relocation {
+ RelocType Type;
+ uint32_t Index;
+ yaml::Hex32 Offset;
+ yaml::Hex32 Addend;
+};
+
+struct DataSegment {
+ uint32_t Index;
+ wasm::WasmInitExpr Offset;
+ yaml::BinaryRef Content;
+};
+
+struct Signature {
+ Signature() : Form(wasm::WASM_TYPE_FUNC) {}
+
+ uint32_t Index;
+ SignatureForm Form;
+ std::vector<ValueType> ParamTypes;
+ ValueType ReturnType;
+};
+
+struct Section {
+ Section(SectionType SecType) : Type(SecType) {}
+ virtual ~Section();
+
+ SectionType Type;
+ std::vector<Relocation> Relocations;
+};
+
+struct CustomSection : Section {
+ CustomSection() : Section(wasm::WASM_SEC_CUSTOM) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_CUSTOM;
+ }
+
+ StringRef Name;
+ yaml::BinaryRef Payload;
+};
+
+struct TypeSection : Section {
+ TypeSection() : Section(wasm::WASM_SEC_TYPE) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_TYPE;
+ }
+
+ std::vector<Signature> Signatures;
+};
+
+struct ImportSection : Section {
+ ImportSection() : Section(wasm::WASM_SEC_IMPORT) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_IMPORT;
+ }
+
+ std::vector<Import> Imports;
+};
+
+struct FunctionSection : Section {
+ FunctionSection() : Section(wasm::WASM_SEC_FUNCTION) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_FUNCTION;
+ }
+
+ std::vector<uint32_t> FunctionTypes;
+};
+
+struct TableSection : Section {
+ TableSection() : Section(wasm::WASM_SEC_TABLE) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_TABLE;
+ }
+
+ std::vector<Table> Tables;
+};
+
+struct MemorySection : Section {
+ MemorySection() : Section(wasm::WASM_SEC_MEMORY) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_MEMORY;
+ }
+
+ std::vector<Limits> Memories;
+};
+
+struct GlobalSection : Section {
+ GlobalSection() : Section(wasm::WASM_SEC_GLOBAL) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_GLOBAL;
+ }
+
+ std::vector<Global> Globals;
+};
+
+struct ExportSection : Section {
+ ExportSection() : Section(wasm::WASM_SEC_EXPORT) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_EXPORT;
+ }
+
+ std::vector<Export> Exports;
+};
+
+struct StartSection : Section {
+ StartSection() : Section(wasm::WASM_SEC_START) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_START;
+ }
+
+ uint32_t StartFunction;
+};
+
+struct ElemSection : Section {
+ ElemSection() : Section(wasm::WASM_SEC_ELEM) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_ELEM;
+ }
+
+ std::vector<ElemSegment> Segments;
+};
+
+struct CodeSection : Section {
+ CodeSection() : Section(wasm::WASM_SEC_CODE) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_CODE;
+ }
+
+ std::vector<Function> Functions;
+};
+
+struct DataSection : Section {
+ DataSection() : Section(wasm::WASM_SEC_DATA) {}
+ static bool classof(const Section *S) {
+ return S->Type == wasm::WASM_SEC_DATA;
+ }
+
+ std::vector<DataSegment> Segments;
+};
+
+struct Object {
+ FileHeader Header;
+ std::vector<std::unique_ptr<Section>> Sections;
+};
+
+} // end namespace WasmYAML
+} // end namespace llvm
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Table)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Import)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Export)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ElemSegment)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Limits)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DataSegment)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Global)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation)
+LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t)
+
+namespace llvm {
+namespace yaml {
+
+template <> struct MappingTraits<WasmYAML::FileHeader> {
+ static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
+};
+
+template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
+ static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
+};
+
+template <> struct MappingTraits<WasmYAML::Object> {
+ static void mapping(IO &IO, WasmYAML::Object &Object);
+};
+
+template <> struct MappingTraits<WasmYAML::Import> {
+ static void mapping(IO &IO, WasmYAML::Import &Import);
+};
+
+template <> struct MappingTraits<WasmYAML::Export> {
+ static void mapping(IO &IO, WasmYAML::Export &Export);
+};
+
+template <> struct MappingTraits<WasmYAML::Global> {
+ static void mapping(IO &IO, WasmYAML::Global &Global);
+};
+
+template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
+ static void enumeration(IO &IO, WasmYAML::SectionType &Type);
+};
+
+template <> struct MappingTraits<WasmYAML::Signature> {
+ static void mapping(IO &IO, WasmYAML::Signature &Signature);
+};
+
+template <> struct MappingTraits<WasmYAML::Table> {
+ static void mapping(IO &IO, WasmYAML::Table &Table);
+};
+
+template <> struct MappingTraits<WasmYAML::Limits> {
+ static void mapping(IO &IO, WasmYAML::Limits &Limits);
+};
+
+template <> struct MappingTraits<WasmYAML::Function> {
+ static void mapping(IO &IO, WasmYAML::Function &Function);
+};
+
+template <> struct MappingTraits<WasmYAML::Relocation> {
+ static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
+};
+
+template <> struct MappingTraits<WasmYAML::LocalDecl> {
+ static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
+};
+
+template <> struct MappingTraits<wasm::WasmInitExpr> {
+ static void mapping(IO &IO, wasm::WasmInitExpr &Expr);
+};
+
+template <> struct MappingTraits<WasmYAML::DataSegment> {
+ static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
+};
+
+template <> struct MappingTraits<WasmYAML::ElemSegment> {
+ static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
+};
+
+template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
+ static void enumeration(IO &IO, WasmYAML::ValueType &Type);
+};
+
+template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
+ static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
+};
+
+template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
+ static void enumeration(IO &IO, WasmYAML::TableType &Type);
+};
+
+template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
+ static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
+};
+
+template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
+ static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
+};
+
+} // end namespace yaml
+} // end namespace llvm
+
+#endif