Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/test/lld.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def args_for_finalize(filename):
ret += ['--side-module']
if 'standalone-wasm' in filename:
ret += ['--standalone-wasm']
if 'bigint' in filename:
ret += ['--bigint']
return ret


Expand Down
12 changes: 10 additions & 2 deletions src/tools/wasm-emscripten-finalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ int main(int argc, const char* argv[]) {
bool DWARF = false;
bool sideModule = false;
bool legalizeJavaScriptFFI = true;
bool bigInt = false;
bool checkStackOverflow = false;
uint64_t globalBase = INVALID_BASE;
bool standaloneWasm = false;
Expand Down Expand Up @@ -118,6 +119,13 @@ int main(int argc, const char* argv[]) {
[&legalizeJavaScriptFFI](Options* o, const std::string&) {
legalizeJavaScriptFFI = false;
})
.add("--bigint",
"-bi",
"Assume JS will use wasm/JS BigInt integration, so wasm i64s will "
"turn into JS BigInts, and there is no need for any legalization at "
"all (not even minimal legalization of dynCalls)",
Options::Arguments::Zero,
[&bigInt](Options* o, const std::string&) { bigInt = true; })
.add("--output-source-map",
"-osm",
"Emit source map to the specified file",
Expand Down Expand Up @@ -272,8 +280,8 @@ int main(int argc, const char* argv[]) {
generator.generateDynCallThunks();
}

// Legalize the wasm.
{
// Legalize the wasm, if BigInts don't make that moot.
if (!bigInt) {
BYN_TRACE("legalizing types\n");
PassRunner passRunner(&wasm);
passRunner.setOptions(options.passOptions);
Expand Down
10 changes: 10 additions & 0 deletions test/lld/bigint.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(module
(table $0 1 1 funcref)
(elem (i32.const 1) $foo)
(export "__data_end" (global $global$1))
(global $global$0 (mut i32) (i32.const 66208))
(global $global$1 i32 (i32.const 658))
(func $foo (param i64) (result i64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting to see imports and exports of i64 functions here... is putting it the table enough to test the legalization?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the legalization path would create a legalized dynCall with i32 pairs etc.

(unreachable)
)
)
88 changes: 88 additions & 0 deletions test/lld/bigint.wat.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
(module
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i64_=>_i64 (func (param i64) (result i64)))
(type $i32_=>_none (func (param i32)))
(type $none_=>_i32 (func (result i32)))
(type $i32_i64_=>_i64 (func (param i32 i64) (result i64)))
(table $0 1 1 funcref)
(elem (i32.const 1) $foo)
(global $global$0 (mut i32) (i32.const 66208))
(global $global$1 i32 (i32.const 658))
(export "__data_end" (global $global$1))
(export "stackSave" (func $stackSave))
(export "stackAlloc" (func $stackAlloc))
(export "stackRestore" (func $stackRestore))
(export "__growWasmMemory" (func $__growWasmMemory))
(export "dynCall_jj" (func $dynCall_jj))
(func $foo (; 0 ;) (param $0 i64) (result i64)
(unreachable)
)
(func $stackSave (; 1 ;) (result i32)
(global.get $global$0)
)
(func $stackAlloc (; 2 ;) (param $0 i32) (result i32)
(local $1 i32)
(global.set $global$0
(local.tee $1
(i32.and
(i32.sub
(global.get $global$0)
(local.get $0)
)
(i32.const -16)
)
)
)
(local.get $1)
)
(func $stackRestore (; 3 ;) (param $0 i32)
(global.set $global$0
(local.get $0)
)
)
(func $__growWasmMemory (; 4 ;) (param $newSize i32) (result i32)
(memory.grow
(local.get $newSize)
)
)
(func $dynCall_jj (; 5 ;) (param $fptr i32) (param $0 i64) (result i64)
(call_indirect (type $i64_=>_i64)
(local.get $0)
(local.get $fptr)
)
)
)
(;
--BEGIN METADATA --
{
"staticBump": 90,
"tableSize": 1,
"declares": [
],
"externs": [
],
"implementedFunctions": [
"_stackSave",
"_stackAlloc",
"_stackRestore",
"___growWasmMemory",
"_dynCall_jj"
],
"exports": [
"stackSave",
"stackAlloc",
"stackRestore",
"__growWasmMemory",
"dynCall_jj"
],
"namedGlobals": {
"__data_end" : "658"
},
"invokeFuncs": [
],
"features": [
],
"mainReadsParams": 0
}
-- END METADATA --
;)