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-eagerly-assume -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-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/lib/ObjectYAML -I /build/llvm-toolchain-snapshot-7~svn338205/lib/ObjectYAML -I /build/llvm-toolchain-snapshot-7~svn338205/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn338205/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/lib/gcc/x86_64-linux-gnu/8/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-class-memaccess -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn338205/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-07-29-043837-17923-1 -x c++ /build/llvm-toolchain-snapshot-7~svn338205/lib/ObjectYAML/ELFYAML.cpp -faddrsig

/build/llvm-toolchain-snapshot-7~svn338205/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")(static_cast <bool> (Object && "The IO context is not initialized"
) ? void (0) : __assert_fail ("Object && \"The IO context is not initialized\""
, "/build/llvm-toolchain-snapshot-7~svn338205/lib/ObjectYAML/ELFYAML.cpp"
, 276, __extension__ __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 BCase(EF_AMDGPU_XNACK);
406 break;
407 case ELF::EM_X86_64:
408 break;
409 default:
410 llvm_unreachable("Unsupported architecture")::llvm::llvm_unreachable_internal("Unsupported architecture",
"/build/llvm-toolchain-snapshot-7~svn338205/lib/ObjectYAML/ELFYAML.cpp"
, 410)
;
411 }
412#undef BCase
413#undef BCaseMask
414}
415
416void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
417 IO &IO, ELFYAML::ELF_SHT &Value) {
418 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
419 assert(Object && "The IO context is not initialized")(static_cast <bool> (Object && "The IO context is not initialized"
) ? void (0) : __assert_fail ("Object && \"The IO context is not initialized\""
, "/build/llvm-toolchain-snapshot-7~svn338205/lib/ObjectYAML/ELFYAML.cpp"
, 419, __extension__ __PRETTY_FUNCTION__))
;
12
Within the expansion of the macro 'assert':
a
Assuming 'Object' is non-null
420#define ECase(X) IO.enumCase(Value, #X, ELF::X)
421 ECase(SHT_NULL);
13
Within the expansion of the macro 'ECase':
a
Calling 'IO::enumCase'
422 ECase(SHT_PROGBITS);
423 ECase(SHT_SYMTAB);
424 // FIXME: Issue a diagnostic with this information.
425 ECase(SHT_STRTAB);
426 ECase(SHT_RELA);
427 ECase(SHT_HASH);
428 ECase(SHT_DYNAMIC);
429 ECase(SHT_NOTE);
430 ECase(SHT_NOBITS);
431 ECase(SHT_REL);
432 ECase(SHT_SHLIB);
433 ECase(SHT_DYNSYM);
434 ECase(SHT_INIT_ARRAY);
435 ECase(SHT_FINI_ARRAY);
436 ECase(SHT_PREINIT_ARRAY);
437 ECase(SHT_GROUP);
438 ECase(SHT_SYMTAB_SHNDX);
439 ECase(SHT_RELR);
440 ECase(SHT_LOOS);
441 ECase(SHT_ANDROID_REL);
442 ECase(SHT_ANDROID_RELA);
443 ECase(SHT_ANDROID_RELR);
444 ECase(SHT_LLVM_ODRTAB);
445 ECase(SHT_LLVM_LINKER_OPTIONS);
446 ECase(SHT_LLVM_CALL_GRAPH_PROFILE);
447 ECase(SHT_LLVM_ADDRSIG);
448 ECase(SHT_GNU_ATTRIBUTES);
449 ECase(SHT_GNU_HASH);
450 ECase(SHT_GNU_verdef);
451 ECase(SHT_GNU_verneed);
452 ECase(SHT_GNU_versym);
453 ECase(SHT_HIOS);
454 ECase(SHT_LOPROC);
455 switch (Object->Header.Machine) {
456 case ELF::EM_ARM:
457 ECase(SHT_ARM_EXIDX);
458 ECase(SHT_ARM_PREEMPTMAP);
459 ECase(SHT_ARM_ATTRIBUTES);
460 ECase(SHT_ARM_DEBUGOVERLAY);
461 ECase(SHT_ARM_OVERLAYSECTION);
462 break;
463 case ELF::EM_HEXAGON:
464 ECase(SHT_HEX_ORDERED);
465 break;
466 case ELF::EM_X86_64:
467 ECase(SHT_X86_64_UNWIND);
468 break;
469 case ELF::EM_MIPS:
470 ECase(SHT_MIPS_REGINFO);
471 ECase(SHT_MIPS_OPTIONS);
472 ECase(SHT_MIPS_ABIFLAGS);
473 break;
474 default:
475 // Nothing to do.
476 break;
477 }
478#undef ECase
479}
480
481void ScalarBitSetTraits<ELFYAML::ELF_PF>::bitset(IO &IO,
482 ELFYAML::ELF_PF &Value) {
483#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
484 BCase(PF_X);
485 BCase(PF_W);
486 BCase(PF_R);
487}
488
489void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO,
490 ELFYAML::ELF_SHF &Value) {
491 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
492#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
493 BCase(SHF_WRITE);
494 BCase(SHF_ALLOC);
495 BCase(SHF_EXCLUDE);
496 BCase(SHF_EXECINSTR);
497 BCase(SHF_MERGE);
498 BCase(SHF_STRINGS);
499 BCase(SHF_INFO_LINK);
500 BCase(SHF_LINK_ORDER);
501 BCase(SHF_OS_NONCONFORMING);
502 BCase(SHF_GROUP);
503 BCase(SHF_TLS);
504 BCase(SHF_COMPRESSED);
505 switch (Object->Header.Machine) {
506 case ELF::EM_ARM:
507 BCase(SHF_ARM_PURECODE);
508 break;
509 case ELF::EM_HEXAGON:
510 BCase(SHF_HEX_GPREL);
511 break;
512 case ELF::EM_MIPS:
513 BCase(SHF_MIPS_NODUPES);
514 BCase(SHF_MIPS_NAMES);
515 BCase(SHF_MIPS_LOCAL);
516 BCase(SHF_MIPS_NOSTRIP);
517 BCase(SHF_MIPS_GPREL);
518 BCase(SHF_MIPS_MERGE);
519 BCase(SHF_MIPS_ADDR);
520 BCase(SHF_MIPS_STRING);
521 break;
522 case ELF::EM_X86_64:
523 BCase(SHF_X86_64_LARGE);
524 break;
525 default:
526 // Nothing to do.
527 break;
528 }
529#undef BCase
530}
531
532void ScalarEnumerationTraits<ELFYAML::ELF_SHN>::enumeration(
533 IO &IO, ELFYAML::ELF_SHN &Value) {
534#define ECase(X) IO.enumCase(Value, #X, ELF::X)
535 ECase(SHN_UNDEF);
536 ECase(SHN_LORESERVE);
537 ECase(SHN_LOPROC);
538 ECase(SHN_HIPROC);
539 ECase(SHN_LOOS);
540 ECase(SHN_HIOS);
541 ECase(SHN_ABS);
542 ECase(SHN_COMMON);
543 ECase(SHN_XINDEX);
544 ECase(SHN_HIRESERVE);
545 ECase(SHN_HEXAGON_SCOMMON);
546 ECase(SHN_HEXAGON_SCOMMON_1);
547 ECase(SHN_HEXAGON_SCOMMON_2);
548 ECase(SHN_HEXAGON_SCOMMON_4);
549 ECase(SHN_HEXAGON_SCOMMON_8);
550#undef ECase
551 IO.enumFallback<Hex32>(Value);
552}
553
554void ScalarEnumerationTraits<ELFYAML::ELF_STT>::enumeration(
555 IO &IO, ELFYAML::ELF_STT &Value) {
556#define ECase(X) IO.enumCase(Value, #X, ELF::X)
557 ECase(STT_NOTYPE);
558 ECase(STT_OBJECT);
559 ECase(STT_FUNC);
560 ECase(STT_SECTION);
561 ECase(STT_FILE);
562 ECase(STT_COMMON);
563 ECase(STT_TLS);
564 ECase(STT_GNU_IFUNC);
565#undef ECase
566}
567
568void ScalarEnumerationTraits<ELFYAML::ELF_STV>::enumeration(
569 IO &IO, ELFYAML::ELF_STV &Value) {
570#define ECase(X) IO.enumCase(Value, #X, ELF::X)
571 ECase(STV_DEFAULT);
572 ECase(STV_INTERNAL);
573 ECase(STV_HIDDEN);
574 ECase(STV_PROTECTED);
575#undef ECase
576}
577
578void ScalarBitSetTraits<ELFYAML::ELF_STO>::bitset(IO &IO,
579 ELFYAML::ELF_STO &Value) {
580 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
581 assert(Object && "The IO context is not initialized")(static_cast <bool> (Object && "The IO context is not initialized"
) ? void (0) : __assert_fail ("Object && \"The IO context is not initialized\""
, "/build/llvm-toolchain-snapshot-7~svn338205/lib/ObjectYAML/ELFYAML.cpp"
, 581, __extension__ __PRETTY_FUNCTION__))
;
582#define BCase(X) IO.bitSetCase(Value, #X, ELF::X)
583 switch (Object->Header.Machine) {
584 case ELF::EM_MIPS:
585 BCase(STO_MIPS_OPTIONAL);
586 BCase(STO_MIPS_PLT);
587 BCase(STO_MIPS_PIC);
588 BCase(STO_MIPS_MICROMIPS);
589 break;
590 default:
591 break; // Nothing to do
592 }
593#undef BCase
594#undef BCaseMask
595}
596
597void ScalarEnumerationTraits<ELFYAML::ELF_RSS>::enumeration(
598 IO &IO, ELFYAML::ELF_RSS &Value) {
599#define ECase(X) IO.enumCase(Value, #X, ELF::X)
600 ECase(RSS_UNDEF);
601 ECase(RSS_GP);
602 ECase(RSS_GP0);
603 ECase(RSS_LOC);
604#undef ECase
605}
606
607void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
608 IO &IO, ELFYAML::ELF_REL &Value) {
609 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
610 assert(Object && "The IO context is not initialized")(static_cast <bool> (Object && "The IO context is not initialized"
) ? void (0) : __assert_fail ("Object && \"The IO context is not initialized\""
, "/build/llvm-toolchain-snapshot-7~svn338205/lib/ObjectYAML/ELFYAML.cpp"
, 610, __extension__ __PRETTY_FUNCTION__))
;
611#define ELF_RELOC(X, Y) IO.enumCase(Value, #X, ELF::X);
612 switch (Object->Header.Machine) {
613 case ELF::EM_X86_64:
614#include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
615 break;
616 case ELF::EM_MIPS:
617#include "llvm/BinaryFormat/ELFRelocs/Mips.def"
618 break;
619 case ELF::EM_HEXAGON:
620#include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
621 break;
622 case ELF::EM_386:
623 case ELF::EM_IAMCU:
624#include "llvm/BinaryFormat/ELFRelocs/i386.def"
625 break;
626 case ELF::EM_AARCH64:
627#include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
628 break;
629 case ELF::EM_ARM:
630#include "llvm/BinaryFormat/ELFRelocs/ARM.def"
631 break;
632 case ELF::EM_ARC:
633#include "llvm/BinaryFormat/ELFRelocs/ARC.def"
634 break;
635 case ELF::EM_RISCV:
636#include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
637 break;
638 case ELF::EM_LANAI:
639#include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
640 break;
641 case ELF::EM_AMDGPU:
642#include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
643 break;
644 case ELF::EM_BPF:
645#include "llvm/BinaryFormat/ELFRelocs/BPF.def"
646 break;
647 default:
648 llvm_unreachable("Unsupported architecture")::llvm::llvm_unreachable_internal("Unsupported architecture",
"/build/llvm-toolchain-snapshot-7~svn338205/lib/ObjectYAML/ELFYAML.cpp"
, 648)
;
649 }
650#undef ELF_RELOC
651 IO.enumFallback<Hex32>(Value);
652}
653
654void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG>::enumeration(
655 IO &IO, ELFYAML::MIPS_AFL_REG &Value) {
656#define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
657 ECase(REG_NONE);
658 ECase(REG_32);
659 ECase(REG_64);
660 ECase(REG_128);
661#undef ECase
662}
663
664void ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP>::enumeration(
665 IO &IO, ELFYAML::MIPS_ABI_FP &Value) {
666#define ECase(X) IO.enumCase(Value, #X, Mips::Val_GNU_MIPS_ABI_##X)
667 ECase(FP_ANY);
668 ECase(FP_DOUBLE);
669 ECase(FP_SINGLE);
670 ECase(FP_SOFT);
671 ECase(FP_OLD_64);
672 ECase(FP_XX);
673 ECase(FP_64);
674 ECase(FP_64A);
675#undef ECase
676}
677
678void ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT>::enumeration(
679 IO &IO, ELFYAML::MIPS_AFL_EXT &Value) {
680#define ECase(X) IO.enumCase(Value, #X, Mips::AFL_##X)
681 ECase(EXT_NONE);
682 ECase(EXT_XLR);
683 ECase(EXT_OCTEON2);
684 ECase(EXT_OCTEONP);
685 ECase(EXT_LOONGSON_3A);
686 ECase(EXT_OCTEON);
687 ECase(EXT_5900);
688 ECase(EXT_4650);
689 ECase(EXT_4010);
690 ECase(EXT_4100);
691 ECase(EXT_3900);
692 ECase(EXT_10000);
693 ECase(EXT_SB1);
694 ECase(EXT_4111);
695 ECase(EXT_4120);
696 ECase(EXT_5400);
697 ECase(EXT_5500);
698 ECase(EXT_LOONGSON_2E);
699 ECase(EXT_LOONGSON_2F);
700 ECase(EXT_OCTEON3);
701#undef ECase
702}
703
704void ScalarEnumerationTraits<ELFYAML::MIPS_ISA>::enumeration(
705 IO &IO, ELFYAML::MIPS_ISA &Value) {
706 IO.enumCase(Value, "MIPS1", 1);
707 IO.enumCase(Value, "MIPS2", 2);
708 IO.enumCase(Value, "MIPS3", 3);
709 IO.enumCase(Value, "MIPS4", 4);
710 IO.enumCase(Value, "MIPS5", 5);
711 IO.enumCase(Value, "MIPS32", 32);
712 IO.enumCase(Value, "MIPS64", 64);
713}
714
715void ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE>::bitset(
716 IO &IO, ELFYAML::MIPS_AFL_ASE &Value) {
717#define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_ASE_##X)
718 BCase(DSP);
719 BCase(DSPR2);
720 BCase(EVA);
721 BCase(MCU);
722 BCase(MDMX);
723 BCase(MIPS3D);
724 BCase(MT);
725 BCase(SMARTMIPS);
726 BCase(VIRT);
727 BCase(MSA);
728 BCase(MIPS16);
729 BCase(MICROMIPS);
730 BCase(XPA);
731#undef BCase
732}
733
734void ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1>::bitset(
735 IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value) {
736#define BCase(X) IO.bitSetCase(Value, #X, Mips::AFL_FLAGS1_##X)
737 BCase(ODDSPREG);
738#undef BCase
739}
740
741void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
742 ELFYAML::FileHeader &FileHdr) {
743 IO.mapRequired("Class", FileHdr.Class);
744 IO.mapRequired("Data", FileHdr.Data);
745 IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
746 IO.mapRequired("Type", FileHdr.Type);
747 IO.mapRequired("Machine", FileHdr.Machine);
748 IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
749 IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
750}
751
752void MappingTraits<ELFYAML::ProgramHeader>::mapping(
753 IO &IO, ELFYAML::ProgramHeader &Phdr) {
754 IO.mapRequired("Type", Phdr.Type);
755 IO.mapOptional("Flags", Phdr.Flags, ELFYAML::ELF_PF(0));
756 IO.mapOptional("Sections", Phdr.Sections);
757 IO.mapOptional("VAddr", Phdr.VAddr, Hex64(0));
758 IO.mapOptional("PAddr", Phdr.PAddr, Hex64(0));
759 IO.mapOptional("Align", Phdr.Align);
760}
761
762namespace {
763
764struct NormalizedOther {
765 NormalizedOther(IO &)
766 : Visibility(ELFYAML::ELF_STV(0)), Other(ELFYAML::ELF_STO(0)) {}
767 NormalizedOther(IO &, uint8_t Original)
768 : Visibility(Original & 0x3), Other(Original & ~0x3) {}
769
770 uint8_t denormalize(IO &) { return Visibility | Other; }
771
772 ELFYAML::ELF_STV Visibility;
773 ELFYAML::ELF_STO Other;
774};
775
776} // end anonymous namespace
777
778void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
779 IO.mapOptional("Name", Symbol.Name, StringRef());
780 IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
781 IO.mapOptional("Section", Symbol.Section, StringRef());
782 IO.mapOptional("Index", Symbol.Index);
783 IO.mapOptional("Value", Symbol.Value, Hex64(0));
784 IO.mapOptional("Size", Symbol.Size, Hex64(0));
785
786 MappingNormalization<NormalizedOther, uint8_t> Keys(IO, Symbol.Other);
787 IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
788 IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
789}
790
791StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
792 ELFYAML::Symbol &Symbol) {
793 if (Symbol.Index && Symbol.Section.data()) {
794 return "Index and Section cannot both be specified for Symbol";
795 }
796 if (Symbol.Index && *Symbol.Index == ELFYAML::ELF_SHN(ELF::SHN_XINDEX)) {
797 return "Large indexes are not supported";
798 }
799 if (Symbol.Index && *Symbol.Index < ELFYAML::ELF_SHN(ELF::SHN_LORESERVE)) {
800 return "Use a section name to define which section a symbol is defined in";
801 }
802 return StringRef();
803}
804
805void MappingTraits<ELFYAML::LocalGlobalWeakSymbols>::mapping(
806 IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols) {
807 IO.mapOptional("Local", Symbols.Local);
808 IO.mapOptional("Global", Symbols.Global);
809 IO.mapOptional("Weak", Symbols.Weak);
810}
811
812static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
813 IO.mapOptional("Name", Section.Name, StringRef());
814 IO.mapRequired("Type", Section.Type);
815 IO.mapOptional("Flags", Section.Flags, ELFYAML::ELF_SHF(0));
816 IO.mapOptional("Address", Section.Address, Hex64(0));
817 IO.mapOptional("Link", Section.Link, StringRef());
818 IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0));
819 IO.mapOptional("Info", Section.Info, StringRef());
820}
821
822static void sectionMapping(IO &IO, ELFYAML::RawContentSection &Section) {
823 commonSectionMapping(IO, Section);
824 IO.mapOptional("Content", Section.Content);
825 IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
826}
827
828static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {
829 commonSectionMapping(IO, Section);
830 IO.mapOptional("Size", Section.Size, Hex64(0));
831}
832
833static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
834 commonSectionMapping(IO, Section);
835 IO.mapOptional("Relocations", Section.Relocations);
836}
837
838static void groupSectionMapping(IO &IO, ELFYAML::Group &group) {
839 commonSectionMapping(IO, group);
840 IO.mapRequired("Members", group.Members);
841}
842
843void MappingTraits<ELFYAML::SectionOrType>::mapping(
844 IO &IO, ELFYAML::SectionOrType &sectionOrType) {
845 IO.mapRequired("SectionOrType", sectionOrType.sectionNameOrType);
846}
847
848void MappingTraits<ELFYAML::SectionName>::mapping(
849 IO &IO, ELFYAML::SectionName &sectionName) {
850 IO.mapRequired("Section", sectionName.Section);
851}
852
853static void sectionMapping(IO &IO, ELFYAML::MipsABIFlags &Section) {
854 commonSectionMapping(IO, Section);
855 IO.mapOptional("Version", Section.Version, Hex16(0));
856 IO.mapRequired("ISA", Section.ISALevel);
857 IO.mapOptional("ISARevision", Section.ISARevision, Hex8(0));
858 IO.mapOptional("ISAExtension", Section.ISAExtension,
859 ELFYAML::MIPS_AFL_EXT(Mips::AFL_EXT_NONE));
860 IO.mapOptional("ASEs", Section.ASEs, ELFYAML::MIPS_AFL_ASE(0));
861 IO.mapOptional("FpABI", Section.FpABI,
862 ELFYAML::MIPS_ABI_FP(Mips::Val_GNU_MIPS_ABI_FP_ANY));
863 IO.mapOptional("GPRSize", Section.GPRSize,
864 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
865 IO.mapOptional("CPR1Size", Section.CPR1Size,
866 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
867 IO.mapOptional("CPR2Size", Section.CPR2Size,
868 ELFYAML::MIPS_AFL_REG(Mips::AFL_REG_NONE));
869 IO.mapOptional("Flags1", Section.Flags1, ELFYAML::MIPS_AFL_FLAGS1(0));
870 IO.mapOptional("Flags2", Section.Flags2, Hex32(0));
871}
872
873void MappingTraits<std::unique_ptr<ELFYAML::Section>>::mapping(
874 IO &IO, std::unique_ptr<ELFYAML::Section> &Section) {
875 ELFYAML::ELF_SHT sectionType;
1
Calling defaulted default constructor for 'ELF_SHT'
3
Returning from default constructor for 'ELF_SHT'
876 if (IO.outputting())
4
Assuming the condition is false
5
Taking false branch
877 sectionType = Section->Type;
878 else
879 IO.mapRequired("Type", sectionType);
6
Calling 'IO::mapRequired'
880
881 switch (sectionType) {
882 case ELF::SHT_REL:
883 case ELF::SHT_RELA:
884 if (!IO.outputting())
885 Section.reset(new ELFYAML::RelocationSection());
886 sectionMapping(IO, *cast<ELFYAML::RelocationSection>(Section.get()));
887 break;
888 case ELF::SHT_GROUP:
889 if (!IO.outputting())
890 Section.reset(new ELFYAML::Group());
891 groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get()));
892 break;
893 case ELF::SHT_NOBITS:
894 if (!IO.outputting())
895 Section.reset(new ELFYAML::NoBitsSection());
896 sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
897 break;
898 case ELF::SHT_MIPS_ABIFLAGS:
899 if (!IO.outputting())
900 Section.reset(new ELFYAML::MipsABIFlags());
901 sectionMapping(IO, *cast<ELFYAML::MipsABIFlags>(Section.get()));
902 break;
903 default:
904 if (!IO.outputting())
905 Section.reset(new ELFYAML::RawContentSection());
906 sectionMapping(IO, *cast<ELFYAML::RawContentSection>(Section.get()));
907 }
908}
909
910StringRef MappingTraits<std::unique_ptr<ELFYAML::Section>>::validate(
911 IO &io, std::unique_ptr<ELFYAML::Section> &Section) {
912 const auto *RawSection = dyn_cast<ELFYAML::RawContentSection>(Section.get());
913 if (!RawSection || RawSection->Size >= RawSection->Content.binary_size())
914 return StringRef();
915 return "Section size must be greater or equal to the content size";
916}
917
918namespace {
919
920struct NormalizedMips64RelType {
921 NormalizedMips64RelType(IO &)
922 : Type(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
923 Type2(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
924 Type3(ELFYAML::ELF_REL(ELF::R_MIPS_NONE)),
925 SpecSym(ELFYAML::ELF_REL(ELF::RSS_UNDEF)) {}
926 NormalizedMips64RelType(IO &, ELFYAML::ELF_REL Original)
927 : Type(Original & 0xFF), Type2(Original >> 8 & 0xFF),
928 Type3(Original >> 16 & 0xFF), SpecSym(Original >> 24 & 0xFF) {}
929
930 ELFYAML::ELF_REL denormalize(IO &) {
931 ELFYAML::ELF_REL Res = Type | Type2 << 8 | Type3 << 16 | SpecSym << 24;
932 return Res;
933 }
934
935 ELFYAML::ELF_REL Type;
936 ELFYAML::ELF_REL Type2;
937 ELFYAML::ELF_REL Type3;
938 ELFYAML::ELF_RSS SpecSym;
939};
940
941} // end anonymous namespace
942
943void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
944 ELFYAML::Relocation &Rel) {
945 const auto *Object = static_cast<ELFYAML::Object *>(IO.getContext());
946 assert(Object && "The IO context is not initialized")(static_cast <bool> (Object && "The IO context is not initialized"
) ? void (0) : __assert_fail ("Object && \"The IO context is not initialized\""
, "/build/llvm-toolchain-snapshot-7~svn338205/lib/ObjectYAML/ELFYAML.cpp"
, 946, __extension__ __PRETTY_FUNCTION__))
;
947
948 IO.mapRequired("Offset", Rel.Offset);
949 IO.mapOptional("Symbol", Rel.Symbol);
950
951 if (Object->Header.Machine == ELFYAML::ELF_EM(ELF::EM_MIPS) &&
952 Object->Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
953 MappingNormalization<NormalizedMips64RelType, ELFYAML::ELF_REL> Key(
954 IO, Rel.Type);
955 IO.mapRequired("Type", Key->Type);
956 IO.mapOptional("Type2", Key->Type2, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
957 IO.mapOptional("Type3", Key->Type3, ELFYAML::ELF_REL(ELF::R_MIPS_NONE));
958 IO.mapOptional("SpecSym", Key->SpecSym, ELFYAML::ELF_RSS(ELF::RSS_UNDEF));
959 } else
960 IO.mapRequired("Type", Rel.Type);
961
962 IO.mapOptional("Addend", Rel.Addend, (int64_t)0);
963}
964
965void MappingTraits<ELFYAML::Object>::mapping(IO &IO, ELFYAML::Object &Object) {
966 assert(!IO.getContext() && "The IO context is initialized already")(static_cast <bool> (!IO.getContext() && "The IO context is initialized already"
) ? void (0) : __assert_fail ("!IO.getContext() && \"The IO context is initialized already\""
, "/build/llvm-toolchain-snapshot-7~svn338205/lib/ObjectYAML/ELFYAML.cpp"
, 966, __extension__ __PRETTY_FUNCTION__))
;
967 IO.setContext(&Object);
968 IO.mapTag("!ELF", true);
969 IO.mapRequired("FileHeader", Object.Header);
970 IO.mapOptional("ProgramHeaders", Object.ProgramHeaders);
971 IO.mapOptional("Sections", Object.Sections);
972 IO.mapOptional("Symbols", Object.Symbols);
973 IO.mapOptional("DynamicSymbols", Object.DynamicSymbols);
974 IO.setContext(nullptr);
975}
976
977LLVM_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; }
;
978LLVM_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; }
;
979LLVM_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;
};
980LLVM_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;
};
981LLVM_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;
};
982
983} // end namespace yaml
984
985} // end namespace llvm

