From 5fa18dd0e445d542a0e3c31fd00946e6d40e9825 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Mon, 7 Mar 2016 12:11:39 -0600 Subject: Split Functions section into Function Signatures and Function Bodies --- BinaryEncoding.md | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'BinaryEncoding.md') diff --git a/BinaryEncoding.md b/BinaryEncoding.md index 186b783..68e8ab4 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -145,28 +145,31 @@ 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 Functions 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 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. + +| Field | Type | Description | | ----- | ----- | ----- | ----- | -| flags | `uint8` | always | flags indicating attributes of a function
bit `1` : the function is an import
bit `2` : the function has local variables
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 -- cgit v1.2.3 From 2ead607c0e2298a81dc27d2b04b114242fc48634 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Mon, 7 Mar 2016 12:47:53 -0600 Subject: Remove now-unnecessary signature index from export --- BinaryEncoding.md | 1 - 1 file changed, 1 deletion(-) (limited to 'BinaryEncoding.md') diff --git a/BinaryEncoding.md b/BinaryEncoding.md index 68e8ab4..7752997 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -187,7 +187,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 | -- cgit v1.2.3 From 29c4de983a67be2dd9a2d8985cb39d122501d71b Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Mon, 7 Mar 2016 12:58:53 -0600 Subject: Address comments --- BinaryEncoding.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'BinaryEncoding.md') diff --git a/BinaryEncoding.md b/BinaryEncoding.md index 7752997..e37bb4a 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -149,9 +149,9 @@ A module may contain at most one import table section. ID: `function_signatures` -The Functions Signatures section declares the signatures of all functions in the +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 section. +module may contain at most one functions signatures section. | Field | Type | Description | | ----- | ----- | ----- | @@ -164,7 +164,8 @@ ID: `function_bodies` 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. +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 | | ----- | ----- | ----- | ----- | -- cgit v1.2.3 From f0ab07c4d53932fc4e812b2d43d1eeac37b1acd4 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Mon, 7 Mar 2016 16:47:32 -0600 Subject: Add back function body size --- BinaryEncoding.md | 1 + 1 file changed, 1 insertion(+) (limited to 'BinaryEncoding.md') diff --git a/BinaryEncoding.md b/BinaryEncoding.md index e37bb4a..7237d44 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -303,6 +303,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 | -- cgit v1.2.3 From b3f5fb96debb55cd6e978421cde63585a38a303d Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Mon, 7 Mar 2016 20:03:23 -0600 Subject: Update references to Function section to Function Signatures section --- BinaryEncoding.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'BinaryEncoding.md') diff --git a/BinaryEncoding.md b/BinaryEncoding.md index 7237d44..6a104a6 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -178,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 | | ----- | ----- | ----- | @@ -197,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 | | ----- | ----- | ----- | @@ -228,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 | | ----- | ----- | ----- | -- cgit v1.2.3