10b57cec5SDimitry Andric //===-- XCOFFYAML.cpp - XCOFF YAMLIO implementation -------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file defines classes for handling the YAML representation of XCOFF.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric #include "llvm/ObjectYAML/XCOFFYAML.h"
140b57cec5SDimitry Andric #include "llvm/BinaryFormat/XCOFF.h"
150b57cec5SDimitry Andric #include <string.h>
160b57cec5SDimitry Andric
170b57cec5SDimitry Andric namespace llvm {
180b57cec5SDimitry Andric namespace XCOFFYAML {
190b57cec5SDimitry Andric
Object()200b57cec5SDimitry Andric Object::Object() { memset(&Header, 0, sizeof(Header)); }
210b57cec5SDimitry Andric
2204eeddc0SDimitry Andric AuxSymbolEnt::~AuxSymbolEnt() = default;
2304eeddc0SDimitry Andric
240b57cec5SDimitry Andric } // namespace XCOFFYAML
250b57cec5SDimitry Andric
260b57cec5SDimitry Andric namespace yaml {
270b57cec5SDimitry Andric
bitset(IO & IO,XCOFF::SectionTypeFlags & Value)28fe6060f1SDimitry Andric void ScalarBitSetTraits<XCOFF::SectionTypeFlags>::bitset(
29fe6060f1SDimitry Andric IO &IO, XCOFF::SectionTypeFlags &Value) {
30fe6060f1SDimitry Andric #define ECase(X) IO.bitSetCase(Value, #X, XCOFF::X)
31fe6060f1SDimitry Andric ECase(STYP_PAD);
32fe6060f1SDimitry Andric ECase(STYP_DWARF);
33fe6060f1SDimitry Andric ECase(STYP_TEXT);
34fe6060f1SDimitry Andric ECase(STYP_DATA);
35fe6060f1SDimitry Andric ECase(STYP_BSS);
36fe6060f1SDimitry Andric ECase(STYP_EXCEPT);
37fe6060f1SDimitry Andric ECase(STYP_INFO);
38fe6060f1SDimitry Andric ECase(STYP_TDATA);
39fe6060f1SDimitry Andric ECase(STYP_TBSS);
40fe6060f1SDimitry Andric ECase(STYP_LOADER);
41fe6060f1SDimitry Andric ECase(STYP_DEBUG);
42fe6060f1SDimitry Andric ECase(STYP_TYPCHK);
43fe6060f1SDimitry Andric ECase(STYP_OVRFLO);
44fe6060f1SDimitry Andric #undef ECase
45fe6060f1SDimitry Andric }
46fe6060f1SDimitry Andric
enumeration(IO & IO,XCOFF::DwarfSectionSubtypeFlags & Value)47*0fca6ea1SDimitry Andric void ScalarEnumerationTraits<XCOFF::DwarfSectionSubtypeFlags>::enumeration(
48*0fca6ea1SDimitry Andric IO &IO, XCOFF::DwarfSectionSubtypeFlags &Value) {
49*0fca6ea1SDimitry Andric #define ECase(X) IO.enumCase(Value, #X, XCOFF::X)
50*0fca6ea1SDimitry Andric ECase(SSUBTYP_DWINFO);
51*0fca6ea1SDimitry Andric ECase(SSUBTYP_DWLINE);
52*0fca6ea1SDimitry Andric ECase(SSUBTYP_DWPBNMS);
53*0fca6ea1SDimitry Andric ECase(SSUBTYP_DWPBTYP);
54*0fca6ea1SDimitry Andric ECase(SSUBTYP_DWARNGE);
55*0fca6ea1SDimitry Andric ECase(SSUBTYP_DWABREV);
56*0fca6ea1SDimitry Andric ECase(SSUBTYP_DWSTR);
57*0fca6ea1SDimitry Andric ECase(SSUBTYP_DWRNGES);
58*0fca6ea1SDimitry Andric ECase(SSUBTYP_DWLOC);
59*0fca6ea1SDimitry Andric ECase(SSUBTYP_DWFRAME);
60*0fca6ea1SDimitry Andric ECase(SSUBTYP_DWMAC);
61*0fca6ea1SDimitry Andric #undef ECase
62*0fca6ea1SDimitry Andric IO.enumFallback<Hex32>(Value);
63*0fca6ea1SDimitry Andric }
64*0fca6ea1SDimitry Andric
enumeration(IO & IO,XCOFF::StorageClass & Value)650b57cec5SDimitry Andric void ScalarEnumerationTraits<XCOFF::StorageClass>::enumeration(
660b57cec5SDimitry Andric IO &IO, XCOFF::StorageClass &Value) {
670b57cec5SDimitry Andric #define ECase(X) IO.enumCase(Value, #X, XCOFF::X)
680b57cec5SDimitry Andric ECase(C_NULL);
690b57cec5SDimitry Andric ECase(C_AUTO);
700b57cec5SDimitry Andric ECase(C_EXT);
710b57cec5SDimitry Andric ECase(C_STAT);
720b57cec5SDimitry Andric ECase(C_REG);
730b57cec5SDimitry Andric ECase(C_EXTDEF);
740b57cec5SDimitry Andric ECase(C_LABEL);
750b57cec5SDimitry Andric ECase(C_ULABEL);
760b57cec5SDimitry Andric ECase(C_MOS);
770b57cec5SDimitry Andric ECase(C_ARG);
780b57cec5SDimitry Andric ECase(C_STRTAG);
790b57cec5SDimitry Andric ECase(C_MOU);
800b57cec5SDimitry Andric ECase(C_UNTAG);
810b57cec5SDimitry Andric ECase(C_TPDEF);
820b57cec5SDimitry Andric ECase(C_USTATIC);
830b57cec5SDimitry Andric ECase(C_ENTAG);
840b57cec5SDimitry Andric ECase(C_MOE);
850b57cec5SDimitry Andric ECase(C_REGPARM);
860b57cec5SDimitry Andric ECase(C_FIELD);
870b57cec5SDimitry Andric ECase(C_BLOCK);
880b57cec5SDimitry Andric ECase(C_FCN);
890b57cec5SDimitry Andric ECase(C_EOS);
900b57cec5SDimitry Andric ECase(C_FILE);
910b57cec5SDimitry Andric ECase(C_LINE);
920b57cec5SDimitry Andric ECase(C_ALIAS);
930b57cec5SDimitry Andric ECase(C_HIDDEN);
940b57cec5SDimitry Andric ECase(C_HIDEXT);
950b57cec5SDimitry Andric ECase(C_BINCL);
960b57cec5SDimitry Andric ECase(C_EINCL);
970b57cec5SDimitry Andric ECase(C_INFO);
980b57cec5SDimitry Andric ECase(C_WEAKEXT);
990b57cec5SDimitry Andric ECase(C_DWARF);
1000b57cec5SDimitry Andric ECase(C_GSYM);
1010b57cec5SDimitry Andric ECase(C_LSYM);
1020b57cec5SDimitry Andric ECase(C_PSYM);
1030b57cec5SDimitry Andric ECase(C_RSYM);
1040b57cec5SDimitry Andric ECase(C_RPSYM);
1050b57cec5SDimitry Andric ECase(C_STSYM);
1060b57cec5SDimitry Andric ECase(C_TCSYM);
1070b57cec5SDimitry Andric ECase(C_BCOMM);
1080b57cec5SDimitry Andric ECase(C_ECOML);
1090b57cec5SDimitry Andric ECase(C_ECOMM);
1100b57cec5SDimitry Andric ECase(C_DECL);
1110b57cec5SDimitry Andric ECase(C_ENTRY);
1120b57cec5SDimitry Andric ECase(C_FUN);
1130b57cec5SDimitry Andric ECase(C_BSTAT);
1140b57cec5SDimitry Andric ECase(C_ESTAT);
1150b57cec5SDimitry Andric ECase(C_GTLS);
1160b57cec5SDimitry Andric ECase(C_STTLS);
1170b57cec5SDimitry Andric ECase(C_EFCN);
1180b57cec5SDimitry Andric #undef ECase
1190b57cec5SDimitry Andric }
1200b57cec5SDimitry Andric
enumeration(IO & IO,XCOFF::StorageMappingClass & Value)12104eeddc0SDimitry Andric void ScalarEnumerationTraits<XCOFF::StorageMappingClass>::enumeration(
12204eeddc0SDimitry Andric IO &IO, XCOFF::StorageMappingClass &Value) {
12304eeddc0SDimitry Andric #define ECase(X) IO.enumCase(Value, #X, XCOFF::X)
12404eeddc0SDimitry Andric ECase(XMC_PR);
12504eeddc0SDimitry Andric ECase(XMC_RO);
12604eeddc0SDimitry Andric ECase(XMC_DB);
12704eeddc0SDimitry Andric ECase(XMC_GL);
12804eeddc0SDimitry Andric ECase(XMC_XO);
12904eeddc0SDimitry Andric ECase(XMC_SV);
13004eeddc0SDimitry Andric ECase(XMC_SV64);
13104eeddc0SDimitry Andric ECase(XMC_SV3264);
13204eeddc0SDimitry Andric ECase(XMC_TI);
13304eeddc0SDimitry Andric ECase(XMC_TB);
13404eeddc0SDimitry Andric ECase(XMC_RW);
13504eeddc0SDimitry Andric ECase(XMC_TC0);
13604eeddc0SDimitry Andric ECase(XMC_TC);
13704eeddc0SDimitry Andric ECase(XMC_TD);
13804eeddc0SDimitry Andric ECase(XMC_DS);
13904eeddc0SDimitry Andric ECase(XMC_UA);
14004eeddc0SDimitry Andric ECase(XMC_BS);
14104eeddc0SDimitry Andric ECase(XMC_UC);
14204eeddc0SDimitry Andric ECase(XMC_TL);
14304eeddc0SDimitry Andric ECase(XMC_UL);
14404eeddc0SDimitry Andric ECase(XMC_TE);
14504eeddc0SDimitry Andric #undef ECase
14604eeddc0SDimitry Andric }
14704eeddc0SDimitry Andric
enumeration(IO & IO,XCOFF::SymbolType & Value)148*0fca6ea1SDimitry Andric void ScalarEnumerationTraits<XCOFF::SymbolType>::enumeration(
149*0fca6ea1SDimitry Andric IO &IO, XCOFF::SymbolType &Value) {
150*0fca6ea1SDimitry Andric #define ECase(X) IO.enumCase(Value, #X, XCOFF::X)
151*0fca6ea1SDimitry Andric ECase(XTY_ER);
152*0fca6ea1SDimitry Andric ECase(XTY_SD);
153*0fca6ea1SDimitry Andric ECase(XTY_LD);
154*0fca6ea1SDimitry Andric ECase(XTY_CM);
155*0fca6ea1SDimitry Andric #undef ECase
156*0fca6ea1SDimitry Andric IO.enumFallback<Hex8>(Value);
157*0fca6ea1SDimitry Andric }
158*0fca6ea1SDimitry Andric
enumeration(IO & IO,XCOFFYAML::AuxSymbolType & Type)15904eeddc0SDimitry Andric void ScalarEnumerationTraits<XCOFFYAML::AuxSymbolType>::enumeration(
16004eeddc0SDimitry Andric IO &IO, XCOFFYAML::AuxSymbolType &Type) {
16104eeddc0SDimitry Andric #define ECase(X) IO.enumCase(Type, #X, XCOFFYAML::X)
16204eeddc0SDimitry Andric ECase(AUX_EXCEPT);
16304eeddc0SDimitry Andric ECase(AUX_FCN);
16404eeddc0SDimitry Andric ECase(AUX_SYM);
16504eeddc0SDimitry Andric ECase(AUX_FILE);
16604eeddc0SDimitry Andric ECase(AUX_CSECT);
16704eeddc0SDimitry Andric ECase(AUX_SECT);
16804eeddc0SDimitry Andric ECase(AUX_STAT);
16904eeddc0SDimitry Andric #undef ECase
17004eeddc0SDimitry Andric }
17104eeddc0SDimitry Andric
enumeration(IO & IO,XCOFF::CFileStringType & Type)17204eeddc0SDimitry Andric void ScalarEnumerationTraits<XCOFF::CFileStringType>::enumeration(
17304eeddc0SDimitry Andric IO &IO, XCOFF::CFileStringType &Type) {
17404eeddc0SDimitry Andric #define ECase(X) IO.enumCase(Type, #X, XCOFF::X)
17504eeddc0SDimitry Andric ECase(XFT_FN);
17604eeddc0SDimitry Andric ECase(XFT_CT);
17704eeddc0SDimitry Andric ECase(XFT_CV);
17804eeddc0SDimitry Andric ECase(XFT_CD);
17904eeddc0SDimitry Andric #undef ECase
18004eeddc0SDimitry Andric }
18104eeddc0SDimitry Andric
182fe6060f1SDimitry Andric struct NSectionFlags {
NSectionFlagsllvm::yaml::NSectionFlags183fe6060f1SDimitry Andric NSectionFlags(IO &) : Flags(XCOFF::SectionTypeFlags(0)) {}
NSectionFlagsllvm::yaml::NSectionFlags184fe6060f1SDimitry Andric NSectionFlags(IO &, uint32_t C) : Flags(XCOFF::SectionTypeFlags(C)) {}
185fe6060f1SDimitry Andric
denormalizellvm::yaml::NSectionFlags186fe6060f1SDimitry Andric uint32_t denormalize(IO &) { return Flags; }
187fe6060f1SDimitry Andric
188fe6060f1SDimitry Andric XCOFF::SectionTypeFlags Flags;
189fe6060f1SDimitry Andric };
190fe6060f1SDimitry Andric
mapping(IO & IO,XCOFFYAML::FileHeader & FileHdr)1910b57cec5SDimitry Andric void MappingTraits<XCOFFYAML::FileHeader>::mapping(
1920b57cec5SDimitry Andric IO &IO, XCOFFYAML::FileHeader &FileHdr) {
193fe6060f1SDimitry Andric IO.mapOptional("MagicNumber", FileHdr.Magic);
194fe6060f1SDimitry Andric IO.mapOptional("NumberOfSections", FileHdr.NumberOfSections);
195fe6060f1SDimitry Andric IO.mapOptional("CreationTime", FileHdr.TimeStamp);
196fe6060f1SDimitry Andric IO.mapOptional("OffsetToSymbolTable", FileHdr.SymbolTableOffset);
197fe6060f1SDimitry Andric IO.mapOptional("EntriesInSymbolTable", FileHdr.NumberOfSymTableEntries);
198fe6060f1SDimitry Andric IO.mapOptional("AuxiliaryHeaderSize", FileHdr.AuxHeaderSize);
199fe6060f1SDimitry Andric IO.mapOptional("Flags", FileHdr.Flags);
200fe6060f1SDimitry Andric }
201fe6060f1SDimitry Andric
mapping(IO & IO,XCOFFYAML::AuxiliaryHeader & AuxHdr)202349cc55cSDimitry Andric void MappingTraits<XCOFFYAML::AuxiliaryHeader>::mapping(
203349cc55cSDimitry Andric IO &IO, XCOFFYAML::AuxiliaryHeader &AuxHdr) {
204349cc55cSDimitry Andric IO.mapOptional("Magic", AuxHdr.Magic);
205349cc55cSDimitry Andric IO.mapOptional("Version", AuxHdr.Version);
206349cc55cSDimitry Andric IO.mapOptional("TextStartAddr", AuxHdr.TextStartAddr);
207349cc55cSDimitry Andric IO.mapOptional("DataStartAddr", AuxHdr.DataStartAddr);
208349cc55cSDimitry Andric IO.mapOptional("TOCAnchorAddr", AuxHdr.TOCAnchorAddr);
209349cc55cSDimitry Andric IO.mapOptional("TextSectionSize", AuxHdr.TextSize);
210349cc55cSDimitry Andric IO.mapOptional("DataSectionSize", AuxHdr.InitDataSize);
211349cc55cSDimitry Andric IO.mapOptional("BssSectionSize", AuxHdr.BssDataSize);
212349cc55cSDimitry Andric IO.mapOptional("SecNumOfEntryPoint", AuxHdr.SecNumOfEntryPoint);
213349cc55cSDimitry Andric IO.mapOptional("SecNumOfText", AuxHdr.SecNumOfText);
214349cc55cSDimitry Andric IO.mapOptional("SecNumOfData", AuxHdr.SecNumOfData);
215349cc55cSDimitry Andric IO.mapOptional("SecNumOfTOC", AuxHdr.SecNumOfTOC);
216349cc55cSDimitry Andric IO.mapOptional("SecNumOfLoader", AuxHdr.SecNumOfLoader);
217349cc55cSDimitry Andric IO.mapOptional("SecNumOfBSS", AuxHdr.SecNumOfBSS);
218349cc55cSDimitry Andric IO.mapOptional("MaxAlignOfText", AuxHdr.MaxAlignOfText);
219349cc55cSDimitry Andric IO.mapOptional("MaxAlignOfData", AuxHdr.MaxAlignOfData);
220349cc55cSDimitry Andric IO.mapOptional("ModuleType", AuxHdr.CpuFlag);
221349cc55cSDimitry Andric IO.mapOptional("TextPageSize", AuxHdr.TextPageSize);
222349cc55cSDimitry Andric IO.mapOptional("DataPageSize", AuxHdr.DataPageSize);
223349cc55cSDimitry Andric IO.mapOptional("StackPageSize", AuxHdr.StackPageSize);
224349cc55cSDimitry Andric IO.mapOptional("FlagAndTDataAlignment", AuxHdr.FlagAndTDataAlignment);
225349cc55cSDimitry Andric IO.mapOptional("EntryPointAddr", AuxHdr.EntryPointAddr);
226349cc55cSDimitry Andric IO.mapOptional("MaxStackSize", AuxHdr.MaxStackSize);
227349cc55cSDimitry Andric IO.mapOptional("MaxDataSize", AuxHdr.MaxDataSize);
228349cc55cSDimitry Andric IO.mapOptional("SecNumOfTData", AuxHdr.SecNumOfTData);
229349cc55cSDimitry Andric IO.mapOptional("SecNumOfTBSS", AuxHdr.SecNumOfTBSS);
230349cc55cSDimitry Andric IO.mapOptional("Flag", AuxHdr.Flag);
231349cc55cSDimitry Andric }
232349cc55cSDimitry Andric
mapping(IO & IO,XCOFFYAML::Relocation & R)233fe6060f1SDimitry Andric void MappingTraits<XCOFFYAML::Relocation>::mapping(IO &IO,
234fe6060f1SDimitry Andric XCOFFYAML::Relocation &R) {
235fe6060f1SDimitry Andric IO.mapOptional("Address", R.VirtualAddress);
236fe6060f1SDimitry Andric IO.mapOptional("Symbol", R.SymbolIndex);
237fe6060f1SDimitry Andric IO.mapOptional("Info", R.Info);
238fe6060f1SDimitry Andric IO.mapOptional("Type", R.Type);
239fe6060f1SDimitry Andric }
240fe6060f1SDimitry Andric
mapping(IO & IO,XCOFFYAML::Section & Sec)241fe6060f1SDimitry Andric void MappingTraits<XCOFFYAML::Section>::mapping(IO &IO,
242fe6060f1SDimitry Andric XCOFFYAML::Section &Sec) {
243fe6060f1SDimitry Andric MappingNormalization<NSectionFlags, uint32_t> NC(IO, Sec.Flags);
244fe6060f1SDimitry Andric IO.mapOptional("Name", Sec.SectionName);
245fe6060f1SDimitry Andric IO.mapOptional("Address", Sec.Address);
246fe6060f1SDimitry Andric IO.mapOptional("Size", Sec.Size);
247fe6060f1SDimitry Andric IO.mapOptional("FileOffsetToData", Sec.FileOffsetToData);
248fe6060f1SDimitry Andric IO.mapOptional("FileOffsetToRelocations", Sec.FileOffsetToRelocations);
249fe6060f1SDimitry Andric IO.mapOptional("FileOffsetToLineNumbers", Sec.FileOffsetToLineNumbers);
250fe6060f1SDimitry Andric IO.mapOptional("NumberOfRelocations", Sec.NumberOfRelocations);
251fe6060f1SDimitry Andric IO.mapOptional("NumberOfLineNumbers", Sec.NumberOfLineNumbers);
252fe6060f1SDimitry Andric IO.mapOptional("Flags", NC->Flags);
253*0fca6ea1SDimitry Andric IO.mapOptional("DWARFSectionSubtype", Sec.SectionSubtype);
254fe6060f1SDimitry Andric IO.mapOptional("SectionData", Sec.SectionData);
255fe6060f1SDimitry Andric IO.mapOptional("Relocations", Sec.Relocations);
2560b57cec5SDimitry Andric }
2570b57cec5SDimitry Andric
auxSymMapping(IO & IO,XCOFFYAML::CsectAuxEnt & AuxSym,bool Is64)25804eeddc0SDimitry Andric static void auxSymMapping(IO &IO, XCOFFYAML::CsectAuxEnt &AuxSym, bool Is64) {
25904eeddc0SDimitry Andric IO.mapOptional("ParameterHashIndex", AuxSym.ParameterHashIndex);
26004eeddc0SDimitry Andric IO.mapOptional("TypeChkSectNum", AuxSym.TypeChkSectNum);
26104eeddc0SDimitry Andric IO.mapOptional("SymbolAlignmentAndType", AuxSym.SymbolAlignmentAndType);
262*0fca6ea1SDimitry Andric IO.mapOptional("SymbolType", AuxSym.SymbolType);
263*0fca6ea1SDimitry Andric IO.mapOptional("SymbolAlignment", AuxSym.SymbolAlignment);
26404eeddc0SDimitry Andric IO.mapOptional("StorageMappingClass", AuxSym.StorageMappingClass);
26504eeddc0SDimitry Andric if (Is64) {
26604eeddc0SDimitry Andric IO.mapOptional("SectionOrLengthLo", AuxSym.SectionOrLengthLo);
26704eeddc0SDimitry Andric IO.mapOptional("SectionOrLengthHi", AuxSym.SectionOrLengthHi);
26804eeddc0SDimitry Andric } else {
26904eeddc0SDimitry Andric IO.mapOptional("SectionOrLength", AuxSym.SectionOrLength);
27004eeddc0SDimitry Andric IO.mapOptional("StabInfoIndex", AuxSym.StabInfoIndex);
27104eeddc0SDimitry Andric IO.mapOptional("StabSectNum", AuxSym.StabSectNum);
27204eeddc0SDimitry Andric }
27304eeddc0SDimitry Andric }
27404eeddc0SDimitry Andric
auxSymMapping(IO & IO,XCOFFYAML::FileAuxEnt & AuxSym)27504eeddc0SDimitry Andric static void auxSymMapping(IO &IO, XCOFFYAML::FileAuxEnt &AuxSym) {
27604eeddc0SDimitry Andric IO.mapOptional("FileNameOrString", AuxSym.FileNameOrString);
27704eeddc0SDimitry Andric IO.mapOptional("FileStringType", AuxSym.FileStringType);
27804eeddc0SDimitry Andric }
27904eeddc0SDimitry Andric
auxSymMapping(IO & IO,XCOFFYAML::BlockAuxEnt & AuxSym,bool Is64)28004eeddc0SDimitry Andric static void auxSymMapping(IO &IO, XCOFFYAML::BlockAuxEnt &AuxSym, bool Is64) {
28104eeddc0SDimitry Andric if (Is64) {
28204eeddc0SDimitry Andric IO.mapOptional("LineNum", AuxSym.LineNum);
28304eeddc0SDimitry Andric } else {
28404eeddc0SDimitry Andric IO.mapOptional("LineNumHi", AuxSym.LineNumHi);
28504eeddc0SDimitry Andric IO.mapOptional("LineNumLo", AuxSym.LineNumLo);
28604eeddc0SDimitry Andric }
28704eeddc0SDimitry Andric }
28804eeddc0SDimitry Andric
auxSymMapping(IO & IO,XCOFFYAML::FunctionAuxEnt & AuxSym,bool Is64)28904eeddc0SDimitry Andric static void auxSymMapping(IO &IO, XCOFFYAML::FunctionAuxEnt &AuxSym,
29004eeddc0SDimitry Andric bool Is64) {
29104eeddc0SDimitry Andric if (!Is64)
29204eeddc0SDimitry Andric IO.mapOptional("OffsetToExceptionTbl", AuxSym.OffsetToExceptionTbl);
29304eeddc0SDimitry Andric IO.mapOptional("SizeOfFunction", AuxSym.SizeOfFunction);
29404eeddc0SDimitry Andric IO.mapOptional("SymIdxOfNextBeyond", AuxSym.SymIdxOfNextBeyond);
29504eeddc0SDimitry Andric IO.mapOptional("PtrToLineNum", AuxSym.PtrToLineNum);
29604eeddc0SDimitry Andric }
29704eeddc0SDimitry Andric
auxSymMapping(IO & IO,XCOFFYAML::ExcpetionAuxEnt & AuxSym)29804eeddc0SDimitry Andric static void auxSymMapping(IO &IO, XCOFFYAML::ExcpetionAuxEnt &AuxSym) {
29904eeddc0SDimitry Andric IO.mapOptional("OffsetToExceptionTbl", AuxSym.OffsetToExceptionTbl);
30004eeddc0SDimitry Andric IO.mapOptional("SizeOfFunction", AuxSym.SizeOfFunction);
30104eeddc0SDimitry Andric IO.mapOptional("SymIdxOfNextBeyond", AuxSym.SymIdxOfNextBeyond);
30204eeddc0SDimitry Andric }
30304eeddc0SDimitry Andric
auxSymMapping(IO & IO,XCOFFYAML::SectAuxEntForDWARF & AuxSym)30404eeddc0SDimitry Andric static void auxSymMapping(IO &IO, XCOFFYAML::SectAuxEntForDWARF &AuxSym) {
30504eeddc0SDimitry Andric IO.mapOptional("LengthOfSectionPortion", AuxSym.LengthOfSectionPortion);
30604eeddc0SDimitry Andric IO.mapOptional("NumberOfRelocEnt", AuxSym.NumberOfRelocEnt);
30704eeddc0SDimitry Andric }
30804eeddc0SDimitry Andric
auxSymMapping(IO & IO,XCOFFYAML::SectAuxEntForStat & AuxSym)30904eeddc0SDimitry Andric static void auxSymMapping(IO &IO, XCOFFYAML::SectAuxEntForStat &AuxSym) {
31004eeddc0SDimitry Andric IO.mapOptional("SectionLength", AuxSym.SectionLength);
31104eeddc0SDimitry Andric IO.mapOptional("NumberOfRelocEnt", AuxSym.NumberOfRelocEnt);
31204eeddc0SDimitry Andric IO.mapOptional("NumberOfLineNum", AuxSym.NumberOfLineNum);
31304eeddc0SDimitry Andric }
31404eeddc0SDimitry Andric
3155f757f3fSDimitry Andric template <typename AuxEntT>
ResetAuxSym(IO & IO,std::unique_ptr<XCOFFYAML::AuxSymbolEnt> & AuxSym)3165f757f3fSDimitry Andric static void ResetAuxSym(IO &IO,
3175f757f3fSDimitry Andric std::unique_ptr<XCOFFYAML::AuxSymbolEnt> &AuxSym) {
3185f757f3fSDimitry Andric if (!IO.outputting())
3195f757f3fSDimitry Andric AuxSym.reset(new AuxEntT);
3205f757f3fSDimitry Andric }
3215f757f3fSDimitry Andric
mapping(IO & IO,std::unique_ptr<XCOFFYAML::AuxSymbolEnt> & AuxSym)32204eeddc0SDimitry Andric void MappingTraits<std::unique_ptr<XCOFFYAML::AuxSymbolEnt>>::mapping(
32304eeddc0SDimitry Andric IO &IO, std::unique_ptr<XCOFFYAML::AuxSymbolEnt> &AuxSym) {
32404eeddc0SDimitry Andric const bool Is64 =
32504eeddc0SDimitry Andric static_cast<XCOFFYAML::Object *>(IO.getContext())->Header.Magic ==
32604eeddc0SDimitry Andric (llvm::yaml::Hex16)XCOFF::XCOFF64;
3275f757f3fSDimitry Andric
32804eeddc0SDimitry Andric XCOFFYAML::AuxSymbolType AuxType;
3295f757f3fSDimitry Andric if (IO.outputting())
330*0fca6ea1SDimitry Andric AuxType = AuxSym->Type;
33104eeddc0SDimitry Andric IO.mapRequired("Type", AuxType);
33204eeddc0SDimitry Andric switch (AuxType) {
33304eeddc0SDimitry Andric case XCOFFYAML::AUX_EXCEPT:
3345f757f3fSDimitry Andric if (!Is64) {
33504eeddc0SDimitry Andric IO.setError("an auxiliary symbol of type AUX_EXCEPT cannot be defined in "
33604eeddc0SDimitry Andric "XCOFF32");
3375f757f3fSDimitry Andric return;
3385f757f3fSDimitry Andric }
3395f757f3fSDimitry Andric ResetAuxSym<XCOFFYAML::ExcpetionAuxEnt>(IO, AuxSym);
34004eeddc0SDimitry Andric auxSymMapping(IO, *cast<XCOFFYAML::ExcpetionAuxEnt>(AuxSym.get()));
34104eeddc0SDimitry Andric break;
34204eeddc0SDimitry Andric case XCOFFYAML::AUX_FCN:
3435f757f3fSDimitry Andric ResetAuxSym<XCOFFYAML::FunctionAuxEnt>(IO, AuxSym);
34404eeddc0SDimitry Andric auxSymMapping(IO, *cast<XCOFFYAML::FunctionAuxEnt>(AuxSym.get()), Is64);
34504eeddc0SDimitry Andric break;
34604eeddc0SDimitry Andric case XCOFFYAML::AUX_SYM:
3475f757f3fSDimitry Andric ResetAuxSym<XCOFFYAML::BlockAuxEnt>(IO, AuxSym);
34804eeddc0SDimitry Andric auxSymMapping(IO, *cast<XCOFFYAML::BlockAuxEnt>(AuxSym.get()), Is64);
34904eeddc0SDimitry Andric break;
35004eeddc0SDimitry Andric case XCOFFYAML::AUX_FILE:
3515f757f3fSDimitry Andric ResetAuxSym<XCOFFYAML::FileAuxEnt>(IO, AuxSym);
35204eeddc0SDimitry Andric auxSymMapping(IO, *cast<XCOFFYAML::FileAuxEnt>(AuxSym.get()));
35304eeddc0SDimitry Andric break;
35404eeddc0SDimitry Andric case XCOFFYAML::AUX_CSECT:
3555f757f3fSDimitry Andric ResetAuxSym<XCOFFYAML::CsectAuxEnt>(IO, AuxSym);
35604eeddc0SDimitry Andric auxSymMapping(IO, *cast<XCOFFYAML::CsectAuxEnt>(AuxSym.get()), Is64);
35704eeddc0SDimitry Andric break;
35804eeddc0SDimitry Andric case XCOFFYAML::AUX_SECT:
3595f757f3fSDimitry Andric ResetAuxSym<XCOFFYAML::SectAuxEntForDWARF>(IO, AuxSym);
36004eeddc0SDimitry Andric auxSymMapping(IO, *cast<XCOFFYAML::SectAuxEntForDWARF>(AuxSym.get()));
36104eeddc0SDimitry Andric break;
36204eeddc0SDimitry Andric case XCOFFYAML::AUX_STAT:
3635f757f3fSDimitry Andric if (Is64) {
36404eeddc0SDimitry Andric IO.setError(
36504eeddc0SDimitry Andric "an auxiliary symbol of type AUX_STAT cannot be defined in XCOFF64");
3665f757f3fSDimitry Andric return;
3675f757f3fSDimitry Andric }
3685f757f3fSDimitry Andric ResetAuxSym<XCOFFYAML::SectAuxEntForStat>(IO, AuxSym);
36904eeddc0SDimitry Andric auxSymMapping(IO, *cast<XCOFFYAML::SectAuxEntForStat>(AuxSym.get()));
37004eeddc0SDimitry Andric break;
37104eeddc0SDimitry Andric }
37204eeddc0SDimitry Andric }
37304eeddc0SDimitry Andric
mapping(IO & IO,XCOFFYAML::Symbol & S)3740b57cec5SDimitry Andric void MappingTraits<XCOFFYAML::Symbol>::mapping(IO &IO, XCOFFYAML::Symbol &S) {
375349cc55cSDimitry Andric IO.mapOptional("Name", S.SymbolName);
376fe6060f1SDimitry Andric IO.mapOptional("Value", S.Value);
377fe6060f1SDimitry Andric IO.mapOptional("Section", S.SectionName);
378349cc55cSDimitry Andric IO.mapOptional("SectionIndex", S.SectionIndex);
379fe6060f1SDimitry Andric IO.mapOptional("Type", S.Type);
380fe6060f1SDimitry Andric IO.mapOptional("StorageClass", S.StorageClass);
381fe6060f1SDimitry Andric IO.mapOptional("NumberOfAuxEntries", S.NumberOfAuxEntries);
38204eeddc0SDimitry Andric IO.mapOptional("AuxEntries", S.AuxEntries);
3830b57cec5SDimitry Andric }
3840b57cec5SDimitry Andric
mapping(IO & IO,XCOFFYAML::StringTable & Str)385*0fca6ea1SDimitry Andric void MappingTraits<XCOFFYAML::StringTable>::mapping(
386*0fca6ea1SDimitry Andric IO &IO, XCOFFYAML::StringTable &Str) {
387349cc55cSDimitry Andric IO.mapOptional("ContentSize", Str.ContentSize);
388349cc55cSDimitry Andric IO.mapOptional("Length", Str.Length);
389349cc55cSDimitry Andric IO.mapOptional("Strings", Str.Strings);
390349cc55cSDimitry Andric IO.mapOptional("RawContent", Str.RawContent);
391349cc55cSDimitry Andric }
392349cc55cSDimitry Andric
mapping(IO & IO,XCOFFYAML::Object & Obj)3930b57cec5SDimitry Andric void MappingTraits<XCOFFYAML::Object>::mapping(IO &IO, XCOFFYAML::Object &Obj) {
39404eeddc0SDimitry Andric IO.setContext(&Obj);
3950b57cec5SDimitry Andric IO.mapTag("!XCOFF", true);
3960b57cec5SDimitry Andric IO.mapRequired("FileHeader", Obj.Header);
397349cc55cSDimitry Andric IO.mapOptional("AuxiliaryHeader", Obj.AuxHeader);
398fe6060f1SDimitry Andric IO.mapOptional("Sections", Obj.Sections);
399fe6060f1SDimitry Andric IO.mapOptional("Symbols", Obj.Symbols);
400349cc55cSDimitry Andric IO.mapOptional("StringTable", Obj.StrTbl);
40104eeddc0SDimitry Andric IO.setContext(nullptr);
4020b57cec5SDimitry Andric }
4030b57cec5SDimitry Andric
4040b57cec5SDimitry Andric } // namespace yaml
4050b57cec5SDimitry Andric } // namespace llvm
406