[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / ObjectYAML / XCOFFYAML.cpp
blob73d188e274b12433e43a0a01ec9c461f10a501e7
1 //===-- XCOFFYAML.cpp - XCOFF YAMLIO implementation -------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines classes for handling the YAML representation of XCOFF.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ObjectYAML/XCOFFYAML.h"
14 #include "llvm/BinaryFormat/XCOFF.h"
15 #include <string.h>
17 namespace llvm {
18 namespace XCOFFYAML {
20 Object::Object() { memset(&Header, 0, sizeof(Header)); }
22 } // namespace XCOFFYAML
24 namespace yaml {
26 void ScalarBitSetTraits<XCOFF::SectionTypeFlags>::bitset(
27 IO &IO, XCOFF::SectionTypeFlags &Value) {
28 #define ECase(X) IO.bitSetCase(Value, #X, XCOFF::X)
29 ECase(STYP_PAD);
30 ECase(STYP_DWARF);
31 ECase(STYP_TEXT);
32 ECase(STYP_DATA);
33 ECase(STYP_BSS);
34 ECase(STYP_EXCEPT);
35 ECase(STYP_INFO);
36 ECase(STYP_TDATA);
37 ECase(STYP_TBSS);
38 ECase(STYP_LOADER);
39 ECase(STYP_DEBUG);
40 ECase(STYP_TYPCHK);
41 ECase(STYP_OVRFLO);
42 #undef ECase
45 void ScalarEnumerationTraits<XCOFF::StorageClass>::enumeration(
46 IO &IO, XCOFF::StorageClass &Value) {
47 #define ECase(X) IO.enumCase(Value, #X, XCOFF::X)
48 ECase(C_NULL);
49 ECase(C_AUTO);
50 ECase(C_EXT);
51 ECase(C_STAT);
52 ECase(C_REG);
53 ECase(C_EXTDEF);
54 ECase(C_LABEL);
55 ECase(C_ULABEL);
56 ECase(C_MOS);
57 ECase(C_ARG);
58 ECase(C_STRTAG);
59 ECase(C_MOU);
60 ECase(C_UNTAG);
61 ECase(C_TPDEF);
62 ECase(C_USTATIC);
63 ECase(C_ENTAG);
64 ECase(C_MOE);
65 ECase(C_REGPARM);
66 ECase(C_FIELD);
67 ECase(C_BLOCK);
68 ECase(C_FCN);
69 ECase(C_EOS);
70 ECase(C_FILE);
71 ECase(C_LINE);
72 ECase(C_ALIAS);
73 ECase(C_HIDDEN);
74 ECase(C_HIDEXT);
75 ECase(C_BINCL);
76 ECase(C_EINCL);
77 ECase(C_INFO);
78 ECase(C_WEAKEXT);
79 ECase(C_DWARF);
80 ECase(C_GSYM);
81 ECase(C_LSYM);
82 ECase(C_PSYM);
83 ECase(C_RSYM);
84 ECase(C_RPSYM);
85 ECase(C_STSYM);
86 ECase(C_TCSYM);
87 ECase(C_BCOMM);
88 ECase(C_ECOML);
89 ECase(C_ECOMM);
90 ECase(C_DECL);
91 ECase(C_ENTRY);
92 ECase(C_FUN);
93 ECase(C_BSTAT);
94 ECase(C_ESTAT);
95 ECase(C_GTLS);
96 ECase(C_STTLS);
97 ECase(C_EFCN);
98 #undef ECase
101 struct NSectionFlags {
102 NSectionFlags(IO &) : Flags(XCOFF::SectionTypeFlags(0)) {}
103 NSectionFlags(IO &, uint32_t C) : Flags(XCOFF::SectionTypeFlags(C)) {}
105 uint32_t denormalize(IO &) { return Flags; }
107 XCOFF::SectionTypeFlags Flags;
110 void MappingTraits<XCOFFYAML::FileHeader>::mapping(
111 IO &IO, XCOFFYAML::FileHeader &FileHdr) {
112 IO.mapOptional("MagicNumber", FileHdr.Magic);
113 IO.mapOptional("NumberOfSections", FileHdr.NumberOfSections);
114 IO.mapOptional("CreationTime", FileHdr.TimeStamp);
115 IO.mapOptional("OffsetToSymbolTable", FileHdr.SymbolTableOffset);
116 IO.mapOptional("EntriesInSymbolTable", FileHdr.NumberOfSymTableEntries);
117 IO.mapOptional("AuxiliaryHeaderSize", FileHdr.AuxHeaderSize);
118 IO.mapOptional("Flags", FileHdr.Flags);
121 void MappingTraits<XCOFFYAML::Relocation>::mapping(IO &IO,
122 XCOFFYAML::Relocation &R) {
123 IO.mapOptional("Address", R.VirtualAddress);
124 IO.mapOptional("Symbol", R.SymbolIndex);
125 IO.mapOptional("Info", R.Info);
126 IO.mapOptional("Type", R.Type);
129 void MappingTraits<XCOFFYAML::Section>::mapping(IO &IO,
130 XCOFFYAML::Section &Sec) {
131 MappingNormalization<NSectionFlags, uint32_t> NC(IO, Sec.Flags);
132 IO.mapOptional("Name", Sec.SectionName);
133 IO.mapOptional("Address", Sec.Address);
134 IO.mapOptional("Size", Sec.Size);
135 IO.mapOptional("FileOffsetToData", Sec.FileOffsetToData);
136 IO.mapOptional("FileOffsetToRelocations", Sec.FileOffsetToRelocations);
137 IO.mapOptional("FileOffsetToLineNumbers", Sec.FileOffsetToLineNumbers);
138 IO.mapOptional("NumberOfRelocations", Sec.NumberOfRelocations);
139 IO.mapOptional("NumberOfLineNumbers", Sec.NumberOfLineNumbers);
140 IO.mapOptional("Flags", NC->Flags);
141 IO.mapOptional("SectionData", Sec.SectionData);
142 IO.mapOptional("Relocations", Sec.Relocations);
145 void MappingTraits<XCOFFYAML::Symbol>::mapping(IO &IO, XCOFFYAML::Symbol &S) {
146 IO.mapRequired("Name", S.SymbolName);
147 IO.mapOptional("Value", S.Value);
148 IO.mapOptional("Section", S.SectionName);
149 IO.mapOptional("Type", S.Type);
150 IO.mapOptional("StorageClass", S.StorageClass);
151 IO.mapOptional("NumberOfAuxEntries", S.NumberOfAuxEntries);
154 void MappingTraits<XCOFFYAML::Object>::mapping(IO &IO, XCOFFYAML::Object &Obj) {
155 IO.mapTag("!XCOFF", true);
156 IO.mapRequired("FileHeader", Obj.Header);
157 IO.mapOptional("Sections", Obj.Sections);
158 IO.mapOptional("Symbols", Obj.Symbols);
161 } // namespace yaml
162 } // namespace llvm