1 //===-- XCOFFYAML.cpp - XCOFF YAMLIO implementation -------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
20 Object::Object() { memset(&Header
, 0, sizeof(Header
)); }
22 } // namespace XCOFFYAML
26 void ScalarBitSetTraits
<XCOFF::SectionTypeFlags
>::bitset(
27 IO
&IO
, XCOFF::SectionTypeFlags
&Value
) {
28 #define ECase(X) IO.bitSetCase(Value, #X, XCOFF::X)
45 void ScalarEnumerationTraits
<XCOFF::StorageClass
>::enumeration(
46 IO
&IO
, XCOFF::StorageClass
&Value
) {
47 #define ECase(X) IO.enumCase(Value, #X, XCOFF::X)
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
);