Skip to content

Commit c795453

Browse files
authored
Support parsing extended const in tools/webassembly.py (#18010)
By forcing the export of a global we force our metadata parsing code to parse the global section which contains that extended const init expressions.
1 parent ad3e5f3 commit c795453

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

test/test_other.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12320,7 +12320,8 @@ def test_unsafe_optimizations(self):
1232012320
@requires_v8
1232112321
def test_extended_const(self):
1232212322
self.v8_args = ['--experimental-wasm-extended-const']
12323-
self.do_runf(test_file('hello_world.c'), emcc_args=['-mextended-const', '-sMAIN_MODULE=2'])
12323+
# Export at least one global so that we exercise the parsing of the global section.
12324+
self.do_runf(test_file('hello_world.c'), emcc_args=['-sEXPORTED_FUNCTIONS=_main,___stdout_used', '-mextended-const', '-sMAIN_MODULE=2'])
1232412325
wat = self.get_wasm_text('hello_world.wasm')
1232512326
# Test that extended-const expressions are used in the data segments.
1232612327
self.assertTrue(re.search(r'\(data \(i32.add\s+\(global.get \$\S+\)\s+\(i32.const \d+\)', wat))

tools/webassembly.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class OpCode(IntEnum):
109109
F32_CONST = 0x43
110110
F64_CONST = 0x44
111111
I32_ADD = 0x6a
112+
I64_ADD = 0x6b
112113
REF_NULL = 0xd0
113114
ATOMIC_PREFIX = 0xfe
114115
MEMORY_PREFIX = 0xfc
@@ -239,7 +240,7 @@ def read_init(self):
239240
args.append(self.read_uleb())
240241
elif opcode in (OpCode.REF_NULL,):
241242
args.append(self.read_type())
242-
elif opcode in (OpCode.END,):
243+
elif opcode in (OpCode.END, OpCode.I32_ADD, OpCode.I64_ADD):
243244
pass
244245
else:
245246
raise Exception('unexpected opcode %s' % opcode)

0 commit comments

Comments
 (0)