Skip to content

Commit b2f9b9c

Browse files
committed
Rename asm to wasmExports under MINIMAL_RUNTIME
This matches the name used by the regualar runtime as of #19816 and removes one of them major differences between the two runtimes.
1 parent d54e9d9 commit b2f9b9c

18 files changed

+97
-104
lines changed

emscripten.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def compute_minimal_runtime_initializer_and_exports(post, exports, receiving):
4949
declares = 'var ' + ',\n '.join(exports_that_are_not_initializers) + ';'
5050
post = shared.do_replace(post, '<<< WASM_MODULE_EXPORTS_DECLARES >>>', declares)
5151

52-
# Generate assignments from all wasm exports out to the JS variables above: e.g. a = asm['a']; b = asm['b'];
52+
# Generate assignments from all wasm exports out to the JS variables above: e.g. a = wasmExports['a']; b = wasmExports['b'];
5353
post = shared.do_replace(post, '<<< WASM_MODULE_EXPORTS >>>', receiving)
5454
return post
5555

@@ -778,8 +778,8 @@ def create_receiving(function_exports):
778778
# existing in top level JS scope, i.e.
779779
# var _main;
780780
# WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
781-
# var asm = output.instance.exports;
782-
# _main = asm["_main"];
781+
# var wasmExports = output.instance.exports;
782+
# _main = wasmExports["_main"];
783783
generate_dyncall_assignment = settings.DYNCALLS and '$dynCall' in settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE
784784
exports_that_are_not_initializers = [x for x in function_exports if x != building.WASM_CALL_CTORS]
785785

@@ -790,7 +790,7 @@ def create_receiving(function_exports):
790790
export_assignment = ''
791791
if settings.MODULARIZE and should_export:
792792
export_assignment = f"Module['{mangled}'] = "
793-
receiving += [f'{export_assignment}{dynCallAssignment}{mangled} = asm["{s}"]']
793+
receiving += [f'{export_assignment}{dynCallAssignment}{mangled} = wasmExports["{s}"]']
794794
else:
795795
receiving += make_export_wrappers(function_exports, delay_assignment)
796796
else:

