Skip to content
Merged
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
66 changes: 33 additions & 33 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8959,39 +8959,39 @@ def test_exported_runtime_methods_metadce(self, use_legacy_name):
for export in exports:
self.assertContained(f'Module["{export}"]', js)

def test_legalize_js_ffi(self):
# test disabling of JS FFI legalization
for (args, js_ffi) in [
(['-sLEGALIZE_JS_FFI=1', '-sSIDE_MODULE', '-O1'], True),
(['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O1'], False),
(['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O0'], False),
(['-sLEGALIZE_JS_FFI=1', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], True),
(['-sLEGALIZE_JS_FFI=0', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], False),
]:
print(args)
delete_file('a.out.wasm')
cmd = [EMCC, test_file('other/ffi.c'), '-g', '-o', 'a.out.wasm'] + args
print(' '.join(cmd))
self.run_process(cmd)
text = self.get_wasm_text('a.out.wasm')
# remove internal comments and extra whitespace
text = re.sub(r'\(;[^;]+;\)', '', text)
text = re.sub(r'\$var\$*.', '', text)
text = re.sub(r'param \$\d+', 'param ', text)
text = re.sub(r' +', ' ', text)
e_add_f32 = re.search(r'func \$add_f \(param f32\) \(param f32\) \(result f32\)', text)
assert e_add_f32, 'add_f export missing'
i_i64_i32 = re.search(r'import "env" "import_ll" .*\(param i32 i32\) \(result i32\)', text)
i_i64_i64 = re.search(r'import "env" "import_ll" .*\(param i64\) \(result i64\)', text)
e_i64_i32 = re.search(r'func \$legalstub\$add_ll \(param i32\) \(param i32\) \(param i32\) \(param i32\) \(result i32\)', text)
if js_ffi:
assert i_i64_i32, 'i64 not converted to i32 in imports'
assert not i_i64_i64, 'i64 not converted to i32 in imports'
assert e_i64_i32, 'i64 not converted to i32 in exports'
else:
assert not i_i64_i32, 'i64 converted to i32 in imports'
assert i_i64_i64, 'i64 converted to i32 in imports'
assert not e_i64_i32, 'i64 converted to i32 in exports'
@parameterized({
'legal_side_O1': (['-sLEGALIZE_JS_FFI=1', '-sSIDE_MODULE', '-O1'], True),
'nolegal_side_O1': (['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O1'], False),
'nolegal_side_O0': (['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O0'], False),
'legal_O0': (['-sLEGALIZE_JS_FFI=1', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], True),
'nolegal_O0': (['-sLEGALIZE_JS_FFI=0', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], False),
})
def test_legalize_js_ffi(self, args, js_ffi):
# test disabling of JS FFI legalization when not using bigint
print(args)
delete_file('a.out.wasm')
cmd = [EMCC, test_file('other/ffi.c'), '-g', '-o', 'a.out.wasm'] + args
print(' '.join(cmd))
self.run_process(cmd)
text = self.get_wasm_text('a.out.wasm')
# remove internal comments and extra whitespace
text = re.sub(r'\(;[^;]+;\)', '', text)
text = re.sub(r'\$var\$*.', '', text)
text = re.sub(r'param \$\d+', 'param ', text)
text = re.sub(r' +', ' ', text)
e_add_f32 = re.search(r'func \$add_f \(param f32\) \(param f32\) \(result f32\)', text)
assert e_add_f32, 'add_f export missing'
i_i64_i32 = re.search(r'import "env" "import_ll" .*\(param i32 i32\) \(result i32\)', text)
i_i64_i64 = re.search(r'import "env" "import_ll" .*\(param i64\) \(result i64\)', text)
e_i64_i32 = re.search(r'func \$legalstub\$add_ll \(param i32\) \(param i32\) \(param i32\) \(param i32\) \(result i32\)', text)
if js_ffi:
assert i_i64_i32, 'i64 not converted to i32 in imports'
assert not i_i64_i64, 'i64 not converted to i32 in imports'
assert e_i64_i32, 'i64 not converted to i32 in exports'
else:
assert not i_i64_i32, 'i64 converted to i32 in imports'
assert i_i64_i64, 'i64 converted to i32 in imports'
assert not e_i64_i32, 'i64 converted to i32 in exports'

@disabled('https://github.com/WebAssembly/binaryen/pull/6428')
def test_no_legalize_js_ffi(self):
Expand Down
Loading