Skip to content

Commit

Permalink
Allow ASM_CONSTS keys to be non-contiguous (emscripten-core#9740)
Browse files Browse the repository at this point in the history
As part of the plan to fix emscripten-core#9013, I plan to use the absolute address
of the string in memory to index into this object.
  • Loading branch information
sbc100 authored and belraquib committed Dec 23, 2020
1 parent 3776262 commit 7b9c7a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -2225,10 +2225,11 @@ def emscript_wasm_backend(infile, outfile, memfile, compiler_engine,

asm_consts, asm_const_funcs = create_asm_consts_wasm(forwarded_json, metadata)
em_js_funcs = create_em_js(forwarded_json, metadata)
asm_const_pairs = ['%s: %s' % (key, value) for key, value in asm_consts]
asm_const_map = 'var ASM_CONSTS = {\n ' + ', \n '.join(asm_const_pairs) + '\n};\n'
pre = pre.replace(
'// === Body ===',
('// === Body ===\n\nvar ASM_CONSTS = [' +
',\n '.join(asm_consts) + '];\n' +
('// === Body ===\n\n' + asm_const_map +
asstr('\n'.join(asm_const_funcs)) +
'\n'.join(em_js_funcs) + '\n'))
pre = apply_table(pre)
Expand Down Expand Up @@ -2342,7 +2343,7 @@ def debug_copy(src, dst):


def create_asm_consts_wasm(forwarded_json, metadata):
asm_consts = [0] * len(metadata['asmConsts'])
asm_consts = {}
all_sigs = []
for k, v in metadata['asmConsts'].items():
const, sigs, call_types = v
Expand Down Expand Up @@ -2417,6 +2418,8 @@ def create_asm_consts_wasm(forwarded_json, metadata):
var args = readAsmConstArgs(sigPtr, argbuf);
return ASM_CONSTS[code].apply(null, args);
}''' % (const_name, preamble))
asm_consts = [(key, value) for key, value in asm_consts.items()]
asm_consts.sort()
return asm_consts, asm_const_funcs


Expand Down
4 changes: 2 additions & 2 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8684,8 +8684,8 @@ def test_js_optimizer_parse_error(self):
var ASM_CONSTS = [function() { var x = !<->5.; }];
^
''', '''
var ASM_CONSTS = [function() {var x = !<->5.;}];
^
0: function() {var x = !<->5.;}
^
'''), stderr)

def test_EM_ASM_ES6(self):
Expand Down

0 comments on commit 7b9c7a3

Please sign in to comment.