wasm_encode_code (wasm v0.16.0)
View SourceInstruction and expression encoding: wasm_decode_code run backwards.
Read this before you add an opcode: an instruction the decoder reads must be
written here too, and wasm_encode_SUITE fails for every decoded opcode this
cannot write back to the same bytes. The prefixed spaces have modules of their
own, as in the decoder: wasm_encode_simd for 0xFD, wasm_encode_gc for
0xFB and wasm_encode_atomic for 0xFE. 0xFC is small and stays here.
Each instruction is one clause, the opcode byte first, so the table reads
against the decoder's line for line. Nested bodies are written in place and
closed with end (0x0B); an if writes else (0x05) only when its else
branch has instructions, because the decoder reads if ... end and
if ... else end the same. A memory argument names its memory only when it
is not memory 0, for the same reason.
Summary
Functions
A block signature: empty, one value type, or a type index.
An expression: its instructions, then end.
One instruction, as the decoder gives it.
A memory argument. Bit 6 of the alignment field says a memory index follows, so it is set only for a memory other than 0.
Types
-type heaptype() :: func | extern | exn | any | eq | i31 | struct | array | nofunc | noextern | noexn | none | {type, typeidx()}.
-type memarg() :: {Align :: non_neg_integer(), Offset :: non_neg_integer(), Mem :: memidx()}.
-type memidx() :: non_neg_integer().
-type numtype() :: i32 | i64 | f32 | f64.
-type reftype() :: {ref, null | nonull, heaptype()}.
-type typeidx() :: non_neg_integer().
-type vectype() :: v128.
Functions
A block signature: empty, one value type, or a type index.
An expression: its instructions, then end.
One instruction, as the decoder gives it.
A memory argument. Bit 6 of the alignment field says a memory index follows, so it is set only for a memory other than 0.