summaryrefslogtreecommitdiff
path: root/src/wasm-traversal.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-05-16 21:40:46 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-05-17 11:03:59 -0700
commit700846f46148cc92485c59b37b46272978ab3e42 (patch)
treec33e362350915a30c0a0068252b417978fb3ddbb /src/wasm-traversal.h
parente86d46fb38ece8c35e50bf1f483cac49796a8b39 (diff)
downloadbinaryen-700846f46148cc92485c59b37b46272978ab3e42.tar.gz
binaryen-700846f46148cc92485c59b37b46272978ab3e42.tar.bz2
binaryen-700846f46148cc92485c59b37b46272978ab3e42.zip
allow inheriting function-parallel classes, add a hook for creation
Diffstat (limited to 'src/wasm-traversal.h')
-rw-r--r--src/wasm-traversal.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h
index afa20ecb5..d7fc83f59 100644
--- a/src/wasm-traversal.h
+++ b/src/wasm-traversal.h
@@ -154,6 +154,14 @@ struct Walker : public VisitorType {
// function either (which could be very inefficient).
bool isFunctionParallel() { return false; }
+ // This method is used to create instances per function for a function-parallel
+ // pass. You may need to override this if you subclass a Walker, as otherwise
+ // this will create the parent class.
+ // Note that this returns nullptr, and we check if the result is nullptr and
+ // do new SubType later. This is important since non-function parallel
+ // passes may not be constructable via new SubType.
+ virtual SubType* create() { return nullptr; }
+
// Useful methods for visitor implementions
// Replace the current node. You can call this in your visit*() methods.
@@ -191,13 +199,14 @@ struct Walker : public VisitorType {
self->visitExport(curr.get());
}
- auto processFunction = [](Module* module, SubType* instance, Function* func) {
+ auto processFunction = [this](Module* module, SubType* instance, Function* func) {
std::unique_ptr<SubType> allocated;
if (!instance) {
- instance = new SubType;
- allocated = std::unique_ptr<SubType>(instance);
+ instance = create();
+ if (!instance) instance = new SubType;
assert(module);
instance->setModule(module);
+ allocated = std::unique_ptr<SubType>(instance);
}
instance->setFunction(func);
instance->walk(func->body);