diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cfg/cfg-traversal.h | 28 | ||||
-rw-r--r-- | src/wasm-traversal.h | 2 |
2 files changed, 16 insertions, 14 deletions
diff --git a/src/cfg/cfg-traversal.h b/src/cfg/cfg-traversal.h index 39f71dd6c..3f2eecb88 100644 --- a/src/cfg/cfg-traversal.h +++ b/src/cfg/cfg-traversal.h @@ -101,6 +101,10 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> { // but their usage does not overlap in time, and this is more efficient. std::vector<std::vector<BasicBlock*>> processCatchStack; + // Stack to store the catch indices within catch bodies. To be used in + // doStartCatch and doEndCatch. + std::vector<Index> catchIndexStack; + BasicBlock* startBasicBlock() { currBasicBlock = ((SubType*)this)->makeBasicBlock(); basicBlocks.push_back(std::unique_ptr<BasicBlock>(currBasicBlock)); @@ -304,16 +308,20 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> { self->processCatchStack.push_back(self->unwindCatchStack.back()); self->unwindCatchStack.pop_back(); self->unwindExprStack.pop_back(); + self->catchIndexStack.push_back(0); } - static void doStartCatch(SubType* self, Expression** currp, Index i) { + static void doStartCatch(SubType* self, Expression** currp) { // Get the block that starts this catch - self->currBasicBlock = self->processCatchStack.back()[i]; + self->currBasicBlock = + self->processCatchStack.back()[self->catchIndexStack.back()]; } - static void doEndCatch(SubType* self, Expression** currp, Index i) { + static void doEndCatch(SubType* self, Expression** currp) { // We are done with this catch; set the block that ends it - self->processCatchStack.back()[i] = self->currBasicBlock; + self->processCatchStack.back()[self->catchIndexStack.back()] = + self->currBasicBlock; + self->catchIndexStack.back()++; } static void doEndTry(SubType* self, Expression** currp) { @@ -326,6 +334,7 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> { self->link(self->tryStack.back(), self->currBasicBlock); self->tryStack.pop_back(); self->processCatchStack.pop_back(); + self->catchIndexStack.pop_back(); } static void doEndThrow(SubType* self, Expression** currp) { @@ -381,17 +390,10 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> { case Expression::Id::TryId: { self->pushTask(SubType::doEndTry, currp); auto& catchBodies = curr->cast<Try>()->catchBodies; - using namespace std::placeholders; for (Index i = 0; i < catchBodies.size(); i++) { - auto doEndCatchI = [i](SubType* self, Expression** currp) { - doEndCatch(self, currp, i); - }; - self->pushTask(doEndCatchI, currp); + self->pushTask(doEndCatch, currp); self->pushTask(SubType::scan, &catchBodies[i]); - auto doStartCatchI = [i](SubType* self, Expression** currp) { - doStartCatch(self, currp, i); - }; - self->pushTask(doStartCatchI, currp); + self->pushTask(doStartCatch, currp); } self->pushTask(SubType::doStartCatches, currp); self->pushTask(SubType::scan, &curr->cast<Try>()->body); diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 388584fd6..eb91184e5 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -282,7 +282,7 @@ struct Walker : public VisitorType { // nested. // Tasks receive the this pointer and a pointer to the pointer to operate on - using TaskFunc = std::function<void(SubType*, Expression**)>; + typedef void (*TaskFunc)(SubType*, Expression**); struct Task { TaskFunc func; |