-
Notifications
You must be signed in to change notification settings - Fork 12
/
webassembly.ksy
396 lines (352 loc) · 9.15 KB
/
webassembly.ksy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# -*- mode: yaml -*-
meta:
id: webassembly
title: Web Assembly parser
file-extension: wasm
endian: le
license: CC0-1.0
file-extension:
- wasm
imports:
- vlq_base128_le
doc: |
WebAssembly is a web standard that defines a binary format and a corresponding
assembly-like text format for executable code in Web pages. It is meant to
enable executing code nearly as fast as running native machine code.
doc-ref: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md
#####################################################################################################
seq:
- id: magic
size: 4
contents: [0x00, "asm"]
- id: version
type: u4
- id: sections
type: sections
#####################################################################################################
types:
func_type:
seq:
- id: form
type: u1
enum: constructor_type
- id: param_count
type: u1
- id: param_types
type: u1
enum: value_type
repeat: expr
repeat-expr: param_count
if: param_count > 0
- id: return_count
type: u1
- id: return_type
type: u1
enum: value_type
if: return_count==1
resizable_limits_type:
seq:
- id: flags
type: u1
- id: initial
type: vlq_base128_le
- id: maximum
type: vlq_base128_le
if: flags == 1
table_type:
seq:
- id: element_type
type: u1
enum: elem_type
- id: limits
type: resizable_limits_type
memory_type:
seq:
- id: limits
type: resizable_limits_type
global_type:
seq:
- id: content_type
type: u1
enum: value_type
- id: mutability
type: u1
enum: mutability_flag
global_variable_type:
seq:
- id: type
type: global_type
- id: init
type: u1
repeat: until
repeat-until: _ == 0x0b
export_entry_type:
seq:
- id: field_len
type: vlq_base128_le
- id: field_str
type: str
encoding: UTF-8
size: field_len.value
- id: kind
type: u1
enum: kind_type
- id: index
type: vlq_base128_le
elem_segment_type:
seq:
- id: index
type: vlq_base128_le
- id: offset
type: u1
repeat: until
repeat-until: _ == 0x0b
- id: num_elem
type: vlq_base128_le
- id: elems
type: vlq_base128_le
repeat: expr
repeat-expr: num_elem.value
function_body_type:
seq:
- id: body_size
type: vlq_base128_le
- id: data
type: function_body_data_type
size: body_size.value
function_body_data_type:
seq:
- id: local_count
type: vlq_base128_le
- id: locals
type: local_entry_type
repeat: expr
repeat-expr: local_count.value
- id: code
size-eos: true
local_entry_type:
seq:
- id: count
type: vlq_base128_le
- id: type
type: u1
enum: value_type
data_segment_type:
seq:
- id: index
type: vlq_base128_le
- id: offset
type: u1
repeat: until
repeat-until: _ == 0x0b
- id: size
type: vlq_base128_le
- id: data
type: u1
repeat: expr
repeat-expr: size.value
section_header:
seq:
- id: id
type: u1
enum: payload_type
- id: payload_len
type: vlq_base128_le
- id: name_len
type: u4
if: id == payload_type::custom_payload
- id: name
size: name_len
if: id == payload_type::custom_payload
section:
seq:
- id: header
type: section_header
- id: payload_data
type:
switch-on: header.id
cases:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#high-level-structure
'payload_type::custom_payload': unimplemented_section
'payload_type::type_payload': type_section
'payload_type::import_payload': import_section
'payload_type::function_payload': function_section
'payload_type::table_payload': table_section
'payload_type::memory_payload': memory_section
'payload_type::global_payload': global_section
'payload_type::export_payload': export_section
'payload_type::start_payload': start_section
'payload_type::element_payload': element_section
'payload_type::code_payload': code_section
'payload_type::data_payload': data_section
sections:
seq:
- id: sections
type: section
repeat: eos
type_section:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#type-section
seq:
- id: count
type: u1
- id: entries
type: func_type
repeat: expr
repeat-expr: count
import_section:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#import-section
seq:
- id: count
type: u1
- id: entries
type: import_entry
if: count > 0
repeat: expr
repeat-expr: count
import_entry:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#import-entry
seq:
- id: module_len
type: vlq_base128_le
- id: module_str
type: str
size: module_len.value
encoding: UTF-8
- id: field_len
type: vlq_base128_le
- id: field_str
type: str
size: field_len.value
encoding: UTF-8
- id: kind
type: u1
enum: kind_type
- id: type
type:
switch-on: kind
cases:
'kind_type::function_kind': vlq_base128_le
'kind_type::table_kind': table_type
'kind_type::memory_kind': memory_type
'kind_type::global_kind': global_type
function_section:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#function-section
seq:
- id: count
type: vlq_base128_le
- id: types
type: vlq_base128_le
repeat: expr
repeat-expr: count.value
table_section:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#table-section
seq:
- id: count
type: vlq_base128_le
- id: entries
type: table_type
repeat: expr
repeat-expr: count.value
memory_section:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#memory-section
seq:
- id: count
type: vlq_base128_le
- id: entries
type: memory_type
repeat: expr
repeat-expr: count.value
global_section:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#global-section
seq:
- id: count
type: vlq_base128_le
- id: globals
type: global_variable_type
repeat: expr
repeat-expr: count.value
export_section:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#export-section
seq:
- id: count
type: vlq_base128_le
- id: entries
type: export_entry_type
repeat: expr
repeat-expr: count.value
start_section:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#start-section
seq:
- id: index
type: vlq_base128_le
element_section:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#element-section
seq:
- id: count
type: vlq_base128_le
- id: entries
type: elem_segment_type
repeat: expr
repeat-expr: count.value
code_section:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#code-section
seq:
- id: count
type: vlq_base128_le
- id: bodies
type: function_body_type
repeat: expr
repeat-expr: count.value
data_section:
# https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#data-section
seq:
- id: count
type: vlq_base128_le
- id: entries
type: data_segment_type
repeat: expr
repeat-expr: count.value
unimplemented_section:
seq:
- id: raw
type: u1
repeat: expr
repeat-expr: _parent.header.payload_len.value
#####################################################################################################
enums:
constructor_type:
0x7f: i32
0x7e: i64
0x7d: f32
0x7c: f64
0x70: anyfunc
0x60: func
0x40: empty_block
value_type:
0x7f: i32
0x7e: i64
0x7d: f32
0x7c: f64
kind_type:
0: function_kind
1: table_kind
2: memory_kind
3: global_kind
payload_type:
0: custom_payload
1: type_payload
2: import_payload
3: function_payload
4: table_payload
5: memory_payload
6: global_payload
7: export_payload
8: start_payload
9: element_payload
10: code_payload
11: data_payload
elem_type:
0x70: anyfunc
mutability_flag:
0: immutable
1: mutable