summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-07-22 18:00:52 -0700
committerGitHub <noreply@github.com>2019-07-22 18:00:52 -0700
commitff2b10bd641039e2cf4eb00b767ac5139a41583e (patch)
tree1d5b392d8708e90ea48cccb6e0a20a424aa198f7 /src/wasm
parentc8101d1b67ffcce38718f07ba560ce56ddb3f240 (diff)
downloadbinaryen-ff2b10bd641039e2cf4eb00b767ac5139a41583e.tar.gz
binaryen-ff2b10bd641039e2cf4eb00b767ac5139a41583e.tar.bz2
binaryen-ff2b10bd641039e2cf4eb00b767ac5139a41583e.zip
wasm-emscripten-finalize: Add mainReadsParams metadata (#2247)
The new flag indicates whether main reads the argc/argv parameters. If it does not, we can avoid emitting code to generate those arguments in the JS, which is not trivial in small programs - it requires some string conversion code. Nicely the existing test inputs were enough for testing this (see outputs). This depends on an emscripten change to land first, as emscripten.py asserts on metadata fields it doesn't recognize.
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-emscripten.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index a3433bf9f..3ee3e4424 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -1042,7 +1042,23 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata(
wasm.features.iterFeatures([&](FeatureSet::Feature f) {
meta << nextElement() << "\"--enable-" << FeatureSet::toString(f) << '"';
});
- meta << "\n ]\n";
+ meta << "\n ],\n";
+
+ auto mainReadsParams = false;
+ if (auto* exp = wasm.getExportOrNull("main")) {
+ if (exp->kind == ExternalKind::Function) {
+ auto* main = wasm.getFunction(exp->value);
+ mainReadsParams = true;
+ // If main does not read its parameters, it will just be a stub that
+ // calls __original_main (which has no parameters).
+ if (auto* call = main->body->dynCast<Call>()) {
+ if (call->operands.empty()) {
+ mainReadsParams = false;
+ }
+ }
+ }
+ }
+ meta << " \"mainReadsParams\": " << int(mainReadsParams) << '\n';
meta << "}\n";