LLVM  8.0.0svn
WasmYAML.h
Go to the documentation of this file.
1 //===- WasmYAML.h - Wasm 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 wasm binaries.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_OBJECTYAML_WASMYAML_H
17 #define LLVM_OBJECTYAML_WASMYAML_H
18 
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/BinaryFormat/Wasm.h"
21 #include "llvm/ObjectYAML/YAML.h"
22 #include "llvm/Support/Casting.h"
23 #include <cstdint>
24 #include <memory>
25 #include <vector>
26 
27 namespace llvm {
28 namespace WasmYAML {
29 
30 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SectionType)
31 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ValueType)
32 LLVM_YAML_STRONG_TYPEDEF(uint32_t, TableType)
33 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SignatureForm)
34 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ExportKind)
35 LLVM_YAML_STRONG_TYPEDEF(uint32_t, Opcode)
36 LLVM_YAML_STRONG_TYPEDEF(uint32_t, RelocType)
37 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolFlags)
38 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SymbolKind)
39 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SegmentFlags)
40 LLVM_YAML_STRONG_TYPEDEF(uint32_t, LimitFlags)
41 LLVM_YAML_STRONG_TYPEDEF(uint32_t, ComdatKind)
42 
43 struct FileHeader {
44  yaml::Hex32 Version;
45 };
46 
47 struct Limits {
48  LimitFlags Flags;
49  yaml::Hex32 Initial;
50  yaml::Hex32 Maximum;
51 };
52 
53 struct Table {
54  TableType ElemType;
56 };
57 
58 struct Export {
60  ExportKind Kind;
62 };
63 
64 struct ElemSegment {
67  std::vector<uint32_t> Functions;
68 };
69 
70 struct Global {
73  bool Mutable;
75 };
76 
77 struct Import {
80  ExportKind Kind;
81  union {
86  };
87 };
88 
89 struct LocalDecl {
92 };
93 
94 struct Function {
96  std::vector<LocalDecl> Locals;
98 };
99 
100 struct Relocation {
101  RelocType Type;
103  yaml::Hex32 Offset;
104  int32_t Addend;
105 };
106 
107 struct DataSegment {
112 };
113 
114 struct NameEntry {
117 };
118 
119 struct SegmentInfo {
123  SegmentFlags Flags;
124 };
125 
126 struct Signature {
128  SignatureForm Form = wasm::WASM_TYPE_FUNC;
129  std::vector<ValueType> ParamTypes;
131 };
132 
133 struct SymbolInfo {
137  SymbolFlags Flags;
138  union {
141  };
142 };
143 
144 struct InitFunction {
147 };
148 
149 struct ComdatEntry {
150  ComdatKind Kind;
152 };
153 
154 struct Comdat {
156  std::vector<ComdatEntry> Entries;
157 };
158 
159 struct Section {
160  explicit Section(SectionType SecType) : Type(SecType) {}
161  virtual ~Section();
162 
164  std::vector<Relocation> Relocations;
165 };
166 
169  : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {}
170 
171  static bool classof(const Section *S) {
172  return S->Type == wasm::WASM_SEC_CUSTOM;
173  }
174 
177 };
178 
180  NameSection() : CustomSection("name") {}
181 
182  static bool classof(const Section *S) {
183  auto C = dyn_cast<CustomSection>(S);
184  return C && C->Name == "name";
185  }
186 
187  std::vector<NameEntry> FunctionNames;
188 };
189 
191  LinkingSection() : CustomSection("linking") {}
192 
193  static bool classof(const Section *S) {
194  auto C = dyn_cast<CustomSection>(S);
195  return C && C->Name == "linking";
196  }
197 
199  std::vector<SymbolInfo> SymbolTable;
200  std::vector<SegmentInfo> SegmentInfos;
201  std::vector<InitFunction> InitFunctions;
202  std::vector<Comdat> Comdats;
203 };
204 
207 
208  static bool classof(const Section *S) {
209  return S->Type == wasm::WASM_SEC_TYPE;
210  }
211 
212  std::vector<Signature> Signatures;
213 };
214 
217 
218  static bool classof(const Section *S) {
219  return S->Type == wasm::WASM_SEC_IMPORT;
220  }
221 
222  std::vector<Import> Imports;
223 };
224 
227 
228  static bool classof(const Section *S) {
229  return S->Type == wasm::WASM_SEC_FUNCTION;
230  }
231 
232  std::vector<uint32_t> FunctionTypes;
233 };
234 
237 
238  static bool classof(const Section *S) {
239  return S->Type == wasm::WASM_SEC_TABLE;
240  }
241 
242  std::vector<Table> Tables;
243 };
244 
247 
248  static bool classof(const Section *S) {
249  return S->Type == wasm::WASM_SEC_MEMORY;
250  }
251 
252  std::vector<Limits> Memories;
253 };
254 
257 
258  static bool classof(const Section *S) {
259  return S->Type == wasm::WASM_SEC_GLOBAL;
260  }
261 
262  std::vector<Global> Globals;
263 };
264 
267 
268  static bool classof(const Section *S) {
269  return S->Type == wasm::WASM_SEC_EXPORT;
270  }
271 
272  std::vector<Export> Exports;
273 };
274 
277 
278  static bool classof(const Section *S) {
279  return S->Type == wasm::WASM_SEC_START;
280  }
281 
283 };
284 
287 
288  static bool classof(const Section *S) {
289  return S->Type == wasm::WASM_SEC_ELEM;
290  }
291 
292  std::vector<ElemSegment> Segments;
293 };
294 
297 
298  static bool classof(const Section *S) {
299  return S->Type == wasm::WASM_SEC_CODE;
300  }
301 
302  std::vector<Function> Functions;
303 };
304 
307 
308  static bool classof(const Section *S) {
309  return S->Type == wasm::WASM_SEC_DATA;
310  }
311 
312  std::vector<DataSegment> Segments;
313 };
314 
315 struct Object {
317  std::vector<std::unique_ptr<Section>> Sections;
318 };
319 
320 } // end namespace WasmYAML
321 } // end namespace llvm
322 
323 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
324 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Signature)
325 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ValueType)
326 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Table)
327 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Import)
328 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Export)
329 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ElemSegment)
330 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Limits)
331 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::DataSegment)
332 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Global)
333 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function)
334 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl)
335 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation)
336 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry)
337 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SegmentInfo)
338 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo)
339 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::InitFunction)
340 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::ComdatEntry)
341 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Comdat)
342 
343 namespace llvm {
344 namespace yaml {
345 
346 template <> struct MappingTraits<WasmYAML::FileHeader> {
347  static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
348 };
349 
350 template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
351  static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
352 };
353 
354 template <> struct MappingTraits<WasmYAML::Object> {
355  static void mapping(IO &IO, WasmYAML::Object &Object);
356 };
357 
358 template <> struct MappingTraits<WasmYAML::Import> {
359  static void mapping(IO &IO, WasmYAML::Import &Import);
360 };
361 
362 template <> struct MappingTraits<WasmYAML::Export> {
363  static void mapping(IO &IO, WasmYAML::Export &Export);
364 };
365 
366 template <> struct MappingTraits<WasmYAML::Global> {
367  static void mapping(IO &IO, WasmYAML::Global &Global);
368 };
369 
370 template <> struct ScalarBitSetTraits<WasmYAML::LimitFlags> {
371  static void bitset(IO &IO, WasmYAML::LimitFlags &Value);
372 };
373 
374 template <> struct ScalarBitSetTraits<WasmYAML::SymbolFlags> {
375  static void bitset(IO &IO, WasmYAML::SymbolFlags &Value);
376 };
377 
378 template <> struct ScalarEnumerationTraits<WasmYAML::SymbolKind> {
379  static void enumeration(IO &IO, WasmYAML::SymbolKind &Kind);
380 };
381 
382 template <> struct ScalarBitSetTraits<WasmYAML::SegmentFlags> {
383  static void bitset(IO &IO, WasmYAML::SegmentFlags &Value);
384 };
385 
386 template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
387  static void enumeration(IO &IO, WasmYAML::SectionType &Type);
388 };
389 
390 template <> struct MappingTraits<WasmYAML::Signature> {
391  static void mapping(IO &IO, WasmYAML::Signature &Signature);
392 };
393 
394 template <> struct MappingTraits<WasmYAML::Table> {
395  static void mapping(IO &IO, WasmYAML::Table &Table);
396 };
397 
398 template <> struct MappingTraits<WasmYAML::Limits> {
399  static void mapping(IO &IO, WasmYAML::Limits &Limits);
400 };
401 
402 template <> struct MappingTraits<WasmYAML::Function> {
403  static void mapping(IO &IO, WasmYAML::Function &Function);
404 };
405 
406 template <> struct MappingTraits<WasmYAML::Relocation> {
407  static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
408 };
409 
410 template <> struct MappingTraits<WasmYAML::NameEntry> {
411  static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry);
412 };
413 
414 template <> struct MappingTraits<WasmYAML::SegmentInfo> {
415  static void mapping(IO &IO, WasmYAML::SegmentInfo &SegmentInfo);
416 };
417 
418 template <> struct MappingTraits<WasmYAML::LocalDecl> {
419  static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
420 };
421 
422 template <> struct MappingTraits<wasm::WasmInitExpr> {
423  static void mapping(IO &IO, wasm::WasmInitExpr &Expr);
424 };
425 
426 template <> struct MappingTraits<WasmYAML::DataSegment> {
427  static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
428 };
429 
430 template <> struct MappingTraits<WasmYAML::ElemSegment> {
431  static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
432 };
433 
434 template <> struct MappingTraits<WasmYAML::SymbolInfo> {
435  static void mapping(IO &IO, WasmYAML::SymbolInfo &Info);
436 };
437 
438 template <> struct MappingTraits<WasmYAML::InitFunction> {
439  static void mapping(IO &IO, WasmYAML::InitFunction &Init);
440 };
441 
442 template <> struct ScalarEnumerationTraits<WasmYAML::ComdatKind> {
443  static void enumeration(IO &IO, WasmYAML::ComdatKind &Kind);
444 };
445 
446 template <> struct MappingTraits<WasmYAML::ComdatEntry> {
447  static void mapping(IO &IO, WasmYAML::ComdatEntry &ComdatEntry);
448 };
449 
450 template <> struct MappingTraits<WasmYAML::Comdat> {
451  static void mapping(IO &IO, WasmYAML::Comdat &Comdat);
452 };
453 
454 template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
455  static void enumeration(IO &IO, WasmYAML::ValueType &Type);
456 };
457 
458 template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
459  static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
460 };
461 
462 template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
463  static void enumeration(IO &IO, WasmYAML::TableType &Type);
464 };
465 
466 template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
467  static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
468 };
469 
470 template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
471  static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
472 };
473 
474 } // end namespace yaml
475 } // end namespace llvm
476 
477 #endif // LLVM_OBJECTYAML_WASMYAML_H
std::vector< InitFunction > InitFunctions
Definition: WasmYAML.h:201
uint64_t CallInst * C
static bool classof(const Section *S)
Definition: WasmYAML.h:182
std::vector< Comdat > Comdats
Definition: WasmYAML.h:202
std::vector< Relocation > Relocations
Definition: WasmYAML.h:164
std::vector< Limits > Memories
Definition: WasmYAML.h:252
static bool classof(const Section *S)
Definition: WasmYAML.h:298
static bool classof(const Section *S)
Definition: WasmYAML.h:288
std::vector< Signature > Signatures
Definition: WasmYAML.h:212
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
yaml::BinaryRef Body
Definition: WasmYAML.h:97
std::vector< std::unique_ptr< Section > > Sections
Definition: WasmYAML.h:317
static bool classof(const Section *S)
Definition: WasmYAML.h:218
static bool classof(const Section *S)
Definition: WasmYAML.h:278
wasm::WasmInitExpr InitExpr
Definition: WasmYAML.h:74
yaml::BinaryRef Content
Definition: WasmYAML.h:111
std::vector< Import > Imports
Definition: WasmYAML.h:222
wasm::WasmInitExpr Offset
Definition: WasmYAML.h:66
CustomSection(StringRef Name)
Definition: WasmYAML.h:168
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Definition: BitVector.h:938
std::vector< SegmentInfo > SegmentInfos
Definition: WasmYAML.h:200
std::vector< SymbolInfo > SymbolTable
Definition: WasmYAML.h:199
static bool classof(const Section *S)
Definition: WasmYAML.h:258
std::vector< Function > Functions
Definition: WasmYAML.h:302
static bool classof(const Section *S)
Definition: WasmYAML.h:248
static bool classof(const Section *S)
Definition: WasmYAML.h:208
yaml::Hex32 Initial
Definition: WasmYAML.h:49
std::vector< ComdatEntry > Entries
Definition: WasmYAML.h:156
Import information from summary.
yaml::Hex32 Maximum
Definition: WasmYAML.h:50
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
static bool classof(const Section *S)
Definition: WasmYAML.h:268
std::vector< Export > Exports
Definition: WasmYAML.h:272
Section(SectionType SecType)
Definition: WasmYAML.h:160
std::vector< uint32_t > FunctionTypes
Definition: WasmYAML.h:232
static bool classof(const Section *S)
Definition: WasmYAML.h:308
static bool classof(const Section *S)
Definition: WasmYAML.h:171
ValueType
Value types.
TableType ElemType
Definition: WasmYAML.h:54
std::vector< Table > Tables
Definition: WasmYAML.h:242
static bool classof(const Section *S)
Definition: WasmYAML.h:228
LimitFlags Flags
Definition: WasmYAML.h:48
std::vector< ElemSegment > Segments
Definition: WasmYAML.h:292
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:64
std::vector< uint32_t > Functions
Definition: WasmYAML.h:67
static bool classof(const Section *S)
Definition: WasmYAML.h:238
std::vector< DataSegment > Segments
Definition: WasmYAML.h:312
wasm::WasmDataReference DataRef
Definition: WasmYAML.h:140
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
std::vector< ValueType > ParamTypes
Definition: WasmYAML.h:129
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:48
std::vector< LocalDecl > Locals
Definition: WasmYAML.h:96
yaml::BinaryRef Payload
Definition: WasmYAML.h:176
std::vector< NameEntry > FunctionNames
Definition: WasmYAML.h:187
const unsigned Kind
static bool classof(const Section *S)
Definition: WasmYAML.h:193
std::vector< Global > Globals
Definition: WasmYAML.h:262
LLVM Value Representation.
Definition: Value.h:73
wasm::WasmInitExpr Offset
Definition: WasmYAML.h:110
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
SectionType
These are the section type and attributes fields.
Definition: MachO.h:115
A discriminated union of two pointer types, with the discriminator in the low bit of the pointer...
Definition: PointerUnion.h:87