Bug Summary

File:include/llvm/ObjectYAML/ELFYAML.h
Warning:line 48, column 1
The left operand of '==' is a garbage value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ELFYAML.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/lib/ObjectYAML -I /build/llvm-toolchain-snapshot-8~svn345461/lib/ObjectYAML -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn345461/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/lib/ObjectYAML -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-10-27-211344-32123-1 -x c++ /build/llvm-toolchain-snapshot-8~svn345461/lib/ObjectYAML/ELFYAML.cpp -faddrsig

/build/llvm-toolchain-snapshot-8~svn345461/lib/ObjectYAML/ELFYAML.cpp

1//===- ELFYAML.cpp - ELF YAMLIO implementation ----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines classes for handling the YAML representation of ELF.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/ObjectYAML/ELFYAML.h"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/BinaryFormat/ELF.h"
17#include "llvm/Support/Casting.h"
18#include "llvm/Support/ErrorHandling.h"
19#include "llvm/Support/MipsABIFlags.h"
20#include "llvm/Support/YAMLTraits.h"
21#include <cassert>
22#include <cstdint>
23
24namespace llvm {
25
26ELFYAML::Section::~Section() = default;
27
28namespace yaml {
29
30void ScalarEnumerationTraits<ELFYAML::ELF_ET>::enumeration(
31 IO &IO, ELFYAML::ELF_ET &Value) {
32#define ECase(X) IO.enumCase(Value, #X, ELF::X)
33 ECase(ET_NONE);
34 ECase(ET_REL);
35 ECase(ET_EXEC);
36 ECase(ET_DYN);
37 ECase(ET_CORE);
38#undef ECase
39 IO.enumFallback<Hex16>(Value);
40}
41
42void ScalarEnumerationTraits<ELFYAML::ELF_PT>::enumeration(
43 IO &IO, ELFYAML::ELF_PT &Value) {
44#define ECase(X) IO.enumCase(Value, #X, ELF::X)
45 ECase(PT_NULL);
46 ECase(PT_LOAD);
47 ECase(PT_DYNAMIC);
48 ECase(PT_INTERP);
49 ECase(PT_NOTE);
50 ECase(PT_SHLIB);
51 ECase(PT_PHDR);
52 ECase(PT_TLS);
53 ECase(PT_GNU_EH_FRAME);
54#undef ECase
55 IO.enumFallback<Hex32>(Value);
56}
57
58void ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration(
59 IO &IO, ELFYAML::ELF_EM &Value) {
60#define ECase(X) IO.enumCase(Value, #X, ELF::X)
61 ECase(EM_NONE);
62 ECase(EM_M32);
63 ECase(EM_SPARC);
64 ECase(EM_386);
65 ECase(EM_68K);
66 ECase(EM_88K);
67 ECase(EM_IAMCU);
68 ECase(EM_860);
69 ECase(EM_MIPS);
70 ECase(EM_S370);
71 ECase(EM_MIPS_RS3_LE);
72 ECase(EM_PARISC);
73 ECase(EM_VPP500);
74 ECase(EM_SPARC32PLUS);
75 ECase(EM_960);
76 ECase(EM_PPC);
77 ECase(EM_PPC64);
78 ECase(EM_S390);
79 ECase(EM_SPU);
80 ECase(EM_V800);
81 ECase(EM_FR20);
82 ECase(EM_RH32);
83 ECase(EM_RCE);
84 ECase(EM_ARM);
85 ECase(EM_ALPHA);
86 ECase(EM_SH);
87 ECase(EM_SPARCV9);
88 ECase(EM_TRICORE);
89 ECase(EM_ARC);
90 ECase(EM_H8_300);
91 ECase(EM_H8_300H);
92 ECase(EM_H8S);
93 ECase(EM_H8_500);
94 ECase(EM_IA_64);
95 ECase(EM_MIPS_X);
96 ECase(EM_COLDFIRE);
97 ECase(EM_68HC12);
98 ECase(EM_MMA);
99 ECase(EM_PCP);
100 ECase(EM_NCPU);
101 ECase(EM_NDR1);
102 ECase(EM_STARCORE);
103 ECase(EM_ME16);
104 ECase(EM_ST100);
105 ECase(EM_TINYJ);
106 ECase(EM_X86_64);
107 ECase(EM_PDSP);
108 ECase(EM_PDP10);
109 ECase(EM_PDP11);
110 ECase(EM_FX66);
111 ECase(EM_ST9PLUS);
112 ECase(EM_ST7);
113 ECase(EM_68HC16);
114 ECase(EM_68HC11);
115 ECase(EM_68HC08);
116 ECase(EM_68HC05);
117 ECase(EM_SVX);
118 ECase(EM_ST19);
119 ECase(EM_VAX);
120 ECase(EM_CRIS);
121 ECase(EM_JAVELIN);
122 ECase(EM_FIREPATH);
123 ECase(EM_ZSP);
124 ECase(EM_MMIX);
125 ECase(EM_HUANY);
126 ECase(EM_PRISM);
127 ECase(EM_AVR);
128 ECase(EM_FR30);
129 ECase(EM_D10V);
130 ECase(EM_D30V);
131 ECase(EM_V850);
132 ECase(EM_M32R);
133 ECase(EM_MN10300);
134 ECase(EM_MN10200);
135 ECase(EM_PJ);
136 ECase(EM_OPENRISC);
137 ECase(EM_ARC_COMPACT);
138 ECase(EM_XTENSA);
139 ECase(EM_VIDEOCORE);
140 ECase(EM_TMM_GPP);
141 ECase(EM_NS32K);
142 ECase(EM_TPC);
143 ECase(EM_SNP1K);
144 ECase(EM_ST200);
145 ECase(EM_IP2K);
146 ECase(EM_MAX);
147 ECase(EM_CR);
148 ECase(EM_F2MC16);
149 ECase(EM_MSP430);
150 ECase(EM_BLACKFIN);
151 ECase(EM_SE_C33);
152 ECase(EM_SEP);
153 ECase(EM_ARCA);
154 ECase(EM_UNICORE);
155 ECase(EM_EXCESS);
156 ECase(EM_DXP);
157 ECase(EM_ALTERA_NIOS2);
158 ECase(EM_CRX);
159 ECase(EM_XGATE);
160 ECase(EM_C166);
161 ECase(EM_M16C);
162 ECase(EM_DSPIC30F);
163 ECase(EM_CE);
164 ECase(EM_M32C);
165 ECase(EM_TSK3000);
166 ECase(EM_RS08);
167 ECase(EM_SHARC);
168 ECase(EM_ECOG2);
169 ECase(EM_SCORE7);
170 ECase(EM_DSP24);
171 ECase(EM_VIDEOCORE3);
172 ECase(EM_LATTICEMICO32);
173 ECase(EM_SE_C17);
174 ECase(EM_TI_C6000);
175 ECase(EM_TI_C2000);
176 ECase(EM_TI_C5500);
177 ECase(EM_MMDSP_PLUS);
178 ECase(EM_CYPRESS_M8C);
179 ECase(EM_R32C);
180 ECase(EM_TRIMEDIA);
181 ECase(EM_HEXAGON);
182 ECase(EM_8051);
183 ECase(EM_STXP7X);
184 ECase(EM_NDS32);
185 ECase(EM_ECOG1);
186 ECase(EM_ECOG1X);
187 ECase(EM_MAXQ30);
188 ECase(EM_XIMO16);
189 ECase(EM_MANIK);
190 ECase(EM_CRAYNV2);
191 ECase(EM_RX);
192 ECase(EM_METAG);
193 ECase(EM_MCST_ELBRUS);
194 ECase(EM_ECOG16);
195 ECase(EM_CR16);
196 ECase(EM_ETPU);
197 ECase(EM_SLE9X);
198 ECase(EM_L10M);
199 ECase(EM_K10M);
200 ECase(EM_AARCH64);
201 ECase(EM_AVR32);
202 ECase(EM_STM8);
203 ECase(EM_TILE64);
204 ECase(EM_TILEPRO);
205 ECase(EM_CUDA);
206 ECase(EM_TILEGX);
207 ECase(EM_CLOUDSHIELD);
208 ECase(EM_COREA_1ST);
209 ECase(EM_COREA_2ND);
210 ECase(EM_ARC_COMPACT2);
211 ECase(EM_OPEN8);
212 ECase(EM_RL78);
213 ECase(EM_VIDEOCORE5);
214 ECase(EM_78KOR);
215 ECase(EM_56800EX);
216 ECase(EM_AMDGPU);
217 ECase(EM_RISCV);
218 ECase(EM_LANAI);
219 ECase(EM_BPF);
220#undef ECase
221}
222
223void ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS>::enumeration(
224 IO &IO, ELFYAML::ELF_ELFCLASS &Value) {
225#define ECase(X) IO.enumCase(Value, #X, ELF::X)
226 // Since the semantics of ELFCLASSNONE is "invalid", just don't accept it
227 // here.
228 ECase(ELFCLASS32);
229 ECase(ELFCLASS64);
230#undef ECase
231}
232
233void ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA>::enumeration(
234 IO &IO, ELFYAML::ELF_ELFDATA &Value) {
235#define ECase(X) IO.enumCase(Value, #X, ELF::X)
236 // Since the semantics of ELFDATANONE is "invalid", just don't accept it
237 // here.
238 ECase(ELFDATA2LSB);
239 ECase(ELFDATA2MSB);
240#undef ECase
241}
242
243void ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI>::enumeration(
244 IO &IO, ELFYAML::ELF_ELFOSABI &Value) {
245#define ECase(X) IO.enumCase(Value, #X, ELF::X)
246 ECase(ELFOSABI_NONE);
247 ECase(ELFOSABI_HPUX);
248 ECase(ELFOSABI_NETBSD);
249 ECase(ELFOSABI_GNU);
250 ECase(ELFOSABI_HURD);
251 ECase(ELFOSABI_SOLARIS);
252 ECase(ELFOSABI_AIX);
253 ECase(ELFOSABI_IRIX);
254 ECase(ELFOSABI_FREEBSD);
255 ECase(ELFOSABI_TRU64);
256 ECase(ELFOSABI_MODESTO);
257 ECase(ELFOSABI_OPENBSD);
258 ECase(ELFOSABI_OPENVMS);
259 ECase(ELFOSABI_NSK);
260 ECase(ELFOSABI_AROS);
261 ECase(ELFOSABI_FENIXOS);
262 ECase(ELFOSABI_CLOUDABI);
263 ECase(ELFOSABI_AMDGPU_HSA);
264 ECase(ELFOSABI_AMDGPU_PAL);
265 ECase(ELFOSABI_AMDGPU_MESA3D);
266 ECase(ELFOSABI_ARM);
267 ECase(ELFOSABI_C6000_ELFABI);
268 ECase(ELFOSABI_C6000_LINUX);
269 ECase(ELFOSABI_STANDALONE);
270#undef ECase
271}
272
273void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO,
274 ELFYAML::ELF_EF &Value) {
275 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
276 assert(Object && "The IO context is not initialized")((Object && "The IO context is not initialized") ? static_cast
<void> (0) : __assert_fail ("Object && \"The IO context is not initialized\""
, "/build/llvm-toolchain-snapshot-8~svn345461/lib/ObjectYAML/ELFYAML.cpp"
, 276, __PRETTY_FUNCTION__))
;
277#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
278#define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, ELF::X, ELF::M)
279 switch (Object->Header.Machine) {
280 case ELF::EM_ARM:
281 BCase(EF_ARM_SOFT_FLOAT);
282 BCase(EF_ARM_VFP_FLOAT);
283 BCaseMask(EF_ARM_EABI_UNKNOWN, EF_ARM_EABIMASK);
284 BCaseMask(EF_ARM_EABI_VER1, EF_ARM_EABIMASK);
285 BCaseMask(EF_ARM_EABI_VER2, EF_ARM_EABIMASK);
286 BCaseMask(EF_ARM_EABI_VER3, EF_ARM_EABIMASK);
287 BCaseMask(EF_ARM_EABI_VER4, EF_ARM_EABIMASK);
288 BCaseMask(EF_ARM_EABI_VER5, EF_ARM_EABIMASK);
289 break;
290 case ELF::EM_MIPS:
291 BCase(EF_MIPS_NOREORDER);
292 BCase(EF_MIPS_PIC);
293 BCase(EF_MIPS_CPIC);
294 BCase(EF_MIPS_ABI2);
295 BCase(EF_MIPS_32BITMODE);
296 BCase(EF_MIPS_FP64);
297 BCase(EF_MIPS_NAN2008);
298 BCase(EF_MIPS_MICROMIPS);
299 BCase(EF_MIPS_ARCH_ASE_M16);
300 BCase(EF_MIPS_ARCH_ASE_MDMX);
301 BCaseMask(EF_MIPS_ABI_O32, EF_MIPS_ABI);
302 BCaseMask(EF_MIPS_ABI_O64, EF_MIPS_ABI);
303 BCaseMask(EF_MIPS_ABI_EABI32, EF_MIPS_ABI);
304 BCaseMask(EF_MIPS_ABI_EABI64, EF_MIPS_ABI);
305 BCaseMask(EF_MIPS_MACH_3900, EF_MIPS_MACH);
306 BCaseMask(EF_MIPS_MACH_4010, EF_MIPS_MACH);
307 BCaseMask(EF_MIPS_MACH_4100, EF_MIPS_MACH);
308 BCaseMask(EF_MIPS_MACH_4650, EF_MIPS_MACH);
309 BCaseMask(EF_MIPS_MACH_4120, EF_MIPS_MACH);
310 BCaseMask(EF_MIPS_MACH_4111, EF_MIPS_MACH);
311 BCaseMask(EF_MIPS_MACH_SB1, EF_MIPS_MACH);
312 BCaseMask(EF_MIPS_MACH_OCTEON, EF_MIPS_MACH);
313 BCaseMask(EF_MIPS_MACH_XLR, EF_MIPS_MACH);
314 BCaseMask(EF_MIPS_MACH_OCTEON2, EF_MIPS_MACH);
315 BCaseMask(EF_MIPS_MACH_OCTEON3, EF_MIPS_MACH);
316 BCaseMask(EF_MIPS_MACH_5400, EF_MIPS_MACH);
317 BCaseMask(EF_MIPS_MACH_5900, EF_MIPS_MACH);
318 BCaseMask(EF_MIPS_MACH_5500, EF_MIPS_MACH);
319 BCaseMask(EF_MIPS_MACH_9000, EF_MIPS_MACH);
320 BCaseMask(EF_MIPS_MACH_LS2E, EF_MIPS_MACH);
321 BCaseMask(EF_MIPS_MACH_LS2F, EF_MIPS_MACH);
322 BCaseMask(EF_MIPS_MACH_LS3A, EF_MIPS_MACH);
323 BCaseMask(EF_MIPS_ARCH_1, EF_MIPS_ARCH);
324 BCaseMask(EF_MIPS_ARCH_2, EF_MIPS_ARCH);
325 BCaseMask(EF_MIPS_ARCH_3, EF_MIPS_ARCH);
326 BCaseMask(EF_MIPS_ARCH_4, EF_MIPS_ARCH);
327 BCaseMask(EF_MIPS_ARCH_5, EF_MIPS_ARCH);
328 BCaseMask(EF_MIPS_ARCH_32, EF_MIPS_ARCH);
329 BCaseMask(EF_MIPS_ARCH_64, EF_MIPS_ARCH);
330 BCaseMask(EF_MIPS_ARCH_32R2, EF_MIPS_ARCH);
331 BCaseMask(EF_MIPS_ARCH_64R2, EF_MIPS_ARCH);
332 BCaseMask(EF_MIPS_ARCH_32R6, EF_MIPS_ARCH);
333 BCaseMask(EF_MIPS_ARCH_64R6, EF_MIPS_ARCH);
334 break;
335 case ELF::EM_HEXAGON:
336 BCase(EF_HEXAGON_MACH_V2);
337 BCase(EF_HEXAGON_MACH_V3);
338 BCase(EF_HEXAGON_MACH_V4);
339 BCase(EF_HEXAGON_MACH_V5);
340 BCase(EF_HEXAGON_ISA_V2);
341 BCase(EF_HEXAGON_ISA_V3);
342 BCase(EF_HEXAGON_ISA_V4);
343 BCase(EF_HEXAGON_ISA_V5);
344 break;
345 case ELF::EM_AVR:
346 BCase(EF_AVR_ARCH_AVR1);
347 BCase(EF_AVR_ARCH_AVR2);
348 BCase(EF_AVR_ARCH_AVR25);
349 BCase(EF_AVR_ARCH_AVR3);
350 BCase(EF_AVR_ARCH_AVR31);
351 BCase(EF_AVR_ARCH_AVR35);
352 BCase(EF_AVR_ARCH_AVR4);
353 BCase(EF_AVR_ARCH_AVR51);
354 BCase(EF_AVR_ARCH_AVR6);
355 BCase(EF_AVR_ARCH_AVRTINY);
356 BCase(EF_AVR_ARCH_XMEGA1);
357 BCase(EF_AVR_ARCH_XMEGA2);
358 BCase(EF_AVR_ARCH_XMEGA3);
359 BCase(EF_AVR_ARCH_XMEGA4);
360 BCase(EF_AVR_ARCH_XMEGA5);
361 BCase(EF_AVR_ARCH_XMEGA6);
362 BCase(EF_AVR_ARCH_XMEGA7);
363 break;
364 case ELF::EM_RISCV:
365 BCase(EF_RISCV_RVC);
366 BCaseMask(EF_RISCV_FLOAT_ABI_SOFT, EF_RISCV_FLOAT_ABI);
367 BCaseMask(EF_RISCV_FLOAT_ABI_SINGLE, EF_RISCV_FLOAT_ABI);
368 BCaseMask(EF_RISCV_FLOAT_ABI_DOUBLE, EF_RISCV_FLOAT_ABI);
369 BCaseMask(EF_RISCV_FLOAT_ABI_QUAD, EF_RISCV_FLOAT_ABI);
370 BCase(EF_RISCV_RVE);
371 break;
372 case ELF::EM_AMDGPU:
373 BCaseMask(EF_AMDGPU_MACH_NONE, EF_AMDGPU_MACH);
374 BCaseMask(EF_AMDGPU_MACH_R600_R600, EF_AMDGPU_MACH);
375 BCaseMask(EF_AMDGPU_MACH_R600_R630, EF_AMDGPU_MACH);
376 BCaseMask(EF_AMDGPU_MACH_R600_RS880, EF_AMDGPU_MACH);
377 BCaseMask(EF_AMDGPU_MACH_R600_RV670, EF_AMDGPU_MACH);
378 BCaseMask(EF_AMDGPU_MACH_R600_RV710, EF_AMDGPU_MACH);
379 BCaseMask(EF_AMDGPU_MACH_R600_RV730, EF_AMDGPU_MACH);
380 BCaseMask(EF_AMDGPU_MACH_R600_RV770, EF_AMDGPU_MACH);
381 BCaseMask(EF_AMDGPU_MACH_R600_CEDAR, EF_AMDGPU_MACH);
382 BCaseMask(EF_AMDGPU_MACH_R600_CYPRESS, EF_AMDGPU_MACH);
383 BCaseMask(EF_AMDGPU_MACH_R600_JUNIPER, EF_AMDGPU_MACH);
384 BCaseMask(EF_AMDGPU_MACH_R600_REDWOOD, EF_AMDGPU_MACH);
385 BCaseMask(EF_AMDGPU_MACH_R600_SUMO, EF_AMDGPU_MACH);
386 BCaseMask(EF_AMDGPU_MACH_R600_BARTS, EF_AMDGPU_MACH);
387 BCaseMask(EF_AMDGPU_MACH_R600_CAICOS, EF_AMDGPU_MACH);
388 BCaseMask(EF_AMDGPU_MACH_R600_CAYMAN, EF_AMDGPU_MACH);
389 BCaseMask(EF_AMDGPU_MACH_R600_TURKS, EF_AMDGPU_MACH);
390 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX600, EF_AMDGPU_MACH);
391 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX601, EF_AMDGPU_MACH);
392 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX700, EF_AMDGPU_MACH);
393 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX701, EF_AMDGPU_MACH);
394 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX702, EF_AMDGPU_MACH);
395 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX703, EF_AMDGPU_MACH);
396 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX704, EF_AMDGPU_MACH);
397 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX801, EF_AMDGPU_MACH);
398 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX802, EF_AMDGPU_MACH);
399 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX803, EF_AMDGPU_MACH);
400 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX810, EF_AMDGPU_MACH);
401 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX900, EF_AMDGPU_MACH);
402 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX902, EF_AMDGPU_MACH);
403 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX904, EF_AMDGPU_MACH);
404 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX906, EF_AMDGPU_MACH);
405 BCaseMask(EF_AMDGPU_MACH_AMDGCN_GFX909, EF_AMDGPU_MACH);
406 BCase(EF_AMDGPU_XNACK);
407 break;
408 case ELF::EM_X86_64:
409 break;
410 default:
411 llvm_unreachable("Unsupported architecture")::llvm::llvm_unreachable_internal("Unsupported architecture",
"/build/llvm-toolchain-snapshot-8~svn345461/lib/ObjectYAML/ELFYAML.cpp"
, 411)
;
412 }
413#undef BCase
414#undef BCaseMask
415}
416
417void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
418 IO &IO, ELFYAML::ELF_SHT &Value) {
419 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
420 assert(Object && "The IO context is not initialized")((Object && "The IO context is not initialized") ? static_cast
<void> (0) : __assert_fail ("Object && \"The IO context is not initialized\""
, "/build/llvm-toolchain-snapshot-8~svn345461/lib/ObjectYAML/ELFYAML.cpp"
, 420, __PRETTY_FUNCTION__))
;
12
Within the expansion of the macro 'assert':
a
Assuming 'Object' is non-null
421#define ECase(X) IO.enumCase(Value, #X, ELF::X)
422 ECase(SHT_NULL);
13
Within the expansion of the macro 'ECase':
a
Calling 'IO::enumCase'
423 ECase(SHT_PROGBITS);
424 ECase(SHT_SYMTAB);
425 // FIXME: Issue a diagnostic with this information.
426 ECase(SHT_STRTAB);
427 ECase(SHT_RELA);
428 ECase(SHT_HASH);
429 ECase(SHT_DYNAMIC);
430 ECase(SHT_NOTE);
431 ECase(SHT_NOBITS);
432 ECase(SHT_REL);
433 ECase(SHT_SHLIB);
434 ECase(SHT_DYNSYM);
435 ECase(SHT_INIT_ARRAY);
436 ECase(SHT_FINI_ARRAY);
437 ECase(SHT_PREINIT_ARRAY);
438 ECase(SHT_GROUP);
439 ECase(SHT_SYMTAB_SHNDX);
440 ECase(SHT_RELR);
441 ECase(SHT_LOOS);
442 ECase(SHT_ANDROID_REL);
443 ECase(SHT_ANDROID_RELA);
444 ECase(SHT_ANDROID_RELR);
445 ECase(SHT_LLVM_ODRTAB);
446 ECase(SHT_LLVM_LINKER_OPTIONS);
447 ECase(SHT_LLVM_CALL_GRAPH_PROFILE);
448 ECase(SHT_LLVM_ADDRSIG);
449 ECase(SHT_GNU_ATTRIBUTES);
450 ECase(SHT_GNU_HASH);
451 ECase(SHT_GNU_verdef);
452 ECase(SHT_GNU_verneed);
453 ECase(SHT_GNU_versym);
454 ECase(SHT_HIOS);
455 ECase(SHT_LOPROC);
456 switch (Object->Header.Machine) {
457 case ELF::EM_ARM:
458 ECase(SHT_ARM_EXIDX);
459 ECase(SHT_ARM_PREEMPTMAP);
460 ECase(SHT_ARM_ATTRIBUTES);
461 ECase(SHT_ARM_DEBUGOVERLAY);
462 ECase(SHT_ARM_OVERLAYSECTION);
463 break;
464 case ELF::EM_HEXAGON:
465 ECase(SHT_HEX_ORDERED);
466 break;
467 case ELF::EM_X86_64:
468 ECase(SHT_X86_64_UNWIND);
469 break;
470 case ELF::EM_MIPS:
471 ECase(SHT_MIPS_REGINFO);
472 ECase(SHT_MIPS_OPTIONS);
473 ECase(SHT_MIPS_ABIFLAGS);
474 break;
475 default:
476 // Nothing to do.
477 break;
478 }
479#undef ECase
480}
481
482void ScalarBitSetTraits<ELFYAML::ELF_PF>::bitset(IO &IO,
483 ELFYAML::ELF_PF &Value) {
484#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
485 BCase(PF_X);
486 BCase(PF_W);
487 BCase(PF_R);
488}
489
490void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO,
491 ELFYAML::ELF_SHF &Value) {
492 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
493#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
494 BCase(SHF_WRITE);
495 BCase(SHF_ALLOC);
496 BCase(SHF_EXCLUDE);
497 BCase(SHF_EXECINSTR);
498 BCase(SHF_MERGE);
499 BCase(SHF_STRINGS);
500 BCase(SHF_INFO_LINK);
501 BCase(SHF_LINK_ORDER);
502 BCase(SHF_OS_NONCONFORMING);
503 BCase(SHF_GROUP);
504 BCase(SHF_TLS);
505 BCase(SHF_COMPRESSED);
506 switch (Object->Header.Machine) {
507 case ELF::EM_ARM:
508 BCase(SHF_ARM_PURECODE);
509 break;
510 case ELF::EM_HEXAGON:
511 BCase(SHF_HEX_GPREL);
512 break;
513 case ELF::EM_MIPS:
514 BCase(SHF_MIPS_NODUPES);
515 BCase(SHF_MIPS_NAMES);
516 BCase(SHF_MIPS_LOCAL);
517 BCase(SHF_MIPS_NOSTRIP);
518 BCase(SHF_MIPS_GPREL);
519 BCase(SHF_MIPS_MERGE);
520 BCase(SHF_MIPS_ADDR);
521 BCase(SHF_MIPS_STRING);
522 break;
523 case ELF::EM_X86_64:
524 BCase(SHF_X86_64_LARGE);
525 break;
526 default:
527 // Nothing to do.
528 break;
529 }
530#undef BCase
531}
532
533void ScalarEnumerationTraits<ELFYAML::ELF_SHN>::enumeration(
534 IO &IO, ELFYAML::ELF_SHN &Value) {
535#define ECase(X) IO.enumCase(Value, #X, ELF::X)
536 ECase(SHN_UNDEF);
537 ECase(SHN_LORESERVE);
538 ECase(SHN_LOPROC);
539 ECase(SHN_HIPROC);
540 ECase(SHN_LOOS);
541 ECase(SHN_HIOS);
542 ECase(SHN_ABS);
543 ECase(SHN_COMMON);
544 ECase(SHN_XINDEX);
545 ECase(SHN_HIRESERVE);
546 ECase(SHN_HEXAGON_SCOMMON);
547 ECase(SHN_HEXAGON_SCOMMON_1);
548 ECase(SHN_HEXAGON_SCOMMON_2);
549 ECase(SHN_HEXAGON_SCOMMON_4);
550 ECase(SHN_HEXAGON_SCOMMON_8);
551#undef ECase
552 IO.enumFallback<Hex32>(Value);
553}
554
555void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
556 IO &IO, ELFYAML::ELF_STT &Value) {
557#define ECase(X) IO.enumCase(Value, #X, ELF::X)
558 ECase(STT_NOTYPE);
559 ECase(STT_OBJECT);
560 ECase(STT_FUNC);
561 ECase(STT_SECTION);
562 ECase(STT_FILE);
563 ECase(STT_COMMON);
564 ECase(STT_TLS);
565 ECase(STT_GNU_IFUNC);
566#undef ECase
567}
568
569void ScalarEnumerationTraits<ELFYAML::ELF_STV>::enumeration(
570 IO &IO, ELFYAML::ELF_STV &Value) {
571#define ECase(X) IO.enumCase(Value, #X, ELF::X)
572 ECase(STV_DEFAULT);
573 ECase(STV_INTERNAL);
574 ECase(STV_HIDDEN);
575 ECase(STV_PROTECTED);
576#undef ECase
577}
578
579void ScalarBitSetTraits<ELFYAML::ELF_STO>::bitset(IO &IO,
580 ELFYAML::ELF_STO &Value) {
581 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
582 assert(Object && "The IO context is not initialized")((Object && "The IO context is not initialized") ? static_cast
<void> (0) : __assert_fail ("Object && \"The IO context is not initialized\""
, "/build/llvm-toolchain-snapshot-8~svn345461/lib/ObjectYAML/ELFYAML.cpp"
, 582, __PRETTY_FUNCTION__))
;
583#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
584 switch (Object->Header.Machine) {
585 case ELF::EM_MIPS:
586 BCase(STO_MIPS_OPTIONAL);
587 BCase(STO_MIPS_PLT);
588 BCase(STO_MIPS_PIC);
589 BCase(STO_MIPS_MICROMIPS);
590 break;
591 default:
592 break; // Nothing to do
593 }
594#undef BCase
595#undef BCaseMask
596}
597
598void ScalarEnumerationTraits<ELFYAML::ELF_RSS>::enumeration(
599 IO &IO, ELFYAML::ELF_RSS &Value) {
600#define ECase(X) IO.enumCase(Value, #X, ELF::X)
601 ECase(RSS_UNDEF);
602 ECase(RSS_GP);
603 ECase(RSS_GP0);
604 ECase(RSS_LOC);
605#undef ECase
606}
607
608void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
609 IO &IO, ELFYAML::ELF_REL &Value) {
610 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
611 assert(Object && "The IO context is not initialized")((Object && "The IO context is not initialized") ? static_cast
<void> (0) : __assert_fail ("Object && \"The IO context is not initialized\""
, "/build/llvm-toolchain-snapshot-8~svn345461/lib/ObjectYAML/ELFYAML.cpp"
, 611, __PRETTY_FUNCTION__))
;
612#define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
613 switch (Object->Header.Machine) {
614 case ELF::EM_X86_64:
615#include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
616 break;
617 case ELF::EM_MIPS:
618#include "llvm/BinaryFormat/ELFRelocs/Mips.def"
619 break;
620 case ELF::EM_HEXAGON:
621#include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
622 break;
623 case ELF::EM_386:
624 case ELF::EM_IAMCU:
625#include "llvm/BinaryFormat/ELFRelocs/i386.def"
626 break;
627 case ELF::EM_AARCH64:
628#include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
629 break;
630 case ELF::EM_ARM:
631#include "llvm/BinaryFormat/ELFRelocs/ARM.def"
632 break;
633 case ELF::EM_ARC:
634#include "llvm/BinaryFormat/ELFRelocs/ARC.def"
635 break;
636 case ELF::EM_RISCV:
637#include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
638 break;
639 case ELF::EM_LANAI:
640#include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
641 break;
642 case ELF::EM_AMDGPU:
643#include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
644 break;
645 case ELF::EM_BPF:
646#include "llvm/BinaryFormat/ELFRelocs/BPF.def"
647 break;
648 default:
649 llvm_unreachable("Unsupported architecture")::llvm::llvm_unreachable_internal("Unsupported architecture",
"/build/llvm-toolchain-snapshot-8~svn345461/lib/ObjectYAML/ELFYAML.cpp"
, 649)
;
650 }
651#undef ELF_RELOC
652 IO.enumFallback<Hex32>(Value);
653}
654
655void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG>::enumeration(
656 IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
657#define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
658 ECase(REG_NONE);
659 ECase(REG_32);
660 ECase(REG_64);
661 ECase(REG_128);
662#undef ECase
663}
664
665void ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP>::enumeration(
666 IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
667#define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
668 ECase(FP_ANY);
669 ECase(FP_DOUBLE);
670 ECase(FP_SINGLE);
671 ECase(FP_SOFT);
672 ECase(FP_OLD_64);
673 ECase(FP_XX);
674 ECase(FP_64);
675 ECase(FP_64A);
676#undef ECase
677}
678
679void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT>::enumeration(
680 IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
681#define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
682 ECase(EXT_NONE);
683 ECase(EXT_XLR);
684 ECase(EXT_OCTEON2);
685 ECase(EXT_OCTEONP);
686 ECase(EXT_LOONGSON_3A);
687 ECase(EXT_OCTEON);
688 ECase(EXT_5900);
689 ECase(EXT_4650);
690 ECase(EXT_4010);
691 ECase(EXT_4100);
692 ECase(EXT_3900);
693 ECase(EXT_10000);
694 ECase(EXT_SB1);
695 ECase(EXT_4111);
696 ECase(EXT_4120);
697 ECase(EXT_5400);
698 ECase(EXT_5500);
699 ECase(EXT_LOONGSON_2E);
700 ECase(EXT_LOONGSON_2F);
701 ECase(EXT_OCTEON3);
702#undef ECase
703}
704
705void ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration(
706 IO &IO, ELFYAML::MIPS_ISA &Value) {
707 IO.enumCase(Value, "MIPS1", 1);
708 IO.enumCase(Value, "MIPS2", 2);
709 IO.enumCase(Value, "MIPS3", 3);
710 IO.enumCase(Value, "MIPS4", 4);
711 IO.enumCase(Value, "MIPS5", 5);
712 IO.enumCase(Value, "MIPS32", 32);
713 IO.enumCase(Value, "MIPS64", 64);
714}
715
716void ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE>::bitset(
717 IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
718#define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
719 BCase(DSP);
720 BCase(DSPR2);
721 BCase(EVA);
722 BCase(MCU);
723 BCase(MDMX);
724 BCase(MIPS3D);
725 BCase(MT);
726 BCase(SMARTMIPS);
727 BCase(VIRT);
728 BCase(MSA);
729 BCase(MIPS16);
730 BCase(MICROMIPS);
731 BCase(XPA);
732#undef BCase
733}
734
735void ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1>::bitset(
736 IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
737#define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
738 BCase(ODDSPREG);
739#undef BCase
740}
741
742void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
743 ELFYAML::FileHeader &FileHdr) {
744 IO.mapRequired("Class", FileHdr.Class);
745 IO.mapRequired("Data", FileHdr.Data);
746 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
747 IO.mapRequired("Type", FileHdr.Type);
748 IO.mapRequired("Machine", FileHdr.Machine);
749 IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
750 IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
751}
752
753void MappingTraits<ELFYAML::ProgramHeader>::mapping(
754 IO &IO, ELFYAML::ProgramHeader &Phdr) {
755 IO.mapRequired("Type", Phdr.Type);
756 IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
757 IO.mapOptional("Sections", Phdr.Sections);
758 IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
759 IO.mapOptional("PAddr", Phdr.PAddr, Hex64(0));
760 IO.mapOptional("Align", Phdr.Align);
761}
762
763namespace {
764
765struct NormalizedOther {
766 NormalizedOther(IO &)
767 : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
768 NormalizedOther(IO &, uint8_t Original)
769 : Visibility(Original & 0x3), Other(Original & ~0x3) {}
770
771 uint8_t denormalize(IO &) { return Visibility | Other; }
772
773 ELFYAML::ELF_STV Visibility;
774 ELFYAML::ELF_STO Other;
775};
776
777} // end anonymous namespace
778
779void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
780 IO.mapOptional("Name", Symbol.Name, StringRef());
781 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
782 IO.mapOptional("Section", Symbol.Section, StringRef());
783 IO.mapOptional("Index", Symbol.Index);
784 IO.mapOptional("Value", Symbol.Value, Hex64(0));
785 IO.mapOptional("Size", Symbol.Size, Hex64(0));
786
787 MappingNormalization<NormalizedOther, uint8_t> Keys(IO, Symbol.Other);
788 IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
789 IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
790}
791
792StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
793 ELFYAML::Symbol &Symbol) {
794 if (Symbol.Index && Symbol.Section.data()) {
795 return "Index and Section cannot both be specified for Symbol";
796 }
797 if (Symbol.Index && *Symbol.Index == ELFYAML::ELF_SHN(ELF::SHN_XINDEX)) {
798 return "Large indexes are not supported";
799 }
800 if (Symbol.Index && *Symbol.Index < ELFYAML::ELF_SHN(ELF::SHN_LORESERVE)) {
801 return "Use a section name to define which section a symbol is defined in";
802 }
803 return StringRef();
804}
805
806void MappingTraits<ELFYAML::LocalGlobalWeakSymbols>::mapping(
807 IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) {
808 IO.mapOptional("Local", Symbols.Local);
809 IO.mapOptional("Global", Symbols.Global);
810 IO.mapOptional("Weak", Symbols.Weak);
811}
812
813static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
814 IO.mapOptional("Name", Section.Name, StringRef());
815 IO.mapRequired("Type", Section.Type);
816 IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
817 IO.mapOptional("Address", Section.Address, Hex64(0));
818 IO.mapOptional("Link", Section.Link, StringRef());
819 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
820 IO.mapOptional("EntSize", Section.EntSize);
821 IO.mapOptional("Info", Section.Info, StringRef());
822}
823
824static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
825 commonSectionMapping(IO, Section);
826 IO.mapOptional("Content", Section.Content);
827 IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
828}
829
830static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {
831 commonSectionMapping(IO, Section);
832 IO.mapOptional("Size", Section.Size, Hex64(0));
833}
834
835static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
836 commonSectionMapping(IO, Section);
837 IO.mapOptional("Relocations", Section.Relocations);
838}
839
840static void groupSectionMapping(IO &IO, ELFYAML::Group &group) {
841 commonSectionMapping(IO, group);
842 IO.mapRequired("Members", group.Members);
843}
844
845void MappingTraits<ELFYAML::SectionOrType>::mapping(
846 IO &IO, ELFYAML::SectionOrType &sectionOrType) {
847 IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
848}
849
850void MappingTraits<ELFYAML::SectionName>::mapping(
851 IO &IO, ELFYAML::SectionName &sectionName) {
852 IO.mapRequired("Section", sectionName.Section);
853}
854
855static void sectionMapping(IO &IO, ELFYAML::MipsABIFlags &Section) {
856 commonSectionMapping(IO, Section);
857 IO.mapOptional("Version", Section.Version, Hex16(0));
858 IO.mapRequired("ISA", Section.ISALevel);
859 IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
860 IO.mapOptional("ISAExtension", Section.ISAExtension,
861 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
862 IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
863 IO.mapOptional("FpABI", Section.FpABI,
864 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
865 IO.mapOptional("GPRSize", Section.GPRSize,
866 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
867 IO.mapOptional("CPR1Size", Section.CPR1Size,
868 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
869 IO.mapOptional("CPR2Size", Section.CPR2Size,
870 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
871 IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
872 IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
873}
874
875void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping(
876 IO &IO, std::unique_ptr<ELFYAML::Section> &Section) {
877 ELFYAML::ELF_SHT sectionType;
1
Calling defaulted default constructor for 'ELF_SHT'
3
Returning from default constructor for 'ELF_SHT'
878 if (IO.outputting())
4
Assuming the condition is false
5
Taking false branch
879 sectionType = Section->Type;
880 else
881 IO.mapRequired("Type", sectionType);
6
Calling 'IO::mapRequired'
882
883 switch (sectionType) {
884 case ELF::SHT_REL:
885 case ELF::SHT_RELA:
886 if (!IO.outputting())
887 Section.reset(new ELFYAML::RelocationSection());
888 sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
889 break;
890 case ELF::SHT_GROUP:
891 if (!IO.outputting())
892 Section.reset(new ELFYAML::Group());
893 groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get()));
894 break;
895 case ELF::SHT_NOBITS:
896 if (!IO.outputting())
897 Section.reset(new ELFYAML::NoBitsSection());
898 sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
899 break;
900 case ELF::SHT_MIPS_ABIFLAGS:
901 if (!IO.outputting())
902 Section.reset(new ELFYAML::MipsABIFlags());
903 sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
904 break;
905 default:
906 if (!IO.outputting())
907 Section.reset(new ELFYAML::RawContentSection());
908 sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get()));
909 }
910}
911
912StringRef MappingTraits<std::unique_ptr<ELFYAML::Section>>::validate(
913 IO &io, std::unique_ptr<ELFYAML::Section> &Section) {
914 const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get());
915 if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
916 return StringRef();
917 return "Section size must be greater or equal to the content size";
918}
919
920namespace {
921
922struct NormalizedMips64RelType {
923 NormalizedMips64RelType(IO &)
924 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
925 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
926 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
927 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
928 NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
929 : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
930 Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
931
932 ELFYAML::ELF_REL denormalize(IO &) {
933 ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
934 return Res;
935 }
936
937 ELFYAML::ELF_REL Type;
938 ELFYAML::ELF_REL Type2;
939 ELFYAML::ELF_REL Type3;
940 ELFYAML::ELF_RSS SpecSym;
941};
942
943} // end anonymous namespace
944
945void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
946 ELFYAML::Relocation &Rel) {
947 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
948 assert(Object && "The IO context is not initialized")((Object && "The IO context is not initialized") ? static_cast
<void> (0) : __assert_fail ("Object && \"The IO context is not initialized\""
, "/build/llvm-toolchain-snapshot-8~svn345461/lib/ObjectYAML/ELFYAML.cpp"
, 948, __PRETTY_FUNCTION__))
;
949
950 IO.mapRequired("Offset", Rel.Offset);
951 IO.mapOptional("Symbol", Rel.Symbol);
952
953 if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
954 Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
955 MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key(
956 IO, Rel.Type);
957 IO.mapRequired("Type", Key->Type);
958 IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
959 IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
960 IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
961 } else
962 IO.mapRequired("Type", Rel.Type);
963
964 IO.mapOptional("Addend", Rel.Addend, (int64_t)0);
965}
966
967void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) {
968 assert(!IO.getContext() && "The IO context is initialized already")((!IO.getContext() && "The IO context is initialized already"
) ? static_cast<void> (0) : __assert_fail ("!IO.getContext() && \"The IO context is initialized already\""
, "/build/llvm-toolchain-snapshot-8~svn345461/lib/ObjectYAML/ELFYAML.cpp"
, 968, __PRETTY_FUNCTION__))
;
969 IO.setContext(&Object);
970 IO.mapTag("!ELF", true);
971 IO.mapRequired("FileHeader", Object.Header);
972 IO.mapOptional("ProgramHeaders", Object.ProgramHeaders);
973 IO.mapOptional("Sections", Object.Sections);
974 IO.mapOptional("Symbols", Object.Symbols);
975 IO.mapOptional("DynamicSymbols", Object.DynamicSymbols);
976 IO.setContext(nullptr);
977}
978
979LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)struct MIPS_AFL_REG { MIPS_AFL_REG() = default; MIPS_AFL_REG(
const uint8_t v) : value(v) {} MIPS_AFL_REG(const MIPS_AFL_REG
&v) = default; MIPS_AFL_REG &operator=(const MIPS_AFL_REG
&rhs) = default; MIPS_AFL_REG &operator=(const uint8_t
&rhs) { value = rhs; return *this; } operator const uint8_t
& () const { return value; } bool operator==(const MIPS_AFL_REG
&rhs) const { return value == rhs.value; } bool operator
==(const uint8_t &rhs) const { return value == rhs; } bool
operator<(const MIPS_AFL_REG &rhs) const { return value
< rhs.value; } uint8_t value; using BaseType = uint8_t; }
;
980LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)struct MIPS_ABI_FP { MIPS_ABI_FP() = default; MIPS_ABI_FP(const
uint8_t v) : value(v) {} MIPS_ABI_FP(const MIPS_ABI_FP &
v) = default; MIPS_ABI_FP &operator=(const MIPS_ABI_FP &
rhs) = default; MIPS_ABI_FP &operator=(const uint8_t &
rhs) { value = rhs; return *this; } operator const uint8_t &
() const { return value; } bool operator==(const MIPS_ABI_FP
&rhs) const { return value == rhs.value; } bool operator
==(const uint8_t &rhs) const { return value == rhs; } bool
operator<(const MIPS_ABI_FP &rhs) const { return value
< rhs.value; } uint8_t value; using BaseType = uint8_t; }
;
981LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)struct MIPS_AFL_EXT { MIPS_AFL_EXT() = default; MIPS_AFL_EXT(
const uint32_t v) : value(v) {} MIPS_AFL_EXT(const MIPS_AFL_EXT
&v) = default; MIPS_AFL_EXT &operator=(const MIPS_AFL_EXT
&rhs) = default; MIPS_AFL_EXT &operator=(const uint32_t
&rhs) { value = rhs; return *this; } operator const uint32_t
& () const { return value; } bool operator==(const MIPS_AFL_EXT
&rhs) const { return value == rhs.value; } bool operator
==(const uint32_t &rhs) const { return value == rhs; } bool
operator<(const MIPS_AFL_EXT &rhs) const { return value
< rhs.value; } uint32_t value; using BaseType = uint32_t;
};
982LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)struct MIPS_AFL_ASE { MIPS_AFL_ASE() = default; MIPS_AFL_ASE(
const uint32_t v) : value(v) {} MIPS_AFL_ASE(const MIPS_AFL_ASE
&v) = default; MIPS_AFL_ASE &operator=(const MIPS_AFL_ASE
&rhs) = default; MIPS_AFL_ASE &operator=(const uint32_t
&rhs) { value = rhs; return *this; } operator const uint32_t
& () const { return value; } bool operator==(const MIPS_AFL_ASE
&rhs) const { return value == rhs.value; } bool operator
==(const uint32_t &rhs) const { return value == rhs; } bool
operator<(const MIPS_AFL_ASE &rhs) const { return value
< rhs.value; } uint32_t value; using BaseType = uint32_t;
};
983LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)struct MIPS_AFL_FLAGS1 { MIPS_AFL_FLAGS1() = default; MIPS_AFL_FLAGS1
(const uint32_t v) : value(v) {} MIPS_AFL_FLAGS1(const MIPS_AFL_FLAGS1
&v) = default; MIPS_AFL_FLAGS1 &operator=(const MIPS_AFL_FLAGS1
&rhs) = default; MIPS_AFL_FLAGS1 &operator=(const uint32_t
&rhs) { value = rhs; return *this; } operator const uint32_t
& () const { return value; } bool operator==(const MIPS_AFL_FLAGS1
&rhs) const { return value == rhs.value; } bool operator
==(const uint32_t &rhs) const { return value == rhs; } bool
operator<(const MIPS_AFL_FLAGS1 &rhs) const { return value
< rhs.value; } uint32_t value; using BaseType = uint32_t;
};
984
985} // end namespace yaml
986
987} // end namespace llvm

