WebAssembly text format

ID: webassembly-text-format

The WebAssembly text format is the readable textual encoding of WebAssembly modules. Parenthesized declarations describe the same structured program that can be encoded in binary. Symbolic identifiers such as $add help readers refer to definitions; numeric indices determine references in the underlying module.[ref]
For example, (module (func (export "add") (param i32 i32) (result i32) local.get 0 local.get 1 i32.add)) declares and exports a function accepting two 32-bit integers. The local.get instructions push its arguments onto the operand stack; i32.add consumes them and produces the result. Inputs 3 and 4 give 7. The folded instruction (i32.add (local.get 0) (local.get 1)) is an alternative notation for the same instruction sequence.[ref]
The parentheses of a folded instruction make operand grouping visible, but do not introduce a different arithmetic operation. Decoding either spelling yields the same instruction structure. Textual readability and runtime behavior are separate: indentation can help a human follow the WebAssembly module, while the declared types and instruction order govern execution.

New to topics? Read the docs here!