@@ -80,15 +80,15 @@ class Flow {
8080 Flow (Name breakTo, Literal value) : values{value}, breakTo(breakTo) {}
8181 Flow (Name breakTo, Literals&& values)
8282 : values(std::move(values)), breakTo(breakTo) {}
83- Flow (Name breakTo, Name suspendTag, Literals&& values)
83+ Flow (Name breakTo, Tag* suspendTag, Literals&& values)
8484 : values(std::move(values)), breakTo(breakTo), suspendTag(suspendTag) {
8585 assert (breakTo == SUSPEND_FLOW);
8686 }
8787
8888 Literals values;
8989 Name breakTo; // if non-null, a break is going on
90- Name suspendTag; // if non-null, breakTo must be SUSPEND_FLOW, and this is the
91- // tag being suspended
90+ Tag* suspendTag = nullptr ; // if non-null, breakTo must be SUSPEND_FLOW, and
91+ // this is the tag being suspended
9292
9393 // A helper function for the common case where there is only one value
9494 const Literal& getSingleValue () {
@@ -123,7 +123,7 @@ class Flow {
123123 o << flow.values [i];
124124 }
125125 if (flow.suspendTag ) {
126- o << " [suspend:" << flow.suspendTag << ' ]' ;
126+ o << " [suspend:" << flow.suspendTag -> name << ' ]' ;
127127 }
128128 o << " })" ;
129129 return o;
@@ -3056,8 +3056,7 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
30563056 virtual ~ExternalInterface () = default ;
30573057 virtual void init (Module& wasm, SubType& instance) {}
30583058 virtual void importGlobals (GlobalValueSet& globals, Module& wasm) = 0;
3059- virtual Literals callImport (Function* import ,
3060- const Literals& arguments) = 0;
3059+ virtual Flow callImport (Function* import , const Literals& arguments) = 0;
30613060 virtual bool growMemory (Name name, Address oldSize, Address newSize) = 0;
30623061 virtual bool growTable (Name name,
30633062 const Literal& value,
@@ -3564,6 +3563,21 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
35643563 return inst->globals [global->name ];
35653564 }
35663565
3566+ // Get a tag object while looking through imports, i.e., this uses the name as
3567+ // the name of the tag in the current module, and finds the actual canonical
3568+ // Tag* object for it: the Tag in this module, if not imported, and if
3569+ // imported, the Tag in the originating module.
3570+ Tag* getCanonicalTag (Name name) {
3571+ auto * inst = self ();
3572+ auto * tag = inst->wasm .getTag (name);
3573+ while (tag->imported ()) {
3574+ inst = inst->linkedInstances .at (tag->module ).get ();
3575+ auto * tagExport = inst->wasm .getExport (tag->base );
3576+ tag = inst->wasm .getTag (*tagExport->getInternalName ());
3577+ }
3578+ return tag;
3579+ }
3580+
35673581public:
35683582 Flow visitCall (Call* curr) {
35693583 Name target = curr->target ;
@@ -4775,7 +4789,8 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
47754789 // We will resume from this precise spot, when the new continuation is
47764790 // resumed.
47774791 new_->resumeExpr = curr;
4778- return Flow (SUSPEND_FLOW, curr->tag , std::move (arguments));
4792+ return Flow (
4793+ SUSPEND_FLOW, self ()->getCanonicalTag (curr->tag ), std::move (arguments));
47794794 }
47804795 Flow visitResume (Resume* curr) {
47814796 Literals arguments;
@@ -4825,10 +4840,10 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
48254840 } else {
48264841 // We are suspending. See if a suspension arrived that we support.
48274842 for (size_t i = 0 ; i < curr->handlerTags .size (); i++) {
4828- auto handlerTag = curr->handlerTags [i];
4843+ auto * handlerTag = self ()-> getCanonicalTag ( curr->handlerTags [i]) ;
48294844 if (handlerTag == ret.suspendTag ) {
48304845 // Switch the flow from suspending to branching.
4831- ret.suspendTag = Name () ;
4846+ ret.suspendTag = nullptr ;
48324847 ret.breakTo = curr->handlerBlocks [i];
48334848 // We can now update the continuation type, which was wrong until now
48344849 // (see comment in visitSuspend). The type is taken from the block we
@@ -4978,7 +4993,7 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
49784993
49794994#if WASM_INTERPRETER_DEBUG
49804995 std::cout << self ()->indent () << " exiting " << function->name << " with "
4981- << flow. values << ' \n ' ;
4996+ << flow << ' \n ' ;
49824997#endif
49834998
49844999 if (flow.suspendTag ) {
0 commit comments