From 1d57ca88b8dc1f18f7a311cd8c2656d87f82d5e1 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 11 Apr 2019 13:38:46 -0700 Subject: [PATCH 1/2] Reorder when we render the pre js code in jsifier.js. Doing it after libraries means we can know at pre render time which library code is included --- src/jsifier.js | 51 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/src/jsifier.js b/src/jsifier.js index 394ef40a2c5f..060ca1ed6982 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -52,42 +52,6 @@ function JSify(data, functionsOnly) { var itemsDict = { type: [], GlobalVariableStub: [], functionStub: [], function: [], GlobalVariable: [], GlobalVariablePostSet: [] }; - if (mainPass) { - var shellFile = SHELL_FILE ? SHELL_FILE : (SIDE_MODULE ? 'shell_sharedlib.js' : (MINIMAL_RUNTIME ? 'shell_minimal.js' : 'shell.js')); - - // We will start to print out the data, but must do so carefully - we are - // dealing with potentially *huge* strings. Convenient replacements and - // manipulations may create in-memory copies, and we may OOM. - // - // Final shape that will be created: - // shell - // (body) - // preamble - // runtime - // generated code - // postamble - // global_vars - // - // First, we print out everything until the generated code. Then the - // functions will print themselves out as they are parsed. Finally, we - // will call finalCombiner in the main pass, to print out everything - // else. This lets us not hold any strings in memory, we simply print - // things out as they are ready. - - var shellParts = read(shellFile).split('{{BODY}}'); - print(processMacros(preprocess(shellParts[0], shellFile))); - var pre; - if (SIDE_MODULE) { - pre = processMacros(preprocess(read('preamble_sharedlib.js'), 'preamble_sharedlib.js')); - } else if (MINIMAL_RUNTIME) { - pre = processMacros(preprocess(read('preamble_minimal.js'), 'preamble_minimal.js')); - } else { - pre = processMacros(preprocess(read('support.js'), 'support.js')) + - processMacros(preprocess(read('preamble.js'), 'preamble.js')); - } - print(pre); - } - if (mainPass) { // Add additional necessary items for the main pass. We can now do this since types are parsed (types can be used through // generateStructInfo in library.js) @@ -445,6 +409,21 @@ function JSify(data, functionsOnly) { return; } + var shellFile = SHELL_FILE ? SHELL_FILE : (SIDE_MODULE ? 'shell_sharedlib.js' : (MINIMAL_RUNTIME ? 'shell_minimal.js' : 'shell.js')); + + var shellParts = read(shellFile).split('{{BODY}}'); + print(processMacros(preprocess(shellParts[0], shellFile))); + var pre; + if (SIDE_MODULE) { + pre = processMacros(preprocess(read('preamble_sharedlib.js'), 'preamble_sharedlib.js')); + } else if (MINIMAL_RUNTIME) { + pre = processMacros(preprocess(read('preamble_minimal.js'), 'preamble_minimal.js')); + } else { + pre = processMacros(preprocess(read('support.js'), 'support.js')) + + processMacros(preprocess(read('preamble.js'), 'preamble.js')); + } + print(pre); + // Print out global variables and postsets TODO: batching var legalizedI64sDefault = legalizedI64s; legalizedI64s = false; From e7bd61d04488085dde106cf09bb9a511aa7e714a Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 11 Apr 2019 13:42:44 -0700 Subject: [PATCH 2/2] remove some closure ignores, which are bad for code size --- src/closure-defined-fs-annotation.js | 10 ---------- src/library_glfw.js | 3 +++ tools/shared.py | 8 +++----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/closure-defined-fs-annotation.js b/src/closure-defined-fs-annotation.js index c38681f5168a..347f61e2ae35 100644 --- a/src/closure-defined-fs-annotation.js +++ b/src/closure-defined-fs-annotation.js @@ -8,16 +8,6 @@ var Browser; */ var SDL; -/** - * @suppress {duplicate, undefinedVars} - */ -var GL; - -/** - * @suppress {duplicate, undefinedVars} - */ -var GLctx; - /** * @suppress {duplicate, undefinedVars} */ diff --git a/src/library_glfw.js b/src/library_glfw.js index 84a7c0b4f865..50ccb13d32be 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js @@ -753,6 +753,7 @@ var LibraryGLFW = { event.preventDefault(); +#if '$FS' in addedLibraryItems var filenames = allocate(new Array(event.dataTransfer.files.length*4), 'i8*', ALLOC_NORMAL); var filenamesArray = []; var count = event.dataTransfer.files.length; @@ -794,6 +795,8 @@ var LibraryGLFW = { save(event.dataTransfer.files[i]); } +#endif // '$FS' in addedLibraryItems + return false; }, diff --git a/tools/shared.py b/tools/shared.py index c90572ce5d5f..f1788189ea3b 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -2378,12 +2378,10 @@ def closure_compiler(filename, pretty=True): if not Settings.ASMFS: # If we have filesystem disabled, tell Closure not to bark when there are syscalls emitted that still reference the nonexisting FS object. - if not Settings.FILESYSTEM: - CLOSURE_ANNOTATIONS += ['--js', path_from_root('src', 'closure-undefined-fs-annotation.js')] - - # If we do have filesystem enabled, tell Closure not to bark when FS references different libraries that might not exist. - if Settings.FILESYSTEM and not Settings.ASMFS: + if Settings.FILESYSTEM: CLOSURE_ANNOTATIONS += ['--js', path_from_root('src', 'closure-defined-fs-annotation.js')] + else: + CLOSURE_ANNOTATIONS += ['--js', path_from_root('src', 'closure-undefined-fs-annotation.js')] # Closure externs file contains known symbols to be extern to the minification, Closure # should not minify these symbol names.