diff options
author | Sam Clegg <sbc@chromium.org> | 2020-08-05 18:27:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-05 18:27:20 -0700 |
commit | 550b36a1866a262f21c008a4d8cbaf65d14d0c01 (patch) | |
tree | 30c0edc27f01b812e67db13bfcdeedbc09d3a695 /src/tools/wasm-emscripten-finalize.cpp | |
parent | e93fbc0c117bcfe645bab1b30d5802e619e68abc (diff) | |
download | binaryen-550b36a1866a262f21c008a4d8cbaf65d14d0c01.tar.gz binaryen-550b36a1866a262f21c008a4d8cbaf65d14d0c01.tar.bz2 binaryen-550b36a1866a262f21c008a4d8cbaf65d14d0c01.zip |
Refactor wasm-emscripten-finalize to use a single pass runner (#2987)
Diffstat (limited to 'src/tools/wasm-emscripten-finalize.cpp')
-rw-r--r-- | src/tools/wasm-emscripten-finalize.cpp | 88 |
1 files changed, 41 insertions, 47 deletions
diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp index 8ca10b79b..7bb8ed310 100644 --- a/src/tools/wasm-emscripten-finalize.cpp +++ b/src/tools/wasm-emscripten-finalize.cpp @@ -241,30 +241,61 @@ int main(int argc, const char* argv[]) { } wasm.updateMaps(); + if (!standaloneWasm) { + // This is also not needed in standalone mode since standalone mode uses + // crt1.c to invoke the main and is aware of __main_argc_argv mangling. + generator.renameMainArgcArgv(); + } + + PassRunner passRunner(&wasm, options.passOptions); + passRunner.setDebug(options.debug); + passRunner.setDebugInfo(debugInfo); + if (checkStackOverflow && !sideModule) { - PassOptions options; if (!standaloneWasm) { // In standalone mode we don't set a handler at all.. which means // just trap on overflow. - options.arguments["stack-check-handler"] = "__handle_stack_overflow"; + passRunner.options.arguments["stack-check-handler"] = + "__handle_stack_overflow"; } - PassRunner passRunner(&wasm, options); passRunner.add("stack-check"); - passRunner.run(); } if (sideModule) { - BYN_TRACE("finalizing as side module\n"); - PassRunner passRunner(&wasm); passRunner.add("replace-stack-pointer"); passRunner.add("emscripten-pic"); - passRunner.run(); + } else { + passRunner.add("emscripten-pic-main-module"); + } + + if (!standaloneWasm) { + // If not standalone wasm then JS is relevant and we need dynCalls. + passRunner.add("generate-dyncalls"); + } + + // Legalize the wasm, if BigInts don't make that moot. + if (!bigInt) { + passRunner.add(ABI::getLegalizationPass( + legalizeJavaScriptFFI ? ABI::LegalizationLevel::Full + : ABI::LegalizationLevel::Minimal)); + } + + // Strip target features section (its information is in the metadata) + passRunner.add("strip-target-features"); + + // If DWARF is unused, strip it out. This avoids us keeping it alive + // until wasm-opt strips it later. + if (!DWARF) { + passRunner.add("strip-dwarf"); + } + + passRunner.run(); + + if (sideModule) { + BYN_TRACE("finalizing as side module\n"); generator.generatePostInstantiateFunction(); } else { BYN_TRACE("finalizing as regular module\n"); - PassRunner passRunner(&wasm); - passRunner.add("emscripten-pic-main-module"); - passRunner.run(); generator.internalizeStackPointerGlobal(); generator.generateMemoryGrowthFunction(); // For side modules these gets called via __post_instantiate @@ -285,28 +316,6 @@ int main(int argc, const char* argv[]) { } } - if (!standaloneWasm) { - // If not standalone wasm then JS is relevant and we need dynCalls. - PassRunner passRunner(&wasm); - passRunner.add("generate-dyncalls"); - passRunner.run(); - // This is also not needed in standalone mode since standalone mode uses - // crt1.c to invoke the main and is aware of __main_argc_argv mangling. - generator.renameMainArgcArgv(); - } - - // Legalize the wasm, if BigInts don't make that moot. - if (!bigInt) { - BYN_TRACE("legalizing types\n"); - PassRunner passRunner(&wasm, options.passOptions); - passRunner.setDebug(options.debug); - passRunner.setDebugInfo(debugInfo); - passRunner.add(ABI::getLegalizationPass( - legalizeJavaScriptFFI ? ABI::LegalizationLevel::Full - : ABI::LegalizationLevel::Minimal)); - passRunner.run(); - } - BYN_TRACE("generated metadata\n"); // Substantial changes to the wasm are done, enough to create the metadata. std::string metadata = @@ -326,21 +335,6 @@ int main(int argc, const char* argv[]) { BYN_DEBUG_WITH_TYPE("emscripten-dump", WasmPrinter::printModule(&wasm, std::cerr)); - // Strip target features section (its information is in the metadata) - { - PassRunner passRunner(&wasm); - passRunner.add("strip-target-features"); - passRunner.run(); - } - - // If DWARF is unused, strip it out. This avoids us keeping it alive - // until wasm-opt strips it later. - if (!DWARF) { - PassRunner passRunner(&wasm); - passRunner.add("strip-dwarf"); - passRunner.run(); - } - Output output(outfile, emitBinary ? Flags::Binary : Flags::Text); ModuleWriter writer; writer.setDebugInfo(debugInfo); |