-
Notifications
You must be signed in to change notification settings - Fork 831
wasm2js: Add Table operations #6650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
854b13e
work
kripken 421f475
work
kripken 45dfb55
work
kripken 0f1d998
work
kripken 6ab13e0
prep
kripken eef7e4b
prep
kripken 0e98b3f
prep
kripken ebc01d4
prep
kripken 709990f
prep
kripken bb61473
prep
kripken 670ee9b
prep
kripken 9ea29ea
work
kripken d92ac97
work
kripken d8f6f81
work
kripken 948803d
work
kripken 468d830
work
kripken 75133c4
fix
kripken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import * as env from 'env'; | ||
|
|
||
|
|
||
| function wasm2js_table_grow(value, delta) { | ||
| // TODO: traps on invalid things | ||
| var oldSize = FUNCTION_TABLE.length; | ||
| FUNCTION_TABLE.length = oldSize + delta; | ||
| if (newSize > oldSize) { | ||
| __wasm_table_fill(oldSize, value, delta) | ||
| } | ||
| return oldSize; | ||
| } | ||
|
|
||
| function __wasm_table_fill(dest, value, size) { | ||
| // TODO: traps on invalid things | ||
| for (var i = 0; i < size; i++) { | ||
| FUNCTION_TABLE[dest + i] = value; | ||
| } | ||
| } | ||
|
|
||
| function __wasm_table_copy(dest, source, size) { | ||
| // TODO: traps on invalid things | ||
| for (var i = 0; i < size; i++) { | ||
| FUNCTION_TABLE[dest + i] = FUNCTION_TABLE[source + i]; | ||
| } | ||
| } | ||
|
|
||
| function asmFunc(imports) { | ||
| var env = imports.env; | ||
| var FUNCTION_TABLE = env.table; | ||
| var Math_imul = Math.imul; | ||
| var Math_fround = Math.fround; | ||
| var Math_abs = Math.abs; | ||
| var Math_clz32 = Math.clz32; | ||
| var Math_min = Math.min; | ||
| var Math_max = Math.max; | ||
| var Math_floor = Math.floor; | ||
| var Math_ceil = Math.ceil; | ||
| var Math_trunc = Math.trunc; | ||
| var Math_sqrt = Math.sqrt; | ||
| function table_get() { | ||
| return FUNCTION_TABLE[1]; | ||
| } | ||
|
|
||
| function table_set() { | ||
| FUNCTION_TABLE[1] = table_set; | ||
| } | ||
|
|
||
| function table_size() { | ||
| return FUNCTION_TABLE.length | 0; | ||
| } | ||
|
|
||
| function table_grow() { | ||
| return wasm2js_table_grow(table_grow, 42) | 0; | ||
| } | ||
|
|
||
| function table_fill(dest, value, size) { | ||
| dest = dest | 0; | ||
| size = size | 0; | ||
| wasm2js_table_fill(dest, value, size); | ||
| } | ||
|
|
||
| function table_copy(dest, source, size) { | ||
| dest = dest | 0; | ||
| source = source | 0; | ||
| size = size | 0; | ||
| wasm2js_table_copy(dest, source, size); | ||
| } | ||
|
|
||
| FUNCTION_TABLE[1] = table_get; | ||
| return { | ||
| "table_get": table_get, | ||
| "table_set": table_set, | ||
| "table_size": table_size, | ||
| "table_grow": table_grow, | ||
| "table_fill": table_fill, | ||
| "table_copy": table_copy | ||
| }; | ||
| } | ||
|
|
||
| var retasmFunc = asmFunc({ | ||
| "env": env, | ||
| }); | ||
| export var table_get = retasmFunc.table_get; | ||
| export var table_set = retasmFunc.table_set; | ||
| export var table_size = retasmFunc.table_size; | ||
| export var table_grow = retasmFunc.table_grow; | ||
| export var table_fill = retasmFunc.table_fill; | ||
| export var table_copy = retasmFunc.table_copy; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import * as env from 'env'; | ||
|
|
||
|
|
||
| function wasm2js_table_grow(value, delta) { | ||
| // TODO: traps on invalid things | ||
| var oldSize = FUNCTION_TABLE.length; | ||
| FUNCTION_TABLE.length = oldSize + delta; | ||
| if (newSize > oldSize) { | ||
| __wasm_table_fill(oldSize, value, delta) | ||
| } | ||
| return oldSize; | ||
| } | ||
|
|
||
| function __wasm_table_fill(dest, value, size) { | ||
| // TODO: traps on invalid things | ||
| for (var i = 0; i < size; i++) { | ||
| FUNCTION_TABLE[dest + i] = value; | ||
| } | ||
| } | ||
|
|
||
| function __wasm_table_copy(dest, source, size) { | ||
| // TODO: traps on invalid things | ||
| for (var i = 0; i < size; i++) { | ||
| FUNCTION_TABLE[dest + i] = FUNCTION_TABLE[source + i]; | ||
| } | ||
| } | ||
|
|
||
| function asmFunc(imports) { | ||
| var env = imports.env; | ||
| var FUNCTION_TABLE = env.table; | ||
| var Math_imul = Math.imul; | ||
| var Math_fround = Math.fround; | ||
| var Math_abs = Math.abs; | ||
| var Math_clz32 = Math.clz32; | ||
| var Math_min = Math.min; | ||
| var Math_max = Math.max; | ||
| var Math_floor = Math.floor; | ||
| var Math_ceil = Math.ceil; | ||
| var Math_trunc = Math.trunc; | ||
| var Math_sqrt = Math.sqrt; | ||
| function table_get() { | ||
| return FUNCTION_TABLE[1]; | ||
| } | ||
|
|
||
| function table_set() { | ||
| FUNCTION_TABLE[1] = table_set; | ||
| } | ||
|
|
||
| function table_size() { | ||
| return FUNCTION_TABLE.length | 0; | ||
| } | ||
|
|
||
| function table_grow() { | ||
| return wasm2js_table_grow(table_grow, 42) | 0; | ||
| } | ||
|
|
||
| function table_fill($0, $1, $2) { | ||
| $0 = $0 | 0; | ||
| $2 = $2 | 0; | ||
| wasm2js_table_fill($0, $1, $2); | ||
| } | ||
|
|
||
| function table_copy($0, $1, $2) { | ||
| $0 = $0 | 0; | ||
| $1 = $1 | 0; | ||
| $2 = $2 | 0; | ||
| wasm2js_table_copy($0, $1, $2); | ||
| } | ||
|
|
||
| FUNCTION_TABLE[1] = table_get; | ||
| return { | ||
| "table_get": table_get, | ||
| "table_set": table_set, | ||
| "table_size": table_size, | ||
| "table_grow": table_grow, | ||
| "table_fill": table_fill, | ||
| "table_copy": table_copy | ||
| }; | ||
| } | ||
|
|
||
| var retasmFunc = asmFunc({ | ||
| "env": env, | ||
| }); | ||
| export var table_get = retasmFunc.table_get; | ||
| export var table_set = retasmFunc.table_set; | ||
| export var table_size = retasmFunc.table_size; | ||
| export var table_grow = retasmFunc.table_grow; | ||
| export var table_fill = retasmFunc.table_fill; | ||
| export var table_copy = retasmFunc.table_copy; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we validate elsewhere that the module has only one table? If not, we might want to raise an error here and on the other operations if the table is not at index 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have an error up front about that, it is a built-in assumption throughout wasm2js.
binaryen/src/tools/wasm2js.cpp
Lines 960 to 963 in cdd94a0