From 1005b1267f70a5a7cf7a8774af6c12d813464720 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 20 Oct 2017 19:38:31 -0700 Subject: Emit binary function index in comment in text format, for convenience (#1232) --- src/passes/Print.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/passes/Print.cpp') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 6d40034fc..beae693d9 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace wasm { @@ -47,6 +48,8 @@ struct PrintSExpression : public Visitor { Function* currFunction = nullptr; Function::DebugLocation lastPrintedLocation; + std::unordered_map functionIndexes; + PrintSExpression(std::ostream& o) : o(o) { setMinify(false); if (!full) full = isFullForced(); @@ -686,6 +689,14 @@ struct PrintSExpression : public Visitor { lastPrintedLocation = { 0, 0, 0 }; printOpening(o, "func ", true); printName(curr->name); + if (currModule && !minify) { + // emit the function index in a comment + if (functionIndexes.empty()) { + ModuleUtils::BinaryIndexes indexes(*currModule); + functionIndexes = std::move(indexes.functionIndexes); + } + o << " (; " << functionIndexes[curr->name] << " ;)"; + } if (curr->type.is()) { o << maybeSpace << "(type " << curr->type << ')'; } -- cgit v1.2.3