summaryrefslogtreecommitdiff
path: root/src/ir/iteration.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir/iteration.h')
-rw-r--r--src/ir/iteration.h23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/ir/iteration.h b/src/ir/iteration.h
index 29d183678..6574e5dff 100644
--- a/src/ir/iteration.h
+++ b/src/ir/iteration.h
@@ -58,15 +58,21 @@ template<class Specific> class AbstractChildIterator {
void operator++() { index++; }
Expression*& operator*() {
- assert(index < parent.children.size());
-
- // The vector of children is in reverse order, as that is how
- // wasm-delegations-fields works. To get the order of execution, reverse
- // things.
- return *parent.children[parent.children.size() - 1 - index];
+ return *parent.children[parent.mapIndex(index)];
}
};
+ friend struct Iterator;
+
+ Index mapIndex(Index index) const {
+ assert(index < children.size());
+
+ // The vector of children is in reverse order, as that is how
+ // wasm-delegations-fields works. To get the order of execution, reverse
+ // things.
+ return children.size() - 1 - index;
+ }
+
public:
// The vector of children in the order emitted by wasm-delegations-fields
// (which is in reverse execution order).
@@ -112,6 +118,11 @@ public:
void addChild(Expression* parent, Expression** child) {
children.push_back(child);
}
+
+ // API for accessing children in random order.
+ Expression*& getChild(Index index) { return *children[mapIndex(index)]; }
+
+ Index getNumChildren() { return children.size(); }
};
class ChildIterator : public AbstractChildIterator<ChildIterator> {