You've already forked linux-packaging-mono
Imported Upstream version 5.18.0.167
Former-commit-id: 289509151e0fee68a1b591a20c9f109c3c789d3a
This commit is contained in:
parent
e19d552987
commit
b084638f15
15
external/llvm/lib/ObjectYAML/CMakeLists.txt
vendored
15
external/llvm/lib/ObjectYAML/CMakeLists.txt
vendored
@ -1,15 +0,0 @@
|
||||
add_llvm_library(LLVMObjectYAML
|
||||
CodeViewYAMLDebugSections.cpp
|
||||
CodeViewYAMLSymbols.cpp
|
||||
CodeViewYAMLTypeHashing.cpp
|
||||
CodeViewYAMLTypes.cpp
|
||||
COFFYAML.cpp
|
||||
DWARFEmitter.cpp
|
||||
DWARFVisitor.cpp
|
||||
DWARFYAML.cpp
|
||||
ELFYAML.cpp
|
||||
MachOYAML.cpp
|
||||
ObjectYAML.cpp
|
||||
WasmYAML.cpp
|
||||
YAML.cpp
|
||||
)
|
589
external/llvm/lib/ObjectYAML/COFFYAML.cpp
vendored
589
external/llvm/lib/ObjectYAML/COFFYAML.cpp
vendored
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
590
external/llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
vendored
590
external/llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
vendored
File diff suppressed because it is too large
Load Diff
@ -1,84 +0,0 @@
|
||||
//===- CodeViewYAMLTypeHashing.cpp - CodeView YAMLIO type hashing ---------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines classes for handling the YAML representation of CodeView
|
||||
// Debug Info.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ObjectYAML/CodeViewYAMLTypeHashing.h"
|
||||
#include "llvm/Support/BinaryByteStream.h"
|
||||
#include "llvm/Support/BinaryStreamReader.h"
|
||||
#include "llvm/Support/BinaryStreamWriter.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::codeview;
|
||||
using namespace llvm::CodeViewYAML;
|
||||
using namespace llvm::yaml;
|
||||
|
||||
namespace llvm {
|
||||
namespace yaml {
|
||||
|
||||
void MappingTraits<DebugHSection>::mapping(IO &io, DebugHSection &DebugH) {
|
||||
io.mapRequired("Version", DebugH.Version);
|
||||
io.mapRequired("HashAlgorithm", DebugH.HashAlgorithm);
|
||||
io.mapOptional("HashValues", DebugH.Hashes);
|
||||
}
|
||||
|
||||
void ScalarTraits<GlobalHash>::output(const GlobalHash &GH, void *Ctx,
|
||||
raw_ostream &OS) {
|
||||
ScalarTraits<BinaryRef>::output(GH.Hash, Ctx, OS);
|
||||
}
|
||||
|
||||
StringRef ScalarTraits<GlobalHash>::input(StringRef Scalar, void *Ctx,
|
||||
GlobalHash &GH) {
|
||||
return ScalarTraits<BinaryRef>::input(Scalar, Ctx, GH.Hash);
|
||||
}
|
||||
|
||||
} // end namespace yaml
|
||||
} // end namespace llvm
|
||||
|
||||
DebugHSection llvm::CodeViewYAML::fromDebugH(ArrayRef<uint8_t> DebugH) {
|
||||
assert(DebugH.size() >= 8);
|
||||
assert((DebugH.size() - 8) % 20 == 0);
|
||||
|
||||
BinaryStreamReader Reader(DebugH, llvm::support::little);
|
||||
DebugHSection DHS;
|
||||
cantFail(Reader.readInteger(DHS.Magic));
|
||||
cantFail(Reader.readInteger(DHS.Version));
|
||||
cantFail(Reader.readInteger(DHS.HashAlgorithm));
|
||||
while (Reader.bytesRemaining() != 0) {
|
||||
ArrayRef<uint8_t> S;
|
||||
cantFail(Reader.readBytes(S, 20));
|
||||
DHS.Hashes.emplace_back(S);
|
||||
}
|
||||
assert(Reader.bytesRemaining() == 0);
|
||||
return DHS;
|
||||
}
|
||||
|
||||
ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugH(const DebugHSection &DebugH,
|
||||
BumpPtrAllocator &Alloc) {
|
||||
uint32_t Size = 8 + 20 * DebugH.Hashes.size();
|
||||
uint8_t *Data = Alloc.Allocate<uint8_t>(Size);
|
||||
MutableArrayRef<uint8_t> Buffer(Data, Size);
|
||||
BinaryStreamWriter Writer(Buffer, llvm::support::little);
|
||||
cantFail(Writer.writeInteger(DebugH.Magic));
|
||||
cantFail(Writer.writeInteger(DebugH.Version));
|
||||
cantFail(Writer.writeInteger(DebugH.HashAlgorithm));
|
||||
SmallString<20> Hash;
|
||||
for (const auto &H : DebugH.Hashes) {
|
||||
Hash.clear();
|
||||
raw_svector_ostream OS(Hash);
|
||||
H.Hash.writeAsBinary(OS);
|
||||
assert((Hash.size() == 20) && "Invalid hash size!");
|
||||
cantFail(Writer.writeFixedString(Hash));
|
||||
}
|
||||
assert(Writer.bytesRemaining() == 0);
|
||||
return Buffer;
|
||||
}
|
803
external/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
vendored
803
external/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
vendored
File diff suppressed because it is too large
Load Diff
335
external/llvm/lib/ObjectYAML/DWARFEmitter.cpp
vendored
335
external/llvm/lib/ObjectYAML/DWARFEmitter.cpp
vendored
@ -1,335 +0,0 @@
|
||||
//===- DWARFEmitter - 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. Provided as library code for tests.
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ObjectYAML/DWARFEmitter.h"
|
||||
#include "DWARFVisitor.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ObjectYAML/DWARFYAML.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/LEB128.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/SwapByteOrder.h"
|
||||
#include "llvm/Support/YAMLTraits.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
template <typename T>
|
||||
static void writeInteger(T Integer, raw_ostream &OS, bool IsLittleEndian) {
|
||||
if (IsLittleEndian != sys::IsLittleEndianHost)
|
||||
sys::swapByteOrder(Integer);
|
||||
OS.write(reinterpret_cast<char *>(&Integer), sizeof(T));
|
||||
}
|
||||
|
||||
static void writeVariableSizedInteger(uint64_t Integer, size_t Size,
|
||||
raw_ostream &OS, bool IsLittleEndian) {
|
||||
if (8 == Size)
|
||||
writeInteger((uint64_t)Integer, OS, IsLittleEndian);
|
||||
else if (4 == Size)
|
||||
writeInteger((uint32_t)Integer, OS, IsLittleEndian);
|
||||
else if (2 == Size)
|
||||
writeInteger((uint16_t)Integer, OS, IsLittleEndian);
|
||||
else if (1 == Size)
|
||||
writeInteger((uint8_t)Integer, OS, IsLittleEndian);
|
||||
else
|
||||
assert(false && "Invalid integer write size.");
|
||||
}
|
||||
|
||||
static void ZeroFillBytes(raw_ostream &OS, size_t Size) {
|
||||
std::vector<uint8_t> FillData;
|
||||
FillData.insert(FillData.begin(), Size, 0);
|
||||
OS.write(reinterpret_cast<char *>(FillData.data()), Size);
|
||||
}
|
||||
|
||||
static void writeInitialLength(const DWARFYAML::InitialLength &Length,
|
||||
raw_ostream &OS, bool IsLittleEndian) {
|
||||
writeInteger((uint32_t)Length.TotalLength, OS, IsLittleEndian);
|
||||
if (Length.isDWARF64())
|
||||
writeInteger((uint64_t)Length.TotalLength64, OS, IsLittleEndian);
|
||||
}
|
||||
|
||||
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 DWARFYAML::EmitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &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);
|
||||
if (Attr.Form == dwarf::DW_FORM_implicit_const)
|
||||
encodeSLEB128(Attr.Value, OS);
|
||||
}
|
||||
encodeULEB128(0, OS);
|
||||
encodeULEB128(0, OS);
|
||||
}
|
||||
}
|
||||
|
||||
void DWARFYAML::EmitDebugAranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
|
||||
for (auto Range : DI.ARanges) {
|
||||
auto HeaderStart = OS.tell();
|
||||
writeInitialLength(Range.Length, OS, DI.IsLittleEndian);
|
||||
writeInteger((uint16_t)Range.Version, OS, DI.IsLittleEndian);
|
||||
writeInteger((uint32_t)Range.CuOffset, OS, DI.IsLittleEndian);
|
||||
writeInteger((uint8_t)Range.AddrSize, OS, DI.IsLittleEndian);
|
||||
writeInteger((uint8_t)Range.SegSize, OS, DI.IsLittleEndian);
|
||||
|
||||
auto HeaderSize = OS.tell() - HeaderStart;
|
||||
auto FirstDescriptor = alignTo(HeaderSize, Range.AddrSize * 2);
|
||||
ZeroFillBytes(OS, FirstDescriptor - HeaderSize);
|
||||
|
||||
for (auto Descriptor : Range.Descriptors) {
|
||||
writeVariableSizedInteger(Descriptor.Address, Range.AddrSize, OS,
|
||||
DI.IsLittleEndian);
|
||||
writeVariableSizedInteger(Descriptor.Length, Range.AddrSize, OS,
|
||||
DI.IsLittleEndian);
|
||||
}
|
||||
ZeroFillBytes(OS, Range.AddrSize * 2);
|
||||
}
|
||||
}
|
||||
|
||||
void DWARFYAML::EmitPubSection(raw_ostream &OS,
|
||||
const DWARFYAML::PubSection &Sect,
|
||||
bool IsLittleEndian) {
|
||||
writeInitialLength(Sect.Length, OS, IsLittleEndian);
|
||||
writeInteger((uint16_t)Sect.Version, OS, IsLittleEndian);
|
||||
writeInteger((uint32_t)Sect.UnitOffset, OS, IsLittleEndian);
|
||||
writeInteger((uint32_t)Sect.UnitSize, OS, IsLittleEndian);
|
||||
for (auto Entry : Sect.Entries) {
|
||||
writeInteger((uint32_t)Entry.DieOffset, OS, IsLittleEndian);
|
||||
if (Sect.IsGNUStyle)
|
||||
writeInteger((uint32_t)Entry.Descriptor, OS, IsLittleEndian);
|
||||
OS.write(Entry.Name.data(), Entry.Name.size());
|
||||
OS.write('\0');
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
/// \brief An extension of the DWARFYAML::ConstVisitor which writes compile
|
||||
/// units and DIEs to a stream.
|
||||
class DumpVisitor : public DWARFYAML::ConstVisitor {
|
||||
raw_ostream &OS;
|
||||
|
||||
protected:
|
||||
void onStartCompileUnit(const DWARFYAML::Unit &CU) override {
|
||||
writeInitialLength(CU.Length, OS, DebugInfo.IsLittleEndian);
|
||||
writeInteger((uint16_t)CU.Version, OS, DebugInfo.IsLittleEndian);
|
||||
if(CU.Version >= 5) {
|
||||
writeInteger((uint8_t)CU.Type, OS, DebugInfo.IsLittleEndian);
|
||||
writeInteger((uint8_t)CU.AddrSize, OS, DebugInfo.IsLittleEndian);
|
||||
writeInteger((uint32_t)CU.AbbrOffset, OS, DebugInfo.IsLittleEndian);
|
||||
}else {
|
||||
writeInteger((uint32_t)CU.AbbrOffset, OS, DebugInfo.IsLittleEndian);
|
||||
writeInteger((uint8_t)CU.AddrSize, OS, DebugInfo.IsLittleEndian);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void onStartDIE(const DWARFYAML::Unit &CU,
|
||||
const DWARFYAML::Entry &DIE) override {
|
||||
encodeULEB128(DIE.AbbrCode, OS);
|
||||
}
|
||||
|
||||
void onValue(const uint8_t U) override {
|
||||
writeInteger(U, OS, DebugInfo.IsLittleEndian);
|
||||
}
|
||||
|
||||
void onValue(const uint16_t U) override {
|
||||
writeInteger(U, OS, DebugInfo.IsLittleEndian);
|
||||
}
|
||||
|
||||
void onValue(const uint32_t U) override {
|
||||
writeInteger(U, OS, DebugInfo.IsLittleEndian);
|
||||
}
|
||||
|
||||
void onValue(const uint64_t U, const bool LEB = false) override {
|
||||
if (LEB)
|
||||
encodeULEB128(U, OS);
|
||||
else
|
||||
writeInteger(U, OS, DebugInfo.IsLittleEndian);
|
||||
}
|
||||
|
||||
void onValue(const int64_t S, const bool LEB = false) override {
|
||||
if (LEB)
|
||||
encodeSLEB128(S, OS);
|
||||
else
|
||||
writeInteger(S, OS, DebugInfo.IsLittleEndian);
|
||||
}
|
||||
|
||||
void onValue(const StringRef String) override {
|
||||
OS.write(String.data(), String.size());
|
||||
OS.write('\0');
|
||||
}
|
||||
|
||||
void onValue(const MemoryBufferRef MBR) override {
|
||||
OS.write(MBR.getBufferStart(), MBR.getBufferSize());
|
||||
}
|
||||
|
||||
public:
|
||||
DumpVisitor(const DWARFYAML::Data &DI, raw_ostream &Out)
|
||||
: DWARFYAML::ConstVisitor(DI), OS(Out) {}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
void DWARFYAML::EmitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
|
||||
DumpVisitor Visitor(DI, OS);
|
||||
Visitor.traverseDebugInfo();
|
||||
}
|
||||
|
||||
static void EmitFileEntry(raw_ostream &OS, const DWARFYAML::File &File) {
|
||||
OS.write(File.Name.data(), File.Name.size());
|
||||
OS.write('\0');
|
||||
encodeULEB128(File.DirIdx, OS);
|
||||
encodeULEB128(File.ModTime, OS);
|
||||
encodeULEB128(File.Length, OS);
|
||||
}
|
||||
|
||||
void DWARFYAML::EmitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
|
||||
for (const auto &LineTable : DI.DebugLines) {
|
||||
writeInitialLength(LineTable.Length, OS, DI.IsLittleEndian);
|
||||
uint64_t SizeOfPrologueLength = LineTable.Length.isDWARF64() ? 8 : 4;
|
||||
writeInteger((uint16_t)LineTable.Version, OS, DI.IsLittleEndian);
|
||||
writeVariableSizedInteger(LineTable.PrologueLength, SizeOfPrologueLength,
|
||||
OS, DI.IsLittleEndian);
|
||||
writeInteger((uint8_t)LineTable.MinInstLength, OS, DI.IsLittleEndian);
|
||||
if (LineTable.Version >= 4)
|
||||
writeInteger((uint8_t)LineTable.MaxOpsPerInst, OS, DI.IsLittleEndian);
|
||||
writeInteger((uint8_t)LineTable.DefaultIsStmt, OS, DI.IsLittleEndian);
|
||||
writeInteger((uint8_t)LineTable.LineBase, OS, DI.IsLittleEndian);
|
||||
writeInteger((uint8_t)LineTable.LineRange, OS, DI.IsLittleEndian);
|
||||
writeInteger((uint8_t)LineTable.OpcodeBase, OS, DI.IsLittleEndian);
|
||||
|
||||
for (auto OpcodeLength : LineTable.StandardOpcodeLengths)
|
||||
writeInteger((uint8_t)OpcodeLength, OS, DI.IsLittleEndian);
|
||||
|
||||
for (auto IncludeDir : LineTable.IncludeDirs) {
|
||||
OS.write(IncludeDir.data(), IncludeDir.size());
|
||||
OS.write('\0');
|
||||
}
|
||||
OS.write('\0');
|
||||
|
||||
for (auto File : LineTable.Files)
|
||||
EmitFileEntry(OS, File);
|
||||
OS.write('\0');
|
||||
|
||||
for (auto Op : LineTable.Opcodes) {
|
||||
writeInteger((uint8_t)Op.Opcode, OS, DI.IsLittleEndian);
|
||||
if (Op.Opcode == 0) {
|
||||
encodeULEB128(Op.ExtLen, OS);
|
||||
writeInteger((uint8_t)Op.SubOpcode, OS, DI.IsLittleEndian);
|
||||
switch (Op.SubOpcode) {
|
||||
case dwarf::DW_LNE_set_address:
|
||||
case dwarf::DW_LNE_set_discriminator:
|
||||
writeVariableSizedInteger(Op.Data, DI.CompileUnits[0].AddrSize, OS,
|
||||
DI.IsLittleEndian);
|
||||
break;
|
||||
case dwarf::DW_LNE_define_file:
|
||||
EmitFileEntry(OS, Op.FileEntry);
|
||||
break;
|
||||
case dwarf::DW_LNE_end_sequence:
|
||||
break;
|
||||
default:
|
||||
for (auto OpByte : Op.UnknownOpcodeData)
|
||||
writeInteger((uint8_t)OpByte, OS, DI.IsLittleEndian);
|
||||
}
|
||||
} else if (Op.Opcode < LineTable.OpcodeBase) {
|
||||
switch (Op.Opcode) {
|
||||
case dwarf::DW_LNS_copy:
|
||||
case dwarf::DW_LNS_negate_stmt:
|
||||
case dwarf::DW_LNS_set_basic_block:
|
||||
case dwarf::DW_LNS_const_add_pc:
|
||||
case dwarf::DW_LNS_set_prologue_end:
|
||||
case dwarf::DW_LNS_set_epilogue_begin:
|
||||
break;
|
||||
|
||||
case dwarf::DW_LNS_advance_pc:
|
||||
case dwarf::DW_LNS_set_file:
|
||||
case dwarf::DW_LNS_set_column:
|
||||
case dwarf::DW_LNS_set_isa:
|
||||
encodeULEB128(Op.Data, OS);
|
||||
break;
|
||||
|
||||
case dwarf::DW_LNS_advance_line:
|
||||
encodeSLEB128(Op.SData, OS);
|
||||
break;
|
||||
|
||||
case dwarf::DW_LNS_fixed_advance_pc:
|
||||
writeInteger((uint16_t)Op.Data, OS, DI.IsLittleEndian);
|
||||
break;
|
||||
|
||||
default:
|
||||
for (auto OpData : Op.StandardOpcodeData) {
|
||||
encodeULEB128(OpData, OS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using EmitFuncType = void (*)(raw_ostream &, const DWARFYAML::Data &);
|
||||
|
||||
static void
|
||||
EmitDebugSectionImpl(const DWARFYAML::Data &DI, EmitFuncType EmitFunc,
|
||||
StringRef Sec,
|
||||
StringMap<std::unique_ptr<MemoryBuffer>> &OutputBuffers) {
|
||||
std::string Data;
|
||||
raw_string_ostream DebugInfoStream(Data);
|
||||
EmitFunc(DebugInfoStream, DI);
|
||||
DebugInfoStream.flush();
|
||||
if (!Data.empty())
|
||||
OutputBuffers[Sec] = MemoryBuffer::getMemBufferCopy(Data);
|
||||
}
|
||||
|
||||
Expected<StringMap<std::unique_ptr<MemoryBuffer>>>
|
||||
DWARFYAML::EmitDebugSections(StringRef YAMLString,
|
||||
bool IsLittleEndian) {
|
||||
StringMap<std::unique_ptr<MemoryBuffer>> DebugSections;
|
||||
|
||||
yaml::Input YIn(YAMLString);
|
||||
|
||||
DWARFYAML::Data DI;
|
||||
DI.IsLittleEndian = IsLittleEndian;
|
||||
YIn >> DI;
|
||||
if (YIn.error())
|
||||
return errorCodeToError(YIn.error());
|
||||
|
||||
EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugInfo, "debug_info",
|
||||
DebugSections);
|
||||
EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugLine, "debug_line",
|
||||
DebugSections);
|
||||
EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugStr, "debug_str",
|
||||
DebugSections);
|
||||
EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugAbbrev, "debug_abbrev",
|
||||
DebugSections);
|
||||
EmitDebugSectionImpl(DI, &DWARFYAML::EmitDebugAranges, "debug_aranges",
|
||||
DebugSections);
|
||||
return std::move(DebugSections);
|
||||
}
|
178
external/llvm/lib/ObjectYAML/DWARFVisitor.cpp
vendored
178
external/llvm/lib/ObjectYAML/DWARFVisitor.cpp
vendored
@ -1,178 +0,0 @@
|
||||
//===--- DWARFVisitor.cpp ---------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "DWARFVisitor.h"
|
||||
#include "llvm/ObjectYAML/DWARFYAML.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
template <typename T>
|
||||
void DWARFYAML::VisitorImpl<T>::onVariableSizeValue(uint64_t U, unsigned Size) {
|
||||
switch (Size) {
|
||||
case 8:
|
||||
onValue((uint64_t)U);
|
||||
break;
|
||||
case 4:
|
||||
onValue((uint32_t)U);
|
||||
break;
|
||||
case 2:
|
||||
onValue((uint16_t)U);
|
||||
break;
|
||||
case 1:
|
||||
onValue((uint8_t)U);
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Invalid integer write size.");
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned getOffsetSize(const DWARFYAML::Unit &Unit) {
|
||||
return Unit.Length.isDWARF64() ? 8 : 4;
|
||||
}
|
||||
|
||||
static unsigned getRefSize(const DWARFYAML::Unit &Unit) {
|
||||
if (Unit.Version == 2)
|
||||
return Unit.AddrSize;
|
||||
return getOffsetSize(Unit);
|
||||
}
|
||||
|
||||
template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
|
||||
for (auto &Unit : DebugInfo.CompileUnits) {
|
||||
onStartCompileUnit(Unit);
|
||||
auto FirstAbbrevCode = Unit.Entries[0].AbbrCode;
|
||||
|
||||
for (auto &Entry : Unit.Entries) {
|
||||
onStartDIE(Unit, Entry);
|
||||
if (Entry.AbbrCode == 0u)
|
||||
continue;
|
||||
auto &Abbrev = DebugInfo.AbbrevDecls[Entry.AbbrCode - FirstAbbrevCode];
|
||||
auto FormVal = Entry.Values.begin();
|
||||
auto AbbrForm = Abbrev.Attributes.begin();
|
||||
for (;
|
||||
FormVal != Entry.Values.end() && AbbrForm != Abbrev.Attributes.end();
|
||||
++FormVal, ++AbbrForm) {
|
||||
onForm(*AbbrForm, *FormVal);
|
||||
dwarf::Form Form = AbbrForm->Form;
|
||||
bool Indirect;
|
||||
do {
|
||||
Indirect = false;
|
||||
switch (Form) {
|
||||
case dwarf::DW_FORM_addr:
|
||||
onVariableSizeValue(FormVal->Value, Unit.AddrSize);
|
||||
break;
|
||||
case dwarf::DW_FORM_ref_addr:
|
||||
onVariableSizeValue(FormVal->Value, getRefSize(Unit));
|
||||
break;
|
||||
case dwarf::DW_FORM_exprloc:
|
||||
case dwarf::DW_FORM_block:
|
||||
onValue((uint64_t)FormVal->BlockData.size(), true);
|
||||
onValue(
|
||||
MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
|
||||
FormVal->BlockData.size()),
|
||||
""));
|
||||
break;
|
||||
case dwarf::DW_FORM_block1: {
|
||||
auto writeSize = FormVal->BlockData.size();
|
||||
onValue((uint8_t)writeSize);
|
||||
onValue(
|
||||
MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
|
||||
FormVal->BlockData.size()),
|
||||
""));
|
||||
break;
|
||||
}
|
||||
case dwarf::DW_FORM_block2: {
|
||||
auto writeSize = FormVal->BlockData.size();
|
||||
onValue((uint16_t)writeSize);
|
||||
onValue(
|
||||
MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
|
||||
FormVal->BlockData.size()),
|
||||
""));
|
||||
break;
|
||||
}
|
||||
case dwarf::DW_FORM_block4: {
|
||||
auto writeSize = FormVal->BlockData.size();
|
||||
onValue((uint32_t)writeSize);
|
||||
onValue(
|
||||
MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
|
||||
FormVal->BlockData.size()),
|
||||
""));
|
||||
break;
|
||||
}
|
||||
case dwarf::DW_FORM_data1:
|
||||
case dwarf::DW_FORM_ref1:
|
||||
case dwarf::DW_FORM_flag:
|
||||
case dwarf::DW_FORM_strx1:
|
||||
case dwarf::DW_FORM_addrx1:
|
||||
onValue((uint8_t)FormVal->Value);
|
||||
break;
|
||||
case dwarf::DW_FORM_data2:
|
||||
case dwarf::DW_FORM_ref2:
|
||||
case dwarf::DW_FORM_strx2:
|
||||
case dwarf::DW_FORM_addrx2:
|
||||
onValue((uint16_t)FormVal->Value);
|
||||
break;
|
||||
case dwarf::DW_FORM_data4:
|
||||
case dwarf::DW_FORM_ref4:
|
||||
case dwarf::DW_FORM_ref_sup4:
|
||||
case dwarf::DW_FORM_strx4:
|
||||
case dwarf::DW_FORM_addrx4:
|
||||
onValue((uint32_t)FormVal->Value);
|
||||
break;
|
||||
case dwarf::DW_FORM_data8:
|
||||
case dwarf::DW_FORM_ref8:
|
||||
case dwarf::DW_FORM_ref_sup8:
|
||||
onValue((uint64_t)FormVal->Value);
|
||||
break;
|
||||
case dwarf::DW_FORM_sdata:
|
||||
onValue((int64_t)FormVal->Value, true);
|
||||
break;
|
||||
case dwarf::DW_FORM_udata:
|
||||
case dwarf::DW_FORM_ref_udata:
|
||||
onValue((uint64_t)FormVal->Value, true);
|
||||
break;
|
||||
case dwarf::DW_FORM_string:
|
||||
onValue(FormVal->CStr);
|
||||
break;
|
||||
case dwarf::DW_FORM_indirect:
|
||||
onValue((uint64_t)FormVal->Value, true);
|
||||
Indirect = true;
|
||||
Form = static_cast<dwarf::Form>((uint64_t)FormVal->Value);
|
||||
++FormVal;
|
||||
break;
|
||||
case dwarf::DW_FORM_strp:
|
||||
case dwarf::DW_FORM_sec_offset:
|
||||
case dwarf::DW_FORM_GNU_ref_alt:
|
||||
case dwarf::DW_FORM_GNU_strp_alt:
|
||||
case dwarf::DW_FORM_line_strp:
|
||||
case dwarf::DW_FORM_strp_sup:
|
||||
onVariableSizeValue(FormVal->Value, getOffsetSize(Unit));
|
||||
break;
|
||||
case dwarf::DW_FORM_ref_sig8:
|
||||
onValue((uint64_t)FormVal->Value);
|
||||
break;
|
||||
case dwarf::DW_FORM_GNU_addr_index:
|
||||
case dwarf::DW_FORM_GNU_str_index:
|
||||
onValue((uint64_t)FormVal->Value, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (Indirect);
|
||||
}
|
||||
onEndDIE(Unit, Entry);
|
||||
}
|
||||
onEndCompileUnit(Unit);
|
||||
}
|
||||
}
|
||||
|
||||
// Explicitly instantiate the two template expansions.
|
||||
template class DWARFYAML::VisitorImpl<DWARFYAML::Data>;
|
||||
template class DWARFYAML::VisitorImpl<const DWARFYAML::Data>;
|
97
external/llvm/lib/ObjectYAML/DWARFVisitor.h
vendored
97
external/llvm/lib/ObjectYAML/DWARFVisitor.h
vendored
@ -1,97 +0,0 @@
|
||||
//===--- DWARFVisitor.h -----------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_OBJECTYAML_DWARFVISITOR_H
|
||||
#define LLVM_OBJECTYAML_DWARFVISITOR_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/BinaryFormat/Dwarf.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
namespace DWARFYAML {
|
||||
|
||||
struct Data;
|
||||
struct Unit;
|
||||
struct Entry;
|
||||
struct FormValue;
|
||||
struct AttributeAbbrev;
|
||||
|
||||
/// \brief A class to visits DWARFYAML Compile Units and DIEs in preorder.
|
||||
///
|
||||
/// Extensions of this class can either maintain const or non-const references
|
||||
/// to the DWARFYAML::Data object.
|
||||
template <typename T> class VisitorImpl {
|
||||
protected:
|
||||
T &DebugInfo;
|
||||
|
||||
/// Visitor Functions
|
||||
/// @{
|
||||
virtual void onStartCompileUnit(Unit &CU) {}
|
||||
virtual void onEndCompileUnit(Unit &CU) {}
|
||||
virtual void onStartDIE(Unit &CU, Entry &DIE) {}
|
||||
virtual void onEndDIE(Unit &CU, Entry &DIE) {}
|
||||
virtual void onForm(AttributeAbbrev &AttAbbrev, FormValue &Value) {}
|
||||
/// @}
|
||||
|
||||
/// Const Visitor Functions
|
||||
/// @{
|
||||
virtual void onStartCompileUnit(const Unit &CU) {}
|
||||
virtual void onEndCompileUnit(const Unit &CU) {}
|
||||
virtual void onStartDIE(const Unit &CU, const Entry &DIE) {}
|
||||
virtual void onEndDIE(const Unit &CU, const Entry &DIE) {}
|
||||
virtual void onForm(const AttributeAbbrev &AttAbbrev,
|
||||
const FormValue &Value) {}
|
||||
/// @}
|
||||
|
||||
/// Value visitors
|
||||
/// @{
|
||||
virtual void onValue(const uint8_t U) {}
|
||||
virtual void onValue(const uint16_t U) {}
|
||||
virtual void onValue(const uint32_t U) {}
|
||||
virtual void onValue(const uint64_t U, const bool LEB = false) {}
|
||||
virtual void onValue(const int64_t S, const bool LEB = false) {}
|
||||
virtual void onValue(const StringRef String) {}
|
||||
virtual void onValue(const MemoryBufferRef MBR) {}
|
||||
/// @}
|
||||
|
||||
public:
|
||||
VisitorImpl(T &DI) : DebugInfo(DI) {}
|
||||
|
||||
virtual ~VisitorImpl() {}
|
||||
|
||||
void traverseDebugInfo();
|
||||
|
||||
private:
|
||||
void onVariableSizeValue(uint64_t U, unsigned Size);
|
||||
};
|
||||
|
||||
// Making the visior instantiations extern and explicit in the cpp file. This
|
||||
// prevents them from being instantiated in every compile unit that uses the
|
||||
// visitors.
|
||||
extern template class VisitorImpl<DWARFYAML::Data>;
|
||||
extern template class VisitorImpl<const DWARFYAML::Data>;
|
||||
|
||||
class Visitor : public VisitorImpl<Data> {
|
||||
public:
|
||||
Visitor(Data &DI) : VisitorImpl<Data>(DI) {}
|
||||
};
|
||||
|
||||
class ConstVisitor : public VisitorImpl<const Data> {
|
||||
public:
|
||||
ConstVisitor(const Data &DI) : VisitorImpl<const Data>(DI) {}
|
||||
};
|
||||
|
||||
} // namespace DWARFYAML
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
176
external/llvm/lib/ObjectYAML/DWARFYAML.cpp
vendored
176
external/llvm/lib/ObjectYAML/DWARFYAML.cpp
vendored
@ -1,176 +0,0 @@
|
||||
//===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines classes for handling the YAML representation of DWARF Debug
|
||||
// Info.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ObjectYAML/DWARFYAML.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
bool DWARFYAML::Data::isEmpty() const {
|
||||
return 0 == DebugStrings.size() + AbbrevDecls.size();
|
||||
}
|
||||
|
||||
namespace yaml {
|
||||
|
||||
void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) {
|
||||
auto oldContext = IO.getContext();
|
||||
IO.setContext(&DWARF);
|
||||
IO.mapOptional("debug_str", DWARF.DebugStrings);
|
||||
IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls);
|
||||
if (!DWARF.ARanges.empty() || !IO.outputting())
|
||||
IO.mapOptional("debug_aranges", DWARF.ARanges);
|
||||
if (!DWARF.PubNames.Entries.empty() || !IO.outputting())
|
||||
IO.mapOptional("debug_pubnames", DWARF.PubNames);
|
||||
if (!DWARF.PubTypes.Entries.empty() || !IO.outputting())
|
||||
IO.mapOptional("debug_pubtypes", DWARF.PubTypes);
|
||||
if (!DWARF.GNUPubNames.Entries.empty() || !IO.outputting())
|
||||
IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames);
|
||||
if (!DWARF.GNUPubTypes.Entries.empty() || !IO.outputting())
|
||||
IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes);
|
||||
IO.mapOptional("debug_info", DWARF.CompileUnits);
|
||||
IO.mapOptional("debug_line", DWARF.DebugLines);
|
||||
IO.setContext(&oldContext);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::Abbrev>::mapping(IO &IO,
|
||||
DWARFYAML::Abbrev &Abbrev) {
|
||||
IO.mapRequired("Code", Abbrev.Code);
|
||||
IO.mapRequired("Tag", Abbrev.Tag);
|
||||
IO.mapRequired("Children", Abbrev.Children);
|
||||
IO.mapRequired("Attributes", Abbrev.Attributes);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::AttributeAbbrev>::mapping(
|
||||
IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev) {
|
||||
IO.mapRequired("Attribute", AttAbbrev.Attribute);
|
||||
IO.mapRequired("Form", AttAbbrev.Form);
|
||||
if(AttAbbrev.Form == dwarf::DW_FORM_implicit_const)
|
||||
IO.mapRequired("Value", AttAbbrev.Value);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::ARangeDescriptor>::mapping(
|
||||
IO &IO, DWARFYAML::ARangeDescriptor &Descriptor) {
|
||||
IO.mapRequired("Address", Descriptor.Address);
|
||||
IO.mapRequired("Length", Descriptor.Length);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::ARange>::mapping(IO &IO,
|
||||
DWARFYAML::ARange &Range) {
|
||||
IO.mapRequired("Length", Range.Length);
|
||||
IO.mapRequired("Version", Range.Version);
|
||||
IO.mapRequired("CuOffset", Range.CuOffset);
|
||||
IO.mapRequired("AddrSize", Range.AddrSize);
|
||||
IO.mapRequired("SegSize", Range.SegSize);
|
||||
IO.mapRequired("Descriptors", Range.Descriptors);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::PubEntry>::mapping(IO &IO,
|
||||
DWARFYAML::PubEntry &Entry) {
|
||||
IO.mapRequired("DieOffset", Entry.DieOffset);
|
||||
if (reinterpret_cast<DWARFYAML::PubSection *>(IO.getContext())->IsGNUStyle)
|
||||
IO.mapRequired("Descriptor", Entry.Descriptor);
|
||||
IO.mapRequired("Name", Entry.Name);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::PubSection>::mapping(
|
||||
IO &IO, DWARFYAML::PubSection &Section) {
|
||||
auto OldContext = IO.getContext();
|
||||
IO.setContext(&Section);
|
||||
|
||||
IO.mapRequired("Length", Section.Length);
|
||||
IO.mapRequired("Version", Section.Version);
|
||||
IO.mapRequired("UnitOffset", Section.UnitOffset);
|
||||
IO.mapRequired("UnitSize", Section.UnitSize);
|
||||
IO.mapRequired("Entries", Section.Entries);
|
||||
|
||||
IO.setContext(OldContext);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
|
||||
IO.mapRequired("Length", Unit.Length);
|
||||
IO.mapRequired("Version", Unit.Version);
|
||||
if (Unit.Version >= 5)
|
||||
IO.mapRequired("UnitType", Unit.Type);
|
||||
IO.mapRequired("AbbrOffset", Unit.AbbrOffset);
|
||||
IO.mapRequired("AddrSize", Unit.AddrSize);
|
||||
IO.mapOptional("Entries", Unit.Entries);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::Entry>::mapping(IO &IO, DWARFYAML::Entry &Entry) {
|
||||
IO.mapRequired("AbbrCode", Entry.AbbrCode);
|
||||
IO.mapRequired("Values", Entry.Values);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::FormValue>::mapping(
|
||||
IO &IO, DWARFYAML::FormValue &FormValue) {
|
||||
IO.mapOptional("Value", FormValue.Value);
|
||||
if (!FormValue.CStr.empty() || !IO.outputting())
|
||||
IO.mapOptional("CStr", FormValue.CStr);
|
||||
if (!FormValue.BlockData.empty() || !IO.outputting())
|
||||
IO.mapOptional("BlockData", FormValue.BlockData);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::File>::mapping(IO &IO, DWARFYAML::File &File) {
|
||||
IO.mapRequired("Name", File.Name);
|
||||
IO.mapRequired("DirIdx", File.DirIdx);
|
||||
IO.mapRequired("ModTime", File.ModTime);
|
||||
IO.mapRequired("Length", File.Length);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::LineTableOpcode>::mapping(
|
||||
IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode) {
|
||||
IO.mapRequired("Opcode", LineTableOpcode.Opcode);
|
||||
if (LineTableOpcode.Opcode == dwarf::DW_LNS_extended_op) {
|
||||
IO.mapRequired("ExtLen", LineTableOpcode.ExtLen);
|
||||
IO.mapRequired("SubOpcode", LineTableOpcode.SubOpcode);
|
||||
}
|
||||
|
||||
if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting())
|
||||
IO.mapOptional("UnknownOpcodeData", LineTableOpcode.UnknownOpcodeData);
|
||||
if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting())
|
||||
IO.mapOptional("StandardOpcodeData", LineTableOpcode.StandardOpcodeData);
|
||||
if (!LineTableOpcode.FileEntry.Name.empty() || !IO.outputting())
|
||||
IO.mapOptional("FileEntry", LineTableOpcode.FileEntry);
|
||||
if (LineTableOpcode.Opcode == dwarf::DW_LNS_advance_line || !IO.outputting())
|
||||
IO.mapOptional("SData", LineTableOpcode.SData);
|
||||
IO.mapOptional("Data", LineTableOpcode.Data);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::LineTable>::mapping(
|
||||
IO &IO, DWARFYAML::LineTable &LineTable) {
|
||||
IO.mapRequired("Length", LineTable.Length);
|
||||
IO.mapRequired("Version", LineTable.Version);
|
||||
IO.mapRequired("PrologueLength", LineTable.PrologueLength);
|
||||
IO.mapRequired("MinInstLength", LineTable.MinInstLength);
|
||||
if(LineTable.Version >= 4)
|
||||
IO.mapRequired("MaxOpsPerInst", LineTable.MaxOpsPerInst);
|
||||
IO.mapRequired("DefaultIsStmt", LineTable.DefaultIsStmt);
|
||||
IO.mapRequired("LineBase", LineTable.LineBase);
|
||||
IO.mapRequired("LineRange", LineTable.LineRange);
|
||||
IO.mapRequired("OpcodeBase", LineTable.OpcodeBase);
|
||||
IO.mapRequired("StandardOpcodeLengths", LineTable.StandardOpcodeLengths);
|
||||
IO.mapRequired("IncludeDirs", LineTable.IncludeDirs);
|
||||
IO.mapRequired("Files", LineTable.Files);
|
||||
IO.mapRequired("Opcodes", LineTable.Opcodes);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::InitialLength>::mapping(
|
||||
IO &IO, DWARFYAML::InitialLength &InitialLength) {
|
||||
IO.mapRequired("TotalLength", InitialLength.TotalLength);
|
||||
if (InitialLength.isDWARF64())
|
||||
IO.mapRequired("TotalLength64", InitialLength.TotalLength64);
|
||||
}
|
||||
|
||||
} // end namespace yaml
|
||||
|
||||
} // end namespace llvm
|
948
external/llvm/lib/ObjectYAML/ELFYAML.cpp
vendored
948
external/llvm/lib/ObjectYAML/ELFYAML.cpp
vendored
File diff suppressed because it is too large
Load Diff
14
external/llvm/lib/ObjectYAML/LLVMBuild.txt
vendored
14
external/llvm/lib/ObjectYAML/LLVMBuild.txt
vendored
@ -1,14 +0,0 @@
|
||||
;===------------------------------------------------------------*- Conf -*--===;
|
||||
;
|
||||
; The LLVM Compiler Infrastructure
|
||||
;
|
||||
; This file is distributed under the University of Illinois Open Source
|
||||
; License. See LICENSE.TXT for details.
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
|
||||
[component_0]
|
||||
type = Library
|
||||
name = ObjectYAML
|
||||
parent = Libraries
|
||||
required_libraries = Support DebugInfoCodeView
|
566
external/llvm/lib/ObjectYAML/MachOYAML.cpp
vendored
566
external/llvm/lib/ObjectYAML/MachOYAML.cpp
vendored
File diff suppressed because it is too large
Load Diff
63
external/llvm/lib/ObjectYAML/ObjectYAML.cpp
vendored
63
external/llvm/lib/ObjectYAML/ObjectYAML.cpp
vendored
@ -1,63 +0,0 @@
|
||||
//===- ObjectYAML.cpp - YAML utilities for object files -------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines a wrapper class for handling tagged YAML input
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ObjectYAML/ObjectYAML.h"
|
||||
#include "llvm/ADT/Twine.h"
|
||||
#include "llvm/Support/YAMLParser.h"
|
||||
#include "llvm/Support/YAMLTraits.h"
|
||||
#include <string>
|
||||
|
||||
using namespace llvm;
|
||||
using namespace yaml;
|
||||
|
||||
void MappingTraits<YamlObjectFile>::mapping(IO &IO,
|
||||
YamlObjectFile &ObjectFile) {
|
||||
if (IO.outputting()) {
|
||||
if (ObjectFile.Elf)
|
||||
MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf);
|
||||
if (ObjectFile.Coff)
|
||||
MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff);
|
||||
if (ObjectFile.MachO)
|
||||
MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO);
|
||||
if (ObjectFile.FatMachO)
|
||||
MappingTraits<MachOYAML::UniversalBinary>::mapping(IO,
|
||||
*ObjectFile.FatMachO);
|
||||
} else {
|
||||
if (IO.mapTag("!ELF")) {
|
||||
ObjectFile.Elf.reset(new ELFYAML::Object());
|
||||
MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf);
|
||||
} else if (IO.mapTag("!COFF")) {
|
||||
ObjectFile.Coff.reset(new COFFYAML::Object());
|
||||
MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff);
|
||||
} else if (IO.mapTag("!mach-o")) {
|
||||
ObjectFile.MachO.reset(new MachOYAML::Object());
|
||||
MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO);
|
||||
} else if (IO.mapTag("!fat-mach-o")) {
|
||||
ObjectFile.FatMachO.reset(new MachOYAML::UniversalBinary());
|
||||
MappingTraits<MachOYAML::UniversalBinary>::mapping(IO,
|
||||
*ObjectFile.FatMachO);
|
||||
} else if (IO.mapTag("!WASM")) {
|
||||
ObjectFile.Wasm.reset(new WasmYAML::Object());
|
||||
MappingTraits<WasmYAML::Object>::mapping(IO, *ObjectFile.Wasm);
|
||||
} else {
|
||||
Input &In = (Input &)IO;
|
||||
std::string Tag = In.getCurrentNode()->getRawTag();
|
||||
if (Tag.empty())
|
||||
IO.setError("YAML Object File missing document type tag!");
|
||||
else
|
||||
IO.setError(
|
||||
Twine("YAML Object File unsupported document type tag '") +
|
||||
Twine(Tag) + Twine("'!"));
|
||||
}
|
||||
}
|
||||
}
|
448
external/llvm/lib/ObjectYAML/WasmYAML.cpp
vendored
448
external/llvm/lib/ObjectYAML/WasmYAML.cpp
vendored
@ -1,448 +0,0 @@
|
||||
//===- WasmYAML.cpp - Wasm YAMLIO implementation --------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines classes for handling the YAML representation of wasm.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ObjectYAML/WasmYAML.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/YAMLTraits.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
namespace WasmYAML {
|
||||
|
||||
// Declared here rather than in the header to comply with:
|
||||
// http://llvm.org/docs/CodingStandards.html#provide-a-virtual-method-anchor-for-classes-in-headers
|
||||
Section::~Section() = default;
|
||||
|
||||
} // end namespace WasmYAML
|
||||
|
||||
namespace yaml {
|
||||
|
||||
void MappingTraits<WasmYAML::FileHeader>::mapping(
|
||||
IO &IO, WasmYAML::FileHeader &FileHdr) {
|
||||
IO.mapRequired("Version", FileHdr.Version);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::Object>::mapping(IO &IO,
|
||||
WasmYAML::Object &Object) {
|
||||
IO.setContext(&Object);
|
||||
IO.mapTag("!WASM", true);
|
||||
IO.mapRequired("FileHeader", Object.Header);
|
||||
IO.mapOptional("Sections", Object.Sections);
|
||||
IO.setContext(nullptr);
|
||||
}
|
||||
|
||||
static void commonSectionMapping(IO &IO, WasmYAML::Section &Section) {
|
||||
IO.mapRequired("Type", Section.Type);
|
||||
IO.mapOptional("Relocations", Section.Relocations);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapRequired("Name", Section.Name);
|
||||
IO.mapOptional("FunctionNames", Section.FunctionNames);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::LinkingSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapRequired("Name", Section.Name);
|
||||
IO.mapRequired("DataSize", Section.DataSize);
|
||||
IO.mapOptional("SymbolInfo", Section.SymbolInfos);
|
||||
IO.mapOptional("SegmentInfo", Section.SegmentInfos);
|
||||
IO.mapOptional("InitFunctions", Section.InitFunctions);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::CustomSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapRequired("Name", Section.Name);
|
||||
IO.mapRequired("Payload", Section.Payload);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::TypeSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapOptional("Signatures", Section.Signatures);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::ImportSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapOptional("Imports", Section.Imports);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::FunctionSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapOptional("FunctionTypes", Section.FunctionTypes);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::TableSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapOptional("Tables", Section.Tables);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::MemorySection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapOptional("Memories", Section.Memories);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::GlobalSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapOptional("Globals", Section.Globals);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::ExportSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapOptional("Exports", Section.Exports);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::StartSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapOptional("StartFunction", Section.StartFunction);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::ElemSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapOptional("Segments", Section.Segments);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::CodeSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapRequired("Functions", Section.Functions);
|
||||
}
|
||||
|
||||
static void sectionMapping(IO &IO, WasmYAML::DataSection &Section) {
|
||||
commonSectionMapping(IO, Section);
|
||||
IO.mapRequired("Segments", Section.Segments);
|
||||
}
|
||||
|
||||
void MappingTraits<std::unique_ptr<WasmYAML::Section>>::mapping(
|
||||
IO &IO, std::unique_ptr<WasmYAML::Section> &Section) {
|
||||
WasmYAML::SectionType SectionType;
|
||||
if (IO.outputting())
|
||||
SectionType = Section->Type;
|
||||
else
|
||||
IO.mapRequired("Type", SectionType);
|
||||
|
||||
switch (SectionType) {
|
||||
case wasm::WASM_SEC_CUSTOM: {
|
||||
StringRef SectionName;
|
||||
if (IO.outputting()) {
|
||||
auto CustomSection = cast<WasmYAML::CustomSection>(Section.get());
|
||||
SectionName = CustomSection->Name;
|
||||
} else {
|
||||
IO.mapRequired("Name", SectionName);
|
||||
}
|
||||
if (SectionName == "linking") {
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::LinkingSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::LinkingSection>(Section.get()));
|
||||
} else if (SectionName == "name") {
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::NameSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::NameSection>(Section.get()));
|
||||
} else {
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::CustomSection(SectionName));
|
||||
sectionMapping(IO, *cast<WasmYAML::CustomSection>(Section.get()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case wasm::WASM_SEC_TYPE:
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::TypeSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::TypeSection>(Section.get()));
|
||||
break;
|
||||
case wasm::WASM_SEC_IMPORT:
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::ImportSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::ImportSection>(Section.get()));
|
||||
break;
|
||||
case wasm::WASM_SEC_FUNCTION:
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::FunctionSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::FunctionSection>(Section.get()));
|
||||
break;
|
||||
case wasm::WASM_SEC_TABLE:
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::TableSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::TableSection>(Section.get()));
|
||||
break;
|
||||
case wasm::WASM_SEC_MEMORY:
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::MemorySection());
|
||||
sectionMapping(IO, *cast<WasmYAML::MemorySection>(Section.get()));
|
||||
break;
|
||||
case wasm::WASM_SEC_GLOBAL:
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::GlobalSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::GlobalSection>(Section.get()));
|
||||
break;
|
||||
case wasm::WASM_SEC_EXPORT:
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::ExportSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::ExportSection>(Section.get()));
|
||||
break;
|
||||
case wasm::WASM_SEC_START:
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::StartSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::StartSection>(Section.get()));
|
||||
break;
|
||||
case wasm::WASM_SEC_ELEM:
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::ElemSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::ElemSection>(Section.get()));
|
||||
break;
|
||||
case wasm::WASM_SEC_CODE:
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::CodeSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::CodeSection>(Section.get()));
|
||||
break;
|
||||
case wasm::WASM_SEC_DATA:
|
||||
if (!IO.outputting())
|
||||
Section.reset(new WasmYAML::DataSection());
|
||||
sectionMapping(IO, *cast<WasmYAML::DataSection>(Section.get()));
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Unknown section type");
|
||||
}
|
||||
}
|
||||
|
||||
void ScalarEnumerationTraits<WasmYAML::SectionType>::enumeration(
|
||||
IO &IO, WasmYAML::SectionType &Type) {
|
||||
#define ECase(X) IO.enumCase(Type, #X, wasm::WASM_SEC_##X);
|
||||
ECase(CUSTOM);
|
||||
ECase(TYPE);
|
||||
ECase(IMPORT);
|
||||
ECase(FUNCTION);
|
||||
ECase(TABLE);
|
||||
ECase(MEMORY);
|
||||
ECase(GLOBAL);
|
||||
ECase(EXPORT);
|
||||
ECase(START);
|
||||
ECase(ELEM);
|
||||
ECase(CODE);
|
||||
ECase(DATA);
|
||||
#undef ECase
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::Signature>::mapping(
|
||||
IO &IO, WasmYAML::Signature &Signature) {
|
||||
IO.mapOptional("Index", Signature.Index);
|
||||
IO.mapRequired("ReturnType", Signature.ReturnType);
|
||||
IO.mapRequired("ParamTypes", Signature.ParamTypes);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::Table>::mapping(IO &IO, WasmYAML::Table &Table) {
|
||||
IO.mapRequired("ElemType", Table.ElemType);
|
||||
IO.mapRequired("Limits", Table.TableLimits);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::Function>::mapping(IO &IO,
|
||||
WasmYAML::Function &Function) {
|
||||
IO.mapRequired("Locals", Function.Locals);
|
||||
IO.mapRequired("Body", Function.Body);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::Relocation>::mapping(
|
||||
IO &IO, WasmYAML::Relocation &Relocation) {
|
||||
IO.mapRequired("Type", Relocation.Type);
|
||||
IO.mapRequired("Index", Relocation.Index);
|
||||
IO.mapRequired("Offset", Relocation.Offset);
|
||||
IO.mapOptional("Addend", Relocation.Addend, 0);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::NameEntry>::mapping(
|
||||
IO &IO, WasmYAML::NameEntry &NameEntry) {
|
||||
IO.mapRequired("Index", NameEntry.Index);
|
||||
IO.mapRequired("Name", NameEntry.Name);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::SegmentInfo>::mapping(
|
||||
IO &IO, WasmYAML::SegmentInfo &SegmentInfo) {
|
||||
IO.mapRequired("Index", SegmentInfo.Index);
|
||||
IO.mapRequired("Name", SegmentInfo.Name);
|
||||
IO.mapRequired("Alignment", SegmentInfo.Alignment);
|
||||
IO.mapRequired("Flags", SegmentInfo.Flags);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::LocalDecl>::mapping(
|
||||
IO &IO, WasmYAML::LocalDecl &LocalDecl) {
|
||||
IO.mapRequired("Type", LocalDecl.Type);
|
||||
IO.mapRequired("Count", LocalDecl.Count);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::Limits>::mapping(IO &IO,
|
||||
WasmYAML::Limits &Limits) {
|
||||
if (!IO.outputting() || Limits.Flags)
|
||||
IO.mapOptional("Flags", Limits.Flags);
|
||||
IO.mapRequired("Initial", Limits.Initial);
|
||||
if (!IO.outputting() || Limits.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX)
|
||||
IO.mapOptional("Maximum", Limits.Maximum);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::ElemSegment>::mapping(
|
||||
IO &IO, WasmYAML::ElemSegment &Segment) {
|
||||
IO.mapRequired("Offset", Segment.Offset);
|
||||
IO.mapRequired("Functions", Segment.Functions);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::Import>::mapping(IO &IO,
|
||||
WasmYAML::Import &Import) {
|
||||
IO.mapRequired("Module", Import.Module);
|
||||
IO.mapRequired("Field", Import.Field);
|
||||
IO.mapRequired("Kind", Import.Kind);
|
||||
if (Import.Kind == wasm::WASM_EXTERNAL_FUNCTION) {
|
||||
IO.mapRequired("SigIndex", Import.SigIndex);
|
||||
} else if (Import.Kind == wasm::WASM_EXTERNAL_GLOBAL) {
|
||||
IO.mapRequired("GlobalType", Import.GlobalImport.Type);
|
||||
IO.mapRequired("GlobalMutable", Import.GlobalImport.Mutable);
|
||||
} else if (Import.Kind == wasm::WASM_EXTERNAL_TABLE) {
|
||||
IO.mapRequired("Table", Import.TableImport);
|
||||
} else if (Import.Kind == wasm::WASM_EXTERNAL_MEMORY ) {
|
||||
IO.mapRequired("Memory", Import.Memory);
|
||||
} else {
|
||||
llvm_unreachable("unhandled import type");
|
||||
}
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::Export>::mapping(IO &IO,
|
||||
WasmYAML::Export &Export) {
|
||||
IO.mapRequired("Name", Export.Name);
|
||||
IO.mapRequired("Kind", Export.Kind);
|
||||
IO.mapRequired("Index", Export.Index);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::Global>::mapping(IO &IO,
|
||||
WasmYAML::Global &Global) {
|
||||
IO.mapRequired("Type", Global.Type);
|
||||
IO.mapRequired("Mutable", Global.Mutable);
|
||||
IO.mapRequired("InitExpr", Global.InitExpr);
|
||||
}
|
||||
|
||||
void MappingTraits<wasm::WasmInitExpr>::mapping(IO &IO,
|
||||
wasm::WasmInitExpr &Expr) {
|
||||
WasmYAML::Opcode Op = Expr.Opcode;
|
||||
IO.mapRequired("Opcode", Op);
|
||||
Expr.Opcode = Op;
|
||||
switch (Expr.Opcode) {
|
||||
case wasm::WASM_OPCODE_I32_CONST:
|
||||
IO.mapRequired("Value", Expr.Value.Int32);
|
||||
break;
|
||||
case wasm::WASM_OPCODE_I64_CONST:
|
||||
IO.mapRequired("Value", Expr.Value.Int64);
|
||||
break;
|
||||
case wasm::WASM_OPCODE_F32_CONST:
|
||||
IO.mapRequired("Value", Expr.Value.Float32);
|
||||
break;
|
||||
case wasm::WASM_OPCODE_F64_CONST:
|
||||
IO.mapRequired("Value", Expr.Value.Float64);
|
||||
break;
|
||||
case wasm::WASM_OPCODE_GET_GLOBAL:
|
||||
IO.mapRequired("Index", Expr.Value.Global);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::DataSegment>::mapping(
|
||||
IO &IO, WasmYAML::DataSegment &Segment) {
|
||||
IO.mapOptional("SectionOffset", Segment.SectionOffset);
|
||||
IO.mapRequired("MemoryIndex", Segment.MemoryIndex);
|
||||
IO.mapRequired("Offset", Segment.Offset);
|
||||
IO.mapRequired("Content", Segment.Content);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::InitFunction>::mapping(
|
||||
IO &IO, WasmYAML::InitFunction &Init) {
|
||||
IO.mapRequired("Priority", Init.Priority);
|
||||
IO.mapRequired("FunctionIndex", Init.FunctionIndex);
|
||||
}
|
||||
|
||||
void MappingTraits<WasmYAML::SymbolInfo>::mapping(IO &IO,
|
||||
WasmYAML::SymbolInfo &Info) {
|
||||
IO.mapRequired("Name", Info.Name);
|
||||
IO.mapRequired("Flags", Info.Flags);
|
||||
}
|
||||
|
||||
void ScalarBitSetTraits<WasmYAML::LimitFlags>::bitset(
|
||||
IO &IO, WasmYAML::LimitFlags &Value) {
|
||||
#define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_LIMITS_FLAG_##X)
|
||||
BCase(HAS_MAX);
|
||||
#undef BCase
|
||||
}
|
||||
|
||||
void ScalarBitSetTraits<WasmYAML::SegmentFlags>::bitset(
|
||||
IO &IO, WasmYAML::SegmentFlags &Value) {
|
||||
}
|
||||
|
||||
void ScalarBitSetTraits<WasmYAML::SymbolFlags>::bitset(
|
||||
IO &IO, WasmYAML::SymbolFlags &Value) {
|
||||
#define BCaseMask(M, X) IO.maskedBitSetCase(Value, #X, wasm::WASM_SYMBOL_##X, wasm::WASM_SYMBOL_##M)
|
||||
//BCaseMask(BINDING_MASK, BINDING_GLOBAL);
|
||||
BCaseMask(BINDING_MASK, BINDING_WEAK);
|
||||
BCaseMask(BINDING_MASK, BINDING_LOCAL);
|
||||
//BCaseMask(VISIBILITY_MASK, VISIBILITY_DEFAULT);
|
||||
BCaseMask(VISIBILITY_MASK, VISIBILITY_HIDDEN);
|
||||
#undef BCaseMask
|
||||
}
|
||||
|
||||
void ScalarEnumerationTraits<WasmYAML::ValueType>::enumeration(
|
||||
IO &IO, WasmYAML::ValueType &Type) {
|
||||
#define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X);
|
||||
ECase(I32);
|
||||
ECase(I64);
|
||||
ECase(F32);
|
||||
ECase(F64);
|
||||
ECase(ANYFUNC);
|
||||
ECase(FUNC);
|
||||
ECase(NORESULT);
|
||||
#undef ECase
|
||||
}
|
||||
|
||||
void ScalarEnumerationTraits<WasmYAML::ExportKind>::enumeration(
|
||||
IO &IO, WasmYAML::ExportKind &Kind) {
|
||||
#define ECase(X) IO.enumCase(Kind, #X, wasm::WASM_EXTERNAL_##X);
|
||||
ECase(FUNCTION);
|
||||
ECase(TABLE);
|
||||
ECase(MEMORY);
|
||||
ECase(GLOBAL);
|
||||
#undef ECase
|
||||
}
|
||||
|
||||
void ScalarEnumerationTraits<WasmYAML::Opcode>::enumeration(
|
||||
IO &IO, WasmYAML::Opcode &Code) {
|
||||
#define ECase(X) IO.enumCase(Code, #X, wasm::WASM_OPCODE_##X);
|
||||
ECase(END);
|
||||
ECase(I32_CONST);
|
||||
ECase(I64_CONST);
|
||||
ECase(F64_CONST);
|
||||
ECase(F32_CONST);
|
||||
ECase(GET_GLOBAL);
|
||||
#undef ECase
|
||||
}
|
||||
|
||||
void ScalarEnumerationTraits<WasmYAML::TableType>::enumeration(
|
||||
IO &IO, WasmYAML::TableType &Type) {
|
||||
#define ECase(X) IO.enumCase(Type, #X, wasm::WASM_TYPE_##X);
|
||||
ECase(ANYFUNC);
|
||||
#undef ECase
|
||||
}
|
||||
|
||||
void ScalarEnumerationTraits<WasmYAML::RelocType>::enumeration(
|
||||
IO &IO, WasmYAML::RelocType &Type) {
|
||||
#define WASM_RELOC(name, value) IO.enumCase(Type, #name, wasm::name);
|
||||
#include "llvm/BinaryFormat/WasmRelocs.def"
|
||||
#undef WASM_RELOC
|
||||
}
|
||||
|
||||
} // end namespace yaml
|
||||
|
||||
} // end namespace llvm
|
62
external/llvm/lib/ObjectYAML/YAML.cpp
vendored
62
external/llvm/lib/ObjectYAML/YAML.cpp
vendored
@ -1,62 +0,0 @@
|
||||
//===- YAML.cpp - YAMLIO utilities for object files -----------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines utility classes for handling the YAML representation of
|
||||
// object files.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ObjectYAML/YAML.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
void yaml::ScalarTraits<yaml::BinaryRef>::output(
|
||||
const yaml::BinaryRef &Val, void *, raw_ostream &Out) {
|
||||
Val.writeAsHex(Out);
|
||||
}
|
||||
|
||||
StringRef yaml::ScalarTraits<yaml::BinaryRef>::input(StringRef Scalar, void *,
|
||||
yaml::BinaryRef &Val) {
|
||||
if (Scalar.size() % 2 != 0)
|
||||
return "BinaryRef hex string must contain an even number of nybbles.";
|
||||
// TODO: Can we improve YAMLIO to permit a more accurate diagnostic here?
|
||||
// (e.g. a caret pointing to the offending character).
|
||||
for (unsigned I = 0, N = Scalar.size(); I != N; ++I)
|
||||
if (!isxdigit(Scalar[I]))
|
||||
return "BinaryRef hex string must contain only hex digits.";
|
||||
Val = yaml::BinaryRef(Scalar);
|
||||
return {};
|
||||
}
|
||||
|
||||
void yaml::BinaryRef::writeAsBinary(raw_ostream &OS) const {
|
||||
if (!DataIsHexString) {
|
||||
OS.write((const char *)Data.data(), Data.size());
|
||||
return;
|
||||
}
|
||||
for (unsigned I = 0, N = Data.size(); I != N; I += 2) {
|
||||
uint8_t Byte;
|
||||
StringRef((const char *)&Data[I], 2).getAsInteger(16, Byte);
|
||||
OS.write(Byte);
|
||||
}
|
||||
}
|
||||
|
||||
void yaml::BinaryRef::writeAsHex(raw_ostream &OS) const {
|
||||
if (binary_size() == 0)
|
||||
return;
|
||||
if (DataIsHexString) {
|
||||
OS.write((const char *)Data.data(), Data.size());
|
||||
return;
|
||||
}
|
||||
for (uint8_t Byte : Data)
|
||||
OS << hexdigit(Byte >> 4) << hexdigit(Byte & 0xf);
|
||||
}
|
Reference in New Issue
Block a user