help
diff --git a/src/passes/hash-stringify-walker.cpp b/src/passes/hash-stringify-walker.cpp
index 3df01b2..b843033 100644
--- a/src/passes/hash-stringify-walker.cpp
+++ b/src/passes/hash-stringify-walker.cpp
@@ -57,15 +57,22 @@
// for Expressions
assert((uint32_t)nextSeparatorVal >= nextVal);
hashString.push_back((uint32_t)nextSeparatorVal);
+ exprs.push_back(NULL);
nextSeparatorVal--;
}
void HashStringifyWalker::visitExpression(Expression* curr) {
auto [it, inserted] = exprToCounter.insert({curr, nextVal});
hashString.push_back(it->second);
+ exprs.push_back(curr);
if (inserted) {
nextVal++;
}
}
+void HashStringifyWalker::markFunctionBegin(Name func) {
+ idxToFuncName.insert({hashString.size(), func});
+ funcIdx.insert(hashString.size());
+}
+
} // namespace wasm
diff --git a/src/passes/stringify-walker-impl.h b/src/passes/stringify-walker-impl.h
index e856773..a27b5ea 100644
--- a/src/passes/stringify-walker-impl.h
+++ b/src/passes/stringify-walker-impl.h
@@ -31,6 +31,7 @@
template<typename SubType>
inline void StringifyWalker<SubType>::doWalkFunction(Function* func) {
+ this->doMarkFunctionBegin(func->name);
walk(func->body);
/*
* We add a unique symbol after walking the function body to separate the
@@ -74,7 +75,8 @@
// This dequeueControlFlow is responsible for visiting the children expressions
// of control flow.
-template<typename SubType> void StringifyWalker<SubType>::dequeueControlFlow() {
+template<typename SubType>
+void StringifyWalker<SubType>::dequeueControlFlow() {
auto& queue = controlFlowQueue;
if (queue.empty()) {
return;
@@ -134,12 +136,20 @@
inline void StringifyWalker<SubType>::addUniqueSymbol() {
// TODO: Add the following static_assert when the compilers running our GitHub
// actions are updated enough to know that this is a constant condition:
- // static_assert(&StringifyWalker<SubType>::addUniqueSymbol !=
- // &SubType::addUniqueSymbol);
+ static_assert(&StringifyWalker<SubType>::addUniqueSymbol !=
+ &SubType::addUniqueSymbol);
auto self = static_cast<SubType*>(this);
self->addUniqueSymbol();
}
+template<typename SubType>
+inline void StringifyWalker<SubType>::doMarkFunctionBegin(Name func) {
+ //static_assert(&StringifyWalker<SubType>::doMarkFunctionBegin !=
+ //&SubType::markFunctionBegin);
+ auto self = static_cast<SubType*>(this);
+ self->markFunctionBegin(func);
+}
+
} // namespace wasm
#endif // wasm_passes_stringify_walker_impl_h
diff --git a/src/passes/stringify-walker.h b/src/passes/stringify-walker.h
index 7e18d3d..b73ef53 100644
--- a/src/passes/stringify-walker.h
+++ b/src/passes/stringify-walker.h
@@ -21,6 +21,7 @@
#include "ir/module-utils.h"
#include "ir/utils.h"
#include "wasm-traversal.h"
+#include "wasm.h"
#include <queue>
namespace wasm {
@@ -84,6 +85,7 @@
static void scan(SubType* self, Expression** currp);
static void doVisitExpression(SubType* self, Expression** currp);
+ void doMarkFunctionBegin(Name func);
private:
void dequeueControlFlow();
};
@@ -128,9 +130,19 @@
// when evaluating if expressions.
std::unordered_map<Expression*, uint32_t, StringifyHasher, StringifyEquator>
exprToCounter;
+ // This map is for keeping track of where each function begins in terms of
+ // index of index relative to the hashString
+ //
+ // The plan is to do a binary search of the keys of the unordered_map in order
+ // to determine which function needs to be iterated through to find the
+ // Expressions represented in the repeat substring
+ std::unordered_map<uint32_t, Name> idxToFuncName;
+ std::set<uint32_t>funcIdx;
void addUniqueSymbol();
void visitExpression(Expression* curr);
+ void markFunctionBegin(Name func);
+ std::vector<Expression *> exprs;
};
} // namespace wasm
diff --git a/test/gtest/stringify.cpp b/test/gtest/stringify.cpp
index 42f4e12..575a30b 100644
--- a/test/gtest/stringify.cpp
+++ b/test/gtest/stringify.cpp
@@ -253,3 +253,35 @@
// 7, 6 appears at idx 11 and again at 24
SuffixTree::RepeatedSubstring{2u, (std::vector<unsigned>{11, 24})}}));
}
+
+TEST_F(StringifyTest, FuncMap) {
+ auto dupFuncModuleText = R"wasm(
+ (module
+ (func $a
+ (block
+ (drop (i32.const 20))
+ )
+ )
+ (func $b
+ (drop (i32.const 5))
+ )
+ )
+ )wasm";
+ Module wasm;
+ parseWast(wasm, dupFuncModuleText);
+
+ HashStringifyWalker stringify = HashStringifyWalker();
+ stringify.walkModule(&wasm);
+ EXPECT_EQ(stringify.hashString,
+ (std::vector<uint32_t>{8}));
+
+ for (size_t i = 0; i < stringify.exprs.size(); i++) {
+ std::cout << i << ": (";
+ if (stringify.exprs[i]) {
+ std::cout << ShallowExpression{stringify.exprs[i], &wasm} << ")";
+ } else {
+ std::cout << "separator)";
+ }
+ std::cout << std::endl;
+ }
+}