diff options
author | Thomas Lively <tlively@google.com> | 2022-11-16 13:44:33 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-16 13:44:33 -0800 |
commit | 570007dbecf86db5ddba8d303896d841fc2b2d27 (patch) | |
tree | 6774a699ed3faf5f6f263b77025c30880e51fead /src/wasm-builder.h | |
parent | 3528a593f5a588d1819c6de9645b63361c13bf6b (diff) | |
download | binaryen-570007dbecf86db5ddba8d303896d841fc2b2d27.tar.gz binaryen-570007dbecf86db5ddba8d303896d841fc2b2d27.tar.bz2 binaryen-570007dbecf86db5ddba8d303896d841fc2b2d27.zip |
Revert "Make `call_ref` type annotations mandatory (#5246)" (#5265)
This reverts commit b2054b72b7daa89b7ad161c0693befad06a20c90.
It looks like the necessary V8 change has not rolled out everywhere yet.
Diffstat (limited to 'src/wasm-builder.h')
-rw-r--r-- | src/wasm-builder.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h index a29867e55..1eb31157d 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -1342,6 +1342,35 @@ public: } return makeBrOn(op, name, ref); } + + template<typename T> + Expression* validateAndMakeCallRef(Expression* target, + const T& args, + bool isReturn = false) { + if (target->type != Type::unreachable && !target->type.isRef()) { + throw ParseException("Non-reference type for a call_ref", line, col); + } + // TODO: This won't be necessary once type annotations are mandatory on + // call_ref. + if (target->type == Type::unreachable || + target->type.getHeapType() == HeapType::nofunc) { + // An unreachable target is not supported. Similiar to br_on_cast, just + // emit an unreachable sequence, since we don't have enough information + // to create a full call_ref. + std::vector<Expression*> children; + for (auto* arg : args) { + children.push_back(makeDrop(arg)); + } + children.push_back(makeDrop(target)); + children.push_back(makeUnreachable()); + return makeBlock(children, Type::unreachable); + } + auto heapType = target->type.getHeapType(); + if (!heapType.isSignature()) { + throw ParseException("Invalid reference type for a call_ref", line, col); + } + return makeCallRef(target, args, heapType.getSignature().results, isReturn); + } }; } // namespace wasm |