wasm_wat_instr (wasm v0.1.0)
View SourceWhat immediate an instruction takes, by name. Add a text-format instruction here if, and only if, it carries an immediate.
There are around four hundred instructions and only about seventy carry an
immediate, so this table holds those seventy and nothing else. Everything absent
from it is a plain instruction whose atom is its name with the dots replaced:
i32.add is i32_add, i64.trunc_sat_f32_u is i64_trunc_sat_f32_u.
That is not a shortcut around knowing the instruction set. The validator is
already the authority on which atoms are instructions and answers
unknown_operator for the rest, so a parser that also kept a list of the four
hundred would be a second copy to disagree with the first. What the parser has
to know, and the validator cannot tell it, is how many tokens to consume.
The memory instructions are recognised by asking the tables the validator and the interpreter already share, so a memory argument is never a name this module has to keep in step by hand.
Summary
Functions
The atom an instruction name denotes: the name with its dots replaced.
The immediate an instruction takes, or plain if it takes none.
Functions
The atom an instruction name denotes: the name with its dots replaced.
i32.add is i32_add and i64.atomic.rmw8.add_u is i64_atomic_rmw8_add_u.
Existing atoms only: a name that denotes no instruction stays a binary and is
reported where it is used, rather than adding an atom the module chose. The
atom table is node-wide and never reclaimed, so a module that could create
atoms is a permanent resource leak.
The immediate an instruction takes, or plain if it takes none.
| answer | means |
|---|---|
plain | no immediate |
{const, Type} | a numeric literal |
{idx, Space} | one index, named or numeric |
{idx_opt, Space} | one index that defaults to 0 when absent |
{idx2, A, B} | two indices, both required |
{copy2, Space} | two indices that default to 0 and 0 together |
{init2, Space, Segment} | an optional space index then a segment index |
{memarg, Natural} | offset= and align=, both optional |
{memarg_lane, Natural, Count} | a memory argument and a lane index |
{lane, Count} | a lane index |
block | a block type and a body |
call_indirect | an optional table index and a type use |
br_table | a vector of labels and a default |
select | an optional result type |
heaptype / reftype | for ref.null and the casts |
br_on_cast | a label and two reference types |
shuffle | sixteen lane indices |
v128const | a shape and its lanes |
Natural is the alignment a missing align= means, in log2 bytes. It comes
from the validator's own tables, which is why the text format cannot drift from
what validation then checks the number against.