LLVM  6.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 /// \brief 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 
32 LLVM_YAML_STRONG_TYPEDEF(int32_t, TableType)
33 LLVM_YAML_STRONG_TYPEDEF(int32_t, SignatureForm)
37 
38 struct FileHeader {
39  yaml::Hex32 Version;
40 };
41 
42 struct Limits {
43  yaml::Hex32 Flags;
44  yaml::Hex32 Initial;
45  yaml::Hex32 Maximum;
46 };
47 
48 struct Table {
49  TableType ElemType;
51 };
52 
53 struct Export {
55  ExportKind Kind;
57 };
58 
59 struct ElemSegment {
62  std::vector<uint32_t> Functions;
63 };
64 
65 struct Global {
67  bool Mutable;
69 };
70 
71 struct Import {
74  ExportKind Kind;
75  union {
80  };
81 };
82 
83 struct LocalDecl {
86 };
87 
88 struct Function {
89  std::vector<LocalDecl> Locals;
91 };
92 
93 struct Relocation {
94  RelocType Type;
96  yaml::Hex32 Offset;
97  int32_t Addend;
98 };
99 
100 struct DataSegment {
105 };
106 
107 struct NameEntry {
110 };
111 
112 struct SegmentInfo {
117 };
118 
119 struct Signature {
121  SignatureForm Form = wasm::WASM_TYPE_FUNC;
122  std::vector<ValueType> ParamTypes;
124 };
125 
126 struct SymbolInfo {
129 };
130 
131 struct Section {
132  explicit Section(SectionType SecType) : Type(SecType) {}
133  virtual ~Section();
134 
136  std::vector<Relocation> Relocations;
137 };
138 
141  : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {}
142 
143  static bool classof(const Section *S) {
144  return S->Type == wasm::WASM_SEC_CUSTOM;
145  }
146 
149 };
150 
152  NameSection() : CustomSection("name") {}
153 
154  static bool classof(const Section *S) {
155  auto C = dyn_cast<CustomSection>(S);
156  return C && C->Name == "name";
157  }
158 
159  std::vector<NameEntry> FunctionNames;
160 };
161 
163  LinkingSection() : CustomSection("linking") {}
164 
165  static bool classof(const Section *S) {
166  auto C = dyn_cast<CustomSection>(S);
167  return C && C->Name == "linking";
168  }
169 
171  std::vector<SymbolInfo> SymbolInfos;
172  std::vector<SegmentInfo> SegmentInfos;
173 };
174 
177 
178  static bool classof(const Section *S) {
179  return S->Type == wasm::WASM_SEC_TYPE;
180  }
181 
182  std::vector<Signature> Signatures;
183 };
184 
187 
188  static bool classof(const Section *S) {
189  return S->Type == wasm::WASM_SEC_IMPORT;
190  }
191 
192  std::vector<Import> Imports;
193 };
194 
197 
198  static bool classof(const Section *S) {
199  return S->Type == wasm::WASM_SEC_FUNCTION;
200  }
201 
202  std::vector<uint32_t> FunctionTypes;
203 };
204 
207 
208  static bool classof(const Section *S) {
209  return S->Type == wasm::WASM_SEC_TABLE;
210  }
211 
212  std::vector<Table> Tables;
213 };
214 
217 
218  static bool classof(const Section *S) {
219  return S->Type == wasm::WASM_SEC_MEMORY;
220  }
221 
222  std::vector<Limits> Memories;
223 };
224 
227 
228  static bool classof(const Section *S) {
229  return S->Type == wasm::WASM_SEC_GLOBAL;
230  }
231 
232  std::vector<Global> Globals;
233 };
234 
237 
238  static bool classof(const Section *S) {
239  return S->Type == wasm::WASM_SEC_EXPORT;
240  }
241 
242  std::vector<Export> Exports;
243 };
244 
247 
248  static bool classof(const Section *S) {
249  return S->Type == wasm::WASM_SEC_START;
250  }
251 
253 };
254 
257 
258  static bool classof(const Section *S) {
259  return S->Type == wasm::WASM_SEC_ELEM;
260  }
261 
262  std::vector<ElemSegment> Segments;
263 };
264 
267 
268  static bool classof(const Section *S) {
269  return S->Type == wasm::WASM_SEC_CODE;
270  }
271 
272  std::vector<Function> Functions;
273 };
274 
277 
278  static bool classof(const Section *S) {
279  return S->Type == wasm::WASM_SEC_DATA;
280  }
281 
282  std::vector<DataSegment> Segments;
283 };
284 
285 struct Object {
287  std::vector<std::unique_ptr<Section>> Sections;
288 };
289 
290 } // end namespace WasmYAML
291 } // end namespace llvm
292 
293 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::WasmYAML::Section>)
309 
310 namespace llvm {
311 namespace yaml {
312 
313 template <> struct MappingTraits<WasmYAML::FileHeader> {
314  static void mapping(IO &IO, WasmYAML::FileHeader &FileHdr);
315 };
316 
317 template <> struct MappingTraits<std::unique_ptr<WasmYAML::Section>> {
318  static void mapping(IO &IO, std::unique_ptr<WasmYAML::Section> &Section);
319 };
320 
321 template <> struct MappingTraits<WasmYAML::Object> {
322  static void mapping(IO &IO, WasmYAML::Object &Object);
323 };
324 
325 template <> struct MappingTraits<WasmYAML::Import> {
326  static void mapping(IO &IO, WasmYAML::Import &Import);
327 };
328 
329 template <> struct MappingTraits<WasmYAML::Export> {
330  static void mapping(IO &IO, WasmYAML::Export &Export);
331 };
332 
333 template <> struct MappingTraits<WasmYAML::Global> {
334  static void mapping(IO &IO, WasmYAML::Global &Global);
335 };
336 
337 template <> struct ScalarEnumerationTraits<WasmYAML::SectionType> {
338  static void enumeration(IO &IO, WasmYAML::SectionType &Type);
339 };
340 
341 template <> struct MappingTraits<WasmYAML::Signature> {
342  static void mapping(IO &IO, WasmYAML::Signature &Signature);
343 };
344 
345 template <> struct MappingTraits<WasmYAML::Table> {
346  static void mapping(IO &IO, WasmYAML::Table &Table);
347 };
348 
349 template <> struct MappingTraits<WasmYAML::Limits> {
350  static void mapping(IO &IO, WasmYAML::Limits &Limits);
351 };
352 
353 template <> struct MappingTraits<WasmYAML::Function> {
354  static void mapping(IO &IO, WasmYAML::Function &Function);
355 };
356 
357 template <> struct MappingTraits<WasmYAML::Relocation> {
358  static void mapping(IO &IO, WasmYAML::Relocation &Relocation);
359 };
360 
361 template <> struct MappingTraits<WasmYAML::NameEntry> {
362  static void mapping(IO &IO, WasmYAML::NameEntry &NameEntry);
363 };
364 
365 template <> struct MappingTraits<WasmYAML::SegmentInfo> {
366  static void mapping(IO &IO, WasmYAML::SegmentInfo &SegmentInfo);
367 };
368 
369 template <> struct MappingTraits<WasmYAML::LocalDecl> {
370  static void mapping(IO &IO, WasmYAML::LocalDecl &LocalDecl);
371 };
372 
373 template <> struct MappingTraits<wasm::WasmInitExpr> {
374  static void mapping(IO &IO, wasm::WasmInitExpr &Expr);
375 };
376 
377 template <> struct MappingTraits<WasmYAML::DataSegment> {
378  static void mapping(IO &IO, WasmYAML::DataSegment &Segment);
379 };
380 
381 template <> struct MappingTraits<WasmYAML::ElemSegment> {
382  static void mapping(IO &IO, WasmYAML::ElemSegment &Segment);
383 };
384 
385 template <> struct MappingTraits<WasmYAML::SymbolInfo> {
386  static void mapping(IO &IO, WasmYAML::SymbolInfo &Info);
387 };
388 
389 template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> {
390  static void enumeration(IO &IO, WasmYAML::ValueType &Type);
391 };
392 
393 template <> struct ScalarEnumerationTraits<WasmYAML::ExportKind> {
394  static void enumeration(IO &IO, WasmYAML::ExportKind &Kind);
395 };
396 
397 template <> struct ScalarEnumerationTraits<WasmYAML::TableType> {
398  static void enumeration(IO &IO, WasmYAML::TableType &Type);
399 };
400 
401 template <> struct ScalarEnumerationTraits<WasmYAML::Opcode> {
402  static void enumeration(IO &IO, WasmYAML::Opcode &Opcode);
403 };
404 
405 template <> struct ScalarEnumerationTraits<WasmYAML::RelocType> {
406  static void enumeration(IO &IO, WasmYAML::RelocType &Kind);
407 };
408 
409 } // end namespace yaml
410 } // end namespace llvm
411 
412 #endif // LLVM_OBJECTYAML_WASMYAML_H
uint64_t CallInst * C
static bool classof(const Section *S)
Definition: WasmYAML.h:154
std::vector< Relocation > Relocations
Definition: WasmYAML.h:136
std::vector< Limits > Memories
Definition: WasmYAML.h:222
static bool classof(const Section *S)
Definition: WasmYAML.h:268
static bool classof(const Section *S)
Definition: WasmYAML.h:258
std::vector< Signature > Signatures
Definition: WasmYAML.h:182
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
yaml::BinaryRef Body
Definition: WasmYAML.h:90
std::vector< std::unique_ptr< Section > > Sections
Definition: WasmYAML.h:287
static bool classof(const Section *S)
Definition: WasmYAML.h:188
static bool classof(const Section *S)
Definition: WasmYAML.h:248
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence...
Definition: YAMLTraits.h:1643
wasm::WasmInitExpr InitExpr
Definition: WasmYAML.h:68
yaml::BinaryRef Content
Definition: WasmYAML.h:104
std::vector< Import > Imports
Definition: WasmYAML.h:192
Export information to summary.
wasm::WasmInitExpr Offset
Definition: WasmYAML.h:61
CustomSection(StringRef Name)
Definition: WasmYAML.h:140
Definition: BitVector.h:920
std::vector< SegmentInfo > SegmentInfos
Definition: WasmYAML.h:172
static bool classof(const Section *S)
Definition: WasmYAML.h:228
std::vector< Function > Functions
Definition: WasmYAML.h:272
static bool classof(const Section *S)
Definition: WasmYAML.h:218
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
static bool classof(const Section *S)
Definition: WasmYAML.h:178
yaml::Hex32 Initial
Definition: WasmYAML.h:44
yaml::Hex32 Flags
Definition: WasmYAML.h:43
Import information from summary.
yaml::Hex32 Maximum
Definition: WasmYAML.h:45
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:238
std::vector< Export > Exports
Definition: WasmYAML.h:242
std::vector< SymbolInfo > SymbolInfos
Definition: WasmYAML.h:171
Section(SectionType SecType)
Definition: WasmYAML.h:132
std::vector< uint32_t > FunctionTypes
Definition: WasmYAML.h:202
static bool classof(const Section *S)
Definition: WasmYAML.h:278
static bool classof(const Section *S)
Definition: WasmYAML.h:143
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition: YAMLTraits.h:98
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
YAML I/O does conversion based on types.
Definition: YAMLTraits.h:1346
ValueType
Value types.
TableType ElemType
Definition: WasmYAML.h:49
std::vector< Table > Tables
Definition: WasmYAML.h:212
static bool classof(const Section *S)
Definition: WasmYAML.h:198
std::vector< ElemSegment > Segments
Definition: WasmYAML.h:262
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:64
std::vector< uint32_t > Functions
Definition: WasmYAML.h:62
static bool classof(const Section *S)
Definition: WasmYAML.h:208
std::vector< DataSegment > Segments
Definition: WasmYAML.h:282
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:122
std::vector< LocalDecl > Locals
Definition: WasmYAML.h:89
yaml::BinaryRef Payload
Definition: WasmYAML.h:148
std::vector< NameEntry > FunctionNames
Definition: WasmYAML.h:159
const unsigned Kind
static bool classof(const Section *S)
Definition: WasmYAML.h:165
std::vector< Global > Globals
Definition: WasmYAML.h:232
wasm::WasmInitExpr Offset
Definition: WasmYAML.h:103
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