Skip to content

Commit 4b02802

Browse files
authored
Allow ASM_CONSTS keys to be non-contiguous (#9740)
As part of the plan to fix #9013, I plan to use the absolute address of the string in memory to index into this object.
1 parent d9b3d6a commit 4b02802

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

emscripten.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,10 +2225,11 @@ def emscript_wasm_backend(infile, outfile, memfile, compiler_engine,
22252225

22262226
asm_consts, asm_const_funcs = create_asm_consts_wasm(forwarded_json, metadata)
22272227
em_js_funcs = create_em_js(forwarded_json, metadata)
2228+
asm_const_pairs = ['%s: %s' % (key, value) for key, value in asm_consts]
2229+
asm_const_map = 'var ASM_CONSTS = {\n ' + ', \n '.join(asm_const_pairs) + '\n};\n'
22282230
pre = pre.replace(
22292231
'// === Body ===',
2230-
('// === Body ===\n\nvar ASM_CONSTS = [' +
2231-
',\n '.join(asm_consts) + '];\n' +
2232+
('// === Body ===\n\n' + asm_const_map +
22322233
asstr('\n'.join(asm_const_funcs)) +
22332234
'\n'.join(em_js_funcs) + '\n'))
22342235
pre = apply_table(pre)
@@ -2342,7 +2343,7 @@ def debug_copy(src, dst):
23422343

23432344

23442345
def create_asm_consts_wasm(forwarded_json, metadata):
2345-
asm_consts = [0] * len(metadata['asmConsts'])
2346+
asm_consts = {}
23462347
all_sigs = []
23472348
for k, v in metadata['asmConsts'].items():
23482349
const, sigs, call_types = v
@@ -2417,6 +2418,8 @@ def create_asm_consts_wasm(forwarded_json, metadata):
24172418
var args = readAsmConstArgs(sigPtr, argbuf);
24182419
return ASM_CONSTS[code].apply(null, args);
24192420
}''' % (const_name, preamble))
2421+
asm_consts = [(key, value) for key, value in asm_consts.items()]
2422+
asm_consts.sort()
24202423
return asm_consts, asm_const_funcs
24212424

24222425

tests/test_other.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8684,8 +8684,8 @@ def test_js_optimizer_parse_error(self):
86848684
var ASM_CONSTS = [function() { var x = !<->5.; }];
86858685
^
86868686
''', '''
8687-
var ASM_CONSTS = [function() {var x = !<->5.;}];
8688-
^
8687+
0: function() {var x = !<->5.;}
8688+
^
86898689
'''), stderr)
86908690

86918691
def test_EM_ASM_ES6(self):

0 commit comments

Comments
 (0)