From e09fb5656d5e791051393bd08e6522f068ec7fe4 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Fri, 23 Sep 2022 10:46:38 -0500 Subject: Emit call_ref with a type annotation (#5079) Emit call_ref instructions with type annotations and a temporary opcode. Also implement support for parsing optional type annotations on call_ref in the text and binary formats. This is part of a multi-part graceful update to switch Binaryen and all of its users over to using the type-annotated version of call_ref without there being any breakage. --- src/wasm/wasm-s-parser.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/wasm/wasm-s-parser.cpp') diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index cf4824323..6de8744a6 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2831,22 +2831,31 @@ Expression* SExpressionWasmBuilder::makeTupleExtract(Element& s) { Expression* SExpressionWasmBuilder::makeCallRef(Element& s, bool isReturn) { Index operandsStart = 1; - HeapType sigType; - if (isReturn) { + std::optional sigType; + try { sigType = parseHeapType(*s[1]); operandsStart = 2; + } catch (ParseException& p) { + // The type annotation is required for return_call_ref but temporarily + // optional for call_ref. + if (isReturn) { + throw; + } } std::vector operands; parseOperands(s, operandsStart, s.size() - 1, operands); auto* target = parseExpression(s[s.size() - 1]); - if (isReturn) { - if (!sigType.isSignature()) { + if (sigType) { + if (!sigType->isSignature()) { throw ParseException( - "return_call_ref type annotation should be a signature", s.line, s.col); + std::string(isReturn ? "return_call_ref" : "call_ref") + + " type annotation should be a signature", + s.line, + s.col); } return Builder(wasm).makeCallRef( - target, operands, sigType.getSignature().results, isReturn); + target, operands, sigType->getSignature().results, isReturn); } return ValidatingBuilder(wasm, s.line, s.col) .validateAndMakeCallRef(target, operands, isReturn); -- cgit v1.2.3