diff options
| author | Ralf Luther <luther.ralf@gmail.com> | 2019-03-27 20:23:17 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit2@aicp-server-3> | 2019-03-27 20:23:17 +0000 |
| commit | 1ce3a9d272e564b22a1333a1e36a3d3ab7cfab01 (patch) | |
| tree | 391382eadd4fec5bb480f2e8934fa352770221d1 /clang-r353983/include/llvm/ObjectYAML | |
| parent | d1d48b140bafaa8a50107292f5fce95562575765 (diff) | |
| parent | 4f56932d3416ac03f646bc1a611b3135fec2fe08 (diff) | |
Merge "Update prebuilt Clang to r353983." into p9.0HEADp9.0-backupp9.0
Diffstat (limited to 'clang-r353983/include/llvm/ObjectYAML')
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/COFFYAML.h | 256 | ||||
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLDebugSections.h | 139 | ||||
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLSymbols.h | 48 | ||||
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLTypeHashing.h | 61 | ||||
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLTypes.h | 70 | ||||
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/DWARFEmitter.h | 49 | ||||
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/DWARFYAML.h | 308 | ||||
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/ELFYAML.h | 410 | ||||
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/MachOYAML.h | 306 | ||||
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/ObjectYAML.h | 39 | ||||
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/WasmYAML.h | 536 | ||||
| -rw-r--r-- | clang-r353983/include/llvm/ObjectYAML/YAML.h | 116 |
12 files changed, 2338 insertions, 0 deletions
diff --git a/clang-r353983/include/llvm/ObjectYAML/COFFYAML.h b/clang-r353983/include/llvm/ObjectYAML/COFFYAML.h new file mode 100644 index 00000000..eec5af92 --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/COFFYAML.h @@ -0,0 +1,256 @@ +//===- COFFYAML.h - COFF YAMLIO implementation ------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file declares classes for handling the YAML representation of COFF. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_COFFYAML_H +#define LLVM_OBJECTYAML_COFFYAML_H + +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/COFF.h" +#include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h" +#include "llvm/ObjectYAML/CodeViewYAMLTypeHashing.h" +#include "llvm/ObjectYAML/CodeViewYAMLTypes.h" +#include "llvm/ObjectYAML/YAML.h" +#include <cstdint> +#include <vector> + +namespace llvm { + +namespace COFF { + +inline Characteristics operator|(Characteristics a, Characteristics b) { + uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b); + return static_cast<Characteristics>(Ret); +} + +inline SectionCharacteristics operator|(SectionCharacteristics a, + SectionCharacteristics b) { + uint32_t Ret = static_cast<uint32_t>(a) | static_cast<uint32_t>(b); + return static_cast<SectionCharacteristics>(Ret); +} + +inline DLLCharacteristics operator|(DLLCharacteristics a, + DLLCharacteristics b) { + uint16_t Ret = static_cast<uint16_t>(a) | static_cast<uint16_t>(b); + return static_cast<DLLCharacteristics>(Ret); +} + +} // end namespace COFF + +// The structure of the yaml files is not an exact 1:1 match to COFF. In order +// to use yaml::IO, we use these structures which are closer to the source. +namespace COFFYAML { + +LLVM_YAML_STRONG_TYPEDEF(uint8_t, COMDATType) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, WeakExternalCharacteristics) +LLVM_YAML_STRONG_TYPEDEF(uint8_t, AuxSymbolType) + +struct Relocation { + uint32_t VirtualAddress; + uint16_t Type; + + // Normally a Relocation can refer to the symbol via its name. + // It can also use a direct symbol table index instead (with no name + // specified), allowing disambiguating between multiple symbols with the + // same name or crafting intentionally broken files for testing. + StringRef SymbolName; + Optional<uint32_t> SymbolTableIndex; +}; + +struct Section { + COFF::section Header; + unsigned Alignment = 0; + yaml::BinaryRef SectionData; + std::vector<CodeViewYAML::YAMLDebugSubsection> DebugS; + std::vector<CodeViewYAML::LeafRecord> DebugT; + std::vector<CodeViewYAML::LeafRecord> DebugP; + Optional<CodeViewYAML::DebugHSection> DebugH; + std::vector<Relocation> Relocations; + StringRef Name; + + Section(); +}; + +struct Symbol { + COFF::symbol Header; + COFF::SymbolBaseType SimpleType = COFF::IMAGE_SYM_TYPE_NULL; + COFF::SymbolComplexType ComplexType = COFF::IMAGE_SYM_DTYPE_NULL; + Optional<COFF::AuxiliaryFunctionDefinition> FunctionDefinition; + Optional<COFF::AuxiliarybfAndefSymbol> bfAndefSymbol; + Optional<COFF::AuxiliaryWeakExternal> WeakExternal; + StringRef File; + Optional<COFF::AuxiliarySectionDefinition> SectionDefinition; + Optional<COFF::AuxiliaryCLRToken> CLRToken; + StringRef Name; + + Symbol(); +}; + +struct PEHeader { + COFF::PE32Header Header; + Optional<COFF::DataDirectory> DataDirectories[COFF::NUM_DATA_DIRECTORIES]; +}; + +struct Object { + Optional<PEHeader> OptionalHeader; + COFF::header Header; + std::vector<Section> Sections; + std::vector<Symbol> Symbols; + + Object(); +}; + +} // end namespace COFFYAML + +} // end namespace llvm + +LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section) +LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol) +LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation) + +namespace llvm { +namespace yaml { + +template <> +struct ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics> { + static void enumeration(IO &IO, COFFYAML::WeakExternalCharacteristics &Value); +}; + +template <> +struct ScalarEnumerationTraits<COFFYAML::AuxSymbolType> { + static void enumeration(IO &IO, COFFYAML::AuxSymbolType &Value); +}; + +template <> +struct ScalarEnumerationTraits<COFFYAML::COMDATType> { + static void enumeration(IO &IO, COFFYAML::COMDATType &Value); +}; + +template <> +struct ScalarEnumerationTraits<COFF::MachineTypes> { + static void enumeration(IO &IO, COFF::MachineTypes &Value); +}; + +template <> +struct ScalarEnumerationTraits<COFF::SymbolBaseType> { + static void enumeration(IO &IO, COFF::SymbolBaseType &Value); +}; + +template <> +struct ScalarEnumerationTraits<COFF::SymbolStorageClass> { + static void enumeration(IO &IO, COFF::SymbolStorageClass &Value); +}; + +template <> +struct ScalarEnumerationTraits<COFF::SymbolComplexType> { + static void enumeration(IO &IO, COFF::SymbolComplexType &Value); +}; + +template <> +struct ScalarEnumerationTraits<COFF::RelocationTypeI386> { + static void enumeration(IO &IO, COFF::RelocationTypeI386 &Value); +}; + +template <> +struct ScalarEnumerationTraits<COFF::RelocationTypeAMD64> { + static void enumeration(IO &IO, COFF::RelocationTypeAMD64 &Value); +}; + +template <> +struct ScalarEnumerationTraits<COFF::RelocationTypesARM> { + static void enumeration(IO &IO, COFF::RelocationTypesARM &Value); +}; + +template <> +struct ScalarEnumerationTraits<COFF::RelocationTypesARM64> { + static void enumeration(IO &IO, COFF::RelocationTypesARM64 &Value); +}; + +template <> +struct ScalarEnumerationTraits<COFF::WindowsSubsystem> { + static void enumeration(IO &IO, COFF::WindowsSubsystem &Value); +}; + +template <> +struct ScalarBitSetTraits<COFF::Characteristics> { + static void bitset(IO &IO, COFF::Characteristics &Value); +}; + +template <> +struct ScalarBitSetTraits<COFF::SectionCharacteristics> { + static void bitset(IO &IO, COFF::SectionCharacteristics &Value); +}; + +template <> +struct ScalarBitSetTraits<COFF::DLLCharacteristics> { + static void bitset(IO &IO, COFF::DLLCharacteristics &Value); +}; + +template <> +struct MappingTraits<COFFYAML::Relocation> { + static void mapping(IO &IO, COFFYAML::Relocation &Rel); +}; + +template <> +struct MappingTraits<COFFYAML::PEHeader> { + static void mapping(IO &IO, COFFYAML::PEHeader &PH); +}; + +template <> +struct MappingTraits<COFF::DataDirectory> { + static void mapping(IO &IO, COFF::DataDirectory &DD); +}; + +template <> +struct MappingTraits<COFF::header> { + static void mapping(IO &IO, COFF::header &H); +}; + +template <> struct MappingTraits<COFF::AuxiliaryFunctionDefinition> { + static void mapping(IO &IO, COFF::AuxiliaryFunctionDefinition &AFD); +}; + +template <> struct MappingTraits<COFF::AuxiliarybfAndefSymbol> { + static void mapping(IO &IO, COFF::AuxiliarybfAndefSymbol &AAS); +}; + +template <> struct MappingTraits<COFF::AuxiliaryWeakExternal> { + static void mapping(IO &IO, COFF::AuxiliaryWeakExternal &AWE); +}; + +template <> struct MappingTraits<COFF::AuxiliarySectionDefinition> { + static void mapping(IO &IO, COFF::AuxiliarySectionDefinition &ASD); +}; + +template <> struct MappingTraits<COFF::AuxiliaryCLRToken> { + static void mapping(IO &IO, COFF::AuxiliaryCLRToken &ACT); +}; + +template <> +struct MappingTraits<COFFYAML::Symbol> { + static void mapping(IO &IO, COFFYAML::Symbol &S); +}; + +template <> +struct MappingTraits<COFFYAML::Section> { + static void mapping(IO &IO, COFFYAML::Section &Sec); +}; + +template <> +struct MappingTraits<COFFYAML::Object> { + static void mapping(IO &IO, COFFYAML::Object &Obj); +}; + +} // end namespace yaml +} // end namespace llvm + +#endif // LLVM_OBJECTYAML_COFFYAML_H diff --git a/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLDebugSections.h b/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLDebugSections.h new file mode 100644 index 00000000..9cbacb88 --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLDebugSections.h @@ -0,0 +1,139 @@ +//=- CodeViewYAMLDebugSections.h - CodeView YAMLIO debug sections -*- C++ -*-=// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines classes for handling the YAML representation of CodeView +// Debug Info. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_CODEVIEWYAMLDEBUGSECTIONS_H +#define LLVM_OBJECTYAML_CODEVIEWYAMLDEBUGSECTIONS_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/DebugSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/YAMLTraits.h" +#include <cstdint> +#include <memory> +#include <vector> + +namespace llvm { + +namespace codeview { + +class StringsAndChecksums; +class StringsAndChecksumsRef; + +} // end namespace codeview + +namespace CodeViewYAML { + +namespace detail { + +struct YAMLSubsectionBase; + +} // end namespace detail + +struct YAMLFrameData { + uint32_t RvaStart; + uint32_t CodeSize; + uint32_t LocalSize; + uint32_t ParamsSize; + uint32_t MaxStackSize; + StringRef FrameFunc; + uint32_t PrologSize; + uint32_t SavedRegsSize; + uint32_t Flags; +}; + +struct YAMLCrossModuleImport { + StringRef ModuleName; + std::vector<uint32_t> ImportIds; +}; + +struct SourceLineEntry { + uint32_t Offset; + uint32_t LineStart; + uint32_t EndDelta; + bool IsStatement; +}; + +struct SourceColumnEntry { + uint16_t StartColumn; + uint16_t EndColumn; +}; + +struct SourceLineBlock { + StringRef FileName; + std::vector<SourceLineEntry> Lines; + std::vector<SourceColumnEntry> Columns; +}; + +struct HexFormattedString { + std::vector<uint8_t> Bytes; +}; + +struct SourceFileChecksumEntry { + StringRef FileName; + codeview::FileChecksumKind Kind; + HexFormattedString ChecksumBytes; +}; + +struct SourceLineInfo { + uint32_t RelocOffset; + uint32_t RelocSegment; + codeview::LineFlags Flags; + uint32_t CodeSize; + std::vector<SourceLineBlock> Blocks; +}; + +struct InlineeSite { + uint32_t Inlinee; + StringRef FileName; + uint32_t SourceLineNum; + std::vector<StringRef> ExtraFiles; +}; + +struct InlineeInfo { + bool HasExtraFiles; + std::vector<InlineeSite> Sites; +}; + +struct YAMLDebugSubsection { + static Expected<YAMLDebugSubsection> + fromCodeViewSubection(const codeview::StringsAndChecksumsRef &SC, + const codeview::DebugSubsectionRecord &SS); + + std::shared_ptr<detail::YAMLSubsectionBase> Subsection; +}; + +struct DebugSubsectionState {}; + +Expected<std::vector<std::shared_ptr<codeview::DebugSubsection>>> +toCodeViewSubsectionList(BumpPtrAllocator &Allocator, + ArrayRef<YAMLDebugSubsection> Subsections, + const codeview::StringsAndChecksums &SC); + +std::vector<YAMLDebugSubsection> +fromDebugS(ArrayRef<uint8_t> Data, const codeview::StringsAndChecksumsRef &SC); + +void initializeStringsAndChecksums(ArrayRef<YAMLDebugSubsection> Sections, + codeview::StringsAndChecksums &SC); + +} // end namespace CodeViewYAML + +} // end namespace llvm + +LLVM_YAML_DECLARE_MAPPING_TRAITS(CodeViewYAML::YAMLDebugSubsection) + +LLVM_YAML_IS_SEQUENCE_VECTOR(CodeViewYAML::YAMLDebugSubsection) + +#endif // LLVM_OBJECTYAML_CODEVIEWYAMLDEBUGSECTIONS_H diff --git a/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLSymbols.h b/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLSymbols.h new file mode 100644 index 00000000..7c05c9ee --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLSymbols.h @@ -0,0 +1,48 @@ +//===- CodeViewYAMLSymbols.h - CodeView YAMLIO Symbol implementation ------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines classes for handling the YAML representation of CodeView +// Debug Info. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_CODEVIEWYAMLSYMBOLS_H +#define LLVM_OBJECTYAML_CODEVIEWYAMLSYMBOLS_H + +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/YAMLTraits.h" +#include <memory> + +namespace llvm { +namespace CodeViewYAML { + +namespace detail { + +struct SymbolRecordBase; + +} // end namespace detail + +struct SymbolRecord { + std::shared_ptr<detail::SymbolRecordBase> Symbol; + + codeview::CVSymbol + toCodeViewSymbol(BumpPtrAllocator &Allocator, + codeview::CodeViewContainer Container) const; + + static Expected<SymbolRecord> fromCodeViewSymbol(codeview::CVSymbol Symbol); +}; + +} // end namespace CodeViewYAML +} // end namespace llvm + +LLVM_YAML_DECLARE_MAPPING_TRAITS(CodeViewYAML::SymbolRecord) +LLVM_YAML_IS_SEQUENCE_VECTOR(CodeViewYAML::SymbolRecord) + +#endif // LLVM_OBJECTYAML_CODEVIEWYAMLSYMBOLS_H diff --git a/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLTypeHashing.h b/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLTypeHashing.h new file mode 100644 index 00000000..d6cec8d3 --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLTypeHashing.h @@ -0,0 +1,61 @@ +//==- CodeViewYAMLTypeHashing.h - CodeView YAMLIO Type hashing ----*- C++-*-==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines classes for handling the YAML representation of CodeView +// Debug Info. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_CODEVIEWYAMLTYPEHASHING_H +#define LLVM_OBJECTYAML_CODEVIEWYAMLTYPEHASHING_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/DebugInfo/CodeView/TypeHashing.h" +#include "llvm/ObjectYAML/YAML.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/YAMLTraits.h" +#include <cstdint> +#include <memory> +#include <vector> + +namespace llvm { + +namespace CodeViewYAML { + +struct GlobalHash { + GlobalHash() = default; + explicit GlobalHash(StringRef S) : Hash(S) { + assert(S.size() == 8 && "Invalid hash size!"); + } + explicit GlobalHash(ArrayRef<uint8_t> S) : Hash(S) { + assert(S.size() == 8 && "Invalid hash size!"); + } + yaml::BinaryRef Hash; +}; + +struct DebugHSection { + uint32_t Magic; + uint16_t Version; + uint16_t HashAlgorithm; + std::vector<GlobalHash> Hashes; +}; + +DebugHSection fromDebugH(ArrayRef<uint8_t> DebugH); +ArrayRef<uint8_t> toDebugH(const DebugHSection &DebugH, + BumpPtrAllocator &Alloc); + +} // end namespace CodeViewYAML + +} // end namespace llvm + +LLVM_YAML_DECLARE_MAPPING_TRAITS(CodeViewYAML::DebugHSection) +LLVM_YAML_DECLARE_SCALAR_TRAITS(CodeViewYAML::GlobalHash, QuotingType::None) +LLVM_YAML_IS_SEQUENCE_VECTOR(CodeViewYAML::GlobalHash) + +#endif // LLVM_OBJECTYAML_CODEVIEWYAMLTYPES_H diff --git a/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLTypes.h b/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLTypes.h new file mode 100644 index 00000000..04b5e0ba --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/CodeViewYAMLTypes.h @@ -0,0 +1,70 @@ +//==- CodeViewYAMLTypes.h - CodeView YAMLIO Type implementation --*- C++ -*-==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines classes for handling the YAML representation of CodeView +// Debug Info. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_CODEVIEWYAMLTYPES_H +#define LLVM_OBJECTYAML_CODEVIEWYAMLTYPES_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/YAMLTraits.h" +#include <cstdint> +#include <memory> +#include <vector> + +namespace llvm { + +namespace codeview { +class AppendingTypeTableBuilder; +} + +namespace CodeViewYAML { + +namespace detail { + +struct LeafRecordBase; +struct MemberRecordBase; + +} // end namespace detail + +struct MemberRecord { + std::shared_ptr<detail::MemberRecordBase> Member; +}; + +struct LeafRecord { + std::shared_ptr<detail::LeafRecordBase> Leaf; + + codeview::CVType + toCodeViewRecord(codeview::AppendingTypeTableBuilder &Serializer) const; + static Expected<LeafRecord> fromCodeViewRecord(codeview::CVType Type); +}; + +std::vector<LeafRecord> fromDebugT(ArrayRef<uint8_t> DebugTorP, + StringRef SectionName); +ArrayRef<uint8_t> toDebugT(ArrayRef<LeafRecord>, BumpPtrAllocator &Alloc, + StringRef SectionName); + +} // end namespace CodeViewYAML + +} // end namespace llvm + +LLVM_YAML_DECLARE_SCALAR_TRAITS(codeview::GUID, QuotingType::Single) + +LLVM_YAML_DECLARE_MAPPING_TRAITS(CodeViewYAML::LeafRecord) +LLVM_YAML_DECLARE_MAPPING_TRAITS(CodeViewYAML::MemberRecord) + +LLVM_YAML_IS_SEQUENCE_VECTOR(CodeViewYAML::LeafRecord) +LLVM_YAML_IS_SEQUENCE_VECTOR(CodeViewYAML::MemberRecord) + +#endif // LLVM_OBJECTYAML_CODEVIEWYAMLTYPES_H diff --git a/clang-r353983/include/llvm/ObjectYAML/DWARFEmitter.h b/clang-r353983/include/llvm/ObjectYAML/DWARFEmitter.h new file mode 100644 index 00000000..2ccc876d --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/DWARFEmitter.h @@ -0,0 +1,49 @@ +//===--- DWARFEmitter.h - ---------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// \file +/// 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> + +namespace llvm { + +class raw_ostream; + +namespace DWARFYAML { + +struct Data; +struct PubSection; + +void EmitDebugAbbrev(raw_ostream &OS, const Data &DI); +void EmitDebugStr(raw_ostream &OS, const Data &DI); + +void EmitDebugAranges(raw_ostream &OS, const Data &DI); +void EmitPubSection(raw_ostream &OS, const PubSection &Sect, + bool IsLittleEndian); +void EmitDebugInfo(raw_ostream &OS, const Data &DI); +void EmitDebugLine(raw_ostream &OS, const Data &DI); + +Expected<StringMap<std::unique_ptr<MemoryBuffer>>> +EmitDebugSections(StringRef YAMLString, bool ApplyFixups = false, + bool IsLittleEndian = sys::IsLittleEndianHost); +StringMap<std::unique_ptr<MemoryBuffer>> +EmitDebugSections(llvm::DWARFYAML::Data &DI, bool ApplyFixups); + +} // end namespace DWARFYAML +} // end namespace llvm + +#endif // LLVM_OBJECTYAML_DWARFEMITTER_H diff --git a/clang-r353983/include/llvm/ObjectYAML/DWARFYAML.h b/clang-r353983/include/llvm/ObjectYAML/DWARFYAML.h new file mode 100644 index 00000000..78d736c3 --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/DWARFYAML.h @@ -0,0 +1,308 @@ +//===- DWARFYAML.h - DWARF YAMLIO implementation ----------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file declares classes for handling the YAML representation +/// of DWARF Debug Info. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_DWARFYAML_H +#define LLVM_OBJECTYAML_DWARFYAML_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/Support/YAMLTraits.h" +#include <cstdint> +#include <vector> + +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 { + llvm::yaml::Hex32 Code; + llvm::dwarf::Tag Tag; + llvm::dwarf::Constants Children; + std::vector<AttributeAbbrev> Attributes; +}; + +struct ARangeDescriptor { + llvm::yaml::Hex64 Address; + uint64_t Length; +}; + +struct ARange { + InitialLength Length; + uint16_t Version; + uint32_t CuOffset; + uint8_t AddrSize; + uint8_t SegSize; + std::vector<ARangeDescriptor> Descriptors; +}; + +struct PubEntry { + llvm::yaml::Hex32 DieOffset; + llvm::yaml::Hex8 Descriptor; + StringRef Name; +}; + +struct PubSection { + InitialLength Length; + uint16_t Version; + uint32_t UnitOffset; + uint32_t UnitSize; + bool IsGNUStyle = false; + std::vector<PubEntry> Entries; +}; + +struct FormValue { + llvm::yaml::Hex64 Value; + StringRef CStr; + std::vector<llvm::yaml::Hex8> BlockData; +}; + +struct Entry { + llvm::yaml::Hex32 AbbrCode; + std::vector<FormValue> Values; +}; + +struct Unit { + InitialLength Length; + uint16_t Version; + llvm::dwarf::UnitType Type; // Added in DWARF 5 + uint32_t AbbrOffset; + uint8_t AddrSize; + std::vector<Entry> Entries; +}; + +struct File { + StringRef Name; + uint64_t DirIdx; + uint64_t ModTime; + uint64_t Length; +}; + +struct LineTableOpcode { + dwarf::LineNumberOps Opcode; + uint64_t ExtLen; + dwarf::LineNumberExtendedOps SubOpcode; + uint64_t Data; + int64_t SData; + File FileEntry; + std::vector<llvm::yaml::Hex8> UnknownOpcodeData; + std::vector<llvm::yaml::Hex64> StandardOpcodeData; +}; + +struct LineTable { + InitialLength Length; + uint16_t Version; + uint64_t PrologueLength; + uint8_t MinInstLength; + uint8_t MaxOpsPerInst; + uint8_t DefaultIsStmt; + uint8_t LineBase; + uint8_t LineRange; + uint8_t OpcodeBase; + std::vector<uint8_t> StandardOpcodeLengths; + std::vector<StringRef> IncludeDirs; + std::vector<File> Files; + std::vector<LineTableOpcode> Opcodes; +}; + +struct Data { + bool IsLittleEndian; + std::vector<Abbrev> AbbrevDecls; + std::vector<StringRef> DebugStrings; + std::vector<ARange> ARanges; + PubSection PubNames; + PubSection PubTypes; + + PubSection GNUPubNames; + PubSection GNUPubTypes; + + std::vector<Unit> CompileUnits; + + std::vector<LineTable> DebugLines; + + bool isEmpty() const; +}; + +} // end namespace DWARFYAML +} // end namespace llvm + +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex64) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex8) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AttributeAbbrev) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Abbrev) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARangeDescriptor) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARange) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::PubEntry) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Unit) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::FormValue) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Entry) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::File) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTable) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTableOpcode) + +namespace llvm { +namespace yaml { + +template <> struct MappingTraits<DWARFYAML::Data> { + static void mapping(IO &IO, DWARFYAML::Data &DWARF); +}; + +template <> struct MappingTraits<DWARFYAML::Abbrev> { + static void mapping(IO &IO, DWARFYAML::Abbrev &Abbrev); +}; + +template <> struct MappingTraits<DWARFYAML::AttributeAbbrev> { + static void mapping(IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev); +}; + +template <> struct MappingTraits<DWARFYAML::ARangeDescriptor> { + static void mapping(IO &IO, DWARFYAML::ARangeDescriptor &Descriptor); +}; + +template <> struct MappingTraits<DWARFYAML::ARange> { + static void mapping(IO &IO, DWARFYAML::ARange &Range); +}; + +template <> struct MappingTraits<DWARFYAML::PubEntry> { + static void mapping(IO &IO, DWARFYAML::PubEntry &Entry); +}; + +template <> struct MappingTraits<DWARFYAML::PubSection> { + static void mapping(IO &IO, DWARFYAML::PubSection &Section); +}; + +template <> struct MappingTraits<DWARFYAML::Unit> { + static void mapping(IO &IO, DWARFYAML::Unit &Unit); +}; + +template <> struct MappingTraits<DWARFYAML::Entry> { + static void mapping(IO &IO, DWARFYAML::Entry &Entry); +}; + +template <> struct MappingTraits<DWARFYAML::FormValue> { + static void mapping(IO &IO, DWARFYAML::FormValue &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); +}; + +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, unused2, unused3) \ + io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name); + +template <> struct ScalarEnumerationTraits<dwarf::Tag> { + static void enumeration(IO &io, dwarf::Tag &value) { +#include "llvm/BinaryFormat/Dwarf.def" + io.enumFallback<Hex16>(value); + } +}; + +#define HANDLE_DW_LNS(unused, name) \ + io.enumCase(value, "DW_LNS_" #name, dwarf::DW_LNS_##name); + +template <> struct ScalarEnumerationTraits<dwarf::LineNumberOps> { + static void enumeration(IO &io, dwarf::LineNumberOps &value) { +#include "llvm/BinaryFormat/Dwarf.def" + io.enumFallback<Hex8>(value); + } +}; + +#define HANDLE_DW_LNE(unused, name) \ + io.enumCase(value, "DW_LNE_" #name, dwarf::DW_LNE_##name); + +template <> struct ScalarEnumerationTraits<dwarf::LineNumberExtendedOps> { + static void enumeration(IO &io, dwarf::LineNumberExtendedOps &value) { +#include "llvm/BinaryFormat/Dwarf.def" + io.enumFallback<Hex16>(value); + } +}; + +#define HANDLE_DW_AT(unused, name, unused2, unused3) \ + io.enumCase(value, "DW_AT_" #name, dwarf::DW_AT_##name); + +template <> struct ScalarEnumerationTraits<dwarf::Attribute> { + static void enumeration(IO &io, dwarf::Attribute &value) { +#include "llvm/BinaryFormat/Dwarf.def" + io.enumFallback<Hex16>(value); + } +}; + +#define HANDLE_DW_FORM(unused, name, unused2, unused3) \ + io.enumCase(value, "DW_FORM_" #name, dwarf::DW_FORM_##name); + +template <> struct ScalarEnumerationTraits<dwarf::Form> { + static void enumeration(IO &io, dwarf::Form &value) { +#include "llvm/BinaryFormat/Dwarf.def" + io.enumFallback<Hex16>(value); + } +}; + +#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/BinaryFormat/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); + io.enumCase(value, "DW_CHILDREN_yes", dwarf::DW_CHILDREN_yes); + io.enumFallback<Hex16>(value); + } +}; + +} // end namespace yaml +} // end namespace llvm + +#endif // LLVM_OBJECTYAML_DWARFYAML_H diff --git a/clang-r353983/include/llvm/ObjectYAML/ELFYAML.h b/clang-r353983/include/llvm/ObjectYAML/ELFYAML.h new file mode 100644 index 00000000..e194e59a --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/ELFYAML.h @@ -0,0 +1,410 @@ +//===- ELFYAML.h - ELF YAMLIO implementation --------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file declares classes for handling the YAML representation +/// of ELF. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_ELFYAML_H +#define LLVM_OBJECTYAML_ELFYAML_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/ObjectYAML/YAML.h" +#include "llvm/Support/YAMLTraits.h" +#include <cstdint> +#include <memory> +#include <vector> + +namespace llvm { +namespace ELFYAML { + +// These types are invariant across 32/64-bit ELF, so for simplicity just +// directly give them their exact sizes. We don't need to worry about +// endianness because these are just the types in the YAMLIO structures, +// and are appropriately converted to the necessary endianness when +// reading/generating binary object files. +// The naming of these types is intended to be ELF_PREFIX, where PREFIX is +// the common prefix of the respective constants. E.g. ELF_EM corresponds +// to the `e_machine` constants, like `EM_X86_64`. +// In the future, these would probably be better suited by C++11 enum +// class's with appropriate fixed underlying type. +LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_ET) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_PT) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM) +LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS) +LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA) +LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI) +// Just use 64, since it can hold 32-bit values too. +LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_EF) +// Just use 64, since it can hold 32-bit values too. +LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_DYNTAG) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_PF) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_REL) +LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_RSS) +// Just use 64, since it can hold 32-bit values too. +LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF) +LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_SHN) +LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT) +LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV) +LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STO) + +LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG) +LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_ISA) + +// For now, hardcode 64 bits everywhere that 32 or 64 would be needed +// since 64-bit can hold 32-bit values too. +struct FileHeader { + ELF_ELFCLASS Class; + ELF_ELFDATA Data; + ELF_ELFOSABI OSABI; + llvm::yaml::Hex8 ABIVersion; + ELF_ET Type; + ELF_EM Machine; + ELF_EF Flags; + llvm::yaml::Hex64 Entry; +}; + +struct SectionName { + StringRef Section; +}; + +struct ProgramHeader { + ELF_PT Type; + ELF_PF Flags; + llvm::yaml::Hex64 VAddr; + llvm::yaml::Hex64 PAddr; + Optional<llvm::yaml::Hex64> Align; + std::vector<SectionName> Sections; +}; + +struct Symbol { + StringRef Name; + ELF_STT Type; + StringRef Section; + Optional<ELF_SHN> Index; + llvm::yaml::Hex64 Value; + llvm::yaml::Hex64 Size; + uint8_t Other; +}; + +struct LocalGlobalWeakSymbols { + std::vector<Symbol> Local; + std::vector<Symbol> Global; + std::vector<Symbol> Weak; +}; + +struct SectionOrType { + StringRef sectionNameOrType; +}; + +struct DynamicEntry { + ELF_DYNTAG Tag; + llvm::yaml::Hex64 Val; +}; + +struct Section { + enum class SectionKind { + Dynamic, + Group, + RawContent, + Relocation, + NoBits, + MipsABIFlags + }; + SectionKind Kind; + StringRef Name; + ELF_SHT Type; + ELF_SHF Flags; + llvm::yaml::Hex64 Address; + StringRef Link; + llvm::yaml::Hex64 AddressAlign; + Optional<llvm::yaml::Hex64> EntSize; + + Section(SectionKind Kind) : Kind(Kind) {} + virtual ~Section(); +}; + +struct DynamicSection : Section { + std::vector<DynamicEntry> Entries; + + DynamicSection() : Section(SectionKind::Dynamic) {} + + static bool classof(const Section *S) { + return S->Kind == SectionKind::Dynamic; + } +}; + +struct RawContentSection : Section { + yaml::BinaryRef Content; + llvm::yaml::Hex64 Size; + + RawContentSection() : Section(SectionKind::RawContent) {} + + static bool classof(const Section *S) { + return S->Kind == SectionKind::RawContent; + } +}; + +struct NoBitsSection : Section { + llvm::yaml::Hex64 Size; + + NoBitsSection() : Section(SectionKind::NoBits) {} + + static bool classof(const Section *S) { + return S->Kind == SectionKind::NoBits; + } +}; + +struct Group : Section { + // Members of a group contain a flag and a list of section indices + // that are part of the group. + std::vector<SectionOrType> Members; + StringRef Signature; /* Info */ + + Group() : Section(SectionKind::Group) {} + + static bool classof(const Section *S) { + return S->Kind == SectionKind::Group; + } +}; + +struct Relocation { + llvm::yaml::Hex64 Offset; + int64_t Addend; + ELF_REL Type; + Optional<StringRef> Symbol; +}; + +struct RelocationSection : Section { + std::vector<Relocation> Relocations; + StringRef RelocatableSec; /* Info */ + + RelocationSection() : Section(SectionKind::Relocation) {} + + static bool classof(const Section *S) { + return S->Kind == SectionKind::Relocation; + } +}; + +// Represents .MIPS.abiflags section +struct MipsABIFlags : Section { + llvm::yaml::Hex16 Version; + MIPS_ISA ISALevel; + llvm::yaml::Hex8 ISARevision; + MIPS_AFL_REG GPRSize; + MIPS_AFL_REG CPR1Size; + MIPS_AFL_REG CPR2Size; + MIPS_ABI_FP FpABI; + MIPS_AFL_EXT ISAExtension; + MIPS_AFL_ASE ASEs; + MIPS_AFL_FLAGS1 Flags1; + llvm::yaml::Hex32 Flags2; + + MipsABIFlags() : Section(SectionKind::MipsABIFlags) {} + + static bool classof(const Section *S) { + return S->Kind == SectionKind::MipsABIFlags; + } +}; + +struct Object { + FileHeader Header; + std::vector<ProgramHeader> ProgramHeaders; + std::vector<std::unique_ptr<Section>> Sections; + // Although in reality the symbols reside in a section, it is a lot + // cleaner and nicer if we read them from the YAML as a separate + // top-level key, which automatically ensures that invariants like there + // being a single SHT_SYMTAB section are upheld. + LocalGlobalWeakSymbols Symbols; + LocalGlobalWeakSymbols DynamicSymbols; +}; + +} // end namespace ELFYAML +} // end namespace llvm + +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::DynamicEntry) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::ProgramHeader) +LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::ELFYAML::Section>) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Relocation) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionOrType) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionName) + +namespace llvm { +namespace yaml { + +template <> +struct ScalarEnumerationTraits<ELFYAML::ELF_ET> { + static void enumeration(IO &IO, ELFYAML::ELF_ET &Value); +}; + +template <> struct ScalarEnumerationTraits<ELFYAML::ELF_PT> { + static void enumeration(IO &IO, ELFYAML::ELF_PT &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::ELF_EM> { + static void enumeration(IO &IO, ELFYAML::ELF_EM &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> { + static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> { + static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI> { + static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value); +}; + +template <> +struct ScalarBitSetTraits<ELFYAML::ELF_EF> { + static void bitset(IO &IO, ELFYAML::ELF_EF &Value); +}; + +template <> struct ScalarBitSetTraits<ELFYAML::ELF_PF> { + static void bitset(IO &IO, ELFYAML::ELF_PF &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::ELF_SHT> { + static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value); +}; + +template <> +struct ScalarBitSetTraits<ELFYAML::ELF_SHF> { + static void bitset(IO &IO, ELFYAML::ELF_SHF &Value); +}; + +template <> struct ScalarEnumerationTraits<ELFYAML::ELF_SHN> { + static void enumeration(IO &IO, ELFYAML::ELF_SHN &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::ELF_STT> { + static void enumeration(IO &IO, ELFYAML::ELF_STT &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::ELF_STV> { + static void enumeration(IO &IO, ELFYAML::ELF_STV &Value); +}; + +template <> +struct ScalarBitSetTraits<ELFYAML::ELF_STO> { + static void bitset(IO &IO, ELFYAML::ELF_STO &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::ELF_REL> { + static void enumeration(IO &IO, ELFYAML::ELF_REL &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::ELF_DYNTAG> { + static void enumeration(IO &IO, ELFYAML::ELF_DYNTAG &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::ELF_RSS> { + static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG> { + static void enumeration(IO &IO, ELFYAML::MIPS_AFL_REG &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP> { + static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT> { + static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value); +}; + +template <> +struct ScalarEnumerationTraits<ELFYAML::MIPS_ISA> { + static void enumeration(IO &IO, ELFYAML::MIPS_ISA &Value); +}; + +template <> +struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE> { + static void bitset(IO &IO, ELFYAML::MIPS_AFL_ASE &Value); +}; + +template <> +struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1> { + static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value); +}; + +template <> +struct MappingTraits<ELFYAML::FileHeader> { + static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr); +}; + +template <> struct MappingTraits<ELFYAML::ProgramHeader> { + static void mapping(IO &IO, ELFYAML::ProgramHeader &FileHdr); +}; + +template <> +struct MappingTraits<ELFYAML::Symbol> { + static void mapping(IO &IO, ELFYAML::Symbol &Symbol); + static StringRef validate(IO &IO, ELFYAML::Symbol &Symbol); +}; + +template <> +struct MappingTraits<ELFYAML::LocalGlobalWeakSymbols> { + static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols); +}; + +template <> struct MappingTraits<ELFYAML::DynamicEntry> { + static void mapping(IO &IO, ELFYAML::DynamicEntry &Rel); +}; + +template <> struct MappingTraits<ELFYAML::Relocation> { + static void mapping(IO &IO, ELFYAML::Relocation &Rel); +}; + +template <> +struct MappingTraits<std::unique_ptr<ELFYAML::Section>> { + static void mapping(IO &IO, std::unique_ptr<ELFYAML::Section> &Section); + static StringRef validate(IO &io, std::unique_ptr<ELFYAML::Section> &Section); +}; + +template <> +struct MappingTraits<ELFYAML::Object> { + static void mapping(IO &IO, ELFYAML::Object &Object); +}; + +template <> struct MappingTraits<ELFYAML::SectionOrType> { + static void mapping(IO &IO, ELFYAML::SectionOrType §ionOrType); +}; + +template <> struct MappingTraits<ELFYAML::SectionName> { + static void mapping(IO &IO, ELFYAML::SectionName §ionName); +}; + +} // end namespace yaml +} // end namespace llvm + +#endif // LLVM_OBJECTYAML_ELFYAML_H diff --git a/clang-r353983/include/llvm/ObjectYAML/MachOYAML.h b/clang-r353983/include/llvm/ObjectYAML/MachOYAML.h new file mode 100644 index 00000000..d7e1c033 --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/MachOYAML.h @@ -0,0 +1,306 @@ +//===- MachOYAML.h - Mach-O YAMLIO implementation ---------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file declares classes for handling the YAML representation +/// of Mach-O. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_MACHOYAML_H +#define LLVM_OBJECTYAML_MACHOYAML_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/MachO.h" +#include "llvm/ObjectYAML/DWARFYAML.h" +#include "llvm/Support/YAMLTraits.h" +#include <cstdint> +#include <string> +#include <vector> + +namespace llvm { +namespace MachOYAML { + +struct Section { + char sectname[16]; + char segname[16]; + llvm::yaml::Hex64 addr; + uint64_t size; + llvm::yaml::Hex32 offset; + uint32_t align; + llvm::yaml::Hex32 reloff; + uint32_t nreloc; + llvm::yaml::Hex32 flags; + llvm::yaml::Hex32 reserved1; + llvm::yaml::Hex32 reserved2; + llvm::yaml::Hex32 reserved3; +}; + +struct FileHeader { + llvm::yaml::Hex32 magic; + llvm::yaml::Hex32 cputype; + llvm::yaml::Hex32 cpusubtype; + llvm::yaml::Hex32 filetype; + uint32_t ncmds; + uint32_t sizeofcmds; + llvm::yaml::Hex32 flags; + llvm::yaml::Hex32 reserved; +}; + +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; +}; + +struct NListEntry { + uint32_t n_strx; + llvm::yaml::Hex8 n_type; + uint8_t n_sect; + uint16_t n_desc; + uint64_t n_value; +}; + +struct RebaseOpcode { + MachO::RebaseOpcode Opcode; + uint8_t Imm; + std::vector<yaml::Hex64> ExtraData; +}; + +struct BindOpcode { + MachO::BindOpcode Opcode; + uint8_t Imm; + std::vector<yaml::Hex64> ULEBExtraData; + std::vector<int64_t> SLEBExtraData; + StringRef Symbol; +}; + +struct ExportEntry { + uint64_t TerminalSize = 0; + uint64_t NodeOffset = 0; + std::string Name; + llvm::yaml::Hex64 Flags = 0; + llvm::yaml::Hex64 Address = 0; + llvm::yaml::Hex64 Other = 0; + std::string ImportName; + std::vector<MachOYAML::ExportEntry> Children; +}; + +struct LinkEditData { + std::vector<MachOYAML::RebaseOpcode> RebaseOpcodes; + std::vector<MachOYAML::BindOpcode> BindOpcodes; + std::vector<MachOYAML::BindOpcode> WeakBindOpcodes; + std::vector<MachOYAML::BindOpcode> LazyBindOpcodes; + MachOYAML::ExportEntry ExportTrie; + std::vector<NListEntry> NameList; + std::vector<StringRef> StringTable; + + bool isEmpty() const; +}; + +struct Object { + bool IsLittleEndian; + FileHeader Header; + std::vector<LoadCommand> LoadCommands; + std::vector<Section> Sections; + LinkEditData LinkEdit; + DWARFYAML::Data DWARF; +}; + +struct FatHeader { + llvm::yaml::Hex32 magic; + uint32_t nfat_arch; +}; + +struct FatArch { + llvm::yaml::Hex32 cputype; + llvm::yaml::Hex32 cpusubtype; + llvm::yaml::Hex64 offset; + uint64_t size; + uint32_t align; + llvm::yaml::Hex32 reserved; +}; + +struct UniversalBinary { + FatHeader Header; + std::vector<FatArch> FatArchs; + std::vector<Object> Slices; +}; + +} // end namespace MachOYAML +} // end namespace llvm + +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::LoadCommand) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::Section) +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 { + +class raw_ostream; + +namespace yaml { + +template <> struct MappingTraits<MachOYAML::FileHeader> { + static void mapping(IO &IO, MachOYAML::FileHeader &FileHeader); +}; + +template <> struct MappingTraits<MachOYAML::Object> { + static void mapping(IO &IO, MachOYAML::Object &Object); +}; + +template <> struct MappingTraits<MachOYAML::FatHeader> { + static void mapping(IO &IO, MachOYAML::FatHeader &FatHeader); +}; + +template <> struct MappingTraits<MachOYAML::FatArch> { + static void mapping(IO &IO, MachOYAML::FatArch &FatArch); +}; + +template <> struct MappingTraits<MachOYAML::UniversalBinary> { + static void mapping(IO &IO, MachOYAML::UniversalBinary &UniversalBinary); +}; + +template <> struct MappingTraits<MachOYAML::LoadCommand> { + static void mapping(IO &IO, MachOYAML::LoadCommand &LoadCommand); +}; + +template <> struct MappingTraits<MachOYAML::LinkEditData> { + static void mapping(IO &IO, MachOYAML::LinkEditData &LinkEditData); +}; + +template <> struct MappingTraits<MachOYAML::RebaseOpcode> { + static void mapping(IO &IO, MachOYAML::RebaseOpcode &RebaseOpcode); +}; + +template <> struct MappingTraits<MachOYAML::BindOpcode> { + static void mapping(IO &IO, MachOYAML::BindOpcode &BindOpcode); +}; + +template <> struct MappingTraits<MachOYAML::ExportEntry> { + static void mapping(IO &IO, MachOYAML::ExportEntry &ExportEntry); +}; + +template <> struct MappingTraits<MachOYAML::Section> { + static void mapping(IO &IO, MachOYAML::Section &Section); +}; + +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); + +template <> struct ScalarEnumerationTraits<MachO::LoadCommandType> { + static void enumeration(IO &io, MachO::LoadCommandType &value) { +#include "llvm/BinaryFormat/MachO.def" + io.enumFallback<Hex32>(value); + } +}; + +#define ENUM_CASE(Enum) io.enumCase(value, #Enum, MachO::Enum); + +template <> struct ScalarEnumerationTraits<MachO::RebaseOpcode> { + static void enumeration(IO &io, MachO::RebaseOpcode &value) { + ENUM_CASE(REBASE_OPCODE_DONE) + ENUM_CASE(REBASE_OPCODE_SET_TYPE_IMM) + ENUM_CASE(REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB) + ENUM_CASE(REBASE_OPCODE_ADD_ADDR_ULEB) + ENUM_CASE(REBASE_OPCODE_ADD_ADDR_IMM_SCALED) + ENUM_CASE(REBASE_OPCODE_DO_REBASE_IMM_TIMES) + ENUM_CASE(REBASE_OPCODE_DO_REBASE_ULEB_TIMES) + ENUM_CASE(REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB) + ENUM_CASE(REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB) + io.enumFallback<Hex8>(value); + } +}; + +template <> struct ScalarEnumerationTraits<MachO::BindOpcode> { + static void enumeration(IO &io, MachO::BindOpcode &value) { + ENUM_CASE(BIND_OPCODE_DONE) + ENUM_CASE(BIND_OPCODE_SET_DYLIB_ORDINAL_IMM) + ENUM_CASE(BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB) + ENUM_CASE(BIND_OPCODE_SET_DYLIB_SPECIAL_IMM) + ENUM_CASE(BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM) + ENUM_CASE(BIND_OPCODE_SET_TYPE_IMM) + ENUM_CASE(BIND_OPCODE_SET_ADDEND_SLEB) + ENUM_CASE(BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB) + ENUM_CASE(BIND_OPCODE_ADD_ADDR_ULEB) + ENUM_CASE(BIND_OPCODE_DO_BIND) + ENUM_CASE(BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB) + ENUM_CASE(BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED) + ENUM_CASE(BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB) + io.enumFallback<Hex8>(value); + } +}; + +// This trait is used for 16-byte chars in Mach structures used for strings +using char_16 = char[16]; + +template <> struct ScalarTraits<char_16> { + static void output(const char_16 &Val, void *, raw_ostream &Out); + static StringRef input(StringRef Scalar, void *, char_16 &Val); + static QuotingType mustQuote(StringRef S); +}; + +// This trait is used for UUIDs. It reads and writes them matching otool's +// formatting style. +using uuid_t = raw_ostream::uuid_t; + +template <> struct ScalarTraits<uuid_t> { + static void output(const uuid_t &Val, void *, raw_ostream &Out); + static StringRef input(StringRef Scalar, void *, uuid_t &Val); + static QuotingType mustQuote(StringRef S); +}; + +// Load Command struct mapping traits + +#define LOAD_COMMAND_STRUCT(LCStruct) \ + template <> struct MappingTraits<MachO::LCStruct> { \ + static void mapping(IO &IO, MachO::LCStruct &LoadCommand); \ + }; + +#include "llvm/BinaryFormat/MachO.def" + +// Extra structures used by load commands +template <> struct MappingTraits<MachO::dylib> { + static void mapping(IO &IO, MachO::dylib &LoadCommand); +}; + +template <> struct MappingTraits<MachO::fvmlib> { + static void mapping(IO &IO, MachO::fvmlib &LoadCommand); +}; + +template <> struct MappingTraits<MachO::section> { + static void mapping(IO &IO, MachO::section &LoadCommand); +}; + +template <> struct MappingTraits<MachO::section_64> { + static void mapping(IO &IO, MachO::section_64 &LoadCommand); +}; + +} // end namespace yaml + +} // end namespace llvm + +#endif // LLVM_OBJECTYAML_MACHOYAML_H diff --git a/clang-r353983/include/llvm/ObjectYAML/ObjectYAML.h b/clang-r353983/include/llvm/ObjectYAML/ObjectYAML.h new file mode 100644 index 00000000..56f5f394 --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/ObjectYAML.h @@ -0,0 +1,39 @@ +//===- ObjectYAML.h ---------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_OBJECTYAML_H +#define LLVM_OBJECTYAML_OBJECTYAML_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" +#include <memory> + +namespace llvm { +namespace yaml { + +class IO; + +struct YamlObjectFile { + std::unique_ptr<ELFYAML::Object> Elf; + 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> { + static void mapping(IO &IO, YamlObjectFile &ObjectFile); +}; + +} // end namespace yaml +} // end namespace llvm + +#endif // LLVM_OBJECTYAML_OBJECTYAML_H diff --git a/clang-r353983/include/llvm/ObjectYAML/WasmYAML.h b/clang-r353983/include/llvm/ObjectYAML/WasmYAML.h new file mode 100644 index 00000000..f5260bbb --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/WasmYAML.h @@ -0,0 +1,536 @@ +//===- WasmYAML.h - Wasm YAMLIO implementation ------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file declares classes for handling the YAML representation +/// of wasm binaries. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_WASMYAML_H +#define LLVM_OBJECTYAML_WASMYAML_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/Wasm.h" +#include "llvm/ObjectYAML/YAML.h" +#include "llvm/Support/Casting.h" +#include <cstdint> +#include <memory> +#include <vector> + +namespace llvm { +namespace WasmYAML { + +LLVM_YAML_STRONG_TYPEDEF(uint32_t, SectionType) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, ValueType) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, TableType) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, SignatureForm) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, ExportKind) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, Opcode) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, RelocType) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolFlags) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolKind) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, SegmentFlags) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, LimitFlags) +LLVM_YAML_STRONG_TYPEDEF(uint32_t, ComdatKind) + +struct FileHeader { + yaml::Hex32 Version; +}; + +struct Limits { + LimitFlags 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 { + uint32_t Index; + ValueType Type; + bool Mutable; + wasm::WasmInitExpr InitExpr; +}; + +struct Event { + uint32_t Index; + uint32_t Attribute; + uint32_t SigIndex; +}; + +struct Import { + StringRef Module; + StringRef Field; + ExportKind Kind; + union { + uint32_t SigIndex; + Global GlobalImport; + Table TableImport; + Limits Memory; + Event EventImport; + }; +}; + +struct LocalDecl { + ValueType Type; + uint32_t Count; +}; + +struct Function { + uint32_t Index; + std::vector<LocalDecl> Locals; + yaml::BinaryRef Body; +}; + +struct Relocation { + RelocType Type; + uint32_t Index; + yaml::Hex32 Offset; + int32_t Addend; +}; + +struct DataSegment { + uint32_t MemoryIndex; + uint32_t SectionOffset; + wasm::WasmInitExpr Offset; + yaml::BinaryRef Content; +}; + +struct NameEntry { + uint32_t Index; + StringRef Name; +}; + +struct ProducerEntry { + std::string Name; + std::string Version; +}; + +struct SegmentInfo { + uint32_t Index; + StringRef Name; + uint32_t Alignment; + SegmentFlags Flags; +}; + +struct Signature { + uint32_t Index; + SignatureForm Form = wasm::WASM_TYPE_FUNC; + std::vector<ValueType> ParamTypes; + ValueType ReturnType; +}; + +struct SymbolInfo { + uint32_t Index; + StringRef Name; + SymbolKind Kind; + SymbolFlags Flags; + union { + uint32_t ElementIndex; + wasm::WasmDataReference DataRef; + }; +}; + +struct InitFunction { + uint32_t Priority; + uint32_t Symbol; +}; + +struct ComdatEntry { + ComdatKind Kind; + uint32_t Index; +}; + +struct Comdat { + StringRef Name; + std::vector<ComdatEntry> Entries; +}; + +struct Section { + explicit Section(SectionType SecType) : Type(SecType) {} + virtual ~Section(); + + SectionType Type; + std::vector<Relocation> Relocations; +}; + +struct CustomSection : Section { + explicit CustomSection(StringRef Name) + : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {} + + static bool classof(const Section *S) { + return S->Type == wasm::WASM_SEC_CUSTOM; + } + + StringRef Name; + yaml::BinaryRef Payload; +}; + +struct DylinkSection : CustomSection { + DylinkSection() : CustomSection("dylink") {} + + static bool classof(const Section *S) { + auto C = dyn_cast<CustomSection>(S); + return C && C->Name == "dylink"; + } + + uint32_t MemorySize; + uint32_t MemoryAlignment; + uint32_t TableSize; + uint32_t TableAlignment; + std::vector<StringRef> Needed; +}; + +struct NameSection : CustomSection { + NameSection() : CustomSection("name") {} + + static bool classof(const Section *S) { + auto C = dyn_cast<CustomSection>(S); + return C && C->Name == "name"; + } + + std::vector<NameEntry> FunctionNames; +}; + +struct LinkingSection : CustomSection { + LinkingSection() : CustomSection("linking") {} + + static bool classof(const Section *S) { + auto C = dyn_cast<CustomSection>(S); + return C && C->Name == "linking"; + } + + uint32_t Version; + std::vector<SymbolInfo> SymbolTable; + std::vector<SegmentInfo> SegmentInfos; + std::vector<InitFunction> InitFunctions; + std::vector<Comdat> Comdats; +}; + +struct ProducersSection : CustomSection { + ProducersSection() : CustomSection("producers") {} + + static bool classof(const Section *S) { + auto C = dyn_cast<CustomSection>(S); + return C && C->Name == "producers"; + } + + std::vector<ProducerEntry> Languages; + std::vector<ProducerEntry> Tools; + std::vector<ProducerEntry> SDKs; +}; + +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 EventSection : Section { + EventSection() : Section(wasm::WASM_SEC_EVENT) {} + + static bool classof(const Section *S) { + return S->Type == wasm::WASM_SEC_EVENT; + } + + std::vector<Event> Events; +}; + +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_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ProducerEntry) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SegmentInfo) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::InitFunction) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ComdatEntry) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Comdat) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Event) + +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 ScalarBitSetTraits<WasmYAML::LimitFlags> { + static void bitset(IO &IO, WasmYAML::LimitFlags &Value); +}; + +template <> struct ScalarBitSetTraits<WasmYAML::SymbolFlags> { + static void bitset(IO &IO, WasmYAML::SymbolFlags &Value); +}; + +template <> struct ScalarEnumerationTraits<WasmYAML::SymbolKind> { + static void enumeration(IO &IO, WasmYAML::SymbolKind &Kind); +}; + +template <> struct ScalarBitSetTraits<WasmYAML::SegmentFlags> { + static void bitset(IO &IO, WasmYAML::SegmentFlags &Value); +}; + +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::NameEntry> { + static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry); +}; + +template <> struct MappingTraits<WasmYAML::ProducerEntry> { + static void mapping(IO &IO, WasmYAML::ProducerEntry &ProducerEntry); +}; + +template <> struct MappingTraits<WasmYAML::SegmentInfo> { + static void mapping(IO &IO, WasmYAML::SegmentInfo &SegmentInfo); +}; + +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 MappingTraits<WasmYAML::SymbolInfo> { + static void mapping(IO &IO, WasmYAML::SymbolInfo &Info); +}; + +template <> struct MappingTraits<WasmYAML::InitFunction> { + static void mapping(IO &IO, WasmYAML::InitFunction &Init); +}; + +template <> struct ScalarEnumerationTraits<WasmYAML::ComdatKind> { + static void enumeration(IO &IO, WasmYAML::ComdatKind &Kind); +}; + +template <> struct MappingTraits<WasmYAML::ComdatEntry> { + static void mapping(IO &IO, WasmYAML::ComdatEntry &ComdatEntry); +}; + +template <> struct MappingTraits<WasmYAML::Comdat> { + static void mapping(IO &IO, WasmYAML::Comdat &Comdat); +}; + +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); +}; + +template <> struct MappingTraits<WasmYAML::Event> { + static void mapping(IO &IO, WasmYAML::Event &Event); +}; + +} // end namespace yaml +} // end namespace llvm + +#endif // LLVM_OBJECTYAML_WASMYAML_H diff --git a/clang-r353983/include/llvm/ObjectYAML/YAML.h b/clang-r353983/include/llvm/ObjectYAML/YAML.h new file mode 100644 index 00000000..a14bfbc5 --- /dev/null +++ b/clang-r353983/include/llvm/ObjectYAML/YAML.h @@ -0,0 +1,116 @@ +//===- YAML.h ---------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJECTYAML_YAML_H +#define LLVM_OBJECTYAML_YAML_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/YAMLTraits.h" +#include <cstdint> + +namespace llvm { + +class raw_ostream; + +namespace yaml { + +/// Specialized YAMLIO scalar type for representing a binary blob. +/// +/// A typical use case would be to represent the content of a section in a +/// binary file. +/// This class has custom YAMLIO traits for convenient reading and writing. +/// It renders as a string of hex digits in a YAML file. +/// For example, it might render as `DEADBEEFCAFEBABE` (YAML does not +/// require the quotation marks, so for simplicity when outputting they are +/// omitted). +/// When reading, any string whose content is an even number of hex digits +/// will be accepted. +/// For example, all of the following are acceptable: +/// `DEADBEEF`, `"DeADbEeF"`, `"\x44EADBEEF"` (Note: '\x44' == 'D') +/// +/// A significant advantage of using this class is that it never allocates +/// temporary strings or buffers for any of its functionality. +/// +/// Example: +/// +/// The YAML mapping: +/// \code +/// Foo: DEADBEEFCAFEBABE +/// \endcode +/// +/// Could be modeled in YAMLIO by the struct: +/// \code +/// struct FooHolder { +/// BinaryRef Foo; +/// }; +/// namespace llvm { +/// namespace yaml { +/// template <> +/// struct MappingTraits<FooHolder> { +/// static void mapping(IO &IO, FooHolder &FH) { +/// IO.mapRequired("Foo", FH.Foo); +/// } +/// }; +/// } // end namespace yaml +/// } // end namespace llvm +/// \endcode +class BinaryRef { + friend bool operator==(const BinaryRef &LHS, const BinaryRef &RHS); + + /// Either raw binary data, or a string of hex bytes (must always + /// be an even number of characters). + ArrayRef<uint8_t> Data; + + /// Discriminator between the two states of the `Data` member. + bool DataIsHexString = true; + +public: + BinaryRef() = default; + BinaryRef(ArrayRef<uint8_t> Data) : Data(Data), DataIsHexString(false) {} + BinaryRef(StringRef Data) + : Data(reinterpret_cast<const uint8_t *>(Data.data()), Data.size()) {} + + /// The number of bytes that are represented by this BinaryRef. + /// This is the number of bytes that writeAsBinary() will write. + ArrayRef<uint8_t>::size_type binary_size() const { + if (DataIsHexString) + return Data.size() / 2; + return Data.size(); + } + + /// Write the contents (regardless of whether it is binary or a + /// hex string) as binary to the given raw_ostream. + void writeAsBinary(raw_ostream &OS) const; + + /// Write the contents (regardless of whether it is binary or a + /// hex string) as hex to the given raw_ostream. + /// + /// For example, a possible output could be `DEADBEEFCAFEBABE`. + void writeAsHex(raw_ostream &OS) const; +}; + +inline bool operator==(const BinaryRef &LHS, const BinaryRef &RHS) { + // Special case for default constructed BinaryRef. + if (LHS.Data.empty() && RHS.Data.empty()) + return true; + + return LHS.DataIsHexString == RHS.DataIsHexString && LHS.Data == RHS.Data; +} + +template <> struct ScalarTraits<BinaryRef> { + static void output(const BinaryRef &, void *, raw_ostream &); + static StringRef input(StringRef, void *, BinaryRef &); + static QuotingType mustQuote(StringRef S) { return needsQuotes(S); } +}; + +} // end namespace yaml + +} // end namespace llvm + +#endif // LLVM_OBJECTYAML_YAML_H |
