Skip to content

Commit a7dc5cd

Browse files
authored
Move common runtime includes to runtime_shared.js. NFC (#23269)
This reduces duplication between preamble.js and preamble_minimal.js. Even though this is completely NFC there were some code size changes due to the ordering of the code.
1 parent b08c9f1 commit a7dc5cd

38 files changed

+79
-114
lines changed

src/preamble.js

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,6 @@ if (typeof WebAssembly != 'object') {
4444
}
4545
#endif
4646

47-
#if SAFE_HEAP
48-
#include "runtime_safe_heap.js"
49-
#endif
50-
51-
#if SHARED_MEMORY && ALLOW_MEMORY_GROWTH
52-
#include "growableHeap.js"
53-
#endif
54-
55-
#if USE_ASAN
56-
#include "runtime_asan.js"
57-
#endif
58-
5947
#if SUPPORT_BASE64_EMBEDDING || FORCE_FILESYSTEM
6048
#include "base64Utils.js"
6149
#endif
@@ -150,12 +138,16 @@ var HEAP,
150138
var HEAP_DATA_VIEW;
151139
#endif
152140

153-
#include "runtime_shared.js"
141+
var runtimeInitialized = false;
154142

155-
#if PTHREADS
156-
#include "runtime_pthread.js"
143+
#if EXIT_RUNTIME
144+
var runtimeExited = false;
157145
#endif
158146

147+
#include "URIUtils.js"
148+
149+
#include "runtime_shared.js"
150+
159151
#if ASSERTIONS
160152
assert(!Module['STACK_SIZE'], 'STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time')
161153
#endif
@@ -174,8 +166,6 @@ assert(!Module['wasmMemory'], 'Use of `wasmMemory` detected. Use -sIMPORTED_MEM
174166
assert(!Module['INITIAL_MEMORY'], 'Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically');
175167
#endif // !IMPORTED_MEMORY && ASSERTIONS
176168

177-
#include "runtime_stack_check.js"
178-
179169
var __ATPRERUN__ = []; // functions called before the runtime is initialized
180170
var __ATINIT__ = []; // functions called during startup
181171
#if HAS_MAIN
@@ -188,12 +178,6 @@ var __ATPOSTRUN__ = []; // functions called after the main() is called
188178
var __RELOC_FUNCS__ = [];
189179
#endif
190180

191-
var runtimeInitialized = false;
192-
193-
#if EXIT_RUNTIME
194-
var runtimeExited = false;
195-
#endif
196-
197181
function preRun() {
198182
#if ASSERTIONS && PTHREADS
199183
assert(!ENVIRONMENT_IS_PTHREAD); // PThreads reuse the runtime from the main thread.
@@ -483,8 +467,6 @@ function abort(what) {
483467
throw e;
484468
}
485469

486-
#include "memoryprofiler.js"
487-
488470
#if ASSERTIONS && !('$FS' in addedLibraryItems)
489471
// show errors on likely calls to FS when it was not included
490472
var FS = {
@@ -506,8 +488,6 @@ Module['FS_createDataFile'] = FS.createDataFile;
506488
Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
507489
#endif
508490

509-
#include "URIUtils.js"
510-
511491
#if ASSERTIONS
512492
function createExportWrapper(name, nargs) {
513493
return (...args) => {
@@ -524,8 +504,6 @@ function createExportWrapper(name, nargs) {
524504
}
525505
#endif
526506

527-
#include "runtime_exceptions.js"
528-
529507
#if ABORT_ON_WASM_EXCEPTIONS
530508
// `abortWrapperDepth` counts the recursion level of the wrapper function so
531509
// that we only handle exceptions at the top level letting the exception
@@ -675,16 +653,6 @@ async function getWasmBinary(binaryFile) {
675653
return getBinarySync(binaryFile);
676654
}
677655

678-
#if LOAD_SOURCE_MAP
679-
var wasmSourceMap;
680-
#include "source_map_support.js"
681-
#endif
682-
683-
#if USE_OFFSET_CONVERTER
684-
var wasmOffsetConverter;
685-
#include "wasm_offset_converter.js"
686-
#endif
687-
688656
#if SPLIT_MODULE
689657
{{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync', true) }}}
690658
var splitModuleProxyHandler = {
@@ -1127,8 +1095,6 @@ var tempDouble;
11271095
var tempI64;
11281096
#endif
11291097

1130-
#include "runtime_debug.js"
1131-
11321098
#if RETAIN_COMPILER_SETTINGS
11331099
var compilerSettings = {{{ JSON.stringify(makeRetainedCompilerSettings()) }}} ;
11341100

src/preamble_minimal.js

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
#if SAFE_HEAP
8-
#include "runtime_safe_heap.js"
9-
#endif
10-
11-
#if SHARED_MEMORY && ALLOW_MEMORY_GROWTH
12-
#include "growableHeap.js"
13-
#endif
14-
15-
#if USE_ASAN
16-
#include "runtime_asan.js"
17-
#endif
18-
197
#if ASSERTIONS
208
/** @type {function(*, string=)} */
219
function assert(condition, text) {
@@ -58,39 +46,19 @@ var HEAP8, HEAP16, HEAP32, HEAPU8, HEAPU16, HEAPU32, HEAPF32, HEAPF64,
5846
#endif
5947
wasmMemory;
6048

61-
#include "runtime_shared.js"
62-
63-
#if PTHREADS
64-
#include "runtime_pthread.js"
65-
#endif
66-
67-
#if IMPORTED_MEMORY
68-
#include "runtime_init_memory.js"
69-
#endif // IMPORTED_MEMORY
70-
71-
#include "runtime_stack_check.js"
72-
73-
#if LOAD_SOURCE_MAP
74-
var wasmSourceMap;
75-
#include "source_map_support.js"
76-
#endif
77-
78-
#if USE_OFFSET_CONVERTER
79-
var wasmOffsetConverter;
80-
#include "wasm_offset_converter.js"
49+
#if ASSERTIONS || SAFE_HEAP || USE_ASAN
50+
var runtimeInitialized = false;
8151
#endif
8252

8353
#if EXIT_RUNTIME
8454
var __ATEXIT__ = []; // functions called during shutdown
8555
var runtimeExited = false;
8656
#endif
8757

88-
#if ASSERTIONS || SAFE_HEAP || USE_ASAN
89-
var runtimeInitialized = false;
90-
#endif
58+
#include "runtime_shared.js"
9159

92-
#include "memoryprofiler.js"
93-
#include "runtime_exceptions.js"
94-
#include "runtime_debug.js"
60+
#if IMPORTED_MEMORY
61+
#include "runtime_init_memory.js"
62+
#endif // IMPORTED_MEMORY
9563

9664
// === Body ===

src/runtime_shared.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,37 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7+
#include "runtime_stack_check.js"
8+
#include "runtime_exceptions.js"
9+
#include "runtime_debug.js"
10+
#include "memoryprofiler.js"
11+
12+
#if SAFE_HEAP
13+
#include "runtime_safe_heap.js"
14+
#endif
15+
16+
#if SHARED_MEMORY && ALLOW_MEMORY_GROWTH
17+
#include "growableHeap.js"
18+
#endif
19+
20+
#if USE_ASAN
21+
#include "runtime_asan.js"
22+
#endif
23+
24+
#if PTHREADS
25+
#include "runtime_pthread.js"
26+
#endif
27+
28+
#if LOAD_SOURCE_MAP
29+
var wasmSourceMap;
30+
#include "source_map_support.js"
31+
#endif
32+
33+
#if USE_OFFSET_CONVERTER
34+
var wasmOffsetConverter;
35+
#include "wasm_offset_converter.js"
36+
#endif
37+
738
{{{
839
// Helper function to export a heap symbol on the module object,
940
// if requested.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8329
1+
8328
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20266
1+
20267
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8329
1+
8328
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20266
1+
20267
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8363
1+
8360
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9375
1+
9374
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3600
1+
3599
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7656
1+
7655
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2837
1+
2836
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7891
1+
7905
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
21016
1+
21012
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2357
1+
2356
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2296
1+
2297
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2296
1+
2297
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2279
1+
2278
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6028
1+
6026
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13317
1+
13316
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1681
1+
1678
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2296
1+
2297
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1873
1+
1874
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2327
1+
2326
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2476
1+
2474
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2177
1+
2175
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2140
1+
2141
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6435
1+
6443
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1381
1+
1380
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1348
1+
1347
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1348
1+
1347
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1348
1+
1347
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1541
1+
1542
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4190
1+
4186
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1348
1+
1347
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
52853
1+
52855
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
28644
1+
28646
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
51636
1+
51638

0 commit comments

Comments
 (0)