@@ -476,15 +476,20 @@ class Asm2WasmBuilder {
476476 }
477477 }
478478
479- FunctionType* getFunctionType (Ref parent, ExpressionList& operands ) {
480- WasmType result = none;
479+ WasmType getResultTypeOfCallUsingParent (Ref parent, AsmData* data ) {
480+ auto result = none;
481481 if (!!parent) {
482482 // if the parent is a seq, we cannot be the last element in it (we would have a coercion, which would be
483483 // the parent), so we must be (us, somethingElse), and so our return is void
484484 if (parent[0 ] != SEQ) {
485- result = detectWasmType (parent, nullptr );
485+ result = detectWasmType (parent, data );
486486 }
487487 }
488+ return result;
489+ }
490+
491+ FunctionType* getFunctionType (Ref parent, ExpressionList& operands, AsmData* data) {
492+ WasmType result = getResultTypeOfCallUsingParent (parent, data);
488493 return ensureFunctionType (getSig (result, operands), &wasm);
489494 }
490495
@@ -2189,7 +2194,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
21892194 if (tableCall) {
21902195 auto specific = ret->dynCast <CallIndirect>();
21912196 // note that we could also get the type from the suffix of the name, e.g., mftCall_vi
2192- auto * fullType = getFunctionType (astStackHelper.getParent (), specific->operands );
2197+ auto * fullType = getFunctionType (astStackHelper.getParent (), specific->operands , &asmData );
21932198 specific->fullType = fullType->name ;
21942199 specific->type = fullType->result ;
21952200 }
@@ -2202,8 +2207,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
22022207 // this is important as we run the optimizer on functions before we get
22032208 // to finalizeCalls (which we can only do once we've read all the functions,
22042209 // and we optimize in parallel starting earlier).
2205- Ref parent = astStackHelper.getParent ();
2206- callImport->type = !!parent ? detectWasmType (parent, &asmData) : none;
2210+ callImport->type = getResultTypeOfCallUsingParent (astStackHelper.getParent (), &asmData);
22072211 noteImportedFunctionCall (ast, callImport->type , callImport);
22082212 }
22092213 return ret;
@@ -2217,7 +2221,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
22172221 for (unsigned i = 0 ; i < args->size (); i++) {
22182222 ret->operands .push_back (process (args[i]));
22192223 }
2220- auto * fullType = getFunctionType (astStackHelper.getParent (), ret->operands );
2224+ auto * fullType = getFunctionType (astStackHelper.getParent (), ret->operands , &asmData );
22212225 ret->fullType = fullType->name ;
22222226 ret->type = fullType->result ;
22232227 // we don't know the table offset yet. emit target = target + callImport(tableName), which we fix up later when we know how asm function tables are layed out inside the wasm table.
0 commit comments