/build/llvm-toolchain-snapshot-7~svn338205/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
127 Section(SectionKind Kind) : Kind(Kind) {}
128 virtual ~Section();
129};
130struct RawContentSection : Section {
131 yaml::BinaryRef Content;
132 llvm::yaml::Hex64 Size;
133
134 RawContentSection() : Section(SectionKind::RawContent) {}
135
136 static bool classof(const Section *S) {
137 return S->Kind == SectionKind::RawContent;
138 }
139};
140
141struct NoBitsSection : Section {
142 llvm::yaml::Hex64 Size;
143
144 NoBitsSection() : Section(SectionKind::NoBits) {}
145
146 static bool classof(const Section *S) {
147 return S->Kind == SectionKind::NoBits;
148 }
149};
150
151struct Group : Section {
152 // Members of a group contain a flag and a list of section indices
153 // that are part of the group.
154 std::vector<SectionOrType> Members;
155
156 Group() : Section(SectionKind::Group) {}
157
158 static bool classof(const Section *S) {
159 return S->Kind == SectionKind::Group;
160 }
161};
162
163struct Relocation {
164 llvm::yaml::Hex64 Offset;
165 int64_t Addend;
166 ELF_REL Type;
167 Optional<StringRef> Symbol;
168};
169
170struct RelocationSection : Section {
171 std::vector<Relocation> Relocations;
172
173 RelocationSection() : Section(SectionKind::Relocation) {}
174
175 static bool classof(const Section *S) {
176 return S->Kind == SectionKind::Relocation;
177 }
178};
179
180// Represents .MIPS.abiflags section
181struct MipsABIFlags : Section {
182 llvm::yaml::Hex16 Version;
183 MIPS_ISA ISALevel;
184 llvm::yaml::Hex8 ISARevision;
185 MIPS_AFL_REG GPRSize;
186 MIPS_AFL_REG CPR1Size;
187 MIPS_AFL_REG CPR2Size;
188 MIPS_ABI_FP FpABI;
189 MIPS_AFL_EXT ISAExtension;
190 MIPS_AFL_ASE ASEs;
191 MIPS_AFL_FLAGS1 Flags1;
192 llvm::yaml::Hex32 Flags2;
193
194 MipsABIFlags() : Section(SectionKind::MipsABIFlags) {}
195
196 static bool classof(const Section *S) {
197 return S->Kind == SectionKind::MipsABIFlags;
198 }
199};
200
201struct Object {
202 FileHeader Header;
203 std::vector<ProgramHeader> ProgramHeaders;
204 std::vector<std::unique_ptr<Section>> Sections;
205 // Although in reality the symbols reside in a section, it is a lot
206 // cleaner and nicer if we read them from the YAML as a separate
207 // top-level key, which automatically ensures that invariants like there
208 // being a single SHT_SYMTAB section are upheld.
209 LocalGlobalWeakSymbols Symbols;
210 LocalGlobalWeakSymbols DynamicSymbols;
211};
212
213} // end namespace ELFYAML
214} // end namespace llvm
215
216LLVM_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; }; } }
217LLVM_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; }; } }
218LLVM_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; }; } }
219LLVM_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; }; } }
220LLVM_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; }; } }
221LLVM_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; }; } }
222
223namespace llvm {
224namespace yaml {
225
226template <>
227struct ScalarEnumerationTraits<ELFYAML::ELF_ET> {
228 static void enumeration(IO &IO, ELFYAML::ELF_ET &Value);
229};
230
231template <> struct ScalarEnumerationTraits<ELFYAML::ELF_PT> {
232 static void enumeration(IO &IO, ELFYAML::ELF_PT &Value);
233};
234
235template <>
236struct ScalarEnumerationTraits<ELFYAML::ELF_EM> {
237 static void enumeration(IO &IO, ELFYAML::ELF_EM &Value);
238};
239
240template <>
241struct ScalarEnumerationTraits<ELFYAML::ELF_ELFCLASS> {
242 static void enumeration(IO &IO, ELFYAML::ELF_ELFCLASS &Value);
243};
244
245template <>
246struct ScalarEnumerationTraits<ELFYAML::ELF_ELFDATA> {
247 static void enumeration(IO &IO, ELFYAML::ELF_ELFDATA &Value);
248};
249
250template <>
251struct ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI> {
252 static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value);
253};
254
255template <>
256struct ScalarBitSetTraits<ELFYAML::ELF_EF> {
257 static void bitset(IO &IO, ELFYAML::ELF_EF &Value);
258};
259
260template <> struct ScalarBitSetTraits<ELFYAML::ELF_PF> {
261 static void bitset(IO &IO, ELFYAML::ELF_PF &Value);
262};
263
264template <>
265struct ScalarEnumerationTraits<ELFYAML::ELF_SHT> {
266 static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value);
267};
268
269template <>
270struct ScalarBitSetTraits<ELFYAML::ELF_SHF> {
271 static void bitset(IO &IO, ELFYAML::ELF_SHF &Value);
272};
273
274template <> struct ScalarEnumerationTraits<ELFYAML::ELF_SHN> {
275 static void enumeration(IO &IO, ELFYAML::ELF_SHN &Value);
276};
277
278template <>
279struct ScalarEnumerationTraits<ELFYAML::ELF_STT> {
280 static void enumeration(IO &IO, ELFYAML::ELF_STT &Value);
281};
282
283template <>
284struct ScalarEnumerationTraits<ELFYAML::ELF_STV> {
285 static void enumeration(IO &IO, ELFYAML::ELF_STV &Value);
286};
287
288template <>
289struct ScalarBitSetTraits<ELFYAML::ELF_STO> {
290 static void bitset(IO &IO, ELFYAML::ELF_STO &Value);
291};
292
293template <>
294struct ScalarEnumerationTraits<ELFYAML::ELF_REL> {
295 static void enumeration(IO &IO, ELFYAML::ELF_REL &Value);
296};
297
298template <>
299struct ScalarEnumerationTraits<ELFYAML::ELF_RSS> {
300 static void enumeration(IO &IO, ELFYAML::ELF_RSS &Value);
301};
302
303template <>
304struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_REG> {
305 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_REG &Value);
306};
307
308template <>
309struct ScalarEnumerationTraits<ELFYAML::MIPS_ABI_FP> {
310 static void enumeration(IO &IO, ELFYAML::MIPS_ABI_FP &Value);
311};
312
313template <>
314struct ScalarEnumerationTraits<ELFYAML::MIPS_AFL_EXT> {
315 static void enumeration(IO &IO, ELFYAML::MIPS_AFL_EXT &Value);
316};
317
318template <>
319struct ScalarEnumerationTraits<ELFYAML::MIPS_ISA> {
320 static void enumeration(IO &IO, ELFYAML::MIPS_ISA &Value);
321};
322
323template <>
324struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_ASE> {
325 static void bitset(IO &IO, ELFYAML::MIPS_AFL_ASE &Value);
326};
327
328template <>
329struct ScalarBitSetTraits<ELFYAML::MIPS_AFL_FLAGS1> {
330 static void bitset(IO &IO, ELFYAML::MIPS_AFL_FLAGS1 &Value);
331};
332
333template <>
334struct MappingTraits<ELFYAML::FileHeader> {
335 static void mapping(IO &IO, ELFYAML::FileHeader &FileHdr);
336};
337
338template <> struct MappingTraits<ELFYAML::ProgramHeader> {
339 static void mapping(IO &IO, ELFYAML::ProgramHeader &FileHdr);
340};
341
342template <>
343struct MappingTraits<ELFYAML::Symbol> {
344 static void mapping(IO &IO, ELFYAML::Symbol &Symbol);
345 static StringRef validate(IO &IO, ELFYAML::Symbol &Symbol);
346};
347
348template <>
349struct MappingTraits<ELFYAML::LocalGlobalWeakSymbols> {
350 static void mapping(IO &IO, ELFYAML::LocalGlobalWeakSymbols &Symbols);
351};
352
353template <> struct MappingTraits<ELFYAML::Relocation> {
354 static void mapping(IO &IO, ELFYAML::Relocation &Rel);
355};
356
357template <>
358struct MappingTraits<std::unique_ptr<ELFYAML::Section>> {
359 static void mapping(IO &IO, std::unique_ptr<ELFYAML::Section> &Section);
360 static StringRef validate(IO &io, std::unique_ptr<ELFYAML::Section> &Section);
361};
362
363template <>
364struct MappingTraits<ELFYAML::Object> {
365 static void mapping(IO &IO, ELFYAML::Object &Object);
366};
367
368template <> struct MappingTraits<ELFYAML::SectionOrType> {
369 static void mapping(IO &IO, ELFYAML::SectionOrType &sectionOrType);
370};
371
372template <> struct MappingTraits<ELFYAML::SectionName> {
373 static void mapping(IO &IO, ELFYAML::SectionName &sectionName);
374};
375
376} // end namespace yaml
377} // end namespace llvm
378
379#endif // LLVM_OBJECTYAML_ELFYAML_H

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