/build/llvm-toolchain-snapshot-8~svn345461/include/llvm/ObjectYAML/ELFYAML.h

1//===- ELFYAML.h - ELF YAMLIO implementation --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// This file declares classes for handling the YAML representation
12/// of ELF.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_OBJECTYAML_ELFYAML_H
17#define LLVM_OBJECTYAML_ELFYAML_H
18
19#include "llvm/ADT/StringRef.h"
20#include "llvm/ObjectYAML/YAML.h"
21#include "llvm/Support/YAMLTraits.h"
22#include <cstdint>
23#include <memory>
24#include <vector>
25
26namespace llvm {
27namespace ELFYAML {
28
29// These types are invariant across 32/64-bit ELF, so for simplicity just
30// directly give them their exact sizes. We don't need to worry about
31// endianness because these are just the types in the YAMLIO structures,
32// and are appropriately converted to the necessary endianness when
33// reading/generating binary object files.
34// The naming of these types is intended to be ELF_PREFIX, where PREFIX is
35// the common prefix of the respective constants. E.g. ELF_EM corresponds
36// to the `e_machine` constants, like `EM_X86_64`.
37// In the future, these would probably be better suited by C++11 enum
38// class's with appropriate fixed underlying type.
39LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_ET)struct ELF_ET { ELF_ET() = default; ELF_ET(const uint16_t v) :
value(v) {} ELF_ET(const ELF_ET &v) = default; ELF_ET &
operator=(const ELF_ET &rhs) = default; ELF_ET &operator
=(const uint16_t &rhs) { value = rhs; return *this; } operator
const uint16_t & () const { return value; } bool operator
==(const ELF_ET &rhs) const { return value == rhs.value; }
bool operator==(const uint16_t &rhs) const { return value
== rhs; } bool operator<(const ELF_ET &rhs) const { return
value < rhs.value; } uint16_t value; using BaseType = uint16_t
; };
40LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_PT)struct ELF_PT { ELF_PT() = default; ELF_PT(const uint32_t v) :
value(v) {} ELF_PT(const ELF_PT &v) = default; ELF_PT &
operator=(const ELF_PT &rhs) = default; ELF_PT &operator
=(const uint32_t &rhs) { value = rhs; return *this; } operator
const uint32_t & () const { return value; } bool operator
==(const ELF_PT &rhs) const { return value == rhs.value; }
bool operator==(const uint32_t &rhs) const { return value
== rhs; } bool operator<(const ELF_PT &rhs) const { return
value < rhs.value; } uint32_t value; using BaseType = uint32_t
; };
41LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM)struct ELF_EM { ELF_EM() = default; ELF_EM(const uint32_t v) :
value(v) {} ELF_EM(const ELF_EM &v) = default; ELF_EM &
operator=(const ELF_EM &rhs) = default; ELF_EM &operator
=(const uint32_t &rhs) { value = rhs; return *this; } operator
const uint32_t & () const { return value; } bool operator
==(const ELF_EM &rhs) const { return value == rhs.value; }
bool operator==(const uint32_t &rhs) const { return value
== rhs; } bool operator<(const ELF_EM &rhs) const { return
value < rhs.value; } uint32_t value; using BaseType = uint32_t
; };
42LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS)struct ELF_ELFCLASS { ELF_ELFCLASS() = default; ELF_ELFCLASS(
const uint8_t v) : value(v) {} ELF_ELFCLASS(const ELF_ELFCLASS
&v) = default; ELF_ELFCLASS &operator=(const ELF_ELFCLASS
&rhs) = default; ELF_ELFCLASS &operator=(const uint8_t
&rhs) { value = rhs; return *this; } operator const uint8_t
& () const { return value; } bool operator==(const ELF_ELFCLASS
&rhs) const { return value == rhs.value; } bool operator
==(const uint8_t &rhs) const { return value == rhs; } bool
operator<(const ELF_ELFCLASS &rhs) const { return value
< rhs.value; } uint8_t value; using BaseType = uint8_t; }
;
43LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA)struct ELF_ELFDATA { ELF_ELFDATA() = default; ELF_ELFDATA(const
uint8_t v) : value(v) {} ELF_ELFDATA(const ELF_ELFDATA &
v) = default; ELF_ELFDATA &operator=(const ELF_ELFDATA &
rhs) = default; ELF_ELFDATA &operator=(const uint8_t &
rhs) { value = rhs; return *this; } operator const uint8_t &
() const { return value; } bool operator==(const ELF_ELFDATA
&rhs) const { return value == rhs.value; } bool operator
==(const uint8_t &rhs) const { return value == rhs; } bool
operator<(const ELF_ELFDATA &rhs) const { return value
< rhs.value; } uint8_t value; using BaseType = uint8_t; }
;
44LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI)struct ELF_ELFOSABI { ELF_ELFOSABI() = default; ELF_ELFOSABI(
const uint8_t v) : value(v) {} ELF_ELFOSABI(const ELF_ELFOSABI
&v) = default; ELF_ELFOSABI &operator=(const ELF_ELFOSABI
&rhs) = default; ELF_ELFOSABI &operator=(const uint8_t
&rhs) { value = rhs; return *this; } operator const uint8_t
& () const { return value; } bool operator==(const ELF_ELFOSABI
&rhs) const { return value == rhs.value; } bool operator
==(const uint8_t &rhs) const { return value == rhs; } bool
operator<(const ELF_ELFOSABI &rhs) const { return value
< rhs.value; } uint8_t value; using BaseType = uint8_t; }
;
45// Just use 64, since it can hold 32-bit values too.
46LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_EF)struct ELF_EF { ELF_EF() = default; ELF_EF(const uint64_t v) :
value(v) {} ELF_EF(const ELF_EF &v) = default; ELF_EF &
operator=(const ELF_EF &rhs) = default; ELF_EF &operator
=(const uint64_t &rhs) { value = rhs; return *this; } operator
const uint64_t & () const { return value; } bool operator
==(const ELF_EF &rhs) const { return value == rhs.value; }
bool operator==(const uint64_t &rhs) const { return value
== rhs; } bool operator<(const ELF_EF &rhs) const { return
value < rhs.value; } uint64_t value; using BaseType = uint64_t
; };
47LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_PF)struct ELF_PF { ELF_PF() = default; ELF_PF(const uint32_t v) :
value(v) {} ELF_PF(const ELF_PF &v) = default; ELF_PF &
operator=(const ELF_PF &rhs) = default; ELF_PF &operator
=(const uint32_t &rhs) { value = rhs; return *this; } operator
const uint32_t & () const { return value; } bool operator
==(const ELF_PF &rhs) const { return value == rhs.value; }
bool operator==(const uint32_t &rhs) const { return value
== rhs; } bool operator<(const ELF_PF &rhs) const { return
value < rhs.value; } uint32_t value; using BaseType = uint32_t
; };
48LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT)struct ELF_SHT { ELF_SHT() = default; ELF_SHT(const uint32_t v
) : value(v) {} ELF_SHT(const ELF_SHT &v) = default; ELF_SHT
&operator=(const ELF_SHT &rhs) = default; ELF_SHT &
operator=(const uint32_t &rhs) { value = rhs; return *this
; } operator const uint32_t & () const { return value; } bool
operator==(const ELF_SHT &rhs) const { return value == rhs
.value; } bool operator==(const uint32_t &rhs) const { return
value == rhs; } bool operator<(const ELF_SHT &rhs) const
{ return value < rhs.value; } uint32_t value; using BaseType
= uint32_t; };
2
Within the expansion of the macro 'LLVM_YAML_STRONG_TYPEDEF':
a
Returning without writing to 'this->value'
16
Within the expansion of the macro 'LLVM_YAML_STRONG_TYPEDEF':
a
The left operand of '==' is a garbage value
49LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_REL)struct ELF_REL { ELF_REL() = default; ELF_REL(const uint32_t v
) : value(v) {} ELF_REL(const ELF_REL &v) = default; ELF_REL
&operator=(const ELF_REL &rhs) = default; ELF_REL &
operator=(const uint32_t &rhs) { value = rhs; return *this
; } operator const uint32_t & () const { return value; } bool
operator==(const ELF_REL &rhs) const { return value == rhs
.value; } bool operator==(const uint32_t &rhs) const { return
value == rhs; } bool operator<(const ELF_REL &rhs) const
{ return value < rhs.value; } uint32_t value; using BaseType
= uint32_t; };
50LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_RSS)struct ELF_RSS { ELF_RSS() = default; ELF_RSS(const uint8_t v
) : value(v) {} ELF_RSS(const ELF_RSS &v) = default; ELF_RSS
&operator=(const ELF_RSS &rhs) = default; ELF_RSS &
operator=(const uint8_t &rhs) { value = rhs; return *this
; } operator const uint8_t & () const { return value; } bool
operator==(const ELF_RSS &rhs) const { return value == rhs
.value; } bool operator==(const uint8_t &rhs) const { return
value == rhs; } bool operator<(const ELF_RSS &rhs) const
{ return value < rhs.value; } uint8_t value; using BaseType
= uint8_t; };
51// Just use 64, since it can hold 32-bit values too.
52LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)struct ELF_SHF { ELF_SHF() = default; ELF_SHF(const uint64_t v
) : value(v) {} ELF_SHF(const ELF_SHF &v) = default; ELF_SHF
&operator=(const ELF_SHF &rhs) = default; ELF_SHF &
operator=(const uint64_t &rhs) { value = rhs; return *this
; } operator const uint64_t & () const { return value; } bool
operator==(const ELF_SHF &rhs) const { return value == rhs
.value; } bool operator==(const uint64_t &rhs) const { return
value == rhs; } bool operator<(const ELF_SHF &rhs) const
{ return value < rhs.value; } uint64_t value; using BaseType
= uint64_t; };
53LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_SHN)struct ELF_SHN { ELF_SHN() = default; ELF_SHN(const uint16_t v
) : value(v) {} ELF_SHN(const ELF_SHN &v) = default; ELF_SHN
&operator=(const ELF_SHN &rhs) = default; ELF_SHN &
operator=(const uint16_t &rhs) { value = rhs; return *this
; } operator const uint16_t & () const { return value; } bool
operator==(const ELF_SHN &rhs) const { return value == rhs
.value; } bool operator==(const uint16_t &rhs) const { return
value == rhs; } bool operator<(const ELF_SHN &rhs) const
{ return value < rhs.value; } uint16_t value; using BaseType
= uint16_t; };
54LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)struct ELF_STT { ELF_STT() = default; ELF_STT(const uint8_t v
) : value(v) {} ELF_STT(const ELF_STT &v) = default; ELF_STT
&operator=(const ELF_STT &rhs) = default; ELF_STT &
operator=(const uint8_t &rhs) { value = rhs; return *this
; } operator const uint8_t & () const { return value; } bool
operator==(const ELF_STT &rhs) const { return value == rhs
.value; } bool operator==(const uint8_t &rhs) const { return
value == rhs; } bool operator<(const ELF_STT &rhs) const
{ return value < rhs.value; } uint8_t value; using BaseType
= uint8_t; };
55LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STV)struct ELF_STV { ELF_STV() = default; ELF_STV(const uint8_t v
) : value(v) {} ELF_STV(const ELF_STV &v) = default; ELF_STV
&operator=(const ELF_STV &rhs) = default; ELF_STV &
operator=(const uint8_t &rhs) { value = rhs; return *this
; } operator const uint8_t & () const { return value; } bool
operator==(const ELF_STV &rhs) const { return value == rhs
.value; } bool operator==(const uint8_t &rhs) const { return
value == rhs; } bool operator<(const ELF_STV &rhs) const
{ return value < rhs.value; } uint8_t value; using BaseType
= uint8_t; };
56LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STO)struct ELF_STO { ELF_STO() = default; ELF_STO(const uint8_t v
) : value(v) {} ELF_STO(const ELF_STO &v) = default; ELF_STO
&operator=(const ELF_STO &rhs) = default; ELF_STO &
operator=(const uint8_t &rhs) { value = rhs; return *this
; } operator const uint8_t & () const { return value; } bool
operator==(const ELF_STO &rhs) const { return value == rhs
.value; } bool operator==(const uint8_t &rhs) const { return
value == rhs; } bool operator<(const ELF_STO &rhs) const
{ return value < rhs.value; } uint8_t value; using BaseType
= uint8_t; };
57
58LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)struct MIPS_AFL_REG { MIPS_AFL_REG() = default; MIPS_AFL_REG(
const uint8_t v) : value(v) {} MIPS_AFL_REG(const MIPS_AFL_REG
&v) = default; MIPS_AFL_REG &operator=(const MIPS_AFL_REG
&rhs) = default; MIPS_AFL_REG &operator=(const uint8_t
&rhs) { value = rhs; return *this; } operator const uint8_t
& () const { return value; } bool operator==(const MIPS_AFL_REG
&rhs) const { return value == rhs.value; } bool operator
==(const uint8_t &rhs) const { return value == rhs; } bool
operator<(const MIPS_AFL_REG &rhs) const { return value
< rhs.value; } uint8_t value; using BaseType = uint8_t; }
;
59LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)struct MIPS_ABI_FP { MIPS_ABI_FP() = default; MIPS_ABI_FP(const
uint8_t v) : value(v) {} MIPS_ABI_FP(const MIPS_ABI_FP &
v) = default; MIPS_ABI_FP &operator=(const MIPS_ABI_FP &
rhs) = default; MIPS_ABI_FP &operator=(const uint8_t &
rhs) { value = rhs; return *this; } operator const uint8_t &
() const { return value; } bool operator==(const MIPS_ABI_FP
&rhs) const { return value == rhs.value; } bool operator
==(const uint8_t &rhs) const { return value == rhs; } bool
operator<(const MIPS_ABI_FP &rhs) const { return value
< rhs.value; } uint8_t value; using BaseType = uint8_t; }
;
60LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_EXT)struct MIPS_AFL_EXT { MIPS_AFL_EXT() = default; MIPS_AFL_EXT(
const uint32_t v) : value(v) {} MIPS_AFL_EXT(const MIPS_AFL_EXT
&v) = default; MIPS_AFL_EXT &operator=(const MIPS_AFL_EXT
&rhs) = default; MIPS_AFL_EXT &operator=(const uint32_t
&rhs) { value = rhs; return *this; } operator const uint32_t
& () const { return value; } bool operator==(const MIPS_AFL_EXT
&rhs) const { return value == rhs.value; } bool operator
==(const uint32_t &rhs) const { return value == rhs; } bool
operator<(const MIPS_AFL_EXT &rhs) const { return value
< rhs.value; } uint32_t value; using BaseType = uint32_t;
};
61LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_ASE)struct MIPS_AFL_ASE { MIPS_AFL_ASE() = default; MIPS_AFL_ASE(
const uint32_t v) : value(v) {} MIPS_AFL_ASE(const MIPS_AFL_ASE
&v) = default; MIPS_AFL_ASE &operator=(const MIPS_AFL_ASE
&rhs) = default; MIPS_AFL_ASE &operator=(const uint32_t
&rhs) { value = rhs; return *this; } operator const uint32_t
& () const { return value; } bool operator==(const MIPS_AFL_ASE
&rhs) const { return value == rhs.value; } bool operator
==(const uint32_t &rhs) const { return value == rhs; } bool
operator<(const MIPS_AFL_ASE &rhs) const { return value
< rhs.value; } uint32_t value; using BaseType = uint32_t;
};
62LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_AFL_FLAGS1)struct MIPS_AFL_FLAGS1 { MIPS_AFL_FLAGS1() = default; MIPS_AFL_FLAGS1
(const uint32_t v) : value(v) {} MIPS_AFL_FLAGS1(const MIPS_AFL_FLAGS1
&v) = default; MIPS_AFL_FLAGS1 &operator=(const MIPS_AFL_FLAGS1
&rhs) = default; MIPS_AFL_FLAGS1 &operator=(const uint32_t
&rhs) { value = rhs; return *this; } operator const uint32_t
& () const { return value; } bool operator==(const MIPS_AFL_FLAGS1
&rhs) const { return value == rhs.value; } bool operator
==(const uint32_t &rhs) const { return value == rhs; } bool
operator<(const MIPS_AFL_FLAGS1 &rhs) const { return value
< rhs.value; } uint32_t value; using BaseType = uint32_t;
};
63LLVM_YAML_STRONG_TYPEDEF(uint32_t, MIPS_ISA)struct MIPS_ISA { MIPS_ISA() = default; MIPS_ISA(const uint32_t
v) : value(v) {} MIPS_ISA(const MIPS_ISA &v) = default; MIPS_ISA
&operator=(const MIPS_ISA &rhs) = default; MIPS_ISA &
operator=(const uint32_t &rhs) { value = rhs; return *this
; } operator const uint32_t & () const { return value; } bool
operator==(const MIPS_ISA &rhs) const { return value == rhs
.value; } bool operator==(const uint32_t &rhs) const { return
value == rhs; } bool operator<(const MIPS_ISA &rhs) const
{ return value < rhs.value; } uint32_t value; using BaseType
= uint32_t; };
64
65// For now, hardcode 64 bits everywhere that 32 or 64 would be needed
66// since 64-bit can hold 32-bit values too.
67struct FileHeader {
68 ELF_ELFCLASS Class;
69 ELF_ELFDATA Data;
70 ELF_ELFOSABI OSABI;
71 ELF_ET Type;
72 ELF_EM Machine;
73 ELF_EF Flags;
74 llvm::yaml::Hex64 Entry;
75};
76
77struct SectionName {
78 StringRef Section;
79};
80
81struct ProgramHeader {
82 ELF_PT Type;
83 ELF_PF Flags;
84 llvm::yaml::Hex64 VAddr;
85 llvm::yaml::Hex64 PAddr;
86 Optional<llvm::yaml::Hex64> Align;
87 std::vector<SectionName> Sections;
88};
89
90struct Symbol {
91 StringRef Name;
92 ELF_STT Type;
93 StringRef Section;
94 Optional<ELF_SHN> Index;
95 llvm::yaml::Hex64 Value;
96 llvm::yaml::Hex64 Size;
97 uint8_t Other;
98};
99
100struct LocalGlobalWeakSymbols {
101 std::vector<Symbol> Local;
102 std::vector<Symbol> Global;
103 std::vector<Symbol> Weak;
104};
105
106struct SectionOrType {
107 StringRef sectionNameOrType;
108};
109
110struct Section {
111 enum class SectionKind {
112 Group,
113 RawContent,
114 Relocation,
115 NoBits,
116 MipsABIFlags
117 };
118 SectionKind Kind;
119 StringRef Name;
120 ELF_SHT Type;
121 ELF_SHF Flags;
122 llvm::yaml::Hex64 Address;
123 StringRef Link;
124 StringRef Info;
125 llvm::yaml::Hex64 AddressAlign;
126 Optional<llvm::yaml::Hex64> EntSize;
127
128 Section(SectionKind Kind) : Kind(Kind) {}
129 virtual ~Section();
130};
131struct RawContentSection : Section {
132 yaml::BinaryRef Content;
133 llvm::yaml::Hex64 Size;
134
135 RawContentSection() : Section(SectionKind::RawContent) {}
136
137 static bool classof(const Section *S) {
138 return S->Kind == SectionKind::RawContent;
139 }
140};
141
142struct NoBitsSection : Section {
143 llvm::yaml::Hex64 Size;
144
145 NoBitsSection() : Section(SectionKind::NoBits) {}
146
147 static bool classof(const Section *S) {
148 return S->Kind == SectionKind::NoBits;
149 }
150};
151
152struct Group : Section {
153 // Members of a group contain a flag and a list of section indices
154 // that are part of the group.
155 std::vector<SectionOrType> Members;
156
157 Group() : Section(SectionKind::Group) {}
158
159 static bool classof(const Section *S) {
160 return S->Kind == SectionKind::Group;
161 }
162};
163
164struct Relocation {
165 llvm::yaml::Hex64 Offset;
166 int64_t Addend;
167 ELF_REL Type;
168 Optional<StringRef> Symbol;
169};
170
171struct RelocationSection : Section {
172 std::vector<Relocation> Relocations;
173
174 RelocationSection() : Section(SectionKind::Relocation) {}
175
176 static bool classof(const Section *S) {
177 return S->Kind == SectionKind::Relocation;
178 }
179};
180
181// Represents .MIPS.abiflags section
182struct MipsABIFlags : Section {
183 llvm::yaml::Hex16 Version;
184 MIPS_ISA ISALevel;
185 llvm::yaml::Hex8 ISARevision;
186 MIPS_AFL_REG GPRSize;
187 MIPS_AFL_REG CPR1Size;
188 MIPS_AFL_REG CPR2Size;
189 MIPS_ABI_FP FpABI;
190 MIPS_AFL_EXT ISAExtension;
191 MIPS_AFL_ASE ASEs;
192 MIPS_AFL_FLAGS1 Flags1;
193 llvm::yaml::Hex32 Flags2;
194
195 MipsABIFlags() : Section(SectionKind::MipsABIFlags) {}
196
197 static bool classof(const Section *S) {
198 return S->Kind == SectionKind::MipsABIFlags;
199 }
200};
201
202struct Object {
203 FileHeader Header;
204 std::vector<ProgramHeader> ProgramHeaders;
205 std::vector<std::unique_ptr<Section>> Sections;
206 // Although in reality the symbols reside in a section, it is a lot
207 // cleaner and nicer if we read them from the YAML as a separate
208 // top-level key, which automatically ensures that invariants like there
209 // being a single SHT_SYMTAB section are upheld.
210 LocalGlobalWeakSymbols Symbols;
211 LocalGlobalWeakSymbols DynamicSymbols;
212};
213
214} // end namespace ELFYAML
215} // end namespace llvm
216
217LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::ProgramHeader)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<llvm::ELFYAML::ProgramHeader>::value && !std::
is_same<llvm::ELFYAML::ProgramHeader, std::string>::value
&& !std::is_same<llvm::ELFYAML::ProgramHeader, llvm
::StringRef>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<llvm::ELFYAML
::ProgramHeader> { static const bool flow = false; }; } }
218LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::ELFYAML::Section>)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<std::unique_ptr<llvm::ELFYAML::Section> >::value
&& !std::is_same<std::unique_ptr<llvm::ELFYAML
::Section>, std::string>::value && !std::is_same
<std::unique_ptr<llvm::ELFYAML::Section>, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<std::unique_ptr
<llvm::ELFYAML::Section> > { static const bool flow =
false; }; } }
219LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Symbol)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<llvm::ELFYAML::Symbol>::value && !std::is_same
<llvm::ELFYAML::Symbol, std::string>::value && !
std::is_same<llvm::ELFYAML::Symbol, llvm::StringRef>::value
, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<llvm::ELFYAML
::Symbol> { static const bool flow = false; }; } }
220LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::Relocation)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<llvm::ELFYAML::Relocation>::value && !std::is_same
<llvm::ELFYAML::Relocation, std::string>::value &&
!std::is_same<llvm::ELFYAML::Relocation, llvm::StringRef>
::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<llvm::ELFYAML
::Relocation> { static const bool flow = false; }; } }
221LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionOrType)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<llvm::ELFYAML::SectionOrType>::value && !std::
is_same<llvm::ELFYAML::SectionOrType, std::string>::value
&& !std::is_same<llvm::ELFYAML::SectionOrType, llvm
::StringRef>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<llvm::ELFYAML
::SectionOrType> { static const bool flow = false; }; } }
222LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::ELFYAML::SectionName)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<llvm::ELFYAML::SectionName>::value && !std::is_same
<llvm::ELFYAML::SectionName, std::string>::value &&
!std::is_same<llvm::ELFYAML::SectionName, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<llvm::ELFYAML
::SectionName> { static const bool flow = false; }; } }
223
224namespace llvm {
225namespace yaml {
226
227template <>
228struct ScalarEnumerationTraits<ELFYAML::ELF_ET> {
229 static void enumeration(IO &IO, ELFYAML::ELF_ET &Value);
230};
231
232template <> struct ScalarEnumerationTraits<ELFYAML::ELF_PT> {
233 static void enumeration(IO &IO, ELFYAML::ELF_PT &Value);
234};
235
236template <>
237struct ScalarEnumerationTraits<ELFYAML::ELF_EM> {
238 static void enumeration(IO &IO, ELFYAML::ELF_EM &Value);
239};
240
241template <>
242struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> {
243 static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value);
244};
245
246template <>
247struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> {
248 static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value);
249};
250
251template <>
252struct ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI> {
253 static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value);
254};
255
256template <>
257struct ScalarBitSetTraits<ELFYAML::ELF_EF> {
258 static void bitset(IO &IO, ELFYAML::ELF_EF &Value);
259};
260
261template <> struct ScalarBitSetTraits<ELFYAML::ELF_PF> {
262 static void bitset(IO &IO, ELFYAML::ELF_PF &Value);
263};
264
265template <>
266struct ScalarEnumerationTraits<ELFYAML::ELF_SHT> {
267 static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value);
268};
269
270template <>
271struct ScalarBitSetTraits<ELFYAML::ELF_SHF> {
272 static void bitset(IO &IO, ELFYAML::ELF_SHF &Value);
273};
274
275template <> struct ScalarEnumerationTraits<ELFYAML::ELF_SHN> {
276 static void enumeration(IO &IO, ELFYAML::ELF_SHN &Value);
277};
278
279template <>
280struct ScalarEnumerationTraits<ELFYAML::ELF_STT> {
281 static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
282};
283
284template <>
285struct ScalarEnumerationTraits<ELFYAML::ELF_STV> {
286 static void enumeration(IO &IO, ELFYAML::ELF_STV &Value);
287};
288
289template <>
290struct ScalarBitSetTraits<ELFYAML::ELF_STO> {
291 static void bitset(IO &IO, ELFYAML::ELF_STO &Value);
292};
293
294template <>
295struct ScalarEnumerationTraits<ELFYAML::ELF_REL> {
296 static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
297};
298
299template <>
300struct ScalarEnumerationTraits<ELFYAML::ELF_RSS> {
301 static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value);
302};
303
304template <>
305struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG> {
306 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_REG &Value);
307};
308
309template <>
310struct ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP> {
311 static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value);
312};
313
314template <>
315struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT> {
316 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value);
317};
318
319template <>
320struct ScalarEnumerationTraits<ELFYAML::MIPS_ISA> {
321 static void enumeration(IO &IO, ELFYAML::MIPS_ISA &Value);
322};
323
324template <>
325struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE> {
326 static void bitset(IO &IO, ELFYAML::MIPS_AFL_ASE &Value);
327};
328
329template <>
330struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1> {
331 static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value);
332};
333
334template <>
335struct MappingTraits<ELFYAML::FileHeader> {
336 static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr);
337};
338
339template <> struct MappingTraits<ELFYAML::ProgramHeader> {
340 static void mapping(IO &IO, ELFYAML::ProgramHeader &FileHdr);
341};
342
343template <>
344struct MappingTraits<ELFYAML::Symbol> {
345 static void mapping(IO &IO, ELFYAML::Symbol &Symbol);
346 static StringRef validate(IO &IO, ELFYAML::Symbol &Symbol);
347};
348
349template <>
350struct MappingTraits<ELFYAML::LocalGlobalWeakSymbols> {
351 static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols);
352};
353
354template <> struct MappingTraits<ELFYAML::Relocation> {
355 static void mapping(IO &IO, ELFYAML::Relocation &Rel);
356};
357
358template <>
359struct MappingTraits<std::unique_ptr<ELFYAML::Section>> {
360 static void mapping(IO &IO, std::unique_ptr<ELFYAML::Section> &Section);
361 static StringRef validate(IO &io, std::unique_ptr<ELFYAML::Section> &Section);
362};
363
364template <>
365struct MappingTraits<ELFYAML::Object> {
366 static void mapping(IO &IO, ELFYAML::Object &Object);
367};
368
369template <> struct MappingTraits<ELFYAML::SectionOrType> {
370 static void mapping(IO &IO, ELFYAML::SectionOrType &sectionOrType);
371};
372
373template <> struct MappingTraits<ELFYAML::SectionName> {
374 static void mapping(IO &IO, ELFYAML::SectionName &sectionName);
375};
376
377} // end namespace yaml
378} // end namespace llvm
379
380#endif // LLVM_OBJECTYAML_ELFYAML_H

