diff --git a/src/pass.h b/src/pass.h index 47e7a2789fc..c9f239e1d08 100644 --- a/src/pass.h +++ b/src/pass.h @@ -188,7 +188,7 @@ struct PassOptions { bool debugInfo = false; // Arbitrary string arguments from the commandline, which we forward to // passes. - std::map arguments; + std::unordered_map arguments; // Effect info computed for functions. One pass can generate this and then // other passes later can benefit from it. It is up to the sequence of passes @@ -217,15 +217,19 @@ struct PassOptions { return PassOptions(); // defaults are to not optimize } + bool hasArgument(std::string key) { + return arguments.count(key) > 0; + } + std::string getArgument(std::string key, std::string errorTextIfMissing) { - if (arguments.count(key) == 0) { + if (!hasArgument(key)) { Fatal() << errorTextIfMissing; } return arguments[key]; } std::string getArgumentOrDefault(std::string key, std::string default_) { - if (arguments.count(key) == 0) { + if (!hasArgument(key)) { return default_; } return arguments[key]; diff --git a/src/passes/Asyncify.cpp b/src/passes/Asyncify.cpp index 9be731d0604..a97c2019e89 100644 --- a/src/passes/Asyncify.cpp +++ b/src/passes/Asyncify.cpp @@ -1536,8 +1536,7 @@ struct Asyncify : public Pass { String::Split listedImports(stateChangingImports, ","); // TODO: consider renaming asyncify-ignore-indirect to // asyncify-ignore-nondirect, but that could break users. - auto ignoreNonDirect = - options.getArgumentOrDefault("asyncify-ignore-indirect", "") == ""; + auto ignoreNonDirect = options.hasArgument("asyncify-ignore-indirect"); std::string removeListInput = options.getArgumentOrDefault("asyncify-removelist", ""); if (removeListInput.empty()) { @@ -1558,12 +1557,10 @@ struct Asyncify : public Pass { } String::Split onlyList( String::trim(read_possible_response_file(onlyListInput)), ","); - auto asserts = options.getArgumentOrDefault("asyncify-asserts", "") != ""; - auto verbose = options.getArgumentOrDefault("asyncify-verbose", "") != ""; - auto relocatable = - options.getArgumentOrDefault("asyncify-relocatable", "") != ""; - auto secondaryMemory = - options.getArgumentOrDefault("asyncify-in-secondary-memory", "") != ""; + auto asserts = options.hasArgument("asyncify-asserts"); + auto verbose = options.hasArgument("asyncify-verbose"); + auto relocatable = options.hasArgument("asyncify-relocatable"); + auto secondaryMemory = options.hasArgument("asyncify-in-secondary-memory"); // Ensure there is a memory, as we need it. if (secondaryMemory) { diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp index 86b7b8bc3ad..ea4922e3a1b 100644 --- a/src/passes/PostEmscripten.cpp +++ b/src/passes/PostEmscripten.cpp @@ -214,12 +214,19 @@ struct PostEmscripten : public Pass { std::vector
segmentOffsets; // segment index => address offset calcSegmentOffsets(module, segmentOffsets); - removeData(module, segmentOffsets, "__start_em_asm", "__stop_em_asm"); + auto& options = getPassOptions(); + auto sideModule = options.hasArgument("post-emscripten-side-module"); + if (!sideModule) { + // Side modules read EM_ASM data from the module based on these exports + // so we need to keep them around in that case. + removeData(module, segmentOffsets, "__start_em_asm", "__stop_em_asm"); + module.removeExport("__start_em_asm"); + module.removeExport("__stop_em_asm"); + } + removeData(module, segmentOffsets, "__start_em_js", "__stop_em_js"); removeData( module, segmentOffsets, "__start_em_lib_deps", "__stop_em_lib_deps"); - module.removeExport("__start_em_asm"); - module.removeExport("__stop_em_asm"); module.removeExport("__start_em_js"); module.removeExport("__stop_em_js"); module.removeExport("__start_em_lib_deps");