summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2020-04-09 11:41:40 -0700
committerGitHub <noreply@github.com>2020-04-09 11:41:40 -0700
commit9c75b8f8ef58347f2fab44463f9a65eb37212742 (patch)
tree8660dbae4ade8d07c7dc62bc76da0da13e35dd73 /src
parentb3d79f406ab80d5f36995e03385df3903e52f46e (diff)
downloadbinaryen-9c75b8f8ef58347f2fab44463f9a65eb37212742.tar.gz
binaryen-9c75b8f8ef58347f2fab44463f9a65eb37212742.tar.bz2
binaryen-9c75b8f8ef58347f2fab44463f9a65eb37212742.zip
Remove function index printing (#2742)
`BinaryIndexes` was only used in two places (Print.cpp and wasm-binary.h), so it didn't seem to be a great fit for module-utils.h. This change moves it to wasm-binary.h and removes its usage in Print.cpp. This means that function indexes are no longer printed, but those were of limited utility and were the source of annoying noise when updating tests, anyway.
Diffstat (limited to 'src')
-rw-r--r--src/ir/module-utils.h52
-rw-r--r--src/passes/Print.cpp10
-rw-r--r--src/wasm-binary.h54
3 files changed, 53 insertions, 63 deletions
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h
index 485bc4833..e589f5052 100644
--- a/src/ir/module-utils.h
+++ b/src/ir/module-utils.h
@@ -28,58 +28,6 @@ namespace wasm {
namespace ModuleUtils {
-// Computes the indexes in a wasm binary, i.e., with function imports
-// and function implementations sharing a single index space, etc.,
-// and with the imports first (the Module's functions and globals
-// arrays are not assumed to be in a particular order, so we can't
-// just use them directly).
-struct BinaryIndexes {
- std::unordered_map<Name, Index> functionIndexes;
- std::unordered_map<Name, Index> eventIndexes;
- std::unordered_map<Name, Index> globalIndexes;
-
- BinaryIndexes(Module& wasm) {
- auto addIndexes = [&](auto& source, auto& indexes) {
- auto addIndex = [&](auto* curr) {
- auto index = indexes.size();
- indexes[curr->name] = index;
- };
- for (auto& curr : source) {
- if (curr->imported()) {
- addIndex(curr.get());
- }
- }
- for (auto& curr : source) {
- if (!curr->imported()) {
- addIndex(curr.get());
- }
- }
- };
- addIndexes(wasm.functions, functionIndexes);
- addIndexes(wasm.events, eventIndexes);
-
- // Globals may have tuple types in the IR, in which case they lower to
- // multiple globals, one for each tuple element, in the binary. Tuple
- // globals therefore occupy multiple binary indices, and we have to take
- // that into account when calculating indices.
- Index globalCount = 0;
- auto addGlobal = [&](auto* curr) {
- globalIndexes[curr->name] = globalCount;
- globalCount += curr->type.size();
- };
- for (auto& curr : wasm.globals) {
- if (curr->imported()) {
- addGlobal(curr.get());
- }
- }
- for (auto& curr : wasm.globals) {
- if (!curr->imported()) {
- addGlobal(curr.get());
- }
- }
- }
-};
-
inline Function* copyFunction(Function* func, Module& out) {
auto* ret = new Function();
ret->name = func->name;
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 18f2beb43..a87eae325 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -1455,8 +1455,6 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
Function::DebugLocation lastPrintedLocation;
bool debugInfo;
- std::unordered_map<Name, Index> functionIndexes;
-
PrintSExpression(std::ostream& o) : o(o) {
setMinify(false);
if (!full) {
@@ -2124,14 +2122,6 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
o << '(';
printMajor(o, "func ");
printName(curr->name, o);
- 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 (!printStackIR && curr->stackIR && !minify) {
o << " (; has Stack IR ;)";
}
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 1a13dbb75..7063dc5f9 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -951,6 +951,58 @@ inline S32LEB binaryType(Type type) {
// Writes out wasm to the binary format
class WasmBinaryWriter {
+ // Computes the indexes in a wasm binary, i.e., with function imports
+ // and function implementations sharing a single index space, etc.,
+ // and with the imports first (the Module's functions and globals
+ // arrays are not assumed to be in a particular order, so we can't
+ // just use them directly).
+ struct BinaryIndexes {
+ std::unordered_map<Name, Index> functionIndexes;
+ std::unordered_map<Name, Index> eventIndexes;
+ std::unordered_map<Name, Index> globalIndexes;
+
+ BinaryIndexes(Module& wasm) {
+ auto addIndexes = [&](auto& source, auto& indexes) {
+ auto addIndex = [&](auto* curr) {
+ auto index = indexes.size();
+ indexes[curr->name] = index;
+ };
+ for (auto& curr : source) {
+ if (curr->imported()) {
+ addIndex(curr.get());
+ }
+ }
+ for (auto& curr : source) {
+ if (!curr->imported()) {
+ addIndex(curr.get());
+ }
+ }
+ };
+ addIndexes(wasm.functions, functionIndexes);
+ addIndexes(wasm.events, eventIndexes);
+
+ // Globals may have tuple types in the IR, in which case they lower to
+ // multiple globals, one for each tuple element, in the binary. Tuple
+ // globals therefore occupy multiple binary indices, and we have to take
+ // that into account when calculating indices.
+ Index globalCount = 0;
+ auto addGlobal = [&](auto* curr) {
+ globalIndexes[curr->name] = globalCount;
+ globalCount += curr->type.size();
+ };
+ for (auto& curr : wasm.globals) {
+ if (curr->imported()) {
+ addGlobal(curr.get());
+ }
+ }
+ for (auto& curr : wasm.globals) {
+ if (!curr->imported()) {
+ addGlobal(curr.get());
+ }
+ }
+ }
+ };
+
public:
WasmBinaryWriter(Module* input, BufferWithRandomAccess& o)
: wasm(input), o(o), indexes(*input) {
@@ -1050,7 +1102,7 @@ public:
private:
Module* wasm;
BufferWithRandomAccess& o;
- ModuleUtils::BinaryIndexes indexes;
+ BinaryIndexes indexes;
std::unordered_map<Signature, Index> typeIndices;
std::vector<Signature> types;