Debian Codegraph @

third_party/rust/wast/src/core/expr.rs

raw
1 use crate::annotation;
2 use crate::core::*;
3 use crate::encode::Encode;
4 use crate::kw;
5 use crate::parser::{Cursor, Parse, Parser, Result};
6 use crate::token::*;
7 use std::mem;
8
9 /// An expression, or a list of instructions, in the WebAssembly text format.
10 ///
11 /// This expression type will parse s-expression-folded instructions into a flat
12 /// list of instructions for emission later on. The implicit `end` instruction
13 /// at the end of an expression is not included in the `instrs` field.
14 #[derive(Debug)]
15 #[allow(missing_docs)]
16 pub struct Expression<'a> {
17 /// Instructions in this expression.
18 pub instrs: Box<[Instruction<'a>]>,
19
20 /// Branch hints, if any, found while parsing instructions.
21 pub branch_hints: Box<[BranchHint]>,
22
23 /// Optionally parsed spans of all instructions in `instrs`.
24 ///
25 /// This value is `None` as it's disabled by default. This can be enabled
26 /// through the
27 /// [`ParseBuffer::track_instr_spans`](crate::parser::ParseBuffer::track_instr_spans)
28 /// function.
29 ///
30 /// This is not tracked by default due to the memory overhead and limited
31 /// use of this field.
32 pub instr_spans: Option<Box<[Span]>>,
33 }
34
35 /// A `@metadata.code.branch_hint` in the code, associated with a If or BrIf
36 /// This instruction is a placeholder and won't produce anything. Its purpose
37 /// is to store the offset of the following instruction and check that
38 /// it's followed by `br_if` or `if`.
39 #[derive(Debug)]
40 pub struct BranchHint {
41 /// Index of instructions in `instrs` field of `Expression` that this hint
42 /// applies to.
43 pub instr_index: usize,
44 /// The value of this branch hint
45 pub value: u32,
46 }
47
48 impl<'a> Parse<'a> for Expression<'a> {
49 fn parse(parser: Parser<'a>) -> Result<Self> {
50 let mut exprs = ExpressionParser::new(parser);
51 exprs.parse(parser)?;
52 Ok(Expression {
53 instrs: exprs.raw_instrs.into(),
54 branch_hints: exprs.branch_hints.into(),
55 instr_spans: exprs.spans.map(|s| s.into()),
56 })
57 }
58 }
59
60 impl<'a> Expression<'a> {
61 /// Creates an expression from the single `instr` specified.
62 pub fn one(instr: Instruction<'a>) -> Expression<'a> {
63 Expression {
64 instrs: [instr].into(),
65 branch_hints: Box::new([]),
66 instr_spans: None,
67 }
68 }
69
70 /// Parse an expression formed from a single folded instruction.
71 ///
72 /// Attempts to parse an expression formed from a single folded instruction.
73 ///
74 /// This method will mutate the state of `parser` after attempting to parse
75 /// the expression. If an error happens then it is likely fatal and
76 /// there is no guarantee of how many tokens have been consumed from
77 /// `parser`.
78 ///
79 /// # Errors
80 ///
81 /// This function will return an error if the expression could not be
82 /// parsed. Note that creating an [`crate::Error`] is not exactly a cheap
83 /// operation, so [`crate::Error`] is typically fatal and propagated all the
84 /// way back to the top parse call site.
85 pub fn parse_folded_instruction(parser: Parser<'a>) -> Result<Self> {
86 let mut exprs = ExpressionParser::new(parser);
87 exprs.parse_folded_instruction(parser)?;
88 Ok(Expression {
89 instrs: exprs.raw_instrs.into(),
90 branch_hints: exprs.branch_hints.into(),
91 instr_spans: exprs.spans.map(|s| s.into()),
92 })
93 }
94 }
95
96 /// Helper struct used to parse an `Expression` with helper methods and such.
97 ///
98 /// The primary purpose of this is to avoid defining expression parsing as a
99 /// call-thread-stack recursive function. Since we're parsing user input that
100 /// runs the risk of blowing the call stack, so we want to be sure to use a heap
101 /// stack structure wherever possible.
102 struct ExpressionParser<'a> {
103 /// The flat list of instructions that we've parsed so far, and will
104 /// eventually become the final `Expression`.
105 ///
106 /// Appended to with `push_instr` to ensure that this is the same length of
107 /// `spans` if `spans` is used.
108 raw_instrs: Vec<Instruction<'a>>,
109
110 /// Descriptor of all our nested s-expr blocks. This only happens when
111 /// instructions themselves are nested.
112 stack: Vec<Level<'a>>,
113
114 /// Related to the branch hints proposal.
115 /// Will be used later to collect the offsets in the final binary.
116 /// <(index of branch instructions, BranchHintAnnotation)>
117 branch_hints: Vec<BranchHint>,
118
119 /// Storage for all span information in `raw_instrs`. Optionally disabled to
120 /// reduce memory consumption of parsing expressions.
121 spans: Option<Vec<Span>>,
122 }
123
124 enum Paren {
125 None,
126 Left,
127 Right(Span),
128 }
129
130 /// A "kind" of nested block that we can be parsing inside of.
131 enum Level<'a> {
132 /// This is a normal `block` or `loop` or similar, where the instruction
133 /// payload here is pushed when the block is exited.
134 EndWith(Instruction<'a>, Option<Span>),
135
136 /// This is a pretty special variant which means that we're parsing an `if`
137 /// statement, and the state of the `if` parsing is tracked internally in
138 /// the payload.
139 If(If<'a>),
140
141 /// This means we're either parsing inside of `(then ...)` or `(else ...)`
142 /// which don't correspond to terminating instructions, we're just in a
143 /// nested block.
144 IfArm,
145
146 /// This means we are finishing the parsing of a branch hint annotation.
147 BranchHint,
148 }
149
150 /// Possible states of "what is currently being parsed?" in an `if` expression.
151 enum If<'a> {
152 /// Only the `if` instruction has been parsed, next thing to parse is the
153 /// clause, if any, of the `if` instruction.
154 ///
155 /// This parse ends when `(then ...)` is encountered.
156 Clause(Instruction<'a>, Span),
157 /// Currently parsing the `then` block, and afterwards a closing paren is
158 /// required or an `(else ...)` expression.
159 Then,
160 /// Parsing the `else` expression, nothing can come after.
161 Else,
162 }
163
164 impl<'a> ExpressionParser<'a> {
165 fn new(parser: Parser<'a>) -> ExpressionParser<'a> {
166 ExpressionParser {
167 raw_instrs: Vec::new(),
168 stack: Vec::new(),
169 branch_hints: Vec::new(),
170 spans: if parser.track_instr_spans() {
171 Some(Vec::new())
172 } else {
173 None
174 },
175 }
176 }
177
178 fn parse(&mut self, parser: Parser<'a>) -> Result<()> {
179 // Here we parse instructions in a loop, and we do not recursively
180 // invoke this parse function to avoid blowing the stack on
181 // deeply-recursive parses.
182 //
183 // Our loop generally only finishes once there's no more input left int
184 // the `parser`. If there's some unclosed delimiters though (on our
185 // `stack`), then we also keep parsing to generate error messages if
186 // there's no input left.
187 while !parser.is_empty() || !self.stack.is_empty() {
188 // As a small ease-of-life adjustment here, if we're parsing inside
189 // of an `if block then we require that all sub-components are
190 // s-expressions surrounded by `(` and `)`, so verify that here.
191 if let Some(Level::If(_)) = self.stack.last() {
192 if !parser.is_empty() && !parser.peek::<LParen>()? {
193 return Err(parser.error("expected `(`"));
194 }
195 }
196
197 match self.paren(parser)? {
198 // No parenthesis seen? Then we just parse the next instruction
199 // and move on.
200 Paren::None => {
201 let span = parser.cur_span();
202 self.push_instr(parser.parse()?, span);
203 }
204
205 // If we see a left-parenthesis then things are a little
206 // special. We handle block-like instructions specially
207 // (`block`, `loop`, and `if`), and otherwise all other
208 // instructions simply get appended once we reach the end of the
209 // s-expression.
210 //
211 // In all cases here we push something onto the `stack` to get
212 // popped when the `)` character is seen.
213 Paren::Left => {
214 // First up is handling `if` parsing, which is funky in a
215 // whole bunch of ways. See the method internally for more
216 // information.
217 if self.handle_if_lparen(parser)? {
218 continue;
219 }
220
221 // Handle the case of a branch hint annotation
222 if parser.peek::<annotation::metadata_code_branch_hint>()? {
223 self.parse_branch_hint(parser)?;
224 self.stack.push(Level::BranchHint);
225 continue;
226 }
227
228 let span = parser.cur_span();
229 match parser.parse()? {
230 // If block/loop show up then we just need to be sure to
231 // push an `end` instruction whenever the `)` token is
232 // seen
233 i @ Instruction::Block(_)
234 | i @ Instruction::Loop(_)
235 | i @ Instruction::TryTable(_) => {
236 self.push_instr(i, span);
237 self.stack
238 .push(Level::EndWith(Instruction::End(None), None));
239 }
240
241 // Parsing an `if` instruction is super tricky, so we
242 // push an `If` scope and we let all our scope-based
243 // parsing handle the remaining items.
244 i @ Instruction::If(_) => {
245 self.stack.push(Level::If(If::Clause(i, span)));
246 }
247
248 // Anything else means that we're parsing a nested form
249 // such as `(i32.add ...)` which means that the
250 // instruction we parsed will be coming at the end.
251 other => self.stack.push(Level::EndWith(other, Some(span))),
252 }
253 }
254
255 // If we registered a `)` token as being seen, then we're
256 // guaranteed there's an item in the `stack` stack for us to
257 // pop. We peel that off and take a look at what it says to do.
258 Paren::Right(span) => match self.stack.pop().unwrap() {
259 Level::EndWith(i, s) => self.push_instr(i, s.unwrap_or(span)),
260 Level::IfArm => {}
261 Level::BranchHint => {}
262
263 // If an `if` statement hasn't parsed the clause or `then`
264 // block, then that's an error because there weren't enough
265 // items in the `if` statement. Otherwise we're just careful
266 // to terminate with an `end` instruction.
267 Level::If(If::Clause(..)) => {
268 return Err(parser.error("previous `if` had no `then`"));
269 }
270 Level::If(_) => {
271 self.push_instr(Instruction::End(None), span);
272 }
273 },
274 }
275 }
276 Ok(())
277 }
278
279 fn parse_folded_instruction(&mut self, parser: Parser<'a>) -> Result<()> {
280 let mut done = false;
281 while !done {
282 match self.paren(parser)? {
283 Paren::Left => {
284 let span = parser.cur_span();
285 self.stack.push(Level::EndWith(parser.parse()?, Some(span)));
286 }
287 Paren::Right(span) => {
288 let (top_instr, span) = match self.stack.pop().unwrap() {
289 Level::EndWith(i, s) => (i, s.unwrap_or(span)),
290 _ => panic!("unknown level type"),
291 };
292 self.push_instr(top_instr, span);
293 if self.stack.is_empty() {
294 done = true;
295 }
296 }
297 Paren::None => {
298 return Err(parser.error("expected to continue a folded instruction"))
299 }
300 }
301 }
302 Ok(())
303 }
304
305 /// Parses either `(`, `)`, or nothing.
306 fn paren(&self, parser: Parser<'a>) -> Result<Paren> {
307 parser.step(|cursor| {
308 Ok(match cursor.lparen()? {
309 Some(rest) => (Paren::Left, rest),
310 None if self.stack.is_empty() => (Paren::None, cursor),
311 None => match cursor.rparen()? {
312 Some(rest) => (Paren::Right(cursor.cur_span()), rest),
313 None => (Paren::None, cursor),
314 },
315 })
316 })
317 }
318
319 /// State transitions with parsing an `if` statement.
320 ///
321 /// The syntactical form of an `if` statement looks like:
322 ///
323 /// ```wat
324 /// (if ($clause)... (then $then) (else $else))
325 /// ```
326 ///
327 /// THis method is called after a `(` is parsed within the `(if ...` block.
328 /// This determines what to do next.
329 ///
330 /// Returns `true` if the rest of the arm above should be skipped, or
331 /// `false` if we should parse the next item as an instruction (because we
332 /// didn't handle the lparen here).
333 fn handle_if_lparen(&mut self, parser: Parser<'a>) -> Result<bool> {
334 // Only execute the code below if there's an `If` listed last.
335 let i = match self.stack.last_mut() {
336 Some(Level::If(i)) => i,
337 _ => return Ok(false),
338 };
339
340 match i {
341 // If the clause is still being parsed then interpret this `(` as a
342 // folded instruction unless it starts with `then`, in which case
343 // this transitions to the `Then` state and a new level has been
344 // reached.
345 If::Clause(if_instr, if_instr_span) => {
346 if !parser.peek::<kw::then>()? {
347 return Ok(false);
348 }
349 parser.parse::<kw::then>()?;
350 let instr = mem::replace(if_instr, Instruction::End(None));
351 let span = *if_instr_span;
352 *i = If::Then;
353 self.push_instr(instr, span);
354 self.stack.push(Level::IfArm);
355 Ok(true)
356 }
357
358 // Previously we were parsing the `(then ...)` clause so this next
359 // `(` must be followed by `else`.
360 If::Then => {
361 let span = parser.parse::<kw::r#else>()?.0;
362 *i = If::Else;
363 self.push_instr(Instruction::Else(None), span);
364 self.stack.push(Level::IfArm);
365 Ok(true)
366 }
367
368 // If after a `(else ...` clause is parsed there's another `(` then
369 // that's not syntactically allowed.
370 If::Else => Err(parser.error("unexpected token: too many payloads inside of `(if)`")),
371 }
372 }
373
374 fn parse_branch_hint(&mut self, parser: Parser<'a>) -> Result<()> {
375 parser.parse::<annotation::metadata_code_branch_hint>()?;
376
377 let hint = parser.parse::<String>()?;
378
379 let value = match hint.as_bytes() {
380 [0] => 0,
381 [1] => 1,
382 _ => return Err(parser.error("invalid value for branch hint")),
383 };
384
385 self.branch_hints.push(BranchHint {
386 instr_index: self.raw_instrs.len(),
387 value,
388 });
389 Ok(())
390 }
391
392 fn push_instr(&mut self, instr: Instruction<'a>, span: Span) {
393 self.raw_instrs.push(instr);
394 if let Some(spans) = &mut self.spans {
395 spans.push(span);
396 }
397 }
398 }
399
400 // TODO: document this obscenity
401 macro_rules! instructions {
402 (pub enum Instruction<'a> {
403 $(
404 $(#[$doc:meta])*
405 $name:ident $(($($arg:tt)*))? : [$($binary:tt)*] : $instr:tt $( | $deprecated:tt )?,
406 )*
407 }) => (
408 /// A listing of all WebAssembly instructions that can be in a module
409 /// that this crate currently parses.
410 #[derive(Debug, Clone)]
411 #[allow(missing_docs)]
412 pub enum Instruction<'a> {
413 $(
414 $(#[$doc])*
415 $name $(( instructions!(@ty $($arg)*) ))?,
416 )*
417 }
418
419 #[allow(non_snake_case)]
420 impl<'a> Parse<'a> for Instruction<'a> {
421 fn parse(parser: Parser<'a>) -> Result<Self> {
422 $(
423 fn $name<'a>(_parser: Parser<'a>) -> Result<Instruction<'a>> {
424 Ok(Instruction::$name $((
425 instructions!(@parse _parser $($arg)*)?
426 ))?)
427 }
428 )*
429 let parse_remainder = parser.step(|c| {
430 let (kw, rest) = match c.keyword() ?{
431 Some(pair) => pair,
432 None => return Err(c.error("expected an instruction")),
433 };
434 match kw {
435 $($instr $( | $deprecated )?=> Ok(($name as fn(_) -> _, rest)),)*
436 _ => return Err(c.error("unknown operator or unexpected token")),
437 }
438 })?;
439 parse_remainder(parser)
440 }
441 }
442
443 impl Encode for Instruction<'_> {
444 #[allow(non_snake_case)]
445 fn encode(&self, v: &mut Vec<u8>) {
446 match self {
447 $(
448 Instruction::$name $((instructions!(@first x $($arg)*)))? => {
449 fn encode<'a>($(arg: &instructions!(@ty $($arg)*),)? v: &mut Vec<u8>) {
450 instructions!(@encode v $($binary)*);
451 $(<instructions!(@ty $($arg)*) as Encode>::encode(arg, v);)?
452 }
453 encode($( instructions!(@first x $($arg)*), )? v)
454 }
455 )*
456 }
457 }
458 }
459
460 impl<'a> Instruction<'a> {
461 /// Returns the associated [`MemArg`] if one is available for this
462 /// instruction.
463 #[allow(unused_variables, non_snake_case)]
464 pub fn memarg_mut(&mut self) -> Option<&mut MemArg<'a>> {
465 match self {
466 $(
467 Instruction::$name $((instructions!(@memarg_binding a $($arg)*)))? => {
468 instructions!(@get_memarg a $($($arg)*)?)
469 }
470 )*
471 }
472 }
473 }
474 );
475
476 (@ty MemArg<$amt:tt>) => (MemArg<'a>);
477 (@ty LoadOrStoreLane<$amt:tt>) => (LoadOrStoreLane<'a>);
478 (@ty $other:ty) => ($other);
479
480 (@first $first:ident $($t:tt)*) => ($first);
481
482 (@parse $parser:ident MemArg<$amt:tt>) => (MemArg::parse($parser, $amt));
483 (@parse $parser:ident MemArg) => (compile_error!("must specify `MemArg` default"));
484 (@parse $parser:ident LoadOrStoreLane<$amt:tt>) => (LoadOrStoreLane::parse($parser, $amt));
485 (@parse $parser:ident LoadOrStoreLane) => (compile_error!("must specify `LoadOrStoreLane` default"));
486 (@parse $parser:ident $other:ty) => ($parser.parse::<$other>());
487
488 // simd opcodes prefixed with `0xfd` get a varuint32 encoding for their payload
489 (@encode $dst:ident 0xfd, $simd:tt) => ({
490 $dst.push(0xfd);
491 <u32 as Encode>::encode(&$simd, $dst);
492 });
493 (@encode $dst:ident $($bytes:tt)*) => ($dst.extend_from_slice(&[$($bytes)*]););
494
495 (@get_memarg $name:ident MemArg<$amt:tt>) => (Some($name));
496 (@get_memarg $name:ident LoadOrStoreLane<$amt:tt>) => (Some(&mut $name.memarg));
497 (@get_memarg $($other:tt)*) => (None);
498
499 (@memarg_binding $name:ident MemArg<$amt:tt>) => ($name);
500 (@memarg_binding $name:ident LoadOrStoreLane<$amt:tt>) => ($name);
501 (@memarg_binding $name:ident $other:ty) => (_);
502 }
503
504 instructions! {
505 pub enum Instruction<'a> {
506 Block(Box<BlockType<'a>>) : [0x02] : "block",
507 If(Box<BlockType<'a>>) : [0x04] : "if",
508 Else(Option<Id<'a>>) : [0x05] : "else",
509 Loop(Box<BlockType<'a>>) : [0x03] : "loop",
510 End(Option<Id<'a>>) : [0x0b] : "end",
511
512 Unreachable : [0x00] : "unreachable",
513 Nop : [0x01] : "nop",
514 Br(Index<'a>) : [0x0c] : "br",
515 BrIf(Index<'a>) : [0x0d] : "br_if",
516 BrTable(BrTableIndices<'a>) : [0x0e] : "br_table",
517 Return : [0x0f] : "return",
518 Call(Index<'a>) : [0x10] : "call",
519 CallIndirect(Box<CallIndirect<'a>>) : [0x11] : "call_indirect",
520
521 // tail-call proposal
522 ReturnCall(Index<'a>) : [0x12] : "return_call",
523 ReturnCallIndirect(Box<CallIndirect<'a>>) : [0x13] : "return_call_indirect",
524
525 // function-references proposal
526 CallRef(Index<'a>) : [0x14] : "call_ref",
527 ReturnCallRef(Index<'a>) : [0x15] : "return_call_ref",
528
529 Drop : [0x1a] : "drop",
530 Select(SelectTypes<'a>) : [] : "select",
531 LocalGet(Index<'a>) : [0x20] : "local.get",
532 LocalSet(Index<'a>) : [0x21] : "local.set",
533 LocalTee(Index<'a>) : [0x22] : "local.tee",
534 GlobalGet(Index<'a>) : [0x23] : "global.get",
535 GlobalSet(Index<'a>) : [0x24] : "global.set",
536
537 TableGet(TableArg<'a>) : [0x25] : "table.get",
538 TableSet(TableArg<'a>) : [0x26] : "table.set",
539
540 I32Load(MemArg<4>) : [0x28] : "i32.load",
541 I64Load(MemArg<8>) : [0x29] : "i64.load",
542 F32Load(MemArg<4>) : [0x2a] : "f32.load",
543 F64Load(MemArg<8>) : [0x2b] : "f64.load",
544 I32Load8s(MemArg<1>) : [0x2c] : "i32.load8_s",
545 I32Load8u(MemArg<1>) : [0x2d] : "i32.load8_u",
546 I32Load16s(MemArg<2>) : [0x2e] : "i32.load16_s",
547 I32Load16u(MemArg<2>) : [0x2f] : "i32.load16_u",
548 I64Load8s(MemArg<1>) : [0x30] : "i64.load8_s",
549 I64Load8u(MemArg<1>) : [0x31] : "i64.load8_u",
550 I64Load16s(MemArg<2>) : [0x32] : "i64.load16_s",
551 I64Load16u(MemArg<2>) : [0x33] : "i64.load16_u",
552 I64Load32s(MemArg<4>) : [0x34] : "i64.load32_s",
553 I64Load32u(MemArg<4>) : [0x35] : "i64.load32_u",
554 I32Store(MemArg<4>) : [0x36] : "i32.store",
555 I64Store(MemArg<8>) : [0x37] : "i64.store",
556 F32Store(MemArg<4>) : [0x38] : "f32.store",
557 F64Store(MemArg<8>) : [0x39] : "f64.store",
558 I32Store8(MemArg<1>) : [0x3a] : "i32.store8",
559 I32Store16(MemArg<2>) : [0x3b] : "i32.store16",
560 I64Store8(MemArg<1>) : [0x3c] : "i64.store8",
561 I64Store16(MemArg<2>) : [0x3d] : "i64.store16",
562 I64Store32(MemArg<4>) : [0x3e] : "i64.store32",
563
564 // Lots of bulk memory proposal here as well
565 MemorySize(MemoryArg<'a>) : [0x3f] : "memory.size",
566 MemoryGrow(MemoryArg<'a>) : [0x40] : "memory.grow",
567 MemoryInit(MemoryInit<'a>) : [0xfc, 0x08] : "memory.init",
568 MemoryCopy(MemoryCopy<'a>) : [0xfc, 0x0a] : "memory.copy",
569 MemoryFill(MemoryArg<'a>) : [0xfc, 0x0b] : "memory.fill",
570 MemoryDiscard(MemoryArg<'a>) : [0xfc, 0x12] : "memory.discard",
571 DataDrop(Index<'a>) : [0xfc, 0x09] : "data.drop",
572 ElemDrop(Index<'a>) : [0xfc, 0x0d] : "elem.drop",
573 TableInit(TableInit<'a>) : [0xfc, 0x0c] : "table.init",
574 TableCopy(TableCopy<'a>) : [0xfc, 0x0e] : "table.copy",
575 TableFill(TableArg<'a>) : [0xfc, 0x11] : "table.fill",
576 TableSize(TableArg<'a>) : [0xfc, 0x10] : "table.size",
577 TableGrow(TableArg<'a>) : [0xfc, 0x0f] : "table.grow",
578
579 RefNull(HeapType<'a>) : [0xd0] : "ref.null",
580 RefIsNull : [0xd1] : "ref.is_null",
581 RefFunc(Index<'a>) : [0xd2] : "ref.func",
582
583 // function-references proposal
584 RefAsNonNull : [0xd4] : "ref.as_non_null",
585 BrOnNull(Index<'a>) : [0xd5] : "br_on_null",
586 BrOnNonNull(Index<'a>) : [0xd6] : "br_on_non_null",
587
588 // gc proposal: eqref
589 RefEq : [0xd3] : "ref.eq",
590
591 // gc proposal: struct
592 StructNew(Index<'a>) : [0xfb, 0x00] : "struct.new",
593 StructNewDefault(Index<'a>) : [0xfb, 0x01] : "struct.new_default",
594 StructGet(StructAccess<'a>) : [0xfb, 0x02] : "struct.get",
595 StructGetS(StructAccess<'a>) : [0xfb, 0x03] : "struct.get_s",
596 StructGetU(StructAccess<'a>) : [0xfb, 0x04] : "struct.get_u",
597 StructSet(StructAccess<'a>) : [0xfb, 0x05] : "struct.set",
598
599 // gc proposal: array
600 ArrayNew(Index<'a>) : [0xfb, 0x06] : "array.new",
601 ArrayNewDefault(Index<'a>) : [0xfb, 0x07] : "array.new_default",
602 ArrayNewFixed(ArrayNewFixed<'a>) : [0xfb, 0x08] : "array.new_fixed",
603 ArrayNewData(ArrayNewData<'a>) : [0xfb, 0x09] : "array.new_data",
604 ArrayNewElem(ArrayNewElem<'a>) : [0xfb, 0x0a] : "array.new_elem",
605 ArrayGet(Index<'a>) : [0xfb, 0x0b] : "array.get",
606 ArrayGetS(Index<'a>) : [0xfb, 0x0c] : "array.get_s",
607 ArrayGetU(Index<'a>) : [0xfb, 0x0d] : "array.get_u",
608 ArraySet(Index<'a>) : [0xfb, 0x0e] : "array.set",
609 ArrayLen : [0xfb, 0x0f] : "array.len",
610 ArrayFill(ArrayFill<'a>) : [0xfb, 0x10] : "array.fill",
611 ArrayCopy(ArrayCopy<'a>) : [0xfb, 0x11] : "array.copy",
612 ArrayInitData(ArrayInit<'a>) : [0xfb, 0x12] : "array.init_data",
613 ArrayInitElem(ArrayInit<'a>) : [0xfb, 0x13] : "array.init_elem",
614
615 // gc proposal, i31
616 RefI31 : [0xfb, 0x1c] : "ref.i31",
617 I31GetS : [0xfb, 0x1d] : "i31.get_s",
618 I31GetU : [0xfb, 0x1e] : "i31.get_u",
619
620 // gc proposal, concrete casting
621 RefTest(RefTest<'a>) : [] : "ref.test",
622 RefCast(RefCast<'a>) : [] : "ref.cast",
623 BrOnCast(Box<BrOnCast<'a>>) : [] : "br_on_cast",
624 BrOnCastFail(Box<BrOnCastFail<'a>>) : [] : "br_on_cast_fail",
625
626 // gc proposal extern/any coercion operations
627 AnyConvertExtern : [0xfb, 0x1a] : "any.convert_extern",
628 ExternConvertAny : [0xfb, 0x1b] : "extern.convert_any",
629
630 I32Const(i32) : [0x41] : "i32.const",
631 I64Const(i64) : [0x42] : "i64.const",
632 F32Const(F32) : [0x43] : "f32.const",
633 F64Const(F64) : [0x44] : "f64.const",
634
635 I32Clz : [0x67] : "i32.clz",
636 I32Ctz : [0x68] : "i32.ctz",
637 I32Popcnt : [0x69] : "i32.popcnt",
638 I32Add : [0x6a] : "i32.add",
639 I32Sub : [0x6b] : "i32.sub",
640 I32Mul : [0x6c] : "i32.mul",
641 I32DivS : [0x6d] : "i32.div_s",
642 I32DivU : [0x6e] : "i32.div_u",
643 I32RemS : [0x6f] : "i32.rem_s",
644 I32RemU : [0x70] : "i32.rem_u",
645 I32And : [0x71] : "i32.and",
646 I32Or : [0x72] : "i32.or",
647 I32Xor : [0x73] : "i32.xor",
648 I32Shl : [0x74] : "i32.shl",
649 I32ShrS : [0x75] : "i32.shr_s",
650 I32ShrU : [0x76] : "i32.shr_u",
651 I32Rotl : [0x77] : "i32.rotl",
652 I32Rotr : [0x78] : "i32.rotr",
653
654 I64Clz : [0x79] : "i64.clz",
655 I64Ctz : [0x7a] : "i64.ctz",
656 I64Popcnt : [0x7b] : "i64.popcnt",
657 I64Add : [0x7c] : "i64.add",
658 I64Sub : [0x7d] : "i64.sub",
659 I64Mul : [0x7e] : "i64.mul",
660 I64DivS : [0x7f] : "i64.div_s",
661 I64DivU : [0x80] : "i64.div_u",
662 I64RemS : [0x81] : "i64.rem_s",
663 I64RemU : [0x82] : "i64.rem_u",
664 I64And : [0x83] : "i64.and",
665 I64Or : [0x84] : "i64.or",
666 I64Xor : [0x85] : "i64.xor",
667 I64Shl : [0x86] : "i64.shl",
668 I64ShrS : [0x87] : "i64.shr_s",
669 I64ShrU : [0x88] : "i64.shr_u",
670 I64Rotl : [0x89] : "i64.rotl",
671 I64Rotr : [0x8a] : "i64.rotr",
672
673 F32Abs : [0x8b] : "f32.abs",
674 F32Neg : [0x8c] : "f32.neg",
675 F32Ceil : [0x8d] : "f32.ceil",
676 F32Floor : [0x8e] : "f32.floor",
677 F32Trunc : [0x8f] : "f32.trunc",
678 F32Nearest : [0x90] : "f32.nearest",
679 F32Sqrt : [0x91] : "f32.sqrt",
680 F32Add : [0x92] : "f32.add",
681 F32Sub : [0x93] : "f32.sub",
682 F32Mul : [0x94] : "f32.mul",
683 F32Div : [0x95] : "f32.div",
684 F32Min : [0x96] : "f32.min",
685 F32Max : [0x97] : "f32.max",
686 F32Copysign : [0x98] : "f32.copysign",
687
688 F64Abs : [0x99] : "f64.abs",
689 F64Neg : [0x9a] : "f64.neg",
690 F64Ceil : [0x9b] : "f64.ceil",
691 F64Floor : [0x9c] : "f64.floor",
692 F64Trunc : [0x9d] : "f64.trunc",
693 F64Nearest : [0x9e] : "f64.nearest",
694 F64Sqrt : [0x9f] : "f64.sqrt",
695 F64Add : [0xa0] : "f64.add",
696 F64Sub : [0xa1] : "f64.sub",
697 F64Mul : [0xa2] : "f64.mul",
698 F64Div : [0xa3] : "f64.div",
699 F64Min : [0xa4] : "f64.min",
700 F64Max : [0xa5] : "f64.max",
701 F64Copysign : [0xa6] : "f64.copysign",
702
703 I32Eqz : [0x45] : "i32.eqz",
704 I32Eq : [0x46] : "i32.eq",
705 I32Ne : [0x47] : "i32.ne",
706 I32LtS : [0x48] : "i32.lt_s",
707 I32LtU : [0x49] : "i32.lt_u",
708 I32GtS : [0x4a] : "i32.gt_s",
709 I32GtU : [0x4b] : "i32.gt_u",
710 I32LeS : [0x4c] : "i32.le_s",
711 I32LeU : [0x4d] : "i32.le_u",
712 I32GeS : [0x4e] : "i32.ge_s",
713 I32GeU : [0x4f] : "i32.ge_u",
714
715 I64Eqz : [0x50] : "i64.eqz",
716 I64Eq : [0x51] : "i64.eq",
717 I64Ne : [0x52] : "i64.ne",
718 I64LtS : [0x53] : "i64.lt_s",
719 I64LtU : [0x54] : "i64.lt_u",
720 I64GtS : [0x55] : "i64.gt_s",
721 I64GtU : [0x56] : "i64.gt_u",
722 I64LeS : [0x57] : "i64.le_s",
723 I64LeU : [0x58] : "i64.le_u",
724 I64GeS : [0x59] : "i64.ge_s",
725 I64GeU : [0x5a] : "i64.ge_u",
726
727 F32Eq : [0x5b] : "f32.eq",
728 F32Ne : [0x5c] : "f32.ne",
729 F32Lt : [0x5d] : "f32.lt",
730 F32Gt : [0x5e] : "f32.gt",
731 F32Le : [0x5f] : "f32.le",
732 F32Ge : [0x60] : "f32.ge",
733
734 F64Eq : [0x61] : "f64.eq",
735 F64Ne : [0x62] : "f64.ne",
736 F64Lt : [0x63] : "f64.lt",
737 F64Gt : [0x64] : "f64.gt",
738 F64Le : [0x65] : "f64.le",
739 F64Ge : [0x66] : "f64.ge",
740
741 I32WrapI64 : [0xa7] : "i32.wrap_i64",
742 I32TruncF32S : [0xa8] : "i32.trunc_f32_s",
743 I32TruncF32U : [0xa9] : "i32.trunc_f32_u",
744 I32TruncF64S : [0xaa] : "i32.trunc_f64_s",
745 I32TruncF64U : [0xab] : "i32.trunc_f64_u",
746 I64ExtendI32S : [0xac] : "i64.extend_i32_s",
747 I64ExtendI32U : [0xad] : "i64.extend_i32_u",
748 I64TruncF32S : [0xae] : "i64.trunc_f32_s",
749 I64TruncF32U : [0xaf] : "i64.trunc_f32_u",
750 I64TruncF64S : [0xb0] : "i64.trunc_f64_s",
751 I64TruncF64U : [0xb1] : "i64.trunc_f64_u",
752 F32ConvertI32S : [0xb2] : "f32.convert_i32_s",
753 F32ConvertI32U : [0xb3] : "f32.convert_i32_u",
754 F32ConvertI64S : [0xb4] : "f32.convert_i64_s",
755 F32ConvertI64U : [0xb5] : "f32.convert_i64_u",
756 F32DemoteF64 : [0xb6] : "f32.demote_f64",
757 F64ConvertI32S : [0xb7] : "f64.convert_i32_s",
758 F64ConvertI32U : [0xb8] : "f64.convert_i32_u",
759 F64ConvertI64S : [0xb9] : "f64.convert_i64_s",
760 F64ConvertI64U : [0xba] : "f64.convert_i64_u",
761 F64PromoteF32 : [0xbb] : "f64.promote_f32",
762 I32ReinterpretF32 : [0xbc] : "i32.reinterpret_f32",
763 I64ReinterpretF64 : [0xbd] : "i64.reinterpret_f64",
764 F32ReinterpretI32 : [0xbe] : "f32.reinterpret_i32",
765 F64ReinterpretI64 : [0xbf] : "f64.reinterpret_i64",
766
767 // non-trapping float to int
768 I32TruncSatF32S : [0xfc, 0x00] : "i32.trunc_sat_f32_s",
769 I32TruncSatF32U : [0xfc, 0x01] : "i32.trunc_sat_f32_u",
770 I32TruncSatF64S : [0xfc, 0x02] : "i32.trunc_sat_f64_s",
771 I32TruncSatF64U : [0xfc, 0x03] : "i32.trunc_sat_f64_u",
772 I64TruncSatF32S : [0xfc, 0x04] : "i64.trunc_sat_f32_s",
773 I64TruncSatF32U : [0xfc, 0x05] : "i64.trunc_sat_f32_u",
774 I64TruncSatF64S : [0xfc, 0x06] : "i64.trunc_sat_f64_s",
775 I64TruncSatF64U : [0xfc, 0x07] : "i64.trunc_sat_f64_u",
776
777 // sign extension proposal
778 I32Extend8S : [0xc0] : "i32.extend8_s",
779 I32Extend16S : [0xc1] : "i32.extend16_s",
780 I64Extend8S : [0xc2] : "i64.extend8_s",
781 I64Extend16S : [0xc3] : "i64.extend16_s",
782 I64Extend32S : [0xc4] : "i64.extend32_s",
783
784 // atomics proposal
785 MemoryAtomicNotify(MemArg<4>) : [0xfe, 0x00] : "memory.atomic.notify",
786 MemoryAtomicWait32(MemArg<4>) : [0xfe, 0x01] : "memory.atomic.wait32",
787 MemoryAtomicWait64(MemArg<8>) : [0xfe, 0x02] : "memory.atomic.wait64",
788 AtomicFence : [0xfe, 0x03, 0x00] : "atomic.fence",
789
790 I32AtomicLoad(MemArg<4>) : [0xfe, 0x10] : "i32.atomic.load",
791 I64AtomicLoad(MemArg<8>) : [0xfe, 0x11] : "i64.atomic.load",
792 I32AtomicLoad8u(MemArg<1>) : [0xfe, 0x12] : "i32.atomic.load8_u",
793 I32AtomicLoad16u(MemArg<2>) : [0xfe, 0x13] : "i32.atomic.load16_u",
794 I64AtomicLoad8u(MemArg<1>) : [0xfe, 0x14] : "i64.atomic.load8_u",
795 I64AtomicLoad16u(MemArg<2>) : [0xfe, 0x15] : "i64.atomic.load16_u",
796 I64AtomicLoad32u(MemArg<4>) : [0xfe, 0x16] : "i64.atomic.load32_u",
797 I32AtomicStore(MemArg<4>) : [0xfe, 0x17] : "i32.atomic.store",
798 I64AtomicStore(MemArg<8>) : [0xfe, 0x18] : "i64.atomic.store",
799 I32AtomicStore8(MemArg<1>) : [0xfe, 0x19] : "i32.atomic.store8",
800 I32AtomicStore16(MemArg<2>) : [0xfe, 0x1a] : "i32.atomic.store16",
801 I64AtomicStore8(MemArg<1>) : [0xfe, 0x1b] : "i64.atomic.store8",
802 I64AtomicStore16(MemArg<2>) : [0xfe, 0x1c] : "i64.atomic.store16",
803 I64AtomicStore32(MemArg<4>) : [0xfe, 0x1d] : "i64.atomic.store32",
804
805 I32AtomicRmwAdd(MemArg<4>) : [0xfe, 0x1e] : "i32.atomic.rmw.add",
806 I64AtomicRmwAdd(MemArg<8>) : [0xfe, 0x1f] : "i64.atomic.rmw.add",
807 I32AtomicRmw8AddU(MemArg<1>) : [0xfe, 0x20] : "i32.atomic.rmw8.add_u",
808 I32AtomicRmw16AddU(MemArg<2>) : [0xfe, 0x21] : "i32.atomic.rmw16.add_u",
809 I64AtomicRmw8AddU(MemArg<1>) : [0xfe, 0x22] : "i64.atomic.rmw8.add_u",
810 I64AtomicRmw16AddU(MemArg<2>) : [0xfe, 0x23] : "i64.atomic.rmw16.add_u",
811 I64AtomicRmw32AddU(MemArg<4>) : [0xfe, 0x24] : "i64.atomic.rmw32.add_u",
812
813 I32AtomicRmwSub(MemArg<4>) : [0xfe, 0x25] : "i32.atomic.rmw.sub",
814 I64AtomicRmwSub(MemArg<8>) : [0xfe, 0x26] : "i64.atomic.rmw.sub",
815 I32AtomicRmw8SubU(MemArg<1>) : [0xfe, 0x27] : "i32.atomic.rmw8.sub_u",
816 I32AtomicRmw16SubU(MemArg<2>) : [0xfe, 0x28] : "i32.atomic.rmw16.sub_u",
817 I64AtomicRmw8SubU(MemArg<1>) : [0xfe, 0x29] : "i64.atomic.rmw8.sub_u",
818 I64AtomicRmw16SubU(MemArg<2>) : [0xfe, 0x2a] : "i64.atomic.rmw16.sub_u",
819 I64AtomicRmw32SubU(MemArg<4>) : [0xfe, 0x2b] : "i64.atomic.rmw32.sub_u",
820
821 I32AtomicRmwAnd(MemArg<4>) : [0xfe, 0x2c] : "i32.atomic.rmw.and",
822 I64AtomicRmwAnd(MemArg<8>) : [0xfe, 0x2d] : "i64.atomic.rmw.and",
823 I32AtomicRmw8AndU(MemArg<1>) : [0xfe, 0x2e] : "i32.atomic.rmw8.and_u",
824 I32AtomicRmw16AndU(MemArg<2>) : [0xfe, 0x2f] : "i32.atomic.rmw16.and_u",
825 I64AtomicRmw8AndU(MemArg<1>) : [0xfe, 0x30] : "i64.atomic.rmw8.and_u",
826 I64AtomicRmw16AndU(MemArg<2>) : [0xfe, 0x31] : "i64.atomic.rmw16.and_u",
827 I64AtomicRmw32AndU(MemArg<4>) : [0xfe, 0x32] : "i64.atomic.rmw32.and_u",
828
829 I32AtomicRmwOr(MemArg<4>) : [0xfe, 0x33] : "i32.atomic.rmw.or",
830 I64AtomicRmwOr(MemArg<8>) : [0xfe, 0x34] : "i64.atomic.rmw.or",
831 I32AtomicRmw8OrU(MemArg<1>) : [0xfe, 0x35] : "i32.atomic.rmw8.or_u",
832 I32AtomicRmw16OrU(MemArg<2>) : [0xfe, 0x36] : "i32.atomic.rmw16.or_u",
833 I64AtomicRmw8OrU(MemArg<1>) : [0xfe, 0x37] : "i64.atomic.rmw8.or_u",
834 I64AtomicRmw16OrU(MemArg<2>) : [0xfe, 0x38] : "i64.atomic.rmw16.or_u",
835 I64AtomicRmw32OrU(MemArg<4>) : [0xfe, 0x39] : "i64.atomic.rmw32.or_u",
836
837 I32AtomicRmwXor(MemArg<4>) : [0xfe, 0x3a] : "i32.atomic.rmw.xor",
838 I64AtomicRmwXor(MemArg<8>) : [0xfe, 0x3b] : "i64.atomic.rmw.xor",
839 I32AtomicRmw8XorU(MemArg<1>) : [0xfe, 0x3c] : "i32.atomic.rmw8.xor_u",
840 I32AtomicRmw16XorU(MemArg<2>) : [0xfe, 0x3d] : "i32.atomic.rmw16.xor_u",
841 I64AtomicRmw8XorU(MemArg<1>) : [0xfe, 0x3e] : "i64.atomic.rmw8.xor_u",
842 I64AtomicRmw16XorU(MemArg<2>) : [0xfe, 0x3f] : "i64.atomic.rmw16.xor_u",
843 I64AtomicRmw32XorU(MemArg<4>) : [0xfe, 0x40] : "i64.atomic.rmw32.xor_u",
844
845 I32AtomicRmwXchg(MemArg<4>) : [0xfe, 0x41] : "i32.atomic.rmw.xchg",
846 I64AtomicRmwXchg(MemArg<8>) : [0xfe, 0x42] : "i64.atomic.rmw.xchg",
847 I32AtomicRmw8XchgU(MemArg<1>) : [0xfe, 0x43] : "i32.atomic.rmw8.xchg_u",
848 I32AtomicRmw16XchgU(MemArg<2>) : [0xfe, 0x44] : "i32.atomic.rmw16.xchg_u",
849 I64AtomicRmw8XchgU(MemArg<1>) : [0xfe, 0x45] : "i64.atomic.rmw8.xchg_u",
850 I64AtomicRmw16XchgU(MemArg<2>) : [0xfe, 0x46] : "i64.atomic.rmw16.xchg_u",
851 I64AtomicRmw32XchgU(MemArg<4>) : [0xfe, 0x47] : "i64.atomic.rmw32.xchg_u",
852
853 I32AtomicRmwCmpxchg(MemArg<4>) : [0xfe, 0x48] : "i32.atomic.rmw.cmpxchg",
854 I64AtomicRmwCmpxchg(MemArg<8>) : [0xfe, 0x49] : "i64.atomic.rmw.cmpxchg",
855 I32AtomicRmw8CmpxchgU(MemArg<1>) : [0xfe, 0x4a] : "i32.atomic.rmw8.cmpxchg_u",
856 I32AtomicRmw16CmpxchgU(MemArg<2>) : [0xfe, 0x4b] : "i32.atomic.rmw16.cmpxchg_u",
857 I64AtomicRmw8CmpxchgU(MemArg<1>) : [0xfe, 0x4c] : "i64.atomic.rmw8.cmpxchg_u",
858 I64AtomicRmw16CmpxchgU(MemArg<2>) : [0xfe, 0x4d] : "i64.atomic.rmw16.cmpxchg_u",
859 I64AtomicRmw32CmpxchgU(MemArg<4>) : [0xfe, 0x4e] : "i64.atomic.rmw32.cmpxchg_u",
860
861 // proposal: shared-everything-threads
862 GlobalAtomicGet(Ordered<Index<'a>>) : [0xfe, 0x4f] : "global.atomic.get",
863 GlobalAtomicSet(Ordered<Index<'a>>) : [0xfe, 0x50] : "global.atomic.set",
864 GlobalAtomicRmwAdd(Ordered<Index<'a>>) : [0xfe, 0x51] : "global.atomic.rmw.add",
865 GlobalAtomicRmwSub(Ordered<Index<'a>>) : [0xfe, 0x52] : "global.atomic.rmw.sub",
866 GlobalAtomicRmwAnd(Ordered<Index<'a>>) : [0xfe, 0x53] : "global.atomic.rmw.and",
867 GlobalAtomicRmwOr(Ordered<Index<'a>>) : [0xfe, 0x54] : "global.atomic.rmw.or",
868 GlobalAtomicRmwXor(Ordered<Index<'a>>) : [0xfe, 0x55] : "global.atomic.rmw.xor",
869 GlobalAtomicRmwXchg(Ordered<Index<'a>>) : [0xfe, 0x56] : "global.atomic.rmw.xchg",
870 GlobalAtomicRmwCmpxchg(Ordered<Index<'a>>) : [0xfe, 0x57] : "global.atomic.rmw.cmpxchg",
871 TableAtomicGet(Ordered<TableArg<'a>>) : [0xfe, 0x58] : "table.atomic.get",
872 TableAtomicSet(Ordered<TableArg<'a>>) : [0xfe, 0x59] : "table.atomic.set",
873 TableAtomicRmwXchg(Ordered<TableArg<'a>>) : [0xfe, 0x5a] : "table.atomic.rmw.xchg",
874 TableAtomicRmwCmpxchg(Ordered<TableArg<'a>>) : [0xfe, 0x5b] : "table.atomic.rmw.cmpxchg",
875 StructAtomicGet(Ordered<StructAccess<'a>>) : [0xfe, 0x5c] : "struct.atomic.get",
876 StructAtomicGetS(Ordered<StructAccess<'a>>) : [0xfe, 0x5d] : "struct.atomic.get_s",
877 StructAtomicGetU(Ordered<StructAccess<'a>>) : [0xfe, 0x5e] : "struct.atomic.get_u",
878 StructAtomicSet(Ordered<StructAccess<'a>>) : [0xfe, 0x5f] : "struct.atomic.set",
879 StructAtomicRmwAdd(Ordered<StructAccess<'a>>) : [0xfe, 0x60] : "struct.atomic.rmw.add",
880 StructAtomicRmwSub(Ordered<StructAccess<'a>>) : [0xfe, 0x61] : "struct.atomic.rmw.sub",
881 StructAtomicRmwAnd(Ordered<StructAccess<'a>>) : [0xfe, 0x62] : "struct.atomic.rmw.and",
882 StructAtomicRmwOr(Ordered<StructAccess<'a>>) : [0xfe, 0x63] : "struct.atomic.rmw.or",
883 StructAtomicRmwXor(Ordered<StructAccess<'a>>) : [0xfe, 0x64] : "struct.atomic.rmw.xor",
884 StructAtomicRmwXchg(Ordered<StructAccess<'a>>) : [0xfe, 0x65] : "struct.atomic.rmw.xchg",
885 StructAtomicRmwCmpxchg(Ordered<StructAccess<'a>>) : [0xfe, 0x66] : "struct.atomic.rmw.cmpxchg",
886 ArrayAtomicGet(Ordered<Index<'a>>) : [0xfe, 0x67] : "array.atomic.get",
887 ArrayAtomicGetS(Ordered<Index<'a>>) : [0xfe, 0x68] : "array.atomic.get_s",
888 ArrayAtomicGetU(Ordered<Index<'a>>) : [0xfe, 0x69] : "array.atomic.get_u",
889 ArrayAtomicSet(Ordered<Index<'a>>) : [0xfe, 0x6a] : "array.atomic.set",
890 ArrayAtomicRmwAdd(Ordered<Index<'a>>) : [0xfe, 0x6b] : "array.atomic.rmw.add",
891 ArrayAtomicRmwSub(Ordered<Index<'a>>) : [0xfe, 0x6c] : "array.atomic.rmw.sub",
892 ArrayAtomicRmwAnd(Ordered<Index<'a>>) : [0xfe, 0x6d] : "array.atomic.rmw.and",
893 ArrayAtomicRmwOr(Ordered<Index<'a>>) : [0xfe, 0x6e] : "array.atomic.rmw.or",
894 ArrayAtomicRmwXor(Ordered<Index<'a>>) : [0xfe, 0x6f] : "array.atomic.rmw.xor",
895 ArrayAtomicRmwXchg(Ordered<Index<'a>>) : [0xfe, 0x70] : "array.atomic.rmw.xchg",
896 ArrayAtomicRmwCmpxchg(Ordered<Index<'a>>) : [0xfe, 0x71] : "array.atomic.rmw.cmpxchg",
897 RefI31Shared : [0xfe, 0x72] : "ref.i31_shared",
898
899 // proposal: simd
900 //
901 // https://webassembly.github.io/simd/core/binary/instructions.html
902 V128Load(MemArg<16>) : [0xfd, 0] : "v128.load",
903 V128Load8x8S(MemArg<8>) : [0xfd, 1] : "v128.load8x8_s",
904 V128Load8x8U(MemArg<8>) : [0xfd, 2] : "v128.load8x8_u",
905 V128Load16x4S(MemArg<8>) : [0xfd, 3] : "v128.load16x4_s",
906 V128Load16x4U(MemArg<8>) : [0xfd, 4] : "v128.load16x4_u",
907 V128Load32x2S(MemArg<8>) : [0xfd, 5] : "v128.load32x2_s",
908 V128Load32x2U(MemArg<8>) : [0xfd, 6] : "v128.load32x2_u",
909 V128Load8Splat(MemArg<1>) : [0xfd, 7] : "v128.load8_splat",
910 V128Load16Splat(MemArg<2>) : [0xfd, 8] : "v128.load16_splat",
911 V128Load32Splat(MemArg<4>) : [0xfd, 9] : "v128.load32_splat",
912 V128Load64Splat(MemArg<8>) : [0xfd, 10] : "v128.load64_splat",
913 V128Load32Zero(MemArg<4>) : [0xfd, 92] : "v128.load32_zero",
914 V128Load64Zero(MemArg<8>) : [0xfd, 93] : "v128.load64_zero",
915 V128Store(MemArg<16>) : [0xfd, 11] : "v128.store",
916
917 V128Load8Lane(LoadOrStoreLane<1>) : [0xfd, 84] : "v128.load8_lane",
918 V128Load16Lane(LoadOrStoreLane<2>) : [0xfd, 85] : "v128.load16_lane",
919 V128Load32Lane(LoadOrStoreLane<4>) : [0xfd, 86] : "v128.load32_lane",
920 V128Load64Lane(LoadOrStoreLane<8>): [0xfd, 87] : "v128.load64_lane",
921 V128Store8Lane(LoadOrStoreLane<1>) : [0xfd, 88] : "v128.store8_lane",
922 V128Store16Lane(LoadOrStoreLane<2>) : [0xfd, 89] : "v128.store16_lane",
923 V128Store32Lane(LoadOrStoreLane<4>) : [0xfd, 90] : "v128.store32_lane",
924 V128Store64Lane(LoadOrStoreLane<8>) : [0xfd, 91] : "v128.store64_lane",
925
926 V128Const(V128Const) : [0xfd, 12] : "v128.const",
927 I8x16Shuffle(I8x16Shuffle) : [0xfd, 13] : "i8x16.shuffle",
928
929 I8x16ExtractLaneS(LaneArg) : [0xfd, 21] : "i8x16.extract_lane_s",
930 I8x16ExtractLaneU(LaneArg) : [0xfd, 22] : "i8x16.extract_lane_u",
931 I8x16ReplaceLane(LaneArg) : [0xfd, 23] : "i8x16.replace_lane",
932 I16x8ExtractLaneS(LaneArg) : [0xfd, 24] : "i16x8.extract_lane_s",
933 I16x8ExtractLaneU(LaneArg) : [0xfd, 25] : "i16x8.extract_lane_u",
934 I16x8ReplaceLane(LaneArg) : [0xfd, 26] : "i16x8.replace_lane",
935 I32x4ExtractLane(LaneArg) : [0xfd, 27] : "i32x4.extract_lane",
936 I32x4ReplaceLane(LaneArg) : [0xfd, 28] : "i32x4.replace_lane",
937 I64x2ExtractLane(LaneArg) : [0xfd, 29] : "i64x2.extract_lane",
938 I64x2ReplaceLane(LaneArg) : [0xfd, 30] : "i64x2.replace_lane",
939 F32x4ExtractLane(LaneArg) : [0xfd, 31] : "f32x4.extract_lane",
940 F32x4ReplaceLane(LaneArg) : [0xfd, 32] : "f32x4.replace_lane",
941 F64x2ExtractLane(LaneArg) : [0xfd, 33] : "f64x2.extract_lane",
942 F64x2ReplaceLane(LaneArg) : [0xfd, 34] : "f64x2.replace_lane",
943
944 I8x16Swizzle : [0xfd, 14] : "i8x16.swizzle",
945 I8x16Splat : [0xfd, 15] : "i8x16.splat",
946 I16x8Splat : [0xfd, 16] : "i16x8.splat",
947 I32x4Splat : [0xfd, 17] : "i32x4.splat",
948 I64x2Splat : [0xfd, 18] : "i64x2.splat",
949 F32x4Splat : [0xfd, 19] : "f32x4.splat",
950 F64x2Splat : [0xfd, 20] : "f64x2.splat",
951
952 I8x16Eq : [0xfd, 35] : "i8x16.eq",
953 I8x16Ne : [0xfd, 36] : "i8x16.ne",
954 I8x16LtS : [0xfd, 37] : "i8x16.lt_s",
955 I8x16LtU : [0xfd, 38] : "i8x16.lt_u",
956 I8x16GtS : [0xfd, 39] : "i8x16.gt_s",
957 I8x16GtU : [0xfd, 40] : "i8x16.gt_u",
958 I8x16LeS : [0xfd, 41] : "i8x16.le_s",
959 I8x16LeU : [0xfd, 42] : "i8x16.le_u",
960 I8x16GeS : [0xfd, 43] : "i8x16.ge_s",
961 I8x16GeU : [0xfd, 44] : "i8x16.ge_u",
962
963 I16x8Eq : [0xfd, 45] : "i16x8.eq",
964 I16x8Ne : [0xfd, 46] : "i16x8.ne",
965 I16x8LtS : [0xfd, 47] : "i16x8.lt_s",
966 I16x8LtU : [0xfd, 48] : "i16x8.lt_u",
967 I16x8GtS : [0xfd, 49] : "i16x8.gt_s",
968 I16x8GtU : [0xfd, 50] : "i16x8.gt_u",
969 I16x8LeS : [0xfd, 51] : "i16x8.le_s",
970 I16x8LeU : [0xfd, 52] : "i16x8.le_u",
971 I16x8GeS : [0xfd, 53] : "i16x8.ge_s",
972 I16x8GeU : [0xfd, 54] : "i16x8.ge_u",
973
974 I32x4Eq : [0xfd, 55] : "i32x4.eq",
975 I32x4Ne : [0xfd, 56] : "i32x4.ne",
976 I32x4LtS : [0xfd, 57] : "i32x4.lt_s",
977 I32x4LtU : [0xfd, 58] : "i32x4.lt_u",
978 I32x4GtS : [0xfd, 59] : "i32x4.gt_s",
979 I32x4GtU : [0xfd, 60] : "i32x4.gt_u",
980 I32x4LeS : [0xfd, 61] : "i32x4.le_s",
981 I32x4LeU : [0xfd, 62] : "i32x4.le_u",
982 I32x4GeS : [0xfd, 63] : "i32x4.ge_s",
983 I32x4GeU : [0xfd, 64] : "i32x4.ge_u",
984
985 I64x2Eq : [0xfd, 214] : "i64x2.eq",
986 I64x2Ne : [0xfd, 215] : "i64x2.ne",
987 I64x2LtS : [0xfd, 216] : "i64x2.lt_s",
988 I64x2GtS : [0xfd, 217] : "i64x2.gt_s",
989 I64x2LeS : [0xfd, 218] : "i64x2.le_s",
990 I64x2GeS : [0xfd, 219] : "i64x2.ge_s",
991
992 F32x4Eq : [0xfd, 65] : "f32x4.eq",
993 F32x4Ne : [0xfd, 66] : "f32x4.ne",
994 F32x4Lt : [0xfd, 67] : "f32x4.lt",
995 F32x4Gt : [0xfd, 68] : "f32x4.gt",
996 F32x4Le : [0xfd, 69] : "f32x4.le",
997 F32x4Ge : [0xfd, 70] : "f32x4.ge",
998
999 F64x2Eq : [0xfd, 71] : "f64x2.eq",
1000 F64x2Ne : [0xfd, 72] : "f64x2.ne",
1001 F64x2Lt : [0xfd, 73] : "f64x2.lt",
1002 F64x2Gt : [0xfd, 74] : "f64x2.gt",
1003 F64x2Le : [0xfd, 75] : "f64x2.le",
1004 F64x2Ge : [0xfd, 76] : "f64x2.ge",
1005
1006 V128Not : [0xfd, 77] : "v128.not",
1007 V128And : [0xfd, 78] : "v128.and",
1008 V128Andnot : [0xfd, 79] : "v128.andnot",
1009 V128Or : [0xfd, 80] : "v128.or",
1010 V128Xor : [0xfd, 81] : "v128.xor",
1011 V128Bitselect : [0xfd, 82] : "v128.bitselect",
1012 V128AnyTrue : [0xfd, 83] : "v128.any_true",
1013
1014 I8x16Abs : [0xfd, 96] : "i8x16.abs",
1015 I8x16Neg : [0xfd, 97] : "i8x16.neg",
1016 I8x16Popcnt : [0xfd, 98] : "i8x16.popcnt",
1017 I8x16AllTrue : [0xfd, 99] : "i8x16.all_true",
1018 I8x16Bitmask : [0xfd, 100] : "i8x16.bitmask",
1019 I8x16NarrowI16x8S : [0xfd, 101] : "i8x16.narrow_i16x8_s",
1020 I8x16NarrowI16x8U : [0xfd, 102] : "i8x16.narrow_i16x8_u",
1021 I8x16Shl : [0xfd, 107] : "i8x16.shl",
1022 I8x16ShrS : [0xfd, 108] : "i8x16.shr_s",
1023 I8x16ShrU : [0xfd, 109] : "i8x16.shr_u",
1024 I8x16Add : [0xfd, 110] : "i8x16.add",
1025 I8x16AddSatS : [0xfd, 111] : "i8x16.add_sat_s",
1026 I8x16AddSatU : [0xfd, 112] : "i8x16.add_sat_u",
1027 I8x16Sub : [0xfd, 113] : "i8x16.sub",
1028 I8x16SubSatS : [0xfd, 114] : "i8x16.sub_sat_s",
1029 I8x16SubSatU : [0xfd, 115] : "i8x16.sub_sat_u",
1030 I8x16MinS : [0xfd, 118] : "i8x16.min_s",
1031 I8x16MinU : [0xfd, 119] : "i8x16.min_u",
1032 I8x16MaxS : [0xfd, 120] : "i8x16.max_s",
1033 I8x16MaxU : [0xfd, 121] : "i8x16.max_u",
1034 I8x16AvgrU : [0xfd, 123] : "i8x16.avgr_u",
1035
1036 I16x8ExtAddPairwiseI8x16S : [0xfd, 124] : "i16x8.extadd_pairwise_i8x16_s",
1037 I16x8ExtAddPairwiseI8x16U : [0xfd, 125] : "i16x8.extadd_pairwise_i8x16_u",
1038 I16x8Abs : [0xfd, 128] : "i16x8.abs",
1039 I16x8Neg : [0xfd, 129] : "i16x8.neg",
1040 I16x8Q15MulrSatS : [0xfd, 130] : "i16x8.q15mulr_sat_s",
1041 I16x8AllTrue : [0xfd, 131] : "i16x8.all_true",
1042 I16x8Bitmask : [0xfd, 132] : "i16x8.bitmask",
1043 I16x8NarrowI32x4S : [0xfd, 133] : "i16x8.narrow_i32x4_s",
1044 I16x8NarrowI32x4U : [0xfd, 134] : "i16x8.narrow_i32x4_u",
1045 I16x8ExtendLowI8x16S : [0xfd, 135] : "i16x8.extend_low_i8x16_s",
1046 I16x8ExtendHighI8x16S : [0xfd, 136] : "i16x8.extend_high_i8x16_s",
1047 I16x8ExtendLowI8x16U : [0xfd, 137] : "i16x8.extend_low_i8x16_u",
1048 I16x8ExtendHighI8x16u : [0xfd, 138] : "i16x8.extend_high_i8x16_u",
1049 I16x8Shl : [0xfd, 139] : "i16x8.shl",
1050 I16x8ShrS : [0xfd, 140] : "i16x8.shr_s",
1051 I16x8ShrU : [0xfd, 141] : "i16x8.shr_u",
1052 I16x8Add : [0xfd, 142] : "i16x8.add",
1053 I16x8AddSatS : [0xfd, 143] : "i16x8.add_sat_s",
1054 I16x8AddSatU : [0xfd, 144] : "i16x8.add_sat_u",
1055 I16x8Sub : [0xfd, 145] : "i16x8.sub",
1056 I16x8SubSatS : [0xfd, 146] : "i16x8.sub_sat_s",
1057 I16x8SubSatU : [0xfd, 147] : "i16x8.sub_sat_u",
1058 I16x8Mul : [0xfd, 149] : "i16x8.mul",
1059 I16x8MinS : [0xfd, 150] : "i16x8.min_s",
1060 I16x8MinU : [0xfd, 151] : "i16x8.min_u",
1061 I16x8MaxS : [0xfd, 152] : "i16x8.max_s",
1062 I16x8MaxU : [0xfd, 153] : "i16x8.max_u",
1063 I16x8AvgrU : [0xfd, 155] : "i16x8.avgr_u",
1064 I16x8ExtMulLowI8x16S : [0xfd, 156] : "i16x8.extmul_low_i8x16_s",
1065 I16x8ExtMulHighI8x16S : [0xfd, 157] : "i16x8.extmul_high_i8x16_s",
1066 I16x8ExtMulLowI8x16U : [0xfd, 158] : "i16x8.extmul_low_i8x16_u",
1067 I16x8ExtMulHighI8x16U : [0xfd, 159] : "i16x8.extmul_high_i8x16_u",
1068
1069 I32x4ExtAddPairwiseI16x8S : [0xfd, 126] : "i32x4.extadd_pairwise_i16x8_s",
1070 I32x4ExtAddPairwiseI16x8U : [0xfd, 127] : "i32x4.extadd_pairwise_i16x8_u",
1071 I32x4Abs : [0xfd, 160] : "i32x4.abs",
1072 I32x4Neg : [0xfd, 161] : "i32x4.neg",
1073 I32x4AllTrue : [0xfd, 163] : "i32x4.all_true",
1074 I32x4Bitmask : [0xfd, 164] : "i32x4.bitmask",
1075 I32x4ExtendLowI16x8S : [0xfd, 167] : "i32x4.extend_low_i16x8_s",
1076 I32x4ExtendHighI16x8S : [0xfd, 168] : "i32x4.extend_high_i16x8_s",
1077 I32x4ExtendLowI16x8U : [0xfd, 169] : "i32x4.extend_low_i16x8_u",
1078 I32x4ExtendHighI16x8U : [0xfd, 170] : "i32x4.extend_high_i16x8_u",
1079 I32x4Shl : [0xfd, 171] : "i32x4.shl",
1080 I32x4ShrS : [0xfd, 172] : "i32x4.shr_s",
1081 I32x4ShrU : [0xfd, 173] : "i32x4.shr_u",
1082 I32x4Add : [0xfd, 174] : "i32x4.add",
1083 I32x4Sub : [0xfd, 177] : "i32x4.sub",
1084 I32x4Mul : [0xfd, 181] : "i32x4.mul",
1085 I32x4MinS : [0xfd, 182] : "i32x4.min_s",
1086 I32x4MinU : [0xfd, 183] : "i32x4.min_u",
1087 I32x4MaxS : [0xfd, 184] : "i32x4.max_s",
1088 I32x4MaxU : [0xfd, 185] : "i32x4.max_u",
1089 I32x4DotI16x8S : [0xfd, 186] : "i32x4.dot_i16x8_s",
1090 I32x4ExtMulLowI16x8S : [0xfd, 188] : "i32x4.extmul_low_i16x8_s",
1091 I32x4ExtMulHighI16x8S : [0xfd, 189] : "i32x4.extmul_high_i16x8_s",
1092 I32x4ExtMulLowI16x8U : [0xfd, 190] : "i32x4.extmul_low_i16x8_u",
1093 I32x4ExtMulHighI16x8U : [0xfd, 191] : "i32x4.extmul_high_i16x8_u",
1094
1095 I64x2Abs : [0xfd, 192] : "i64x2.abs",
1096 I64x2Neg : [0xfd, 193] : "i64x2.neg",
1097 I64x2AllTrue : [0xfd, 195] : "i64x2.all_true",
1098 I64x2Bitmask : [0xfd, 196] : "i64x2.bitmask",
1099 I64x2ExtendLowI32x4S : [0xfd, 199] : "i64x2.extend_low_i32x4_s",
1100 I64x2ExtendHighI32x4S : [0xfd, 200] : "i64x2.extend_high_i32x4_s",
1101 I64x2ExtendLowI32x4U : [0xfd, 201] : "i64x2.extend_low_i32x4_u",
1102 I64x2ExtendHighI32x4U : [0xfd, 202] : "i64x2.extend_high_i32x4_u",
1103 I64x2Shl : [0xfd, 203] : "i64x2.shl",
1104 I64x2ShrS : [0xfd, 204] : "i64x2.shr_s",
1105 I64x2ShrU : [0xfd, 205] : "i64x2.shr_u",
1106 I64x2Add : [0xfd, 206] : "i64x2.add",
1107 I64x2Sub : [0xfd, 209] : "i64x2.sub",
1108 I64x2Mul : [0xfd, 213] : "i64x2.mul",
1109 I64x2ExtMulLowI32x4S : [0xfd, 220] : "i64x2.extmul_low_i32x4_s",
1110 I64x2ExtMulHighI32x4S : [0xfd, 221] : "i64x2.extmul_high_i32x4_s",
1111 I64x2ExtMulLowI32x4U : [0xfd, 222] : "i64x2.extmul_low_i32x4_u",
1112 I64x2ExtMulHighI32x4U : [0xfd, 223] : "i64x2.extmul_high_i32x4_u",
1113
1114 F32x4Ceil : [0xfd, 103] : "f32x4.ceil",
1115 F32x4Floor : [0xfd, 104] : "f32x4.floor",
1116 F32x4Trunc : [0xfd, 105] : "f32x4.trunc",
1117 F32x4Nearest : [0xfd, 106] : "f32x4.nearest",
1118 F32x4Abs : [0xfd, 224] : "f32x4.abs",
1119 F32x4Neg : [0xfd, 225] : "f32x4.neg",
1120 F32x4Sqrt : [0xfd, 227] : "f32x4.sqrt",
1121 F32x4Add : [0xfd, 228] : "f32x4.add",
1122 F32x4Sub : [0xfd, 229] : "f32x4.sub",
1123 F32x4Mul : [0xfd, 230] : "f32x4.mul",
1124 F32x4Div : [0xfd, 231] : "f32x4.div",
1125 F32x4Min : [0xfd, 232] : "f32x4.min",
1126 F32x4Max : [0xfd, 233] : "f32x4.max",
1127 F32x4PMin : [0xfd, 234] : "f32x4.pmin",
1128 F32x4PMax : [0xfd, 235] : "f32x4.pmax",
1129
1130 F64x2Ceil : [0xfd, 116] : "f64x2.ceil",
1131 F64x2Floor : [0xfd, 117] : "f64x2.floor",
1132 F64x2Trunc : [0xfd, 122] : "f64x2.trunc",
1133 F64x2Nearest : [0xfd, 148] : "f64x2.nearest",
1134 F64x2Abs : [0xfd, 236] : "f64x2.abs",
1135 F64x2Neg : [0xfd, 237] : "f64x2.neg",
1136 F64x2Sqrt : [0xfd, 239] : "f64x2.sqrt",
1137 F64x2Add : [0xfd, 240] : "f64x2.add",
1138 F64x2Sub : [0xfd, 241] : "f64x2.sub",
1139 F64x2Mul : [0xfd, 242] : "f64x2.mul",
1140 F64x2Div : [0xfd, 243] : "f64x2.div",
1141 F64x2Min : [0xfd, 244] : "f64x2.min",
1142 F64x2Max : [0xfd, 245] : "f64x2.max",
1143 F64x2PMin : [0xfd, 246] : "f64x2.pmin",
1144 F64x2PMax : [0xfd, 247] : "f64x2.pmax",
1145
1146 I32x4TruncSatF32x4S : [0xfd, 248] : "i32x4.trunc_sat_f32x4_s",
1147 I32x4TruncSatF32x4U : [0xfd, 249] : "i32x4.trunc_sat_f32x4_u",
1148 F32x4ConvertI32x4S : [0xfd, 250] : "f32x4.convert_i32x4_s",
1149 F32x4ConvertI32x4U : [0xfd, 251] : "f32x4.convert_i32x4_u",
1150 I32x4TruncSatF64x2SZero : [0xfd, 252] : "i32x4.trunc_sat_f64x2_s_zero",
1151 I32x4TruncSatF64x2UZero : [0xfd, 253] : "i32x4.trunc_sat_f64x2_u_zero",
1152 F64x2ConvertLowI32x4S : [0xfd, 254] : "f64x2.convert_low_i32x4_s",
1153 F64x2ConvertLowI32x4U : [0xfd, 255] : "f64x2.convert_low_i32x4_u",
1154 F32x4DemoteF64x2Zero : [0xfd, 94] : "f32x4.demote_f64x2_zero",
1155 F64x2PromoteLowF32x4 : [0xfd, 95] : "f64x2.promote_low_f32x4",
1156
1157 // Exception handling proposal
1158 ThrowRef : [0x0a] : "throw_ref",
1159 TryTable(TryTable<'a>) : [0x1f] : "try_table",
1160 Throw(Index<'a>) : [0x08] : "throw",
1161
1162 // Deprecated exception handling opcodes
1163 Try(Box<BlockType<'a>>) : [0x06] : "try",
1164 Catch(Index<'a>) : [0x07] : "catch",
1165 Rethrow(Index<'a>) : [0x09] : "rethrow",
1166 Delegate(Index<'a>) : [0x18] : "delegate",
1167 CatchAll : [0x19] : "catch_all",
1168
1169 // Relaxed SIMD proposal
1170 I8x16RelaxedSwizzle : [0xfd, 0x100]: "i8x16.relaxed_swizzle",
1171 I32x4RelaxedTruncF32x4S : [0xfd, 0x101]: "i32x4.relaxed_trunc_f32x4_s",
1172 I32x4RelaxedTruncF32x4U : [0xfd, 0x102]: "i32x4.relaxed_trunc_f32x4_u",
1173 I32x4RelaxedTruncF64x2SZero : [0xfd, 0x103]: "i32x4.relaxed_trunc_f64x2_s_zero",
1174 I32x4RelaxedTruncF64x2UZero : [0xfd, 0x104]: "i32x4.relaxed_trunc_f64x2_u_zero",
1175 F32x4RelaxedMadd : [0xfd, 0x105]: "f32x4.relaxed_madd",
1176 F32x4RelaxedNmadd : [0xfd, 0x106]: "f32x4.relaxed_nmadd",
1177 F64x2RelaxedMadd : [0xfd, 0x107]: "f64x2.relaxed_madd",
1178 F64x2RelaxedNmadd : [0xfd, 0x108]: "f64x2.relaxed_nmadd",
1179 I8x16RelaxedLaneselect : [0xfd, 0x109]: "i8x16.relaxed_laneselect",
1180 I16x8RelaxedLaneselect : [0xfd, 0x10A]: "i16x8.relaxed_laneselect",
1181 I32x4RelaxedLaneselect : [0xfd, 0x10B]: "i32x4.relaxed_laneselect",
1182 I64x2RelaxedLaneselect : [0xfd, 0x10C]: "i64x2.relaxed_laneselect",
1183 F32x4RelaxedMin : [0xfd, 0x10D]: "f32x4.relaxed_min",
1184 F32x4RelaxedMax : [0xfd, 0x10E]: "f32x4.relaxed_max",
1185 F64x2RelaxedMin : [0xfd, 0x10F]: "f64x2.relaxed_min",
1186 F64x2RelaxedMax : [0xfd, 0x110]: "f64x2.relaxed_max",
1187 I16x8RelaxedQ15mulrS: [0xfd, 0x111]: "i16x8.relaxed_q15mulr_s",
1188 I16x8RelaxedDotI8x16I7x16S: [0xfd, 0x112]: "i16x8.relaxed_dot_i8x16_i7x16_s",
1189 I32x4RelaxedDotI8x16I7x16AddS: [0xfd, 0x113]: "i32x4.relaxed_dot_i8x16_i7x16_add_s",
1190
1191 // Stack switching proposal
1192 ContNew(Index<'a>) : [0xe0] : "cont.new",
1193 ContBind(ContBind<'a>) : [0xe1] : "cont.bind",
1194 Suspend(Index<'a>) : [0xe2] : "suspend",
1195 Resume(Resume<'a>) : [0xe3] : "resume",
1196 ResumeThrow(ResumeThrow<'a>) : [0xe4] : "resume_throw",
1197 Switch(Switch<'a>) : [0xe5] : "switch",
1198
1199 // Wide arithmetic proposal
1200 I64Add128 : [0xfc, 19] : "i64.add128",
1201 I64Sub128 : [0xfc, 20] : "i64.sub128",
1202 I64MulWideS : [0xfc, 21] : "i64.mul_wide_s",
1203 I64MulWideU : [0xfc, 22] : "i64.mul_wide_u",
1204 }
1205 }
1206
1207 // As shown in #1095 the size of this variant is somewhat performance-sensitive
1208 // since big `*.wat` files will have a lot of these. This is a small ratchet to
1209 // make sure that this enum doesn't become larger than it already is, although
1210 // ideally it also wouldn't be as large as it is now.
1211 const _: () = {
1212 let size = std::mem::size_of::<Instruction<'_>>();
1213 let pointer = std::mem::size_of::<u64>();
1214 assert!(size <= pointer * 11);
1215 };
1216
1217 impl<'a> Instruction<'a> {
1218 pub(crate) fn needs_data_count(&self) -> bool {
1219 match self {
1220 Instruction::MemoryInit(_)
1221 | Instruction::DataDrop(_)
1222 | Instruction::ArrayNewData(_)
1223 | Instruction::ArrayInitData(_) => true,
1224 _ => false,
1225 }
1226 }
1227 }
1228
1229 /// Extra information associated with block-related instructions.
1230 ///
1231 /// This is used to label blocks and also annotate what types are expected for
1232 /// the block.
1233 #[derive(Debug, Clone)]
1234 #[allow(missing_docs)]
1235 pub struct BlockType<'a> {
1236 pub label: Option<Id<'a>>,
1237 pub label_name: Option<NameAnnotation<'a>>,
1238 pub ty: TypeUse<'a, FunctionType<'a>>,
1239 }
1240
1241 impl<'a> Parse<'a> for BlockType<'a> {
1242 fn parse(parser: Parser<'a>) -> Result<Self> {
1243 Ok(BlockType {
1244 label: parser.parse()?,
1245 label_name: parser.parse()?,
1246 ty: parser
1247 .parse::<TypeUse<'a, FunctionTypeNoNames<'a>>>()?
1248 .into(),
1249 })
1250 }
1251 }
1252
1253 /// Extra information associated with the cont.bind instruction
1254 #[derive(Debug, Clone)]
1255 #[allow(missing_docs)]
1256 pub struct ContBind<'a> {
1257 pub argument_index: Index<'a>,
1258 pub result_index: Index<'a>,
1259 }
1260
1261 impl<'a> Parse<'a> for ContBind<'a> {
1262 fn parse(parser: Parser<'a>) -> Result<Self> {
1263 Ok(ContBind {
1264 argument_index: parser.parse()?,
1265 result_index: parser.parse()?,
1266 })
1267 }
1268 }
1269
1270 /// Extra information associated with the resume instruction
1271 #[derive(Debug, Clone)]
1272 #[allow(missing_docs)]
1273 pub struct Resume<'a> {
1274 pub type_index: Index<'a>,
1275 pub table: ResumeTable<'a>,
1276 }
1277
1278 impl<'a> Parse<'a> for Resume<'a> {
1279 fn parse(parser: Parser<'a>) -> Result<Self> {
1280 Ok(Resume {
1281 type_index: parser.parse()?,
1282 table: parser.parse()?,
1283 })
1284 }
1285 }
1286
1287 /// Extra information associated with the resume_throw instruction
1288 #[derive(Debug, Clone)]
1289 #[allow(missing_docs)]
1290 pub struct ResumeThrow<'a> {
1291 pub type_index: Index<'a>,
1292 pub tag_index: Index<'a>,
1293 pub table: ResumeTable<'a>,
1294 }
1295
1296 impl<'a> Parse<'a> for ResumeThrow<'a> {
1297 fn parse(parser: Parser<'a>) -> Result<Self> {
1298 Ok(ResumeThrow {
1299 type_index: parser.parse()?,
1300 tag_index: parser.parse()?,
1301 table: parser.parse()?,
1302 })
1303 }
1304 }
1305
1306 /// Extra information associated with the switch instruction
1307 #[derive(Debug, Clone)]
1308 #[allow(missing_docs)]
1309 pub struct Switch<'a> {
1310 pub type_index: Index<'a>,
1311 pub tag_index: Index<'a>,
1312 }
1313
1314 impl<'a> Parse<'a> for Switch<'a> {
1315 fn parse(parser: Parser<'a>) -> Result<Self> {
1316 Ok(Switch {
1317 type_index: parser.parse()?,
1318 tag_index: parser.parse()?,
1319 })
1320 }
1321 }
1322
1323 /// A representation of resume tables
1324 #[derive(Debug, Clone)]
1325 #[allow(missing_docs)]
1326 pub struct ResumeTable<'a> {
1327 pub handlers: Vec<Handle<'a>>,
1328 }
1329
1330 /// A representation of resume table entries
1331 #[derive(Debug, Clone)]
1332 #[allow(missing_docs)]
1333 pub enum Handle<'a> {
1334 OnLabel { tag: Index<'a>, label: Index<'a> },
1335 OnSwitch { tag: Index<'a> },
1336 }
1337
1338 impl<'a> Parse<'a> for ResumeTable<'a> {
1339 fn parse(parser: Parser<'a>) -> Result<Self> {
1340 let mut handlers = Vec::new();
1341 while parser.peek::<LParen>()? && parser.peek2::<kw::on>()? {
1342 handlers.push(parser.parens(|p| {
1343 p.parse::<kw::on>()?;
1344 let tag: Index<'a> = p.parse()?;
1345 if p.peek::<kw::switch>()? {
1346 p.parse::<kw::switch>()?;
1347 Ok(Handle::OnSwitch { tag })
1348 } else {
1349 Ok(Handle::OnLabel {
1350 tag,
1351 label: p.parse()?,
1352 })
1353 }
1354 })?);
1355 }
1356 Ok(ResumeTable { handlers })
1357 }
1358 }
1359
1360 #[derive(Debug, Clone)]
1361 #[allow(missing_docs)]
1362 pub struct TryTable<'a> {
1363 pub block: Box<BlockType<'a>>,
1364 pub catches: Vec<TryTableCatch<'a>>,
1365 }
1366
1367 impl<'a> Parse<'a> for TryTable<'a> {
1368 fn parse(parser: Parser<'a>) -> Result<Self> {
1369 let block = parser.parse()?;
1370
1371 let mut catches = Vec::new();
1372 while parser.peek::<LParen>()?
1373 && (parser.peek2::<kw::catch>()?
1374 || parser.peek2::<kw::catch_ref>()?
1375 || parser.peek2::<kw::catch_all>()?
1376 || parser.peek2::<kw::catch_all_ref>()?)
1377 {
1378 catches.push(parser.parens(|p| {
1379 let kind = if parser.peek::<kw::catch_ref>()? {
1380 p.parse::<kw::catch_ref>()?;
1381 TryTableCatchKind::CatchRef(p.parse()?)
1382 } else if parser.peek::<kw::catch>()? {
1383 p.parse::<kw::catch>()?;
1384 TryTableCatchKind::Catch(p.parse()?)
1385 } else if parser.peek::<kw::catch_all>()? {
1386 p.parse::<kw::catch_all>()?;
1387 TryTableCatchKind::CatchAll
1388 } else {
1389 p.parse::<kw::catch_all_ref>()?;
1390 TryTableCatchKind::CatchAllRef
1391 };
1392
1393 Ok(TryTableCatch {
1394 kind,
1395 label: p.parse()?,
1396 })
1397 })?);
1398 }
1399
1400 Ok(TryTable { block, catches })
1401 }
1402 }
1403
1404 #[derive(Debug, Clone)]
1405 #[allow(missing_docs)]
1406 pub enum TryTableCatchKind<'a> {
1407 // Catch a tagged exception, do not capture an exnref.
1408 Catch(Index<'a>),
1409 // Catch a tagged exception, and capture the exnref.
1410 CatchRef(Index<'a>),
1411 // Catch any exception, do not capture an exnref.
1412 CatchAll,
1413 // Catch any exception, and capture the exnref.
1414 CatchAllRef,
1415 }
1416
1417 impl<'a> TryTableCatchKind<'a> {
1418 #[allow(missing_docs)]
1419 pub fn tag_index_mut(&mut self) -> Option<&mut Index<'a>> {
1420 match self {
1421 TryTableCatchKind::Catch(tag) | TryTableCatchKind::CatchRef(tag) => Some(tag),
1422 TryTableCatchKind::CatchAll | TryTableCatchKind::CatchAllRef => None,
1423 }
1424 }
1425 }
1426
1427 #[derive(Debug, Clone)]
1428 #[allow(missing_docs)]
1429 pub struct TryTableCatch<'a> {
1430 pub kind: TryTableCatchKind<'a>,
1431 pub label: Index<'a>,
1432 }
1433
1434 /// Extra information associated with the `br_table` instruction.
1435 #[allow(missing_docs)]
1436 #[derive(Debug, Clone)]
1437 pub struct BrTableIndices<'a> {
1438 pub labels: Vec<Index<'a>>,
1439 pub default: Index<'a>,
1440 }
1441
1442 impl<'a> Parse<'a> for BrTableIndices<'a> {
1443 fn parse(parser: Parser<'a>) -> Result<Self> {
1444 let mut labels = vec![parser.parse()?];
1445 while parser.peek::<Index>()? {
1446 labels.push(parser.parse()?);
1447 }
1448 let default = labels.pop().unwrap();
1449 Ok(BrTableIndices { labels, default })
1450 }
1451 }
1452
1453 /// Payload for lane-related instructions. Unsigned with no + prefix.
1454 #[derive(Debug, Clone)]
1455 pub struct LaneArg {
1456 /// The lane argument.
1457 pub lane: u8,
1458 }
1459
1460 impl<'a> Parse<'a> for LaneArg {
1461 fn parse(parser: Parser<'a>) -> Result<Self> {
1462 let lane = parser.step(|c| {
1463 if let Some((i, rest)) = c.integer()? {
1464 if i.sign() == None {
1465 let (src, radix) = i.val();
1466 let val = u8::from_str_radix(src, radix)
1467 .map_err(|_| c.error("malformed lane index"))?;
1468 Ok((val, rest))
1469 } else {
1470 Err(c.error("unexpected token"))
1471 }
1472 } else {
1473 Err(c.error("expected a lane index"))
1474 }
1475 })?;
1476 Ok(LaneArg { lane })
1477 }
1478 }
1479
1480 /// Payload for memory-related instructions indicating offset/alignment of
1481 /// memory accesses.
1482 #[derive(Debug, Clone)]
1483 pub struct MemArg<'a> {
1484 /// The alignment of this access.
1485 ///
1486 /// This is not stored as a log, this is the actual alignment (e.g. 1, 2, 4,
1487 /// 8, etc).
1488 pub align: u32,
1489 /// The offset, in bytes of this access.
1490 pub offset: u64,
1491 /// The memory index we're accessing
1492 pub memory: Index<'a>,
1493 }
1494
1495 impl<'a> MemArg<'a> {
1496 fn parse(parser: Parser<'a>, default_align: u32) -> Result<Self> {
1497 fn parse_field<T>(
1498 name: &str,
1499 parser: Parser<'_>,
1500 f: impl FnOnce(Cursor<'_>, &str, u32) -> Result<T>,
1501 ) -> Result<Option<T>> {
1502 parser.step(|c| {
1503 let (kw, rest) = match c.keyword()? {
1504 Some(p) => p,
1505 None => return Ok((None, c)),
1506 };
1507 if !kw.starts_with(name) {
1508 return Ok((None, c));
1509 }
1510 let kw = &kw[name.len()..];
1511 if !kw.starts_with('=') {
1512 return Ok((None, c));
1513 }
1514 let num = &kw[1..];
1515 let num = if let Some(stripped) = num.strip_prefix("0x") {
1516 f(c, stripped, 16)?
1517 } else {
1518 f(c, num, 10)?
1519 };
1520
1521 Ok((Some(num), rest))
1522 })
1523 }
1524
1525 fn parse_u32(name: &str, parser: Parser<'_>) -> Result<Option<u32>> {
1526 parse_field(name, parser, |c, num, radix| {
1527 u32::from_str_radix(num, radix).map_err(|_| c.error("i32 constant out of range"))
1528 })
1529 }
1530
1531 fn parse_u64(name: &str, parser: Parser<'_>) -> Result<Option<u64>> {
1532 parse_field(name, parser, |c, num, radix| {
1533 u64::from_str_radix(num, radix).map_err(|_| c.error("i64 constant out of range"))
1534 })
1535 }
1536
1537 let memory = parser
1538 .parse::<Option<_>>()?
1539 .unwrap_or_else(|| Index::Num(0, parser.prev_span()));
1540 let offset = parse_u64("offset", parser)?.unwrap_or(0);
1541 let align = match parse_u32("align", parser)? {
1542 Some(n) if !n.is_power_of_two() => {
1543 return Err(parser.error("alignment must be a power of two"))
1544 }
1545 n => n.unwrap_or(default_align),
1546 };
1547
1548 Ok(MemArg {
1549 offset,
1550 align,
1551 memory,
1552 })
1553 }
1554 }
1555
1556 /// Extra data associated with the `loadN_lane` and `storeN_lane` instructions.
1557 #[derive(Debug, Clone)]
1558 pub struct LoadOrStoreLane<'a> {
1559 /// The memory argument for this instruction.
1560 pub memarg: MemArg<'a>,
1561 /// The lane argument for this instruction.
1562 pub lane: LaneArg,
1563 }
1564
1565 impl<'a> LoadOrStoreLane<'a> {
1566 fn parse(parser: Parser<'a>, default_align: u32) -> Result<Self> {
1567 // This is sort of funky. The first integer we see could be the lane
1568 // index, but it could also be the memory index. To determine what it is
1569 // then if we see a second integer we need to look further.
1570 let has_memarg = parser.step(|c| match c.integer()? {
1571 Some((_, after_int)) => {
1572 // Two integers in a row? That means that the first one is the
1573 // memory index and the second must be the lane index.
1574 if after_int.integer()?.is_some() {
1575 return Ok((true, c));
1576 }
1577
1578 // If the first integer is trailed by `offset=...` or
1579 // `align=...` then this is definitely a memarg.
1580 if let Some((kw, _)) = after_int.keyword()? {
1581 if kw.starts_with("offset=") || kw.starts_with("align=") {
1582 return Ok((true, c));
1583 }
1584 }
1585
1586 // Otherwise the first integer was trailed by something that
1587 // didn't look like a memarg, so this must be the lane index.
1588 Ok((false, c))
1589 }
1590
1591 // Not an integer here? That must mean that this must be the memarg
1592 // first followed by the trailing index.
1593 None => Ok((true, c)),
1594 })?;
1595 Ok(LoadOrStoreLane {
1596 memarg: if has_memarg {
1597 MemArg::parse(parser, default_align)?
1598 } else {
1599 MemArg {
1600 align: default_align,
1601 offset: 0,
1602 memory: Index::Num(0, parser.prev_span()),
1603 }
1604 },
1605 lane: LaneArg::parse(parser)?,
1606 })
1607 }
1608 }
1609
1610 /// Extra data associated with the `call_indirect` instruction.
1611 #[derive(Debug, Clone)]
1612 pub struct CallIndirect<'a> {
1613 /// The table that this call is going to be indexing.
1614 pub table: Index<'a>,
1615 /// Type type signature that this `call_indirect` instruction is using.
1616 pub ty: TypeUse<'a, FunctionType<'a>>,
1617 }
1618
1619 impl<'a> Parse<'a> for CallIndirect<'a> {
1620 fn parse(parser: Parser<'a>) -> Result<Self> {
1621 let prev_span = parser.prev_span();
1622 let table: Option<_> = parser.parse()?;
1623 let ty = parser.parse::<TypeUse<'a, FunctionTypeNoNames<'a>>>()?;
1624 Ok(CallIndirect {
1625 table: table.unwrap_or(Index::Num(0, prev_span)),
1626 ty: ty.into(),
1627 })
1628 }
1629 }
1630
1631 /// Extra data associated with the `table.init` instruction
1632 #[derive(Debug, Clone)]
1633 pub struct TableInit<'a> {
1634 /// The index of the table we're copying into.
1635 pub table: Index<'a>,
1636 /// The index of the element segment we're copying into a table.
1637 pub elem: Index<'a>,
1638 }
1639
1640 impl<'a> Parse<'a> for TableInit<'a> {
1641 fn parse(parser: Parser<'a>) -> Result<Self> {
1642 let prev_span = parser.prev_span();
1643 let (elem, table) = if parser.peek2::<Index>()? {
1644 let table = parser.parse()?;
1645 (parser.parse()?, table)
1646 } else {
1647 (parser.parse()?, Index::Num(0, prev_span))
1648 };
1649 Ok(TableInit { table, elem })
1650 }
1651 }
1652
1653 /// Extra data associated with the `table.copy` instruction.
1654 #[derive(Debug, Clone)]
1655 pub struct TableCopy<'a> {
1656 /// The index of the destination table to copy into.
1657 pub dst: Index<'a>,
1658 /// The index of the source table to copy from.
1659 pub src: Index<'a>,
1660 }
1661
1662 impl<'a> Parse<'a> for TableCopy<'a> {
1663 fn parse(parser: Parser<'a>) -> Result<Self> {
1664 let (dst, src) = match parser.parse::<Option<_>>()? {
1665 Some(dst) => (dst, parser.parse()?),
1666 None => (
1667 Index::Num(0, parser.prev_span()),
1668 Index::Num(0, parser.prev_span()),
1669 ),
1670 };
1671 Ok(TableCopy { dst, src })
1672 }
1673 }
1674
1675 /// Extra data associated with unary table instructions.
1676 #[derive(Debug, Clone)]
1677 pub struct TableArg<'a> {
1678 /// The index of the table argument.
1679 pub dst: Index<'a>,
1680 }
1681
1682 // `TableArg` could be an unwrapped as an `Index` if not for this custom parse
1683 // behavior: if we cannot parse a table index, we default to table `0`.
1684 impl<'a> Parse<'a> for TableArg<'a> {
1685 fn parse(parser: Parser<'a>) -> Result<Self> {
1686 let dst = if let Some(dst) = parser.parse()? {
1687 dst
1688 } else {
1689 Index::Num(0, parser.prev_span())
1690 };
1691 Ok(TableArg { dst })
1692 }
1693 }
1694
1695 /// Extra data associated with unary memory instructions.
1696 #[derive(Debug, Clone)]
1697 pub struct MemoryArg<'a> {
1698 /// The index of the memory space.
1699 pub mem: Index<'a>,
1700 }
1701
1702 impl<'a> Parse<'a> for MemoryArg<'a> {
1703 fn parse(parser: Parser<'a>) -> Result<Self> {
1704 let mem = if let Some(mem) = parser.parse()? {
1705 mem
1706 } else {
1707 Index::Num(0, parser.prev_span())
1708 };
1709 Ok(MemoryArg { mem })
1710 }
1711 }
1712
1713 /// Extra data associated with the `memory.init` instruction
1714 #[derive(Debug, Clone)]
1715 pub struct MemoryInit<'a> {
1716 /// The index of the data segment we're copying into memory.
1717 pub data: Index<'a>,
1718 /// The index of the memory we're copying into,
1719 pub mem: Index<'a>,
1720 }
1721
1722 impl<'a> Parse<'a> for MemoryInit<'a> {
1723 fn parse(parser: Parser<'a>) -> Result<Self> {
1724 let prev_span = parser.prev_span();
1725 let (data, mem) = if parser.peek2::<Index>()? {
1726 let memory = parser.parse()?;
1727 (parser.parse()?, memory)
1728 } else {
1729 (parser.parse()?, Index::Num(0, prev_span))
1730 };
1731 Ok(MemoryInit { data, mem })
1732 }
1733 }
1734
1735 /// Extra data associated with the `memory.copy` instruction
1736 #[derive(Debug, Clone)]
1737 pub struct MemoryCopy<'a> {
1738 /// The index of the memory we're copying from.
1739 pub src: Index<'a>,
1740 /// The index of the memory we're copying to.
1741 pub dst: Index<'a>,
1742 }
1743
1744 impl<'a> Parse<'a> for MemoryCopy<'a> {
1745 fn parse(parser: Parser<'a>) -> Result<Self> {
1746 let (src, dst) = match parser.parse()? {
1747 Some(dst) => (parser.parse()?, dst),
1748 None => (
1749 Index::Num(0, parser.prev_span()),
1750 Index::Num(0, parser.prev_span()),
1751 ),
1752 };
1753 Ok(MemoryCopy { src, dst })
1754 }
1755 }
1756
1757 /// Extra data associated with the `struct.get/set` instructions
1758 #[derive(Debug, Clone)]
1759 pub struct StructAccess<'a> {
1760 /// The index of the struct type we're accessing.
1761 pub r#struct: Index<'a>,
1762 /// The index of the field of the struct we're accessing
1763 pub field: Index<'a>,
1764 }
1765
1766 impl<'a> Parse<'a> for StructAccess<'a> {
1767 fn parse(parser: Parser<'a>) -> Result<Self> {
1768 Ok(StructAccess {
1769 r#struct: parser.parse()?,
1770 field: parser.parse()?,
1771 })
1772 }
1773 }
1774
1775 /// Extra data associated with the `array.fill` instruction
1776 #[derive(Debug, Clone)]
1777 pub struct ArrayFill<'a> {
1778 /// The index of the array type we're filling.
1779 pub array: Index<'a>,
1780 }
1781
1782 impl<'a> Parse<'a> for ArrayFill<'a> {
1783 fn parse(parser: Parser<'a>) -> Result<Self> {
1784 Ok(ArrayFill {
1785 array: parser.parse()?,
1786 })
1787 }
1788 }
1789
1790 /// Extra data associated with the `array.copy` instruction
1791 #[derive(Debug, Clone)]
1792 pub struct ArrayCopy<'a> {
1793 /// The index of the array type we're copying to.
1794 pub dest_array: Index<'a>,
1795 /// The index of the array type we're copying from.
1796 pub src_array: Index<'a>,
1797 }
1798
1799 impl<'a> Parse<'a> for ArrayCopy<'a> {
1800 fn parse(parser: Parser<'a>) -> Result<Self> {
1801 Ok(ArrayCopy {
1802 dest_array: parser.parse()?,
1803 src_array: parser.parse()?,
1804 })
1805 }
1806 }
1807
1808 /// Extra data associated with the `array.init_[data/elem]` instruction
1809 #[derive(Debug, Clone)]
1810 pub struct ArrayInit<'a> {
1811 /// The index of the array type we're initializing.
1812 pub array: Index<'a>,
1813 /// The index of the data or elem segment we're reading from.
1814 pub segment: Index<'a>,
1815 }
1816
1817 impl<'a> Parse<'a> for ArrayInit<'a> {
1818 fn parse(parser: Parser<'a>) -> Result<Self> {
1819 Ok(ArrayInit {
1820 array: parser.parse()?,
1821 segment: parser.parse()?,
1822 })
1823 }
1824 }
1825
1826 /// Extra data associated with the `array.new_fixed` instruction
1827 #[derive(Debug, Clone)]
1828 pub struct ArrayNewFixed<'a> {
1829 /// The index of the array type we're accessing.
1830 pub array: Index<'a>,
1831 /// The amount of values to initialize the array with.
1832 pub length: u32,
1833 }
1834
1835 impl<'a> Parse<'a> for ArrayNewFixed<'a> {
1836 fn parse(parser: Parser<'a>) -> Result<Self> {
1837 Ok(ArrayNewFixed {
1838 array: parser.parse()?,
1839 length: parser.parse()?,
1840 })
1841 }
1842 }
1843
1844 /// Extra data associated with the `array.new_data` instruction
1845 #[derive(Debug, Clone)]
1846 pub struct ArrayNewData<'a> {
1847 /// The index of the array type we're accessing.
1848 pub array: Index<'a>,
1849 /// The data segment to initialize from.
1850 pub data_idx: Index<'a>,
1851 }
1852
1853 impl<'a> Parse<'a> for ArrayNewData<'a> {
1854 fn parse(parser: Parser<'a>) -> Result<Self> {
1855 Ok(ArrayNewData {
1856 array: parser.parse()?,
1857 data_idx: parser.parse()?,
1858 })
1859 }
1860 }
1861
1862 /// Extra data associated with the `array.new_elem` instruction
1863 #[derive(Debug, Clone)]
1864 pub struct ArrayNewElem<'a> {
1865 /// The index of the array type we're accessing.
1866 pub array: Index<'a>,
1867 /// The elem segment to initialize from.
1868 pub elem_idx: Index<'a>,
1869 }
1870
1871 impl<'a> Parse<'a> for ArrayNewElem<'a> {
1872 fn parse(parser: Parser<'a>) -> Result<Self> {
1873 Ok(ArrayNewElem {
1874 array: parser.parse()?,
1875 elem_idx: parser.parse()?,
1876 })
1877 }
1878 }
1879
1880 /// Extra data associated with the `ref.cast` instruction
1881 #[derive(Debug, Clone)]
1882 pub struct RefCast<'a> {
1883 /// The type to cast to.
1884 pub r#type: RefType<'a>,
1885 }
1886
1887 impl<'a> Parse<'a> for RefCast<'a> {
1888 fn parse(parser: Parser<'a>) -> Result<Self> {
1889 Ok(RefCast {
1890 r#type: parser.parse()?,
1891 })
1892 }
1893 }
1894
1895 /// Extra data associated with the `ref.test` instruction
1896 #[derive(Debug, Clone)]
1897 pub struct RefTest<'a> {
1898 /// The type to test for.
1899 pub r#type: RefType<'a>,
1900 }
1901
1902 impl<'a> Parse<'a> for RefTest<'a> {
1903 fn parse(parser: Parser<'a>) -> Result<Self> {
1904 Ok(RefTest {
1905 r#type: parser.parse()?,
1906 })
1907 }
1908 }
1909
1910 /// Extra data associated with the `br_on_cast` instruction
1911 #[derive(Debug, Clone)]
1912 pub struct BrOnCast<'a> {
1913 /// The label to branch to.
1914 pub label: Index<'a>,
1915 /// The type we're casting from.
1916 pub from_type: RefType<'a>,
1917 /// The type we're casting to.
1918 pub to_type: RefType<'a>,
1919 }
1920
1921 impl<'a> Parse<'a> for BrOnCast<'a> {
1922 fn parse(parser: Parser<'a>) -> Result<Self> {
1923 Ok(BrOnCast {
1924 label: parser.parse()?,
1925 from_type: parser.parse()?,
1926 to_type: parser.parse()?,
1927 })
1928 }
1929 }
1930
1931 /// Extra data associated with the `br_on_cast_fail` instruction
1932 #[derive(Debug, Clone)]
1933 pub struct BrOnCastFail<'a> {
1934 /// The label to branch to.
1935 pub label: Index<'a>,
1936 /// The type we're casting from.
1937 pub from_type: RefType<'a>,
1938 /// The type we're casting to.
1939 pub to_type: RefType<'a>,
1940 }
1941
1942 impl<'a> Parse<'a> for BrOnCastFail<'a> {
1943 fn parse(parser: Parser<'a>) -> Result<Self> {
1944 Ok(BrOnCastFail {
1945 label: parser.parse()?,
1946 from_type: parser.parse()?,
1947 to_type: parser.parse()?,
1948 })
1949 }
1950 }
1951
1952 /// The memory ordering for atomic instructions.
1953 ///
1954 /// For an in-depth explanation of memory orderings, see the C++ documentation
1955 /// for [`memory_order`] or the Rust documentation for [`atomic::Ordering`].
1956 ///
1957 /// [`memory_order`]: https://en.cppreference.com/w/cpp/atomic/memory_order
1958 /// [`atomic::Ordering`]: https://doc.rust-lang.org/std/sync/atomic/enum.Ordering.html
1959 #[derive(Clone, Debug)]
1960 pub enum Ordering {
1961 /// Like `AcqRel` but all threads see all sequentially consistent operations
1962 /// in the same order.
1963 AcqRel,
1964 /// For a load, it acquires; this orders all operations before the last
1965 /// "releasing" store. For a store, it releases; this orders all operations
1966 /// before it at the next "acquiring" load.
1967 SeqCst,
1968 }
1969
1970 impl<'a> Parse<'a> for Ordering {
1971 fn parse(parser: Parser<'a>) -> Result<Self> {
1972 if parser.peek::<kw::seq_cst>()? {
1973 parser.parse::<kw::seq_cst>()?;
1974 Ok(Ordering::SeqCst)
1975 } else if parser.peek::<kw::acq_rel>()? {
1976 parser.parse::<kw::acq_rel>()?;
1977 Ok(Ordering::AcqRel)
1978 } else {
1979 Err(parser.error("expected a memory ordering: `seq_cst` or `acq_rel`"))
1980 }
1981 }
1982 }
1983
1984 /// Add a memory [`Ordering`] to the argument `T` of some instruction.
1985 ///
1986 /// This is helpful for many kinds of `*.atomic.*` instructions introduced by
1987 /// the shared-everything-threads proposal. Many of these instructions "build
1988 /// on" existing instructions by simply adding a memory order to them.
1989 #[derive(Clone, Debug)]
1990 pub struct Ordered<T> {
1991 /// The memory ordering for this atomic instruction.
1992 pub ordering: Ordering,
1993 /// The original argument type.
1994 pub inner: T,
1995 }
1996
1997 impl<'a, T> Parse<'a> for Ordered<T>
1998 where
1999 T: Parse<'a>,
2000 {
2001 fn parse(parser: Parser<'a>) -> Result<Self> {
2002 let ordering = parser.parse()?;
2003 let inner = parser.parse()?;
2004 Ok(Ordered { ordering, inner })
2005 }
2006 }
2007
2008 /// Different ways to specify a `v128.const` instruction
2009 #[derive(Clone, Debug)]
2010 #[allow(missing_docs)]
2011 pub enum V128Const {
2012 I8x16([i8; 16]),
2013 I16x8([i16; 8]),
2014 I32x4([i32; 4]),
2015 I64x2([i64; 2]),
2016 F32x4([F32; 4]),
2017 F64x2([F64; 2]),
2018 }
2019
2020 impl V128Const {
2021 /// Returns the raw little-ended byte sequence used to represent this
2022 /// `v128` constant`
2023 ///
2024 /// This is typically suitable for encoding as the payload of the
2025 /// `v128.const` instruction.
2026 #[rustfmt::skip]
2027 pub fn to_le_bytes(&self) -> [u8; 16] {
2028 match self {
2029 V128Const::I8x16(arr) => [
2030 arr[0] as u8,
2031 arr[1] as u8,
2032 arr[2] as u8,
2033 arr[3] as u8,
2034 arr[4] as u8,
2035 arr[5] as u8,
2036 arr[6] as u8,
2037 arr[7] as u8,
2038 arr[8] as u8,
2039 arr[9] as u8,
2040 arr[10] as u8,
2041 arr[11] as u8,
2042 arr[12] as u8,
2043 arr[13] as u8,
2044 arr[14] as u8,
2045 arr[15] as u8,
2046 ],
2047 V128Const::I16x8(arr) => {
2048 let a1 = arr[0].to_le_bytes();
2049 let a2 = arr[1].to_le_bytes();
2050 let a3 = arr[2].to_le_bytes();
2051 let a4 = arr[3].to_le_bytes();
2052 let a5 = arr[4].to_le_bytes();
2053 let a6 = arr[5].to_le_bytes();
2054 let a7 = arr[6].to_le_bytes();
2055 let a8 = arr[7].to_le_bytes();
2056 [
2057 a1[0], a1[1],
2058 a2[0], a2[1],
2059 a3[0], a3[1],
2060 a4[0], a4[1],
2061 a5[0], a5[1],
2062 a6[0], a6[1],
2063 a7[0], a7[1],
2064 a8[0], a8[1],
2065 ]
2066 }
2067 V128Const::I32x4(arr) => {
2068 let a1 = arr[0].to_le_bytes();
2069 let a2 = arr[1].to_le_bytes();
2070 let a3 = arr[2].to_le_bytes();
2071 let a4 = arr[3].to_le_bytes();
2072 [
2073 a1[0], a1[1], a1[2], a1[3],
2074 a2[0], a2[1], a2[2], a2[3],
2075 a3[0], a3[1], a3[2], a3[3],
2076 a4[0], a4[1], a4[2], a4[3],
2077 ]
2078 }
2079 V128Const::I64x2(arr) => {
2080 let a1 = arr[0].to_le_bytes();
2081 let a2 = arr[1].to_le_bytes();
2082 [
2083 a1[0], a1[1], a1[2], a1[3], a1[4], a1[5], a1[6], a1[7],
2084 a2[0], a2[1], a2[2], a2[3], a2[4], a2[5], a2[6], a2[7],
2085 ]
2086 }
2087 V128Const::F32x4(arr) => {
2088 let a1 = arr[0].bits.to_le_bytes();
2089 let a2 = arr[1].bits.to_le_bytes();
2090 let a3 = arr[2].bits.to_le_bytes();
2091 let a4 = arr[3].bits.to_le_bytes();
2092 [
2093 a1[0], a1[1], a1[2], a1[3],
2094 a2[0], a2[1], a2[2], a2[3],
2095 a3[0], a3[1], a3[2], a3[3],
2096 a4[0], a4[1], a4[2], a4[3],
2097 ]
2098 }
2099 V128Const::F64x2(arr) => {
2100 let a1 = arr[0].bits.to_le_bytes();
2101 let a2 = arr[1].bits.to_le_bytes();
2102 [
2103 a1[0], a1[1], a1[2], a1[3], a1[4], a1[5], a1[6], a1[7],
2104 a2[0], a2[1], a2[2], a2[3], a2[4], a2[5], a2[6], a2[7],
2105 ]
2106 }
2107 }
2108 }
2109 }
2110
2111 impl<'a> Parse<'a> for V128Const {
2112 fn parse(parser: Parser<'a>) -> Result<Self> {
2113 let mut l = parser.lookahead1();
2114 if l.peek::<kw::i8x16>()? {
2115 parser.parse::<kw::i8x16>()?;
2116 Ok(V128Const::I8x16([
2117 parser.parse()?,
2118 parser.parse()?,
2119 parser.parse()?,
2120 parser.parse()?,
2121 parser.parse()?,
2122 parser.parse()?,
2123 parser.parse()?,
2124 parser.parse()?,
2125 parser.parse()?,
2126 parser.parse()?,
2127 parser.parse()?,
2128 parser.parse()?,
2129 parser.parse()?,
2130 parser.parse()?,
2131 parser.parse()?,
2132 parser.parse()?,
2133 ]))
2134 } else if l.peek::<kw::i16x8>()? {
2135 parser.parse::<kw::i16x8>()?;
2136 Ok(V128Const::I16x8([
2137 parser.parse()?,
2138 parser.parse()?,
2139 parser.parse()?,
2140 parser.parse()?,
2141 parser.parse()?,
2142 parser.parse()?,
2143 parser.parse()?,
2144 parser.parse()?,
2145 ]))
2146 } else if l.peek::<kw::i32x4>()? {
2147 parser.parse::<kw::i32x4>()?;
2148 Ok(V128Const::I32x4([
2149 parser.parse()?,
2150 parser.parse()?,
2151 parser.parse()?,
2152 parser.parse()?,
2153 ]))
2154 } else if l.peek::<kw::i64x2>()? {
2155 parser.parse::<kw::i64x2>()?;
2156 Ok(V128Const::I64x2([parser.parse()?, parser.parse()?]))
2157 } else if l.peek::<kw::f32x4>()? {
2158 parser.parse::<kw::f32x4>()?;
2159 Ok(V128Const::F32x4([
2160 parser.parse()?,
2161 parser.parse()?,
2162 parser.parse()?,
2163 parser.parse()?,
2164 ]))
2165 } else if l.peek::<kw::f64x2>()? {
2166 parser.parse::<kw::f64x2>()?;
2167 Ok(V128Const::F64x2([parser.parse()?, parser.parse()?]))
2168 } else {
2169 Err(l.error())
2170 }
2171 }
2172 }
2173
2174 /// Lanes being shuffled in the `i8x16.shuffle` instruction
2175 #[derive(Debug, Clone)]
2176 pub struct I8x16Shuffle {
2177 #[allow(missing_docs)]
2178 pub lanes: [u8; 16],
2179 }
2180
2181 impl<'a> Parse<'a> for I8x16Shuffle {
2182 fn parse(parser: Parser<'a>) -> Result<Self> {
2183 Ok(I8x16Shuffle {
2184 lanes: [
2185 parser.parse()?,
2186 parser.parse()?,
2187 parser.parse()?,
2188 parser.parse()?,
2189 parser.parse()?,
2190 parser.parse()?,
2191 parser.parse()?,
2192 parser.parse()?,
2193 parser.parse()?,
2194 parser.parse()?,
2195 parser.parse()?,
2196 parser.parse()?,
2197 parser.parse()?,
2198 parser.parse()?,
2199 parser.parse()?,
2200 parser.parse()?,
2201 ],
2202 })
2203 }
2204 }
2205
2206 /// Payload of the `select` instructions
2207 #[derive(Debug, Clone)]
2208 pub struct SelectTypes<'a> {
2209 #[allow(missing_docs)]
2210 pub tys: Option<Vec<ValType<'a>>>,
2211 }
2212
2213 impl<'a> Parse<'a> for SelectTypes<'a> {
2214 fn parse(parser: Parser<'a>) -> Result<Self> {
2215 let mut found = false;
2216 let mut list = Vec::new();
2217 while parser.peek2::<kw::result>()? {
2218 found = true;
2219 parser.parens(|p| {
2220 p.parse::<kw::result>()?;
2221 while !p.is_empty() {
2222 list.push(p.parse()?);
2223 }
2224 Ok(())
2225 })?;
2226 }
2227 Ok(SelectTypes {
2228 tys: if found { Some(list) } else { None },
2229 })
2230 }
2231 }