Skip to content

Commit a322ea5

Browse files
committed
Allow ASM_CONSTS keys to be non-contiguous
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 4cc1626 commit a322ea5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
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

0 commit comments

Comments
 (0)