Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build-js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions src/passes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ SET(passes_SOURCES
Print.cpp
PrintCallGraph.cpp
PrintFeatures.cpp
PrintFunctionMap.cpp
StackIR.cpp
Strip.cpp
StripTargetFeatures.cpp
Expand Down
45 changes: 45 additions & 0 deletions src/passes/PrintFunctionMap.cpp
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/passes/pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/passes/passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Pass* createPrecomputePropagatePass();
Pass* createPrinterPass();
Pass* createPrintCallGraphPass();
Pass* createPrintFeaturesPass();
Pass* createPrintFunctionMapPass();
Pass* createPrintStackIRPass();
Pass* createRelooperJumpThreadingPass();
Pass* createRemoveNonJSOpsPass();
Expand Down
13 changes: 13 additions & 0 deletions test/passes/print-function-map.txt
Original file line number Diff line number Diff line change
@@ -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)
)
)
6 changes: 6 additions & 0 deletions test/passes/print-function-map.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(module
(import "env" "foo" (func $Foo))
(func $bar)
(func $baz)
)