wasm_decode_code (wasm v0.1.0)
View SourceInstruction and expression decoding.
Read this before you add an opcode. Block bodies nest directly rather than being flattened with end markers.
WebAssembly control flow is structured, so nesting is lossless, and it lets
wasm_ir build continuation lists without a separate label-resolution pass.
A flat stream would have to be re-scanned to pair every block with its
end anyway.
The opcode dispatch is a dense integer match, which the BEAM compiler turns into a jump table. Writing one clause per opcode is verbose but it is the shape the compiler optimises best, and it keeps each opcode's immediate operands visible at the point of decoding.
Summary
Functions
Block signature. Value types are encoded as negative s33 values, type indices as non-negative ones, so a single signed read distinguishes them.
Decode an expression: instructions up to and including the end byte.
Types
-type heaptype() :: func | extern | exn | any | eq | i31 | struct | array | nofunc | noextern | noexn | none | {type, typeidx()}.
-type numtype() :: i32 | i64 | f32 | f64.
-type reftype() :: {ref, null | nonull, heaptype()}.
-type typeidx() :: non_neg_integer().
-type vectype() :: v128.
Functions
Block signature. Value types are encoded as negative s33 values, type indices as non-negative ones, so a single signed read distinguishes them.
Decode an expression: instructions up to and including the end byte.