aboutsummaryrefslogtreecommitdiff
path: root/BinaryEncoding.md
diff options
context:
space:
mode:
authorLuke Wagner <mail@lukewagner.name>2016-03-09 13:09:06 -0600
committerLuke Wagner <mail@lukewagner.name>2016-03-09 13:09:06 -0600
commit1df788016ee70b04d14a8d1852343c63a4f877d3 (patch)
tree0f11115cfe62b508077bf70e42ed7fb28c430954 /BinaryEncoding.md
parentd678a1350fc1ce980dc7699264976955d825c8ce (diff)
parentb3f5fb96debb55cd6e978421cde63585a38a303d (diff)
downloadnanowasm-design-1df788016ee70b04d14a8d1852343c63a4f877d3.tar.gz
Merge pull request #591 from WebAssembly/split-functions
Split Functions section into Function Signatures and Function Bodies
Diffstat (limited to 'BinaryEncoding.md')
-rw-r--r--BinaryEncoding.md39
1 files changed, 21 insertions, 18 deletions
diff --git a/BinaryEncoding.md b/BinaryEncoding.md
index 186b783..6a104a6 100644
--- a/BinaryEncoding.md
+++ b/BinaryEncoding.md
@@ -145,28 +145,32 @@ A module may contain at most one import table section.
| function_len | `varuint32` | function string length |
| function_str | `bytes` | function string of `function_len` bytes |
-### Functions section
+### Function Signatures section
-ID: `functions`
+ID: `function_signatures`
-The Functions section declares the functions in the module and must be preceded by a [Signatures](#signatures-section) section. A module may contain at most one functions section.
+The Function Signatures section declares the signatures of all functions in the
+module and must be preceded by the [Signatures](#signatures-section) section. A
+module may contain at most one functions signatures section.
| Field | Type | Description |
| ----- | ----- | ----- |
-| count | `varuint32` | count of function entries to follow |
-| entries | `function_entry*` | repeated function entries as described below |
+| count | `varuint32` | count of signature indices to follow |
+| signatures | `varuint32*` | sequence of indices into the Signature section |
-#### Function Entry
+### Function Bodies section
-Each function entry describes a function that can be optionally named, imported and/or exported. Non-imported functions
-must contain a function body. Imported and exported functions must have a name. Imported functions do not contain a body.
+ID: `function_bodies`
-| Field | Type | Present? | Description |
+The Function Bodies section assigns a body to every function in the module and
+must be preceded by the [Function Signatures](#function-signatures-section) section.
+The count of function signatures and function bodies must be the same and the `i`th
+signature corresponds to the `i`th function body.
+
+| Field | Type | Description |
| ----- | ----- | ----- | ----- |
-| flags | `uint8` | always | flags indicating attributes of a function <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 |
-| body size | `uint16` | `flags[0] == 0` | size of function body to follow, in bytes |
-| body | `bytes` | `flags[0] == 0` | function body |
+| count | `varuint32` | count of function bodies to follow |
+| bodies | `function_body*` | sequence of [Function Bodies](#function-bodies) |
### Export Table section
@@ -174,7 +178,7 @@ ID: `export_table`
The export table section declares all exports from the module.
A module may contain at most one export table section.
-This section must be preceded by a [Functions](#functions-section) section.
+This section must be preceded by the [Function Signatures](#function-signatures-section) section.
| Field | Type | Description |
| ----- | ----- | ----- |
@@ -184,7 +188,6 @@ This section must be preceded by a [Functions](#functions-section) section.
#### Export entry
| Field | Type | Description |
| ----- | ----- | ----- |
-| sig_index | `uint16` | signature index of the export |
| func_index | `uint16` | index into the function table |
| function_len | `varuint32` | function string length |
| function_str | `bytes` | function string of `function_len` bytes |
@@ -194,7 +197,7 @@ This section must be preceded by a [Functions](#functions-section) section.
ID: `start_function`
A module may contain at most one start fuction section.
-This section must be preceded by a [Functions](#functions-section) section.
+This section must be preceded by a [Function Signatures](#function-signatures-section) section.
| Field | Type | Description |
| ----- | ----- | ----- |
@@ -225,8 +228,7 @@ a `data_segment` is:
ID: `function_table`
The indirect function table section declares the size and entries of the indirect function table, which consist
-of indexes into the [Functions](#functions-section) section.
-This section must be preceded by a [Functions](#functions-section) section.
+of indexes into the [Function Signatures](#function-signatures-section) section (which must come before).
| Field | Type | Description |
| ----- | ----- | ----- |
@@ -300,6 +302,7 @@ nodes (if any).
| Name | Opcode |Description |
| ----- | ----- | ----- |
+| body size | `varuint32` | size of function body to follow, in bytes |
| local count | `varuint32` | number of local entries |
| locals | `local_entry*` | local variables |
| ast | `byte*` | pre-order encoded AST |