4
4
* SPDX-License-Identifier: MIT
5
5
*/
6
6
7
- // "use strict";
8
-
9
7
// Convert analyzed data to javascript. Everything has already been calculated
10
8
// before this stage, which just does the final conversion to JavaScript.
11
9
12
- globalThis . addedLibraryItems = { } ;
13
-
14
- globalThis . extraLibraryFuncs = [ ] ;
10
+ import {
11
+ ATEXITS ,
12
+ ATINITS ,
13
+ ATMAINS ,
14
+ defineI64Param ,
15
+ indentify ,
16
+ makeReturn64 ,
17
+ modifyJSFunction ,
18
+ preprocess ,
19
+ processMacros ,
20
+ receiveI64ParamAsI53 ,
21
+ } from './parseTools.mjs' ;
22
+ import {
23
+ addToCompileTimeContext ,
24
+ assert ,
25
+ error ,
26
+ errorOccured ,
27
+ isDecorator ,
28
+ isJsOnlySymbol ,
29
+ compileTimeContext ,
30
+ print ,
31
+ printErr ,
32
+ read ,
33
+ warn ,
34
+ warningOccured ,
35
+ } from './utility.mjs' ;
36
+ import { LibraryManager , librarySymbols } from './modules.mjs' ;
37
+
38
+ const addedLibraryItems = { } ;
39
+
40
+ const extraLibraryFuncs = [ ] ;
15
41
16
42
// Some JS-implemented library functions are proxied to be called on the main
17
43
// browser thread, if the Emscripten runtime is executing in a Web Worker.
18
44
// Each such proxied function is identified via an ordinal number (this is not
19
45
// the same namespace as function pointers in general).
20
- globalThis . proxiedFunctionTable = [ ] ;
46
+ const proxiedFunctionTable = [ ] ;
21
47
22
48
// Mangles the given C/JS side function name to assembly level function name (adds an underscore)
23
49
function mangleCSymbolName ( f ) {
@@ -121,7 +147,7 @@ function preJS() {
121
147
return result ;
122
148
}
123
149
124
- function runJSify ( ) {
150
+ export function runJSify ( symbolsOnly ) {
125
151
const libraryItems = [ ] ;
126
152
const symbolDeps = { } ;
127
153
const asyncFuncs = [ ] ;
@@ -162,7 +188,6 @@ function runJSify() {
162
188
. split ( ',' )
163
189
. map ( ( name ) => name . trim ( ) ) ;
164
190
const newArgs = [ ] ;
165
- let innerArgs = [ ] ;
166
191
let argConversions = '' ;
167
192
if ( sig . length > argNames . length + 1 ) {
168
193
error ( `handleI64Signatures: signature too long for ${ symbol } ` ) ;
@@ -188,7 +213,6 @@ function runJSify() {
188
213
}
189
214
}
190
215
191
- var origArgs = args ;
192
216
if ( ! WASM_BIGINT ) {
193
217
args = newArgs . join ( ',' ) ;
194
218
}
@@ -266,7 +290,7 @@ function(${args}) {
266
290
( ( i53abi && sig . includes ( 'j' ) ) || ( ( MEMORY64 || CAN_ADDRESS_2GB ) && sig . includes ( 'p' ) ) )
267
291
) {
268
292
snippet = handleI64Signatures ( symbol , snippet , sig , i53abi ) ;
269
- i53ConversionDeps . forEach ( ( d ) => deps . push ( d ) ) ;
293
+ compileTimeContext . i53ConversionDeps . forEach ( ( d ) => deps . push ( d ) ) ;
270
294
}
271
295
272
296
const proxyingMode = LibraryManager . library [ symbol + '__proxy' ] ;
@@ -348,7 +372,7 @@ function(${args}) {
348
372
if ( ! ( symbol in LibraryManager . library ) ) {
349
373
// Create a new __cxa_find_matching_catch variant on demand.
350
374
const num = + symbol . split ( '_' ) . slice ( - 1 ) [ 0 ] ;
351
- addCxaCatch ( num ) ;
375
+ compileTimeContext . addCxaCatch ( num ) ;
352
376
}
353
377
// Continue, with the code below emitting the proper JavaScript based on
354
378
// what we just added to the library.
@@ -376,7 +400,7 @@ function(${args}) {
376
400
LibraryManager . library [ symbol + '__deps' ] = [ ] ;
377
401
}
378
402
379
- deps = LibraryManager . library [ symbol + '__deps' ] ;
403
+ const deps = LibraryManager . library [ symbol + '__deps' ] ;
380
404
let sig = LibraryManager . library [ symbol + '__sig' ] ;
381
405
if ( ! WASM_BIGINT && sig && sig [ 0 ] == 'j' ) {
382
406
// Without WASM_BIGINT functions that return i64 depend on setTempRet0
@@ -466,12 +490,11 @@ function(${args}) {
466
490
// Create a stub for this symbol which can later be replaced by the
467
491
// dynamic linker. If this stub is called before the symbol is
468
492
// resolved assert in debug builds or trap in release builds.
493
+ let target = `wasmImports['${ symbol } ']` ;
469
494
if ( ASYNCIFY ) {
470
495
// See the definition of asyncifyStubs in preamble.js for why this
471
496
// is needed.
472
497
target = `asyncifyStubs['${ symbol } ']` ;
473
- } else {
474
- target = `wasmImports['${ symbol } ']` ;
475
498
}
476
499
let assertion = '' ;
477
500
if ( ASSERTIONS ) {
@@ -536,8 +559,6 @@ function(${args}) {
536
559
if ( VERBOSE ) {
537
560
printErr ( `adding ${ symbol } (referenced by ${ dependent } )` ) ;
538
561
}
539
- const deps_list = deps . join ( "','" ) ;
540
- const identDependents = symbol + `__deps: ['${ deps_list } ']` ;
541
562
function addDependency ( dep ) {
542
563
// dependencies can be JS functions, which we just run
543
564
if ( typeof dep == 'function' ) {
@@ -695,7 +716,7 @@ var proxiedFunctionTable = [
695
716
` ) ;
696
717
}
697
718
698
- if ( abortExecution ) {
719
+ if ( errorOccured ( ) ) {
699
720
throw Error ( 'Aborting compilation due to previous errors' ) ;
700
721
}
701
722
@@ -716,7 +737,7 @@ var proxiedFunctionTable = [
716
737
'//FORWARDED_DATA:' +
717
738
JSON . stringify ( {
718
739
librarySymbols,
719
- warnings,
740
+ warnings : warningOccured ( ) ,
720
741
asyncFuncs,
721
742
ATINITS : ATINITS . join ( '\n' ) ,
722
743
ATMAINS : STRICT ? '' : ATMAINS . join ( '\n' ) ,
@@ -741,7 +762,13 @@ var proxiedFunctionTable = [
741
762
finalCombiner ( ) ;
742
763
}
743
764
744
- if ( abortExecution ) {
765
+ if ( errorOccured ( ) ) {
745
766
throw Error ( 'Aborting compilation due to previous errors' ) ;
746
767
}
747
768
}
769
+
770
+ addToCompileTimeContext ( {
771
+ extraLibraryFuncs,
772
+ addedLibraryItems,
773
+ preJS,
774
+ } ) ;
0 commit comments