From 1b06ff98d6c91b737a387ca50dd4387405b83c25 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Fri, 10 Feb 2017 12:46:09 -0600 Subject: [PATCH 1/4] Make Names section extensible --- BinaryEncoding.md | 62 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/BinaryEncoding.md b/BinaryEncoding.md index b1412f64..b7efa40d 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -436,34 +436,62 @@ The expectation is that, when a binary WebAssembly module is viewed in a browser environment, the data in this section will be used as the names of functions and locals in the [text format](TextFormat.md). +The name section contains a sequence of name subsections: + | Field | Type | Description | | ----- | ---- | ----------- | -| count | `varuint32` | count of entries to follow | -| entries | `function_names*` | sequence of names | +| name_type | `varuint7` | code identifying type of name contained in this subsection | +| name_payload_len | `varuint32` | size of this subsection in bytes | +| name_payload_data | `bytes` | content of this section, of length `name_payload_len` | + +Since name subsections have a given length, unknown or unwanted names can be +skipped over by an engine. The current list of valid `name_type` codes are: + +| Name Type | Code | Description | +| --------- | ---- | ----------- | +| [Function](#function-names) | `1` | Assigns names to functions | +| [Local](#local-names) | `2` | Assigns names to locals in functions | + +When present, name subsections must appear in this order and at most once. The +end of the last subsection must coincide with the last byte of the name +section to be a well-formed name section. + +#### Name List + +In any of the subsequent subsections, a `name_list` is encoded as: -The sequence of `function_names` assigns names to the corresponding -[function index](Modules.md#function-index-space). (Note: this assigns names to both -imported and module-defined functions.) The count may differ from the actual number of functions. +| Name Type | Type | Description | +| --------- | ---- | ----------- | +| count | `varuint32` | number of `name` in names | +| names | `name*` | sequence of `name` | + +where a `name` is encoded as: + +| Name Type | Type | Description | +| --------- | ---- | ----------- | +| name_len | `varuint32` | number of bytes in name_str | +| name_str | `bytes` | UTF8 encoding of the name | #### Function names -| Field | Type | Description | -| ----- | ---- | ----------- | -| fun_name_len | `varuint32` | string length, in bytes | -| fun_name_str | `bytes` | valid utf8 encoding | -| local_count | `varuint32` | count of local names to follow | -| local_names | `local_name*` | sequence of local names | +The function names subsection is a `name_list` which assign a name to each +function by [function index](Modules.md#function-index-space). (Note: this +assigns names to both imported and module-defined functions.) The count +may differ from the actual number of functions. -The sequence of `local_name` assigns names to the corresponding local index. The -count may differ from the actual number of locals. +#### Local names -#### Local name +The local names subsection assigns a `name_list` to each function defined inside +the module according to its index in the [Function section](#function-section). +(Note: this does not assign names to imports; imports have no locals.) The +`name_list` for a given function assigns a name to each local. The counts may +differ from both the number of functions and number of locals in a given +function. | Field | Type | Description | | ----- | ---- | ----------- | -| local_name_len | `varuint32` | string length, in bytes | -| local_name_str | `bytes` | valid utf8 encoding | - +| count | `varuint32` | count of `name_list` in func_locals | +| func_locals | `name_list*` | sequence of `name_list`, one per function | # Function Bodies From 05b6581e83673b22c7410a5a3e840964701f9981 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Fri, 10 Feb 2017 18:38:56 -0600 Subject: [PATCH 2/4] Fix typo --- BinaryEncoding.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BinaryEncoding.md b/BinaryEncoding.md index b7efa40d..f576720d 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -444,8 +444,8 @@ The name section contains a sequence of name subsections: | name_payload_len | `varuint32` | size of this subsection in bytes | | name_payload_data | `bytes` | content of this section, of length `name_payload_len` | -Since name subsections have a given length, unknown or unwanted names can be -skipped over by an engine. The current list of valid `name_type` codes are: +Since name subsections have a given length, unknown or unwanted names types can +be skipped over by an engine. The current list of valid `name_type` codes are: | Name Type | Code | Description | | --------- | ---- | ----------- | From 81ea41e280ea5ff6cb0a09e962e332b12b2af45e Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Mon, 13 Feb 2017 15:49:43 -0600 Subject: [PATCH 3/4] Switch name list to name map and drop mention of UTF8 --- BinaryEncoding.md | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/BinaryEncoding.md b/BinaryEncoding.md index f576720d..a11a6e92 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -456,42 +456,47 @@ When present, name subsections must appear in this order and at most once. The end of the last subsection must coincide with the last byte of the name section to be a well-formed name section. -#### Name List +#### Name Map -In any of the subsequent subsections, a `name_list` is encoded as: +In the following subsections, a `name_map` is encoded as: -| Name Type | Type | Description | -| --------- | ---- | ----------- | +| Field | Type | Description | +| ----- | ---- | ----------- | | count | `varuint32` | number of `name` in names | -| names | `name*` | sequence of `name` | +| names | `name*` | sequence of `name` sorted by index | where a `name` is encoded as: -| Name Type | Type | Description | -| --------- | ---- | ----------- | +| Field | Type | Description | +| ----- | ---- | ----------- | +| index | `varuint32` | the index which is being named | | name_len | `varuint32` | number of bytes in name_str | -| name_str | `bytes` | UTF8 encoding of the name | +| name_str | `bytes` | binary encoding of the name | #### Function names -The function names subsection is a `name_list` which assign a name to each -function by [function index](Modules.md#function-index-space). (Note: this -assigns names to both imported and module-defined functions.) The count -may differ from the actual number of functions. +The function names subsection is a `name_map` which assigns names to +a subset of the [function index space](Modules.md#function-index-space) +(both imports and module-defined). #### Local names -The local names subsection assigns a `name_list` to each function defined inside -the module according to its index in the [Function section](#function-section). -(Note: this does not assign names to imports; imports have no locals.) The -`name_list` for a given function assigns a name to each local. The counts may -differ from both the number of functions and number of locals in a given -function. +The local names subsection assigns `name_map`s to a subset of functions in the +[function index space](Modules.md#function-index-space) (both imports and +module-defined). The `name_map` for a given function assigns names to a +subset of local variable indices. + +| Field | Type | Description | +| ----- | ---- | ----------- | +| count | `varuint32` | count of `local_names` in funcs | +| funcs | `local_names*` | sequence of `local_names` sorted by index | + +where a `local_name` is encoded as: | Field | Type | Description | | ----- | ---- | ----------- | -| count | `varuint32` | count of `name_list` in func_locals | -| func_locals | `name_list*` | sequence of `name_list`, one per function | +| index | `varuint32` | the index of the function whose locals are being named | +| local_map | `name_map` | assignment of names to local indices | # Function Bodies From ec29e079975091d9c97ff3fcc846db87504107fa Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Tue, 14 Feb 2017 11:52:53 -0600 Subject: [PATCH 4/4] Change to --- BinaryEncoding.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BinaryEncoding.md b/BinaryEncoding.md index a11a6e92..8327a886 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -462,10 +462,10 @@ In the following subsections, a `name_map` is encoded as: | Field | Type | Description | | ----- | ---- | ----------- | -| count | `varuint32` | number of `name` in names | -| names | `name*` | sequence of `name` sorted by index | +| count | `varuint32` | number of `naming` in names | +| names | `naming*` | sequence of `naming` sorted by index | -where a `name` is encoded as: +where a `naming` is encoded as: | Field | Type | Description | | ----- | ---- | ----------- |