diff options
| author | titzer <titzer@google.com> | 2016-03-02 13:29:01 -0800 |
|---|---|---|
| committer | titzer <titzer@google.com> | 2016-03-02 13:29:01 -0800 |
| commit | 8fe466975b514feffacffe2df52e3cfc2817895e (patch) | |
| tree | 3d8488a856906d154a4be04bef10e3a965b642cf /BinaryEncoding.md | |
| parent | e8f8df239a748a5bb7f9dc50cd788fc52d1e98fe (diff) | |
| parent | cfae7ce7c0b8788776d19f73225c595681d4e0c4 (diff) | |
| download | nanowasm-design-8fe466975b514feffacffe2df52e3cfc2817895e.tar.gz | |
Merge pull request #572 from WebAssembly/locals_to_func_body
Move local entries to be part of the function body.
Diffstat (limited to 'BinaryEncoding.md')
| -rw-r--r-- | BinaryEncoding.md | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/BinaryEncoding.md b/BinaryEncoding.md index a91dd58..1452887 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -168,21 +168,9 @@ must contain a function body. Imported and exported functions must have a name. | flags | `uint8` | always | flags indicating attributes of a function <br>bit `0` : a name is present<br>bit `1` : the function is an import<br>bit `2` : the function has local variables<br>bit `3` : the function is an export | | signature | `uint16` | always | index into the Signature section | | name | `uint32` | `flags[0] == 1` | name of the function as an offset within the module | -| local count | `varuint32` | always | number of local entries | -| locals | `local_entry*` | always | local variables | | body size | `uint16` | `flags[0] == 0` | size of function body to follow, in bytes | | body | `bytes` | `flags[0] == 0` | function body | -#### Local Entry - -Each local entry declares a number of local variables of a given type. -It is legal to have several entries with the same type. - -| Field | Type | Description | -| ----- | ----- | ----- | -| count | `varuint32` | number of local variables of the following type | -| type | `value_type` | type of the variables | - ### Export Table section ID: `export_table` @@ -287,13 +275,31 @@ stored to from dedicated instructions. Sections whose ID is unknown to the WebAssembly implementation are ignored. -# AST Encoding +# Function Bodies -Function bodies consist of a dense pre-order encoding of an [Abstract Syntax Tree](AstSemantics.md). +Function bodies consist of a sequence of local variable declarations followed by a +dense pre-order encoding of an [Abstract Syntax Tree](AstSemantics.md). Each node in the abstract syntax tree corresponds to an operator, such as `i32.add` or `if` or `block`. Operators are encoding by an opcode byte followed by immediate bytes (if any), followed by children nodes (if any). +| Name | Opcode |Description | +| ----- | ----- | ----- | +| local count | `varuint32` | number of local entries | +| locals | `local_entry*` | local variables | +| ast | `byte*` | pre-order encoded AST | + +#### Local Entry + +Each local entry declares a number of local variables of a given type. +It is legal to have several entries with the same type. + +| Field | Type | Description | +| ----- | ----- | ----- | +| count | `varuint32` | number of local variables of the following type | +| type | `value_type` | type of the variables | + + ## Control flow operators ([described here](AstSemantics.md#control-flow-structures)) | Name | Opcode | Immediate | Description | |
