summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild-js.sh1
-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
-rw-r--r--test/passes/print-function-map.txt13
-rw-r--r--test/passes/print-function-map.wast6
7 files changed, 70 insertions, 0 deletions
diff --git a/build-js.sh b/build-js.sh
index 61bed4b8f..71bed923e 100755
--- a/build-js.sh
+++ b/build-js.sh
@@ -129,6 +129,7 @@ mkdir -p ${OUT}
$BINARYEN_SRC/passes/Precompute.cpp \
$BINARYEN_SRC/passes/Print.cpp \
$BINARYEN_SRC/passes/PrintFeatures.cpp \
+ $BINARYEN_SRC/passes/PrintFunctionMap.cpp \
$BINARYEN_SRC/passes/PrintCallGraph.cpp \
$BINARYEN_SRC/passes/RedundantSetElimination.cpp \
$BINARYEN_SRC/passes/RelooperJumpThreading.cpp \
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();
diff --git a/test/passes/print-function-map.txt b/test/passes/print-function-map.txt
new file mode 100644
index 000000000..a10c11a1b
--- /dev/null
+++ b/test/passes/print-function-map.txt
@@ -0,0 +1,13 @@
+0:Foo
+1:bar
+2:baz
+(module
+ (type $FUNCSIG$v (func))
+ (import "env" "foo" (func $Foo))
+ (func $bar (; 1 ;) (type $FUNCSIG$v)
+ (nop)
+ )
+ (func $baz (; 2 ;) (type $FUNCSIG$v)
+ (nop)
+ )
+)
diff --git a/test/passes/print-function-map.wast b/test/passes/print-function-map.wast
new file mode 100644
index 000000000..91b638ba9
--- /dev/null
+++ b/test/passes/print-function-map.wast
@@ -0,0 +1,6 @@
+(module
+ (import "env" "foo" (func $Foo))
+ (func $bar)
+ (func $baz)
+)
+