src/library.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,7 +2983,7 @@ mergeInto(LibraryManager.library, {
29832983
// When DECLARE_ASM_MODULE_EXPORTS is not set we export native symbols
29842984
// at runtime rather than statically in JS code.
29852985
$exportAsmFunctions__deps: ['$asmjsMangle'],
2986-
$exportAsmFunctions: (asm) => {
2986+
$exportAsmFunctions: (wasmExports) => {
29872987
#if ENVIRONMENT_MAY_BE_NODE && ENVIRONMENT_MAY_BE_WEB
29882988
var global_object = (typeof process != "undefined" ? global : this);
29892989
#elif ENVIRONMENT_MAY_BE_NODE
@@ -2992,12 +2992,12 @@ mergeInto(LibraryManager.library, {
29922992
var global_object = this;
29932993
#endif
29942994

2995-
for (var __exportedFunc in asm) {
2995+
for (var __exportedFunc in wasmExports) {
29962996
var jsname = asmjsMangle(__exportedFunc);
29972997
#if MINIMAL_RUNTIME
2998-
global_object[jsname] = asm[__exportedFunc];
2998+
global_object[jsname] = wasmExports[__exportedFunc];
29992999
#else
3000-
global_object[jsname] = Module[jsname] = asm[__exportedFunc];
3000+
global_object[jsname] = Module[jsname] = wasmExports[__exportedFunc];
30013001
#endif
30023002
}
30033003

src/library_async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ mergeInto(LibraryManager.library, {
533533
// Add a callback for when all run dependencies are fulfilled, which happens when async wasm loading is done.
534534
dependenciesFulfilled = wakeUp;
535535
// Load the new wasm.
536-
asm = createWasm();
536+
wasmExports = createWasm();
537537
});
538538
},
539539

src/library_exports.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ mergeInto(LibraryManager.library, {
1212
// Wasm backend does not use C name mangling on exports,
1313
// so adjust for that manually.
1414
if (name[0] == '_') name = name.substr(1);
15-
#if MINIMAL_RUNTIME
16-
var exportedFunc = asm[name];
17-
#else
18-
// In regular runtime, exports are available on the Module object.
1915
var exportedFunc = wasmExports[name];
20-
#endif
2116
if (exportedFunc) {
2217
// Record the created function pointer to each function object,
2318
// so that if the same function pointer is obtained several times,
@@ -26,7 +21,7 @@ mergeInto(LibraryManager.library, {
2621
return exportedFunc.ptr;
2722
}
2823
#if ASSERTIONS
29-
err('No exported function found by name "' + exportedFunc + '"');
24+
err(`No exported function found by name "{exportedFunc}"`);
3025
#endif
3126
// implicit return 0;
3227
}

src/postamble_minimal.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function run() {
4848
}
4949
#endif
5050

51-
function initRuntime(asm) {
51+
function initRuntime(wasmExports) {
5252
#if ASSERTIONS || SAFE_HEAP || USE_ASAN
5353
runtimeInitialized = true;
5454
#endif
@@ -77,11 +77,11 @@ function initRuntime(asm) {
7777
#endif
7878

7979
#if PTHREADS
80-
PThread.tlsInitFunctions.push(asm['_emscripten_tls_init']);
80+
PThread.tlsInitFunctions.push(wasmExports['_emscripten_tls_init']);
8181
#endif
8282

8383
#if hasExportedSymbol('__wasm_call_ctors')
84-
asm['__wasm_call_ctors']();
84+
wasmExports['__wasm_call_ctors']();
8585
#endif
8686

8787
<<< ATINITS >>>
@@ -101,7 +101,7 @@ var imports = {
101101
// In non-fastcomp non-asm.js builds, grab wasm exports to outer scope
102102
// for emscripten_get_exported_function() to be able to access them.
103103
#if LibraryManager.has('library_exports.js')
104-
var asm;
104+
var wasmExports;
105105
#endif
106106

107107
#if PTHREADS
@@ -142,7 +142,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
142142

143143
#if !LibraryManager.has('library_exports.js') && !EMBIND
144144
// If not using the emscripten_get_exported_function() API or embind, keep the
145-
// `asm` exports variable in local scope to this instantiate function to save
145+
// `wasmExports` variable in local scope to this instantiate function to save
146146
// code size. (otherwise access it without to export it to outer scope)
147147
var
148148
#endif
@@ -163,16 +163,16 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
163163
// that case, 'output' is a WebAssembly.Instance.
164164
// In main thread, Module['wasm'] is either a typed array or a fetch stream.
165165
// In that case, 'output.instance' is the WebAssembly.Instance.
166-
asm = (output.instance || output).exports;
166+
wasmExports = (output.instance || output).exports;
167167
#else
168-
asm = output.exports;
168+
wasmExports = output.exports;
169169
#endif
170170
#else
171-
asm = output.instance.exports;
171+
wasmExports = output.instance.exports;
172172
#endif
173173

174174
#if MEMORY64 || CAN_ADDRESS_2GB
175-
asm = applySignatureConversions(asm);
175+
wasmExports = applySignatureConversions(wasmExports);
176176
#endif
177177

178178
#if USE_OFFSET_CONVERTER
@@ -183,11 +183,11 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
183183
#endif
184184

185185
#if !DECLARE_ASM_MODULE_EXPORTS
186-
exportAsmFunctions(asm);
186+
exportAsmFunctions(wasmExports);
187187
#else
188188
<<< WASM_MODULE_EXPORTS >>>
189189
#endif
190-
wasmTable = asm['__indirect_function_table'];
190+
wasmTable = wasmExports['__indirect_function_table'];
191191
#if ASSERTIONS
192192
assert(wasmTable);
193193
#endif
@@ -211,7 +211,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
211211
#endif
212212

213213
#if !IMPORTED_MEMORY
214-
wasmMemory = asm['memory'];
214+
wasmMemory = wasmExports['memory'];
215215
#if ASSERTIONS
216216
assert(wasmMemory);
217217
assert(wasmMemory.buffer.byteLength === {{{ INITIAL_MEMORY }}});
@@ -226,7 +226,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => {
226226
HEAPU8.set(new Uint8Array(Module['mem']), {{{ GLOBAL_BASE }}});
227227
#endif
228228

229-
initRuntime(asm);
229+
initRuntime(wasmExports);
230230
#if PTHREADS
231231
// Export Wasm module for pthread creation to access.
232232
wasmModule = output.module || Module['wasm'];

test/optimizer/applyDCEGraphRemovals-output.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ var wasmImports = {
55
save2: 2
66
};
77

8-
var expD1 = Module["expD1"] = asm["expD1"];
8+
var expD1 = Module["expD1"] = wasmExports["expD1"];
99

10-
var expD2 = Module["expD2"] = asm["expD2"];
10+
var expD2 = Module["expD2"] = wasmExports["expD2"];
1111

12-
var expD3 = Module["expD3"] = asm["expD3"];
12+
var expD3 = Module["expD3"] = wasmExports["expD3"];
1313

1414
var expD4;
1515

16-
var expD5 = asm["expD5"];
16+
var expD5 = wasmExports["expD5"];
1717

1818
var expD6;
1919

@@ -33,10 +33,10 @@ expD1;
3333

3434
Module["expD2"];
3535

36-
asm["expD3"];
36+
wasmExports["expD3"];
3737

3838
expI1;
3939

4040
Module["expI2"];
4141

42-
asm["expI3"];
42+
wasmExports["expI3"];

test/optimizer/applyDCEGraphRemovals.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ var name;
22
var wasmImports = { save1: 1, number: 33, name: name, func: function() {}, save2: 2 };
33

44
// exports gotten directly
5-
var expD1 = Module['expD1'] = asm['expD1'];
6-
var expD2 = Module['expD2'] = asm['expD2'];
7-
var expD3 = Module['expD3'] = asm['expD3'];
8-
var expD4 = Module['expD4'] = asm['expD4'];
5+
var expD1 = Module['expD1'] = wasmExports['expD1'];
6+
var expD2 = Module['expD2'] = wasmExports['expD2'];
7+
var expD3 = Module['expD3'] = wasmExports['expD3'];
8+
var expD4 = Module['expD4'] = wasmExports['expD4'];
99
// Like above, but not exported on the Module
10-
var expD5 = asm['expD5'];
11-
var expD6 = asm['expD6'];
10+
var expD5 = wasmExports['expD5'];
11+
var expD6 = wasmExports['expD6'];
1212

1313
// exports gotten indirectly (async compilation
1414
var expI1 = Module['expI1'] = () => (expI1 = Module['expI1'] = wasmExports['expI1'])();
@@ -23,10 +23,10 @@ var expI6 = () => (expI6 = wasmExports['expI6'])();
2323
// add uses for some of them, leave *4 as non-roots
2424
expD1;
2525
Module['expD2'];
26-
asm['expD3'];
26+
wasmExports['expD3'];
2727

2828
expI1;
2929
Module['expI2'];
30-
asm['expI3'];
30+
wasmExports['expI3'];
3131

3232
// EXTRA_INFO: { "unused": ["emcc$import$number", "emcc$import$name", "emcc$import$func", "emcc$export$expD4", "emcc$export$expD6", "emcc$export$expI4", "emcc$export$expI6"] }

test/optimizer/applyImportAndExportNameChanges-output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var wasmImports = {
1414
q: ___syscall146
1515
};
1616

17-
var expD1 = Module["expD1"] = asm["c"];
17+
var expD1 = Module["expD1"] = wasmExports["c"];
1818

1919
var expI1 = Module["expI1"] = function() {
2020
return wasmExports["d"].apply(null, arguments);

test/optimizer/applyImportAndExportNameChanges.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var wasmImports = {
1414
};
1515

1616
// exports
17-
var expD1 = Module['expD1'] = asm['expD1'];
17+
var expD1 = Module['expD1'] = wasmExports['expD1'];
1818

1919
// exports gotten indirectly (async compilation
2020
var expI1 = Module['expI1'] = (function() {

test/optimizer/applyImportAndExportNameChanges2-output.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ function run() {
227227
var ret = _main();
228228
}
229229

230-
function initRuntime(asm) {
231-
asm["i"]();
230+
function initRuntime(wasmExports) {
231+
wasmExports["i"]();
232232
}
233233

234234
var env = wasmImports;
@@ -265,14 +265,14 @@ var imports = {
265265
var ___errno_location, _llvm_bswap_i32, _main, _memcpy, _memset, dynCall_ii, dynCall_iiii;
266266

267267
WebAssembly.instantiate(Module["wasm"], imports).then(output => {
268-
var asm = output.instance.exports;
269-
___errno_location = asm["j"];
270-
_llvm_bswap_i32 = asm["k"];
271-
_main = asm["l"];
272-
_memcpy = asm["m"];
273-
_memset = asm["n"];
274-
dynCall_ii = asm["o"];
275-
dynCall_iiii = asm["p"];
276-
initRuntime(asm);
268+
var wasmExports = output.instance.exports;
269+
___errno_location = wasmExports["j"];
270+
_llvm_bswap_i32 = wasmExports["k"];
271+
_main = wasmExports["l"];
272+
_memcpy = wasmExports["m"];
273+
_memset = wasmExports["n"];
274+
dynCall_ii = wasmExports["o"];
275+
dynCall_iiii = wasmExports["p"];
276+
initRuntime(wasmExports);
277277
ready();
278278
});

test/optimizer/applyImportAndExportNameChanges2.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ function run() {
218218
var ret = _main()
219219
}
220220

221-
function initRuntime(asm) {
222-
asm["__GLOBAL__sub_I_test_global_initializer_cpp"]()
221+
function initRuntime(wasmExports) {
222+
wasmExports["__GLOBAL__sub_I_test_global_initializer_cpp"]()
223223
}
224224
var env = wasmImports;
225225
env["memory"] = wasmMemory;
@@ -248,15 +248,15 @@ var imports = {
248248
};
249249
var ___errno_location, _llvm_bswap_i32, _main, _memcpy, _memset, dynCall_ii, dynCall_iiii;
250250
WebAssembly.instantiate(Module["wasm"], imports).then(((output) => {
251-
var asm = output.instance.exports;
252-
___errno_location = asm["___errno_location"];
253-
_llvm_bswap_i32 = asm["_llvm_bswap_i32"];
254-
_main = asm["_main"];
255-
_memcpy = asm["_memcpy"];
256-
_memset = asm["_memset"];
257-
dynCall_ii = asm["dynCall_ii"];
258-
dynCall_iiii = asm["dynCall_iiii"];
259-
initRuntime(asm);
251+
var wasmExports = output.instance.exports;
252+
___errno_location = wasmExports["___errno_location"];
253+
_llvm_bswap_i32 = wasmExports["_llvm_bswap_i32"];
254+
_main = wasmExports["_main"];
255+
_memcpy = wasmExports["_memcpy"];
256+
_memset = wasmExports["_memset"];
257+
dynCall_ii = wasmExports["dynCall_ii"];
258+
dynCall_iiii = wasmExports["dynCall_iiii"];
259+
initRuntime(wasmExports);
260260
ready()
261261
}))
262262

test/optimizer/emitDCEGraph.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ var wasmImports = {
4545
};
4646

4747
// exports gotten directly
48-
var expD1 = Module['expD1'] = asm['expD1'];
49-
var expD2 = Module['expD2'] = asm['expD2'];
50-
var expD3 = Module['expD3'] = asm['expD3'];
51-
var expD4 = Module['expD4'] = asm['expD4'];
48+
var expD1 = Module['expD1'] = wasmExports['expD1'];
49+
var expD2 = Module['expD2'] = wasmExports['expD2'];
50+
var expD3 = Module['expD3'] = wasmExports['expD3'];
51+
var expD4 = Module['expD4'] = wasmExports['expD4'];
5252
// Same as above but not export on the Module
53-
var expD5 = asm['expD5'];
53+
var expD5 = wasmExports['expD5'];
5454

5555
// exports gotten indirectly (async compilation
5656
var expI1 = Module['expI1'] = () => (expI1 = Module['expI1'] = wasmExports['expI1'])();
@@ -64,7 +64,7 @@ var expI5 = () => (expI5 = wasmExports['expI5'])();
6464
// add uses for some of them
6565
expD1;
6666
Module['expD2'];
67-
asm['expD3'];
67+
wasmExports['expD3'];
6868

6969
expI1;
7070
Module['expI2'];

test/optimizer/minimal-runtime-2-emitDCEGraph.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ var imports = {
6464
})
6565
}
6666
};
67-
var _main, _unused, asm;
67+
var _main, _unused, wasmExports;
6868
WebAssembly.instantiate(Module["wasm"], imports).then(((output) => {
69-
asm = output.instance.exports;
70-
_main = asm["b"];
71-
_unused = asm["c"];
69+
wasmExports = output.instance.exports;
70+
_main = wasmExports["b"];
71+
_unused = wasmExports["c"];
7272
initRuntime();
7373
ready();
7474
}));

test/optimizer/minimal-runtime-applyDCEGraphRemovals-output.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ var wasmImports = {
66
};
77

88
WebAssembly.instantiate(Module["wasm"], imports).then(output => {
9-
asm = output.instance.exports;
10-
expD1 = asm["expD1"];
11-
expD2 = asm["expD2"];
12-
expD3 = asm["expD3"];
13-
initRuntime(asm);
9+
wasmExports = output.instance.exports;
10+
expD1 = wasmExports["expD1"];
11+
expD2 = wasmExports["expD2"];
12+
expD3 = wasmExports["expD3"];
13+
initRuntime(wasmExports);
1414
ready();
1515
});
1616

1717
expD1;
1818

1919
Module["expD2"];
2020

21-
asm["expD3"];
21+
wasmExports["expD3"];

0 commit comments

Comments
 (0)