summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-05-31 19:57:09 -0700
committerGitHub <noreply@github.com>2019-05-31 19:57:09 -0700
commit7306f60a4474ca1fa948bddee5c068e7c2f635f6 (patch)
treefa6536fabca61c76b6ddc332c004285db32df3f6 /src
parentc0fba4a898273b9998c7ce09a3663bb35271dbd7 (diff)
downloadbinaryen-7306f60a4474ca1fa948bddee5c068e7c2f635f6.tar.gz
binaryen-7306f60a4474ca1fa948bddee5c068e7c2f635f6.tar.bz2
binaryen-7306f60a4474ca1fa948bddee5c068e7c2f635f6.zip
Add --print-function-map to print out a map of function index to name (#2155)
* work * fix * fix * format
Diffstat (limited to 'src')
-rw-r--r--src/passes/CMakeLists.txt1
-rw-r--r--src/passes/PrintFunctionMap.cpp45
-rw-r--r--src/passes/pass.cpp3
-rw-r--r--src/passes/passes.h1
4 files changed, 50 insertions, 0 deletions
diff --git a/src/passes/CMakeLists.txt b/src/passes/CMakeLists.txt
index 6605d7a09..9120328d3 100644
--- a/src/passes/CMakeLists.txt
+++ b/src/passes/CMakeLists.txt
@@ -43,6 +43,7 @@ SET(passes_SOURCES
Print.cpp
PrintCallGraph.cpp
PrintFeatures.cpp
+ PrintFunctionMap.cpp
StackIR.cpp
Strip.cpp
StripTargetFeatures.cpp
diff --git a/src/passes/PrintFunctionMap.cpp b/src/passes/PrintFunctionMap.cpp
new file mode 100644
index 000000000..75db495fa
--- /dev/null
+++ b/src/passes/PrintFunctionMap.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2019 WebAssembly Community Group participants
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Prints the a map of function indexes to function names. This can be
+// useful for interpreting a stack trace from a production environment
+// where names did not exist on the client. The map looks like this:
+//
+// 0:foo
+// 1:bar
+// 2:baz
+//
+
+#include "pass.h"
+#include "wasm.h"
+
+namespace wasm {
+
+struct PrintFunctionMap : public Pass {
+ bool modifiesBinaryenIR() override { return false; }
+
+ void run(PassRunner* runner, Module* module) override {
+ Index i = 0;
+ for (auto& func : module->functions) {
+ std::cout << i++ << ':' << func->name.str << '\n';
+ }
+ }
+};
+
+Pass* createPrintFunctionMapPass() { return new PrintFunctionMap(); }
+
+} // namespace wasm
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index 84914f819..c29bb1e1a 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -211,6 +211,9 @@ void PassRegistry::registerPasses() {
"print-full", "print in full s-expression format", createFullPrinterPass);
registerPass(
"print-call-graph", "print call graph", createPrintCallGraphPass);
+ registerPass("print-function-map",
+ "print a map of function indexes to names",
+ createPrintFunctionMapPass);
registerPass("print-stack-ir",
"print out Stack IR (useful for internal debugging)",
createPrintStackIRPass);
diff --git a/src/passes/passes.h b/src/passes/passes.h
index f3bec3f04..f7c8fae77 100644
--- a/src/passes/passes.h
+++ b/src/passes/passes.h
@@ -72,6 +72,7 @@ Pass* createPrecomputePropagatePass();
Pass* createPrinterPass();
Pass* createPrintCallGraphPass();
Pass* createPrintFeaturesPass();
+Pass* createPrintFunctionMapPass();
Pass* createPrintStackIRPass();
Pass* createRelooperJumpThreadingPass();
Pass* createRemoveNonJSOpsPass();