/build/llvm-toolchain-snapshot-8~svn345461/include/llvm/Support/YAMLTraits.h

1//===- llvm/Support/YAMLTraits.h --------------------------------*- C++ -*-===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_SUPPORT_YAMLTRAITS_H
11#define LLVM_SUPPORT_YAMLTRAITS_H
12
13#include "llvm/ADT/Optional.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/ADT/StringExtras.h"
16#include "llvm/ADT/StringMap.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/ADT/Twine.h"
19#include "llvm/Support/AlignOf.h"
20#include "llvm/Support/Allocator.h"
21#include "llvm/Support/Endian.h"
22#include "llvm/Support/Regex.h"
23#include "llvm/Support/SourceMgr.h"
24#include "llvm/Support/YAMLParser.h"
25#include "llvm/Support/raw_ostream.h"
26#include <cassert>
27#include <cctype>
28#include <cstddef>
29#include <cstdint>
30#include <iterator>
31#include <map>
32#include <memory>
33#include <new>
34#include <string>
35#include <system_error>
36#include <type_traits>
37#include <vector>
38
39namespace llvm {
40namespace yaml {
41
42struct EmptyContext {};
43
44/// This class should be specialized by any type that needs to be converted
45/// to/from a YAML mapping. For example:
46///
47/// struct MappingTraits<MyStruct> {
48/// static void mapping(IO &io, MyStruct &s) {
49/// io.mapRequired("name", s.name);
50/// io.mapRequired("size", s.size);
51/// io.mapOptional("age", s.age);
52/// }
53/// };
54template<class T>
55struct MappingTraits {
56 // Must provide:
57 // static void mapping(IO &io, T &fields);
58 // Optionally may provide:
59 // static StringRef validate(IO &io, T &fields);
60 //
61 // The optional flow flag will cause generated YAML to use a flow mapping
62 // (e.g. { a: 0, b: 1 }):
63 // static const bool flow = true;
64};
65
66/// This class is similar to MappingTraits<T> but allows you to pass in
67/// additional context for each map operation. For example:
68///
69/// struct MappingContextTraits<MyStruct, MyContext> {
70/// static void mapping(IO &io, MyStruct &s, MyContext &c) {
71/// io.mapRequired("name", s.name);
72/// io.mapRequired("size", s.size);
73/// io.mapOptional("age", s.age);
74/// ++c.TimesMapped;
75/// }
76/// };
77template <class T, class Context> struct MappingContextTraits {
78 // Must provide:
79 // static void mapping(IO &io, T &fields, Context &Ctx);
80 // Optionally may provide:
81 // static StringRef validate(IO &io, T &fields, Context &Ctx);
82 //
83 // The optional flow flag will cause generated YAML to use a flow mapping
84 // (e.g. { a: 0, b: 1 }):
85 // static const bool flow = true;
86};
87
88/// This class should be specialized by any integral type that converts
89/// to/from a YAML scalar where there is a one-to-one mapping between
90/// in-memory values and a string in YAML. For example:
91///
92/// struct ScalarEnumerationTraits<Colors> {
93/// static void enumeration(IO &io, Colors &value) {
94/// io.enumCase(value, "red", cRed);
95/// io.enumCase(value, "blue", cBlue);
96/// io.enumCase(value, "green", cGreen);
97/// }
98/// };
99template<typename T>
100struct ScalarEnumerationTraits {
101 // Must provide:
102 // static void enumeration(IO &io, T &value);
103};
104
105/// This class should be specialized by any integer type that is a union
106/// of bit values and the YAML representation is a flow sequence of
107/// strings. For example:
108///
109/// struct ScalarBitSetTraits<MyFlags> {
110/// static void bitset(IO &io, MyFlags &value) {
111/// io.bitSetCase(value, "big", flagBig);
112/// io.bitSetCase(value, "flat", flagFlat);
113/// io.bitSetCase(value, "round", flagRound);
114/// }
115/// };
116template<typename T>
117struct ScalarBitSetTraits {
118 // Must provide:
119 // static void bitset(IO &io, T &value);
120};
121
122/// Describe which type of quotes should be used when quoting is necessary.
123/// Some non-printable characters need to be double-quoted, while some others
124/// are fine with simple-quoting, and some don't need any quoting.
125enum class QuotingType { None, Single, Double };
126
127/// This class should be specialized by type that requires custom conversion
128/// to/from a yaml scalar. For example:
129///
130/// template<>
131/// struct ScalarTraits<MyType> {
132/// static void output(const MyType &val, void*, llvm::raw_ostream &out) {
133/// // stream out custom formatting
134/// out << llvm::format("%x", val);
135/// }
136/// static StringRef input(StringRef scalar, void*, MyType &value) {
137/// // parse scalar and set `value`
138/// // return empty string on success, or error string
139/// return StringRef();
140/// }
141/// static QuotingType mustQuote(StringRef) { return QuotingType::Single; }
142/// };
143template<typename T>
144struct ScalarTraits {
145 // Must provide:
146 //
147 // Function to write the value as a string:
148 //static void output(const T &value, void *ctxt, llvm::raw_ostream &out);
149 //
150 // Function to convert a string to a value. Returns the empty
151 // StringRef on success or an error string if string is malformed:
152 //static StringRef input(StringRef scalar, void *ctxt, T &value);
153 //
154 // Function to determine if the value should be quoted.
155 //static QuotingType mustQuote(StringRef);
156};
157
158/// This class should be specialized by type that requires custom conversion
159/// to/from a YAML literal block scalar. For example:
160///
161/// template <>
162/// struct BlockScalarTraits<MyType> {
163/// static void output(const MyType &Value, void*, llvm::raw_ostream &Out)
164/// {
165/// // stream out custom formatting
166/// Out << Val;
167/// }
168/// static StringRef input(StringRef Scalar, void*, MyType &Value) {
169/// // parse scalar and set `value`
170/// // return empty string on success, or error string
171/// return StringRef();
172/// }
173/// };
174template <typename T>
175struct BlockScalarTraits {
176 // Must provide:
177 //
178 // Function to write the value as a string:
179 // static void output(const T &Value, void *ctx, llvm::raw_ostream &Out);
180 //
181 // Function to convert a string to a value. Returns the empty
182 // StringRef on success or an error string if string is malformed:
183 // static StringRef input(StringRef Scalar, void *ctxt, T &Value);
184};
185
186/// This class should be specialized by any type that needs to be converted
187/// to/from a YAML sequence. For example:
188///
189/// template<>
190/// struct SequenceTraits<MyContainer> {
191/// static size_t size(IO &io, MyContainer &seq) {
192/// return seq.size();
193/// }
194/// static MyType& element(IO &, MyContainer &seq, size_t index) {
195/// if ( index >= seq.size() )
196/// seq.resize(index+1);
197/// return seq[index];
198/// }
199/// };
200template<typename T, typename EnableIf = void>
201struct SequenceTraits {
202 // Must provide:
203 // static size_t size(IO &io, T &seq);
204 // static T::value_type& element(IO &io, T &seq, size_t index);
205 //
206 // The following is option and will cause generated YAML to use
207 // a flow sequence (e.g. [a,b,c]).
208 // static const bool flow = true;
209};
210
211/// This class should be specialized by any type for which vectors of that
212/// type need to be converted to/from a YAML sequence.
213template<typename T, typename EnableIf = void>
214struct SequenceElementTraits {
215 // Must provide:
216 // static const bool flow;
217};
218
219/// This class should be specialized by any type that needs to be converted
220/// to/from a list of YAML documents.
221template<typename T>
222struct DocumentListTraits {
223 // Must provide:
224 // static size_t size(IO &io, T &seq);
225 // static T::value_type& element(IO &io, T &seq, size_t index);
226};
227
228/// This class should be specialized by any type that needs to be converted
229/// to/from a YAML mapping in the case where the names of the keys are not known
230/// in advance, e.g. a string map.
231template <typename T>
232struct CustomMappingTraits {
233 // static void inputOne(IO &io, StringRef key, T &elem);
234 // static void output(IO &io, T &elem);
235};
236
237// Only used for better diagnostics of missing traits
238template <typename T>
239struct MissingTrait;
240
241// Test if ScalarEnumerationTraits<T> is defined on type T.
242template <class T>
243struct has_ScalarEnumerationTraits
244{
245 using Signature_enumeration = void (*)(class IO&, T&);
246
247 template <typename U>
248 static char test(SameType<Signature_enumeration, &U::enumeration>*);
249
250 template <typename U>
251 static double test(...);
252
253 static bool const value =
254 (sizeof(test<ScalarEnumerationTraits<T>>(nullptr)) == 1);
255};
256
257// Test if ScalarBitSetTraits<T> is defined on type T.
258template <class T>
259struct has_ScalarBitSetTraits
260{
261 using Signature_bitset = void (*)(class IO&, T&);
262
263 template <typename U>
264 static char test(SameType<Signature_bitset, &U::bitset>*);
265
266 template <typename U>
267 static double test(...);
268
269 static bool const value = (sizeof(test<ScalarBitSetTraits<T>>(nullptr)) == 1);
270};
271
272// Test if ScalarTraits<T> is defined on type T.
273template <class T>
274struct has_ScalarTraits
275{
276 using Signature_input = StringRef (*)(StringRef, void*, T&);
277 using Signature_output = void (*)(const T&, void*, raw_ostream&);
278 using Signature_mustQuote = QuotingType (*)(StringRef);
279
280 template <typename U>
281 static char test(SameType<Signature_input, &U::input> *,
282 SameType<Signature_output, &U::output> *,
283 SameType<Signature_mustQuote, &U::mustQuote> *);
284
285 template <typename U>
286 static double test(...);
287
288 static bool const value =
289 (sizeof(test<ScalarTraits<T>>(nullptr, nullptr, nullptr)) == 1);
290};
291
292// Test if BlockScalarTraits<T> is defined on type T.
293template <class T>
294struct has_BlockScalarTraits
295{
296 using Signature_input = StringRef (*)(StringRef, void *, T &);
297 using Signature_output = void (*)(const T &, void *, raw_ostream &);
298
299 template <typename U>
300 static char test(SameType<Signature_input, &U::input> *,
301 SameType<Signature_output, &U::output> *);
302
303 template <typename U>
304 static double test(...);
305
306 static bool const value =
307 (sizeof(test<BlockScalarTraits<T>>(nullptr, nullptr)) == 1);
308};
309
310// Test if MappingContextTraits<T> is defined on type T.
311template <class T, class Context> struct has_MappingTraits {
312 using Signature_mapping = void (*)(class IO &, T &, Context &);
313
314 template <typename U>
315 static char test(SameType<Signature_mapping, &U::mapping>*);
316
317 template <typename U>
318 static double test(...);
319
320 static bool const value =
321 (sizeof(test<MappingContextTraits<T, Context>>(nullptr)) == 1);
322};
323
324// Test if MappingTraits<T> is defined on type T.
325template <class T> struct has_MappingTraits<T, EmptyContext> {
326 using Signature_mapping = void (*)(class IO &, T &);
327
328 template <typename U>
329 static char test(SameType<Signature_mapping, &U::mapping> *);
330
331 template <typename U> static double test(...);
332
333 static bool const value = (sizeof(test<MappingTraits<T>>(nullptr)) == 1);
334};
335
336// Test if MappingContextTraits<T>::validate() is defined on type T.
337template <class T, class Context> struct has_MappingValidateTraits {
338 using Signature_validate = StringRef (*)(class IO &, T &, Context &);
339
340 template <typename U>
341 static char test(SameType<Signature_validate, &U::validate>*);
342
343 template <typename U>
344 static double test(...);
345
346 static bool const value =
347 (sizeof(test<MappingContextTraits<T, Context>>(nullptr)) == 1);
348};
349
350// Test if MappingTraits<T>::validate() is defined on type T.
351template <class T> struct has_MappingValidateTraits<T, EmptyContext> {
352 using Signature_validate = StringRef (*)(class IO &, T &);
353
354 template <typename U>
355 static char test(SameType<Signature_validate, &U::validate> *);
356
357 template <typename U> static double test(...);
358
359 static bool const value = (sizeof(test<MappingTraits<T>>(nullptr)) == 1);
360};
361
362// Test if SequenceTraits<T> is defined on type T.
363template <class T>
364struct has_SequenceMethodTraits
365{
366 using Signature_size = size_t (*)(class IO&, T&);
367
368 template <typename U>
369 static char test(SameType<Signature_size, &U::size>*);
370
371 template <typename U>
372 static double test(...);
373
374 static bool const value = (sizeof(test<SequenceTraits<T>>(nullptr)) == 1);
375};
376
377// Test if CustomMappingTraits<T> is defined on type T.
378template <class T>
379struct has_CustomMappingTraits
380{
381 using Signature_input = void (*)(IO &io, StringRef key, T &v);
382
383 template <typename U>
384 static char test(SameType<Signature_input, &U::inputOne>*);
385
386 template <typename U>
387 static double test(...);
388
389 static bool const value =
390 (sizeof(test<CustomMappingTraits<T>>(nullptr)) == 1);
391};
392
393// has_FlowTraits<int> will cause an error with some compilers because
394// it subclasses int. Using this wrapper only instantiates the
395// real has_FlowTraits only if the template type is a class.
396template <typename T, bool Enabled = std::is_class<T>::value>
397class has_FlowTraits
398{
399public:
400 static const bool value = false;
401};
402
403// Some older gcc compilers don't support straight forward tests
404// for members, so test for ambiguity cause by the base and derived
405// classes both defining the member.
406template <class T>
407struct has_FlowTraits<T, true>
408{
409 struct Fallback { bool flow; };
410 struct Derived : T, Fallback { };
411
412 template<typename C>
413 static char (&f(SameType<bool Fallback::*, &C::flow>*))[1];
414
415 template<typename C>
416 static char (&f(...))[2];
417
418 static bool const value = sizeof(f<Derived>(nullptr)) == 2;
419};
420
421// Test if SequenceTraits<T> is defined on type T
422template<typename T>
423struct has_SequenceTraits : public std::integral_constant<bool,
424 has_SequenceMethodTraits<T>::value > { };
425
426// Test if DocumentListTraits<T> is defined on type T
427template <class T>
428struct has_DocumentListTraits
429{
430 using Signature_size = size_t (*)(class IO &, T &);
431
432 template <typename U>
433 static char test(SameType<Signature_size, &U::size>*);
434
435 template <typename U>
436 static double test(...);
437
438 static bool const value = (sizeof(test<DocumentListTraits<T>>(nullptr))==1);
439};
440
441inline bool isNumeric(StringRef S) {
442 const static auto skipDigits = [](StringRef Input) {
443 return Input.drop_front(
444 std::min(Input.find_first_not_of("0123456789"), Input.size()));
445 };
446
447 // Make S.front() and S.drop_front().front() (if S.front() is [+-]) calls
448 // safe.
449 if (S.empty() || S.equals("+") || S.equals("-"))
450 return false;
451
452 if (S.equals(".nan") || S.equals(".NaN") || S.equals(".NAN"))
453 return true;
454
455 // Infinity and decimal numbers can be prefixed with sign.
456 StringRef Tail = (S.front() == '-' || S.front() == '+') ? S.drop_front() : S;
457
458 // Check for infinity first, because checking for hex and oct numbers is more
459 // expensive.
460 if (Tail.equals(".inf") || Tail.equals(".Inf") || Tail.equals(".INF"))
461 return true;
462
463 // Section 10.3.2 Tag Resolution
464 // YAML 1.2 Specification prohibits Base 8 and Base 16 numbers prefixed with
465 // [-+], so S should be used instead of Tail.
466 if (S.startswith("0o"))
467 return S.size() > 2 &&
468 S.drop_front(2).find_first_not_of("01234567") == StringRef::npos;
469
470 if (S.startswith("0x"))
471 return S.size() > 2 && S.drop_front(2).find_first_not_of(
472 "0123456789abcdefABCDEF") == StringRef::npos;
473
474 // Parse float: [-+]? (\. [0-9]+ | [0-9]+ (\. [0-9]* )?) ([eE] [-+]? [0-9]+)?
475 S = Tail;
476
477 // Handle cases when the number starts with '.' and hence needs at least one
478 // digit after dot (as opposed by number which has digits before the dot), but
479 // doesn't have one.
480 if (S.startswith(".") &&
481 (S.equals(".") ||
482 (S.size() > 1 && std::strchr("0123456789", S[1]) == nullptr)))
483 return false;
484
485 if (S.startswith("E") || S.startswith("e"))
486 return false;
487
488 enum ParseState {
489 Default,
490 FoundDot,
491 FoundExponent,
492 };
493 ParseState State = Default;
494
495 S = skipDigits(S);
496
497 // Accept decimal integer.
498 if (S.empty())
499 return true;
500
501 if (S.front() == '.') {
502 State = FoundDot;
503 S = S.drop_front();
504 } else if (S.front() == 'e' || S.front() == 'E') {
505 State = FoundExponent;
506 S = S.drop_front();
507 } else {
508 return false;
509 }
510
511 if (State == FoundDot) {
512 S = skipDigits(S);
513 if (S.empty())
514 return true;
515
516 if (S.front() == 'e' || S.front() == 'E') {
517 State = FoundExponent;
518 S = S.drop_front();
519 } else {
520 return false;
521 }
522 }
523
524 assert(State == FoundExponent && "Should have found exponent at this point.")((State == FoundExponent && "Should have found exponent at this point."
) ? static_cast<void> (0) : __assert_fail ("State == FoundExponent && \"Should have found exponent at this point.\""
, "/build/llvm-toolchain-snapshot-8~svn345461/include/llvm/Support/YAMLTraits.h"
, 524, __PRETTY_FUNCTION__))
;
525 if (S.empty())
526 return false;
527
528 if (S.front() == '+' || S.front() == '-') {
529 S = S.drop_front();
530 if (S.empty())
531 return false;
532 }
533
534 return skipDigits(S).empty();
535}
536
537inline bool isNull(StringRef S) {
538 return S.equals("null") || S.equals("Null") || S.equals("NULL") ||
539 S.equals("~");
540}
541
542inline bool isBool(StringRef S) {
543 return S.equals("true") || S.equals("True") || S.equals("TRUE") ||
544 S.equals("false") || S.equals("False") || S.equals("FALSE");
545}
546
547// 5.1. Character Set
548// The allowed character range explicitly excludes the C0 control block #x0-#x1F
549// (except for TAB #x9, LF #xA, and CR #xD which are allowed), DEL #x7F, the C1
550// control block #x80-#x9F (except for NEL #x85 which is allowed), the surrogate
551// block #xD800-#xDFFF, #xFFFE, and #xFFFF.
552inline QuotingType needsQuotes(StringRef S) {
553 if (S.empty())
554 return QuotingType::Single;
555 if (isspace(S.front()) || isspace(S.back()))
556 return QuotingType::Single;
557 if (isNull(S))
558 return QuotingType::Single;
559 if (isBool(S))
560 return QuotingType::Single;
561 if (isNumeric(S))
562 return QuotingType::Single;
563
564 // 7.3.3 Plain Style
565 // Plain scalars must not begin with most indicators, as this would cause
566 // ambiguity with other YAML constructs.
567 static constexpr char Indicators[] = R"(-?:\,[]{}#&*!|>'"%@`)";
568 if (S.find_first_of(Indicators) == 0)
569 return QuotingType::Single;
570
571 QuotingType MaxQuotingNeeded = QuotingType::None;
572 for (unsigned char C : S) {
573 // Alphanum is safe.
574 if (isAlnum(C))
575 continue;
576
577 switch (C) {
578 // Safe scalar characters.
579 case '_':
580 case '-':
581 case '^':
582 case '.':
583 case ',':
584 case ' ':
585 // TAB (0x9) is allowed in unquoted strings.
586 case 0x9:
587 continue;
588 // LF(0xA) and CR(0xD) may delimit values and so require at least single
589 // quotes.
590 case 0xA:
591 case 0xD:
592 MaxQuotingNeeded = QuotingType::Single;
593 continue;
594 // DEL (0x7F) are excluded from the allowed character range.
595 case 0x7F:
596 return QuotingType::Double;
597 // Forward slash is allowed to be unquoted, but we quote it anyway. We have
598 // many tests that use FileCheck against YAML output, and this output often
599 // contains paths. If we quote backslashes but not forward slashes then
600 // paths will come out either quoted or unquoted depending on which platform
601 // the test is run on, making FileCheck comparisons difficult.
602 case '/':
603 default: {
604 // C0 control block (0x0 - 0x1F) is excluded from the allowed character
605 // range.
606 if (C <= 0x1F)
607 return QuotingType::Double;
608
609 // Always double quote UTF-8.
610 if ((C & 0x80) != 0)
611 return QuotingType::Double;
612
613 // The character is not safe, at least simple quoting needed.
614 MaxQuotingNeeded = QuotingType::Single;
615 }
616 }
617 }
618
619 return MaxQuotingNeeded;
620}
621
622template <typename T, typename Context>
623struct missingTraits
624 : public std::integral_constant<bool,
625 !has_ScalarEnumerationTraits<T>::value &&
626 !has_ScalarBitSetTraits<T>::value &&
627 !has_ScalarTraits<T>::value &&
628 !has_BlockScalarTraits<T>::value &&
629 !has_MappingTraits<T, Context>::value &&
630 !has_SequenceTraits<T>::value &&
631 !has_CustomMappingTraits<T>::value &&
632 !has_DocumentListTraits<T>::value> {};
633
634template <typename T, typename Context>
635struct validatedMappingTraits
636 : public std::integral_constant<
637 bool, has_MappingTraits<T, Context>::value &&
638 has_MappingValidateTraits<T, Context>::value> {};
639
640template <typename T, typename Context>
641struct unvalidatedMappingTraits
642 : public std::integral_constant<
643 bool, has_MappingTraits<T, Context>::value &&
644 !has_MappingValidateTraits<T, Context>::value> {};
645
646// Base class for Input and Output.
647class IO {
648public:
649 IO(void *Ctxt = nullptr);
650 virtual ~IO();
651
652 virtual bool outputting() = 0;
653
654 virtual unsigned beginSequence() = 0;
655 virtual bool preflightElement(unsigned, void *&) = 0;
656 virtual void postflightElement(void*) = 0;
657 virtual void endSequence() = 0;
658 virtual bool canElideEmptySequence() = 0;
659
660 virtual unsigned beginFlowSequence() = 0;
661 virtual bool preflightFlowElement(unsigned, void *&) = 0;
662 virtual void postflightFlowElement(void*) = 0;
663 virtual void endFlowSequence() = 0;
664
665 virtual bool mapTag(StringRef Tag, bool Default=false) = 0;
666 virtual void beginMapping() = 0;
667 virtual void endMapping() = 0;
668 virtual bool preflightKey(const char*, bool, bool, bool &, void *&) = 0;
669 virtual void postflightKey(void*) = 0;
670 virtual std::vector<StringRef> keys() = 0;
671
672 virtual void beginFlowMapping() = 0;
673 virtual void endFlowMapping() = 0;
674
675 virtual void beginEnumScalar() = 0;
676 virtual bool matchEnumScalar(const char*, bool) = 0;
677 virtual bool matchEnumFallback() = 0;
678 virtual void endEnumScalar() = 0;
679
680 virtual bool beginBitSetScalar(bool &) = 0;
681 virtual bool bitSetMatch(const char*, bool) = 0;
682 virtual void endBitSetScalar() = 0;
683
684 virtual void scalarString(StringRef &, QuotingType) = 0;
685 virtual void blockScalarString(StringRef &) = 0;
686
687 virtual void setError(const Twine &) = 0;
688
689 template <typename T>
690 void enumCase(T &Val, const char* Str, const T ConstVal) {
691 if ( matchEnumScalar(Str, outputting() && Val == ConstVal) ) {
692 Val = ConstVal;
693 }
694 }
695
696 // allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF
697 template <typename T>
698 void enumCase(T &Val, const char* Str, const uint32_t ConstVal) {
699 if ( matchEnumScalar(Str, outputting() && Val == static_cast<T>(ConstVal)) ) {
14
Assuming the condition is true
15
Calling 'ELF_SHT::operator=='
700 Val = ConstVal;
701 }
702 }
703
704 template <typename FBT, typename T>
705 void enumFallback(T &Val) {
706 if (matchEnumFallback()) {
707 EmptyContext Context;
708 // FIXME: Force integral conversion to allow strong typedefs to convert.
709 FBT Res = static_cast<typename FBT::BaseType>(Val);
710 yamlize(*this, Res, true, Context);
711 Val = static_cast<T>(static_cast<typename FBT::BaseType>(Res));
712 }
713 }
714
715 template <typename T>
716 void bitSetCase(T &Val, const char* Str, const T ConstVal) {
717 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
718 Val = static_cast<T>(Val | ConstVal);
719 }
720 }
721
722 // allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF
723 template <typename T>
724 void bitSetCase(T &Val, const char* Str, const uint32_t ConstVal) {
725 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
726 Val = static_cast<T>(Val | ConstVal);
727 }
728 }
729
730 template <typename T>
731 void maskedBitSetCase(T &Val, const char *Str, T ConstVal, T Mask) {
732 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
733 Val = Val | ConstVal;
734 }
735
736 template <typename T>
737 void maskedBitSetCase(T &Val, const char *Str, uint32_t ConstVal,
738 uint32_t Mask) {
739 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
740 Val = Val | ConstVal;
741 }
742
743 void *getContext();
744 void setContext(void *);
745
746 template <typename T> void mapRequired(const char *Key, T &Val) {
747 EmptyContext Ctx;
748 this->processKey(Key, Val, true, Ctx);
7
Calling 'IO::processKey'
749 }
750
751 template <typename T, typename Context>
752 void mapRequired(const char *Key, T &Val, Context &Ctx) {
753 this->processKey(Key, Val, true, Ctx);
754 }
755
756 template <typename T> void mapOptional(const char *Key, T &Val) {
757 EmptyContext Ctx;
758 mapOptionalWithContext(Key, Val, Ctx);
759 }
760
761 template <typename T>
762 void mapOptional(const char *Key, T &Val, const T &Default) {
763 EmptyContext Ctx;
764 mapOptionalWithContext(Key, Val, Default, Ctx);
765 }
766
767 template <typename T, typename Context>
768 typename std::enable_if<has_SequenceTraits<T>::value, void>::type
769 mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
770 // omit key/value instead of outputting empty sequence
771 if (this->canElideEmptySequence() && !(Val.begin() != Val.end()))
772 return;
773 this->processKey(Key, Val, false, Ctx);
774 }
775
776 template <typename T, typename Context>
777 void mapOptionalWithContext(const char *Key, Optional<T> &Val, Context &Ctx) {
778 this->processKeyWithDefault(Key, Val, Optional<T>(), /*Required=*/false,
779 Ctx);
780 }
781
782 template <typename T, typename Context>
783 typename std::enable_if<!has_SequenceTraits<T>::value, void>::type
784 mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
785 this->processKey(Key, Val, false, Ctx);
786 }
787
788 template <typename T, typename Context>
789 void mapOptionalWithContext(const char *Key, T &Val, const T &Default,
790 Context &Ctx) {
791 this->processKeyWithDefault(Key, Val, Default, false, Ctx);
792 }
793
794private:
795 template <typename T, typename Context>
796 void processKeyWithDefault(const char *Key, Optional<T> &Val,
797 const Optional<T> &DefaultValue, bool Required,
798 Context &Ctx) {
799 assert(DefaultValue.hasValue() == false &&((DefaultValue.hasValue() == false && "Optional<T> shouldn't have a value!"
) ? static_cast<void> (0) : __assert_fail ("DefaultValue.hasValue() == false && \"Optional<T> shouldn't have a value!\""
, "/build/llvm-toolchain-snapshot-8~svn345461/include/llvm/Support/YAMLTraits.h"
, 800, __PRETTY_FUNCTION__))
800 "Optional<T> shouldn't have a value!")((DefaultValue.hasValue() == false && "Optional<T> shouldn't have a value!"
) ? static_cast<void> (0) : __assert_fail ("DefaultValue.hasValue() == false && \"Optional<T> shouldn't have a value!\""
, "/build/llvm-toolchain-snapshot-8~svn345461/include/llvm/Support/YAMLTraits.h"
, 800, __PRETTY_FUNCTION__))
;
801 void *SaveInfo;
802 bool UseDefault = true;
803 const bool sameAsDefault = outputting() && !Val.hasValue();
804 if (!outputting() && !Val.hasValue())
805 Val = T();
806 if (Val.hasValue() &&
807 this->preflightKey(Key, Required, sameAsDefault, UseDefault,
808 SaveInfo)) {
809 yamlize(*this, Val.getValue(), Required, Ctx);
810 this->postflightKey(SaveInfo);
811 } else {
812 if (UseDefault)
813 Val = DefaultValue;
814 }
815 }
816
817 template <typename T, typename Context>
818 void processKeyWithDefault(const char *Key, T &Val, const T &DefaultValue,
819 bool Required, Context &Ctx) {
820 void *SaveInfo;
821 bool UseDefault;
822 const bool sameAsDefault = outputting() && Val == DefaultValue;
823 if ( this->preflightKey(Key, Required, sameAsDefault, UseDefault,
824 SaveInfo) ) {
825 yamlize(*this, Val, Required, Ctx);
826 this->postflightKey(SaveInfo);
827 }
828 else {
829 if ( UseDefault )
830 Val = DefaultValue;
831 }
832 }
833
834 template <typename T, typename Context>
835 void processKey(const char *Key, T &Val, bool Required, Context &Ctx) {
836 void *SaveInfo;
837 bool UseDefault;
838 if ( this->preflightKey(Key, Required, false, UseDefault, SaveInfo) ) {
8
Assuming the condition is true
9
Taking true branch
839 yamlize(*this, Val, Required, Ctx);
10
Calling 'yamlize<llvm::ELFYAML::ELF_SHT>'
840 this->postflightKey(SaveInfo);
841 }
842 }
843
844private:
845 void *Ctxt;
846};
847
848namespace detail {
849
850template <typename T, typename Context>
851void doMapping(IO &io, T &Val, Context &Ctx) {
852 MappingContextTraits<T, Context>::mapping(io, Val, Ctx);
853}
854
855template <typename T> void doMapping(IO &io, T &Val, EmptyContext &Ctx) {
856 MappingTraits<T>::mapping(io, Val);
857}
858
859} // end namespace detail
860
861template <typename T>
862typename std::enable_if<has_ScalarEnumerationTraits<T>::value, void>::type
863yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
864 io.beginEnumScalar();
865 ScalarEnumerationTraits<T>::enumeration(io, Val);
11
Calling 'ScalarEnumerationTraits::enumeration'
866 io.endEnumScalar();
867}
868
869template <typename T>
870typename std::enable_if<has_ScalarBitSetTraits<T>::value, void>::type
871yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
872 bool DoClear;
873 if ( io.beginBitSetScalar(DoClear) ) {
874 if ( DoClear )
875 Val = static_cast<T>(0);
876 ScalarBitSetTraits<T>::bitset(io, Val);
877 io.endBitSetScalar();
878 }
879}
880
881template <typename T>
882typename std::enable_if<has_ScalarTraits<T>::value, void>::type
883yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
884 if ( io.outputting() ) {
885 std::string Storage;
886 raw_string_ostream Buffer(Storage);
887 ScalarTraits<T>::output(Val, io.getContext(), Buffer);
888 StringRef Str = Buffer.str();
889 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
890 }
891 else {
892 StringRef Str;
893 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
894 StringRef Result = ScalarTraits<T>::input(Str, io.getContext(), Val);
895 if ( !Result.empty() ) {
896 io.setError(Twine(Result));
897 }
898 }
899}
900
901template <typename T>
902typename std::enable_if<has_BlockScalarTraits<T>::value, void>::type
903yamlize(IO &YamlIO, T &Val, bool, EmptyContext &Ctx) {
904 if (YamlIO.outputting()) {
905 std::string Storage;
906 raw_string_ostream Buffer(Storage);
907 BlockScalarTraits<T>::output(Val, YamlIO.getContext(), Buffer);
908 StringRef Str = Buffer.str();
909 YamlIO.blockScalarString(Str);
910 } else {
911 StringRef Str;
912 YamlIO.blockScalarString(Str);
913 StringRef Result =
914 BlockScalarTraits<T>::input(Str, YamlIO.getContext(), Val);
915 if (!Result.empty())
916 YamlIO.setError(Twine(Result));
917 }
918}
919
920template <typename T, typename Context>
921typename std::enable_if<validatedMappingTraits<T, Context>::value, void>::type
922yamlize(IO &io, T &Val, bool, Context &Ctx) {
923 if (has_FlowTraits<MappingTraits<T>>::value)
924 io.beginFlowMapping();
925 else
926 io.beginMapping();
927 if (io.outputting()) {
928 StringRef Err = MappingTraits<T>::validate(io, Val);
929 if (!Err.empty()) {
930 errs() << Err << "\n";
931 assert(Err.empty() && "invalid struct trying to be written as yaml")((Err.empty() && "invalid struct trying to be written as yaml"
) ? static_cast<void> (0) : __assert_fail ("Err.empty() && \"invalid struct trying to be written as yaml\""
, "/build/llvm-toolchain-snapshot-8~svn345461/include/llvm/Support/YAMLTraits.h"
, 931, __PRETTY_FUNCTION__))
;
932 }
933 }
934 detail::doMapping(io, Val, Ctx);
935 if (!io.outputting()) {
936 StringRef Err = MappingTraits<T>::validate(io, Val);
937 if (!Err.empty())
938 io.setError(Err);
939 }
940 if (has_FlowTraits<MappingTraits<T>>::value)
941 io.endFlowMapping();
942 else
943 io.endMapping();
944}
945
946template <typename T, typename Context>
947typename std::enable_if<unvalidatedMappingTraits<T, Context>::value, void>::type
948yamlize(IO &io, T &Val, bool, Context &Ctx) {
949 if (has_FlowTraits<MappingTraits<T>>::value) {
950 io.beginFlowMapping();
951 detail::doMapping(io, Val, Ctx);
952 io.endFlowMapping();
953 } else {
954 io.beginMapping();
955 detail::doMapping(io, Val, Ctx);
956 io.endMapping();
957 }
958}
959
960template <typename T>
961typename std::enable_if<has_CustomMappingTraits<T>::value, void>::type
962yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
963 if ( io.outputting() ) {
964 io.beginMapping();
965 CustomMappingTraits<T>::output(io, Val);
966 io.endMapping();
967 } else {
968 io.beginMapping();
969 for (StringRef key : io.keys())
970 CustomMappingTraits<T>::inputOne(io, key, Val);
971 io.endMapping();
972 }
973}
974
975template <typename T>
976typename std::enable_if<missingTraits<T, EmptyContext>::value, void>::type
977yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
978 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
979}
980
981template <typename T, typename Context>
982typename std::enable_if<has_SequenceTraits<T>::value, void>::type
983yamlize(IO &io, T &Seq, bool, Context &Ctx) {
984 if ( has_FlowTraits< SequenceTraits<T>>::value ) {
985 unsigned incnt = io.beginFlowSequence();
986 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
987 for(unsigned i=0; i < count; ++i) {
988 void *SaveInfo;
989 if ( io.preflightFlowElement(i, SaveInfo) ) {
990 yamlize(io, SequenceTraits<T>::element(io, Seq, i), true, Ctx);
991 io.postflightFlowElement(SaveInfo);
992 }
993 }
994 io.endFlowSequence();
995 }
996 else {
997 unsigned incnt = io.beginSequence();
998 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
999 for(unsigned i=0; i < count; ++i) {
1000 void *SaveInfo;
1001 if ( io.preflightElement(i, SaveInfo) ) {
1002 yamlize(io, SequenceTraits<T>::element(io, Seq, i), true, Ctx);
1003 io.postflightElement(SaveInfo);
1004 }
1005 }
1006 io.endSequence();
1007 }
1008}
1009
1010template<>
1011struct ScalarTraits<bool> {
1012 static void output(const bool &, void* , raw_ostream &);
1013 static StringRef input(StringRef, void *, bool &);
1014 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1015};
1016
1017template<>
1018struct ScalarTraits<StringRef> {
1019 static void output(const StringRef &, void *, raw_ostream &);
1020 static StringRef input(StringRef, void *, StringRef &);
1021 static QuotingType mustQuote(StringRef S) { return needsQuotes(S); }
1022};
1023
1024template<>
1025struct ScalarTraits<std::string> {
1026 static void output(const std::string &, void *, raw_ostream &);
1027 static StringRef input(StringRef, void *, std::string &);
1028 static QuotingType mustQuote(StringRef S) { return needsQuotes(S); }
1029};
1030
1031template<>
1032struct ScalarTraits<uint8_t> {
1033 static void output(const uint8_t &, void *, raw_ostream &);
1034 static StringRef input(StringRef, void *, uint8_t &);
1035 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1036};
1037
1038template<>
1039struct ScalarTraits<uint16_t> {
1040 static void output(const uint16_t &, void *, raw_ostream &);
1041 static StringRef input(StringRef, void *, uint16_t &);
1042 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1043};
1044
1045template<>
1046struct ScalarTraits<uint32_t> {
1047 static void output(const uint32_t &, void *, raw_ostream &);
1048 static StringRef input(StringRef, void *, uint32_t &);
1049 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1050};
1051
1052template<>
1053struct ScalarTraits<uint64_t> {
1054 static void output(const uint64_t &, void *, raw_ostream &);
1055 static StringRef input(StringRef, void *, uint64_t &);
1056 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1057};
1058
1059template<>
1060struct ScalarTraits<int8_t> {
1061 static void output(const int8_t &, void *, raw_ostream &);
1062 static StringRef input(StringRef, void *, int8_t &);
1063 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1064};
1065
1066template<>
1067struct ScalarTraits<int16_t> {
1068 static void output(const int16_t &, void *, raw_ostream &);
1069 static StringRef input(StringRef, void *, int16_t &);
1070 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1071};
1072
1073template<>
1074struct ScalarTraits<int32_t> {
1075 static void output(const int32_t &, void *, raw_ostream &);
1076 static StringRef input(StringRef, void *, int32_t &);
1077 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1078};
1079
1080template<>
1081struct ScalarTraits<int64_t> {
1082 static void output(const int64_t &, void *, raw_ostream &);
1083 static StringRef input(StringRef, void *, int64_t &);
1084 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1085};
1086
1087template<>
1088struct ScalarTraits<float> {
1089 static void output(const float &, void *, raw_ostream &);
1090 static StringRef input(StringRef, void *, float &);
1091 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1092};
1093
1094template<>
1095struct ScalarTraits<double> {
1096 static void output(const double &, void *, raw_ostream &);
1097 static StringRef input(StringRef, void *, double &);
1098 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1099};
1100
1101// For endian types, we just use the existing ScalarTraits for the underlying
1102// type. This way endian aware types are supported whenever a ScalarTraits
1103// is defined for the underlying type.
1104template <typename value_type, support::endianness endian, size_t alignment>
1105struct ScalarTraits<support::detail::packed_endian_specific_integral<
1106 value_type, endian, alignment>> {
1107 using endian_type =
1108 support::detail::packed_endian_specific_integral<value_type, endian,
1109 alignment>;
1110
1111 static void output(const endian_type &E, void *Ctx, raw_ostream &Stream) {
1112 ScalarTraits<value_type>::output(static_cast<value_type>(E), Ctx, Stream);
1113 }
1114
1115 static StringRef input(StringRef Str, void *Ctx, endian_type &E) {
1116 value_type V;
1117 auto R = ScalarTraits<value_type>::input(Str, Ctx, V);
1118 E = static_cast<endian_type>(V);
1119 return R;
1120 }
1121
1122 static QuotingType mustQuote(StringRef Str) {
1123 return ScalarTraits<value_type>::mustQuote(Str);
1124 }
1125};
1126
1127// Utility for use within MappingTraits<>::mapping() method
1128// to [de]normalize an object for use with YAML conversion.
1129template <typename TNorm, typename TFinal>
1130struct MappingNormalization {
1131 MappingNormalization(IO &i_o, TFinal &Obj)
1132 : io(i_o), BufPtr(nullptr), Result(Obj) {
1133 if ( io.outputting() ) {
1134 BufPtr = new (&Buffer) TNorm(io, Obj);
1135 }
1136 else {
1137 BufPtr = new (&Buffer) TNorm(io);
1138 }
1139 }
1140
1141 ~MappingNormalization() {
1142 if ( ! io.outputting() ) {
1143 Result = BufPtr->denormalize(io);
1144 }
1145 BufPtr->~TNorm();
1146 }
1147
1148 TNorm* operator->() { return BufPtr; }
1149
1150private:
1151 using Storage = AlignedCharArrayUnion<TNorm>;
1152
1153 Storage Buffer;
1154 IO &io;
1155 TNorm *BufPtr;
1156 TFinal &Result;
1157};
1158
1159// Utility for use within MappingTraits<>::mapping() method
1160// to [de]normalize an object for use with YAML conversion.
1161template <typename TNorm, typename TFinal>
1162struct MappingNormalizationHeap {
1163 MappingNormalizationHeap(IO &i_o, TFinal &Obj, BumpPtrAllocator *allocator)
1164 : io(i_o), Result(Obj) {
1165 if ( io.outputting() ) {
1166 BufPtr = new (&Buffer) TNorm(io, Obj);
1167 }
1168 else if (allocator) {
1169 BufPtr = allocator->Allocate<TNorm>();
1170 new (BufPtr) TNorm(io);
1171 } else {
1172 BufPtr = new TNorm(io);
1173 }
1174 }
1175
1176 ~MappingNormalizationHeap() {
1177 if ( io.outputting() ) {
1178 BufPtr->~TNorm();
1179 }
1180 else {
1181 Result = BufPtr->denormalize(io);
1182 }
1183 }
1184
1185 TNorm* operator->() { return BufPtr; }
1186
1187private:
1188 using Storage = AlignedCharArrayUnion<TNorm>;
1189
1190 Storage Buffer;
1191 IO &io;
1192 TNorm *BufPtr = nullptr;
1193 TFinal &Result;
1194};
1195
1196///
1197/// The Input class is used to parse a yaml document into in-memory structs
1198/// and vectors.
1199///
1200/// It works by using YAMLParser to do a syntax parse of the entire yaml
1201/// document, then the Input class builds a graph of HNodes which wraps
1202/// each yaml Node. The extra layer is buffering. The low level yaml
1203/// parser only lets you look at each node once. The buffering layer lets
1204/// you search and interate multiple times. This is necessary because
1205/// the mapRequired() method calls may not be in the same order
1206/// as the keys in the document.
1207///
1208class Input : public IO {
1209public:
1210 // Construct a yaml Input object from a StringRef and optional
1211 // user-data. The DiagHandler can be specified to provide
1212 // alternative error reporting.
1213 Input(StringRef InputContent,
1214 void *Ctxt = nullptr,
1215 SourceMgr::DiagHandlerTy DiagHandler = nullptr,
1216 void *DiagHandlerCtxt = nullptr);
1217 Input(MemoryBufferRef Input,
1218 void *Ctxt = nullptr,
1219 SourceMgr::DiagHandlerTy DiagHandler = nullptr,
1220 void *DiagHandlerCtxt = nullptr);
1221 ~Input() override;
1222
1223 // Check if there was an syntax or semantic error during parsing.
1224 std::error_code error();
1225
1226private:
1227 bool outputting() override;
1228 bool mapTag(StringRef, bool) override;
1229 void beginMapping() override;
1230 void endMapping() override;
1231 bool preflightKey(const char *, bool, bool, bool &, void *&) override;
1232 void postflightKey(void *) override;
1233 std::vector<StringRef> keys() override;
1234 void beginFlowMapping() override;
1235 void endFlowMapping() override;
1236 unsigned beginSequence() override;
1237 void endSequence() override;
1238 bool preflightElement(unsigned index, void *&) override;
1239 void postflightElement(void *) override;
1240 unsigned beginFlowSequence() override;
1241 bool preflightFlowElement(unsigned , void *&) override;
1242 void postflightFlowElement(void *) override;
1243 void endFlowSequence() override;
1244 void beginEnumScalar() override;
1245 bool matchEnumScalar(const char*, bool) override;
1246 bool matchEnumFallback() override;
1247 void endEnumScalar() override;
1248 bool beginBitSetScalar(bool &) override;
1249 bool bitSetMatch(const char *, bool ) override;
1250 void endBitSetScalar() override;
1251 void scalarString(StringRef &, QuotingType) override;
1252 void blockScalarString(StringRef &) override;
1253 void setError(const Twine &message) override;
1254 bool canElideEmptySequence() override;
1255
1256 class HNode {
1257 virtual void anchor();
1258
1259 public:
1260 HNode(Node *n) : _node(n) { }
1261 virtual ~HNode() = default;
1262
1263 static bool classof(const HNode *) { return true; }
1264
1265 Node *_node;
1266 };
1267
1268 class EmptyHNode : public HNode {
1269 void anchor() override;
1270
1271 public:
1272 EmptyHNode(Node *n) : HNode(n) { }
1273
1274 static bool classof(const HNode *n) { return NullNode::classof(n->_node); }
1275
1276 static bool classof(const EmptyHNode *) { return true; }
1277 };
1278
1279 class ScalarHNode : public HNode {
1280 void anchor() override;
1281
1282 public:
1283 ScalarHNode(Node *n, StringRef s) : HNode(n), _value(s) { }
1284
1285 StringRef value() const { return _value; }
1286
1287 static bool classof(const HNode *n) {
1288 return ScalarNode::classof(n->_node) ||
1289 BlockScalarNode::classof(n->_node);
1290 }
1291
1292 static bool classof(const ScalarHNode *) { return true; }
1293
1294 protected:
1295 StringRef _value;
1296 };
1297
1298 class MapHNode : public HNode {
1299 void anchor() override;
1300
1301 public:
1302 MapHNode(Node *n) : HNode(n) { }
1303
1304 static bool classof(const HNode *n) {
1305 return MappingNode::classof(n->_node);
1306 }
1307
1308 static bool classof(const MapHNode *) { return true; }
1309
1310 using NameToNode = StringMap<std::unique_ptr<HNode>>;
1311
1312 NameToNode Mapping;
1313 SmallVector<std::string, 6> ValidKeys;
1314 };
1315
1316 class SequenceHNode : public HNode {
1317 void anchor() override;
1318
1319 public:
1320 SequenceHNode(Node *n) : HNode(n) { }
1321
1322 static bool classof(const HNode *n) {
1323 return SequenceNode::classof(n->_node);
1324 }
1325
1326 static bool classof(const SequenceHNode *) { return true; }
1327
1328 std::vector<std::unique_ptr<HNode>> Entries;
1329 };
1330
1331 std::unique_ptr<Input::HNode> createHNodes(Node *node);
1332 void setError(HNode *hnode, const Twine &message);
1333 void setError(Node *node, const Twine &message);
1334
1335public:
1336 // These are only used by operator>>. They could be private
1337 // if those templated things could be made friends.
1338 bool setCurrentDocument();
1339 bool nextDocument();
1340
1341 /// Returns the current node that's being parsed by the YAML Parser.
1342 const Node *getCurrentNode() const;
1343
1344private:
1345 SourceMgr SrcMgr; // must be before Strm
1346 std::unique_ptr<llvm::yaml::Stream> Strm;
1347 std::unique_ptr<HNode> TopNode;
1348 std::error_code EC;
1349 BumpPtrAllocator StringAllocator;
1350 document_iterator DocIterator;
1351 std::vector<bool> BitValuesUsed;
1352 HNode *CurrentNode = nullptr;
1353 bool ScalarMatchFound;
1354};
1355
1356///
1357/// The Output class is used to generate a yaml document from in-memory structs
1358/// and vectors.
1359///
1360class Output : public IO {
1361public:
1362 Output(raw_ostream &, void *Ctxt = nullptr, int WrapColumn = 70);
1363 ~Output() override;
1364
1365 /// Set whether or not to output optional values which are equal
1366 /// to the default value. By default, when outputting if you attempt
1367 /// to write a value that is equal to the default, the value gets ignored.
1368 /// Sometimes, it is useful to be able to see these in the resulting YAML
1369 /// anyway.
1370 void setWriteDefaultValues(bool Write) { WriteDefaultValues = Write; }
1371
1372 bool outputting() override;
1373 bool mapTag(StringRef, bool) override;
1374 void beginMapping() override;
1375 void endMapping() override;
1376 bool preflightKey(const char *key, bool, bool, bool &, void *&) override;
1377 void postflightKey(void *) override;
1378 std::vector<StringRef> keys() override;
1379 void beginFlowMapping() override;
1380 void endFlowMapping() override;
1381 unsigned beginSequence() override;
1382 void endSequence() override;
1383 bool preflightElement(unsigned, void *&) override;
1384 void postflightElement(void *) override;
1385 unsigned beginFlowSequence() override;
1386 bool preflightFlowElement(unsigned, void *&) override;
1387 void postflightFlowElement(void *) override;
1388 void endFlowSequence() override;
1389 void beginEnumScalar() override;
1390 bool matchEnumScalar(const char*, bool) override;
1391 bool matchEnumFallback() override;
1392 void endEnumScalar() override;
1393 bool beginBitSetScalar(bool &) override;
1394 bool bitSetMatch(const char *, bool ) override;
1395 void endBitSetScalar() override;
1396 void scalarString(StringRef &, QuotingType) override;
1397 void blockScalarString(StringRef &) override;
1398 void setError(const Twine &message) override;
1399 bool canElideEmptySequence() override;
1400
1401 // These are only used by operator<<. They could be private
1402 // if that templated operator could be made a friend.
1403 void beginDocuments();
1404 bool preflightDocument(unsigned);
1405 void postflightDocument();
1406 void endDocuments();
1407
1408private:
1409 void output(StringRef s);
1410 void outputUpToEndOfLine(StringRef s);
1411 void newLineCheck();
1412 void outputNewLine();
1413 void paddedKey(StringRef key);
1414 void flowKey(StringRef Key);
1415
1416 enum InState {
1417 inSeq,
1418 inFlowSeq,
1419 inMapFirstKey,
1420 inMapOtherKey,
1421 inFlowMapFirstKey,
1422 inFlowMapOtherKey
1423 };
1424
1425 raw_ostream &Out;
1426 int WrapColumn;
1427 SmallVector<InState, 8> StateStack;
1428 int Column = 0;
1429 int ColumnAtFlowStart = 0;
1430 int ColumnAtMapFlowStart = 0;
1431 bool NeedBitValueComma = false;
1432 bool NeedFlowSequenceComma = false;
1433 bool EnumerationMatchFound = false;
1434 bool NeedsNewLine = false;
1435 bool WriteDefaultValues = false;
1436};
1437
1438/// YAML I/O does conversion based on types. But often native data types
1439/// are just a typedef of built in intergral types (e.g. int). But the C++
1440/// type matching system sees through the typedef and all the typedefed types
1441/// look like a built in type. This will cause the generic YAML I/O conversion
1442/// to be used. To provide better control over the YAML conversion, you can
1443/// use this macro instead of typedef. It will create a class with one field
1444/// and automatic conversion operators to and from the base type.
1445/// Based on BOOST_STRONG_TYPEDEF
1446#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)struct _type { _type() = default; _type(const _base v) : value
(v) {} _type(const _type &v) = default; _type &operator
=(const _type &rhs) = default; _type &operator=(const
_base &rhs) { value = rhs; return *this; } operator const
_base & () const { return value; } bool operator==(const
_type &rhs) const { return value == rhs.value; } bool operator
==(const _base &rhs) const { return value == rhs; } bool operator
<(const _type &rhs) const { return value < rhs.value
; } _base value; using BaseType = _base; };
\
1447 struct _type { \
1448 _type() = default; \
1449 _type(const _base v) : value(v) {} \
1450 _type(const _type &v) = default; \
1451 _type &operator=(const _type &rhs) = default; \
1452 _type &operator=(const _base &rhs) { value = rhs; return *this; } \
1453 operator const _base & () const { return value; } \
1454 bool operator==(const _type &rhs) const { return value == rhs.value; } \
1455 bool operator==(const _base &rhs) const { return value == rhs; } \
1456 bool operator<(const _type &rhs) const { return value < rhs.value; } \
1457 _base value; \
1458 using BaseType = _base; \
1459 };
1460
1461///
1462/// Use these types instead of uintXX_t in any mapping to have
1463/// its yaml output formatted as hexadecimal.
1464///
1465LLVM_YAML_STRONG_TYPEDEF(uint8_t, Hex8)struct Hex8 { Hex8() = default; Hex8(const uint8_t v) : value
(v) {} Hex8(const Hex8 &v) = default; Hex8 &operator=
(const Hex8 &rhs) = default; Hex8 &operator=(const uint8_t
&rhs) { value = rhs; return *this; } operator const uint8_t
& () const { return value; } bool operator==(const Hex8 &
rhs) const { return value == rhs.value; } bool operator==(const
uint8_t &rhs) const { return value == rhs; } bool operator
<(const Hex8 &rhs) const { return value < rhs.value
; } uint8_t value; using BaseType = uint8_t; };
1466LLVM_YAML_STRONG_TYPEDEF(uint16_t, Hex16)struct Hex16 { Hex16() = default; Hex16(const uint16_t v) : value
(v) {} Hex16(const Hex16 &v) = default; Hex16 &operator
=(const Hex16 &rhs) = default; Hex16 &operator=(const
uint16_t &rhs) { value = rhs; return *this; } operator const
uint16_t & () const { return value; } bool operator==(const
Hex16 &rhs) const { return value == rhs.value; } bool operator
==(const uint16_t &rhs) const { return value == rhs; } bool
operator<(const Hex16 &rhs) const { return value <
rhs.value; } uint16_t value; using BaseType = uint16_t; };
1467LLVM_YAML_STRONG_TYPEDEF(uint32_t, Hex32)struct Hex32 { Hex32() = default; Hex32(const uint32_t v) : value
(v) {} Hex32(const Hex32 &v) = default; Hex32 &operator
=(const Hex32 &rhs) = default; Hex32 &operator=(const
uint32_t &rhs) { value = rhs; return *this; } operator const
uint32_t & () const { return value; } bool operator==(const
Hex32 &rhs) const { return value == rhs.value; } bool operator
==(const uint32_t &rhs) const { return value == rhs; } bool
operator<(const Hex32 &rhs) const { return value <
rhs.value; } uint32_t value; using BaseType = uint32_t; };
1468LLVM_YAML_STRONG_TYPEDEF(uint64_t, Hex64)struct Hex64 { Hex64() = default; Hex64(const uint64_t v) : value
(v) {} Hex64(const Hex64 &v) = default; Hex64 &operator
=(const Hex64 &rhs) = default; Hex64 &operator=(const
uint64_t &rhs) { value = rhs; return *this; } operator const
uint64_t & () const { return value; } bool operator==(const
Hex64 &rhs) const { return value == rhs.value; } bool operator
==(const uint64_t &rhs) const { return value == rhs; } bool
operator<(const Hex64 &rhs) const { return value <
rhs.value; } uint64_t value; using BaseType = uint64_t; };
1469
1470template<>
1471struct ScalarTraits<Hex8> {
1472 static void output(const Hex8 &, void *, raw_ostream &);
1473 static StringRef input(StringRef, void *, Hex8 &);
1474 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1475};
1476
1477template<>
1478struct ScalarTraits<Hex16> {
1479 static void output(const Hex16 &, void *, raw_ostream &);
1480 static StringRef input(StringRef, void *, Hex16 &);
1481 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1482};
1483
1484template<>
1485struct ScalarTraits<Hex32> {
1486 static void output(const Hex32 &, void *, raw_ostream &);
1487 static StringRef input(StringRef, void *, Hex32 &);
1488 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1489};
1490
1491template<>
1492struct ScalarTraits<Hex64> {
1493 static void output(const Hex64 &, void *, raw_ostream &);
1494 static StringRef input(StringRef, void *, Hex64 &);
1495 static QuotingType mustQuote(StringRef) { return QuotingType::None; }
1496};
1497
1498// Define non-member operator>> so that Input can stream in a document list.
1499template <typename T>
1500inline
1501typename std::enable_if<has_DocumentListTraits<T>::value, Input &>::type
1502operator>>(Input &yin, T &docList) {
1503 int i = 0;
1504 EmptyContext Ctx;
1505 while ( yin.setCurrentDocument() ) {
1506 yamlize(yin, DocumentListTraits<T>::element(yin, docList, i), true, Ctx);
1507 if ( yin.error() )
1508 return yin;
1509 yin.nextDocument();
1510 ++i;
1511 }
1512 return yin;
1513}
1514
1515// Define non-member operator>> so that Input can stream in a map as a document.
1516template <typename T>
1517inline typename std::enable_if<has_MappingTraits<T, EmptyContext>::value,
1518 Input &>::type
1519operator>>(Input &yin, T &docMap) {
1520 EmptyContext Ctx;
1521 yin.setCurrentDocument();
1522 yamlize(yin, docMap, true, Ctx);
1523 return yin;
1524}
1525
1526// Define non-member operator>> so that Input can stream in a sequence as
1527// a document.
1528template <typename T>
1529inline
1530typename std::enable_if<has_SequenceTraits<T>::value, Input &>::type
1531operator>>(Input &yin, T &docSeq) {
1532 EmptyContext Ctx;
1533 if (yin.setCurrentDocument())
1534 yamlize(yin, docSeq, true, Ctx);
1535 return yin;
1536}
1537
1538// Define non-member operator>> so that Input can stream in a block scalar.
1539template <typename T>
1540inline
1541typename std::enable_if<has_BlockScalarTraits<T>::value, Input &>::type
1542operator>>(Input &In, T &Val) {
1543 EmptyContext Ctx;
1544 if (In.setCurrentDocument())
1545 yamlize(In, Val, true, Ctx);
1546 return In;
1547}
1548
1549// Define non-member operator>> so that Input can stream in a string map.
1550template <typename T>
1551inline
1552typename std::enable_if<has_CustomMappingTraits<T>::value, Input &>::type
1553operator>>(Input &In, T &Val) {
1554 EmptyContext Ctx;
1555 if (In.setCurrentDocument())
1556 yamlize(In, Val, true, Ctx);
1557 return In;
1558}
1559
1560// Provide better error message about types missing a trait specialization
1561template <typename T>
1562inline typename std::enable_if<missingTraits<T, EmptyContext>::value,
1563 Input &>::type
1564operator>>(Input &yin, T &docSeq) {
1565 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
1566 return yin;
1567}
1568
1569// Define non-member operator<< so that Output can stream out document list.
1570template <typename T>
1571inline
1572typename std::enable_if<has_DocumentListTraits<T>::value, Output &>::type
1573operator<<(Output &yout, T &docList) {
1574 EmptyContext Ctx;
1575 yout.beginDocuments();
1576 const size_t count = DocumentListTraits<T>::size(yout, docList);
1577 for(size_t i=0; i < count; ++i) {
1578 if ( yout.preflightDocument(i) ) {
1579 yamlize(yout, DocumentListTraits<T>::element(yout, docList, i), true,
1580 Ctx);
1581 yout.postflightDocument();
1582 }
1583 }
1584 yout.endDocuments();
1585 return yout;
1586}
1587
1588// Define non-member operator<< so that Output can stream out a map.
1589template <typename T>
1590inline typename std::enable_if<has_MappingTraits<T, EmptyContext>::value,
1591 Output &>::type
1592operator<<(Output &yout, T &map) {
1593 EmptyContext Ctx;
1594 yout.beginDocuments();
1595 if ( yout.preflightDocument(0) ) {
1596 yamlize(yout, map, true, Ctx);
1597 yout.postflightDocument();
1598 }
1599 yout.endDocuments();
1600 return yout;
1601}
1602
1603// Define non-member operator<< so that Output can stream out a sequence.
1604template <typename T>
1605inline
1606typename std::enable_if<has_SequenceTraits<T>::value, Output &>::type
1607operator<<(Output &yout, T &seq) {
1608 EmptyContext Ctx;
1609 yout.beginDocuments();
1610 if ( yout.preflightDocument(0) ) {
1611 yamlize(yout, seq, true, Ctx);
1612 yout.postflightDocument();
1613 }
1614 yout.endDocuments();
1615 return yout;
1616}
1617
1618// Define non-member operator<< so that Output can stream out a block scalar.
1619template <typename T>
1620inline
1621typename std::enable_if<has_BlockScalarTraits<T>::value, Output &>::type
1622operator<<(Output &Out, T &Val) {
1623 EmptyContext Ctx;
1624 Out.beginDocuments();
1625 if (Out.preflightDocument(0)) {
1626 yamlize(Out, Val, true, Ctx);
1627 Out.postflightDocument();
1628 }
1629 Out.endDocuments();
1630 return Out;
1631}
1632
1633// Define non-member operator<< so that Output can stream out a string map.
1634template <typename T>
1635inline
1636typename std::enable_if<has_CustomMappingTraits<T>::value, Output &>::type
1637operator<<(Output &Out, T &Val) {
1638 EmptyContext Ctx;
1639 Out.beginDocuments();
1640 if (Out.preflightDocument(0)) {
1641 yamlize(Out, Val, true, Ctx);
1642 Out.postflightDocument();
1643 }
1644 Out.endDocuments();
1645 return Out;
1646}
1647
1648// Provide better error message about types missing a trait specialization
1649template <typename T>
1650inline typename std::enable_if<missingTraits<T, EmptyContext>::value,
1651 Output &>::type
1652operator<<(Output &yout, T &seq) {
1653 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
1654 return yout;
1655}
1656
1657template <bool B> struct IsFlowSequenceBase {};
1658template <> struct IsFlowSequenceBase<true> { static const bool flow = true; };
1659
1660template <typename T, bool Flow>
1661struct SequenceTraitsImpl : IsFlowSequenceBase<Flow> {
1662private:
1663 using type = typename T::value_type;
1664
1665public:
1666 static size_t size(IO &io, T &seq) { return seq.size(); }
1667
1668 static type &element(IO &io, T &seq, size_t index) {
1669 if (index >= seq.size())
1670 seq.resize(index + 1);
1671 return seq[index];
1672 }
1673};
1674
1675// Simple helper to check an expression can be used as a bool-valued template
1676// argument.
1677template <bool> struct CheckIsBool { static const bool value = true; };
1678
1679// If T has SequenceElementTraits, then vector<T> and SmallVector<T, N> have
1680// SequenceTraits that do the obvious thing.
1681template <typename T>
1682struct SequenceTraits<std::vector<T>,
1683 typename std::enable_if<CheckIsBool<
1684 SequenceElementTraits<T>::flow>::value>::type>
1685 : SequenceTraitsImpl<std::vector<T>, SequenceElementTraits<T>::flow> {};
1686template <typename T, unsigned N>
1687struct SequenceTraits<SmallVector<T, N>,
1688 typename std::enable_if<CheckIsBool<
1689 SequenceElementTraits<T>::flow>::value>::type>
1690 : SequenceTraitsImpl<SmallVector<T, N>, SequenceElementTraits<T>::flow> {};
1691
1692// Sequences of fundamental types use flow formatting.
1693template <typename T>
1694struct SequenceElementTraits<
1695 T, typename std::enable_if<std::is_fundamental<T>::value>::type> {
1696 static const bool flow = true;
1697};
1698
1699// Sequences of strings use block formatting.
1700template<> struct SequenceElementTraits<std::string> {
1701 static const bool flow = false;
1702};
1703template<> struct SequenceElementTraits<StringRef> {
1704 static const bool flow = false;
1705};
1706template<> struct SequenceElementTraits<std::pair<std::string, std::string>> {
1707 static const bool flow = false;
1708};
1709
1710/// Implementation of CustomMappingTraits for std::map<std::string, T>.
1711template <typename T> struct StdMapStringCustomMappingTraitsImpl {
1712 using map_type = std::map<std::string, T>;
1713
1714 static void inputOne(IO &io, StringRef key, map_type &v) {
1715 io.mapRequired(key.str().c_str(), v[key]);
1716 }
1717
1718 static void output(IO &io, map_type &v) {
1719 for (auto &p : v)
1720 io.mapRequired(p.first.c_str(), p.second);
1721 }
1722};
1723
1724} // end namespace yaml
1725} // end namespace llvm
1726
1727#define LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(TYPE, FLOW)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<TYPE>::value && !std::is_same<TYPE, std::string
>::value && !std::is_same<TYPE, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<TYPE>
{ static const bool flow = FLOW; }; } }
\
1728 namespace llvm { \
1729 namespace yaml { \
1730 static_assert( \
1731 !std::is_fundamental<TYPE>::value && \
1732 !std::is_same<TYPE, std::string>::value && \
1733 !std::is_same<TYPE, llvm::StringRef>::value, \
1734 "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"); \
1735 template <> struct SequenceElementTraits<TYPE> { \
1736 static const bool flow = FLOW; \
1737 }; \
1738 } \
1739 }
1740
1741/// Utility for declaring that a std::vector of a particular type
1742/// should be considered a YAML sequence.
1743#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<type>::value && !std::is_same<type, std::string
>::value && !std::is_same<type, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<type>
{ static const bool flow = false; }; } }
\
1744 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, false)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<type>::value && !std::is_same<type, std::string
>::value && !std::is_same<type, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<type>
{ static const bool flow = false; }; } }
1745
1746/// Utility for declaring that a std::vector of a particular type
1747/// should be considered a YAML flow sequence.
1748#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<type>::value && !std::is_same<type, std::string
>::value && !std::is_same<type, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<type>
{ static const bool flow = true; }; } }
\
1749 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, true)namespace llvm { namespace yaml { static_assert( !std::is_fundamental
<type>::value && !std::is_same<type, std::string
>::value && !std::is_same<type, llvm::StringRef
>::value, "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"
); template <> struct SequenceElementTraits<type>
{ static const bool flow = true; }; } }
1750
1751#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type)namespace llvm { namespace yaml { template <> struct MappingTraits
<Type> { static void mapping(IO &IO, Type &Obj)
; }; } }
\
1752 namespace llvm { \
1753 namespace yaml { \
1754 template <> struct MappingTraits<Type> { \
1755 static void mapping(IO &IO, Type &Obj); \
1756 }; \
1757 } \
1758 }
1759
1760#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type)namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits
<Type> { static void enumeration(IO &io, Type &
Value); }; } }
\
1761 namespace llvm { \
1762 namespace yaml { \
1763 template <> struct ScalarEnumerationTraits<Type> { \
1764 static void enumeration(IO &io, Type &Value); \
1765 }; \
1766 } \
1767 }
1768
1769#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type)namespace llvm { namespace yaml { template <> struct ScalarBitSetTraits
<Type> { static void bitset(IO &IO, Type &Options
); }; } }
\
1770 namespace llvm { \
1771 namespace yaml { \
1772 template <> struct ScalarBitSetTraits<Type> { \
1773 static void bitset(IO &IO, Type &Options); \
1774 }; \
1775 } \
1776 }
1777
1778#define LLVM_YAML_DECLARE_SCALAR_TRAITS(Type, MustQuote)namespace llvm { namespace yaml { template <> struct ScalarTraits
<Type> { static void output(const Type &Value, void
*ctx, raw_ostream &Out); static StringRef input(StringRef
Scalar, void *ctxt, Type &Value); static QuotingType mustQuote
(StringRef) { return MustQuote; } }; } }
\
1779 namespace llvm { \
1780 namespace yaml { \
1781 template <> struct ScalarTraits<Type> { \
1782 static void output(const Type &Value, void *ctx, raw_ostream &Out); \
1783 static StringRef input(StringRef Scalar, void *ctxt, Type &Value); \
1784 static QuotingType mustQuote(StringRef) { return MustQuote; } \
1785 }; \
1786 } \
1787 }
1788
1789/// Utility for declaring that a std::vector of a particular type
1790/// should be considered a YAML document list.
1791#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type)namespace llvm { namespace yaml { template <unsigned N>
struct DocumentListTraits<SmallVector<_type, N>>
: public SequenceTraitsImpl<SmallVector<_type, N>, false
> {}; template <> struct DocumentListTraits<std::
vector<_type>> : public SequenceTraitsImpl<std::vector
<_type>, false> {}; } }
\
1792 namespace llvm { \
1793 namespace yaml { \
1794 template <unsigned N> \
1795 struct DocumentListTraits<SmallVector<_type, N>> \
1796 : public SequenceTraitsImpl<SmallVector<_type, N>, false> {}; \
1797 template <> \
1798 struct DocumentListTraits<std::vector<_type>> \
1799 : public SequenceTraitsImpl<std::vector<_type>, false> {}; \
1800 } \
1801 }
1802
1803/// Utility for declaring that std::map<std::string, _type> should be considered
1804/// a YAML map.
1805#define LLVM_YAML_IS_STRING_MAP(_type)namespace llvm { namespace yaml { template <> struct CustomMappingTraits
<std::map<std::string, _type>> : public StdMapStringCustomMappingTraitsImpl
<_type> {}; } }
\
1806 namespace llvm { \
1807 namespace yaml { \
1808 template <> \
1809 struct CustomMappingTraits<std::map<std::string, _type>> \
1810 : public StdMapStringCustomMappingTraitsImpl<_type> {}; \
1811 } \
1812 }
1813
1814#endif // LLVM_SUPPORT_YAMLTRAITS_H