diff options
author | Thomas Lively <tlively@google.com> | 2023-01-10 13:53:12 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-10 11:53:12 -0800 |
commit | 36e2abbcdd22b2b1707757b49fb4ac8844f28e5d (patch) | |
tree | f869cebf2c8d772f8f85db83f39aadfd6ac6f7cb /src/passes/Print.cpp | |
parent | e6efd7b991a9c55115771ea121b0eff2bace7d3e (diff) | |
download | binaryen-36e2abbcdd22b2b1707757b49fb4ac8844f28e5d.tar.gz binaryen-36e2abbcdd22b2b1707757b49fb4ac8844f28e5d.tar.bz2 binaryen-36e2abbcdd22b2b1707757b49fb4ac8844f28e5d.zip |
Represent ref.as_{func,data,i31} with RefCast (#5413)
These operations are deprecated and directly representable as casts, so remove
their opcodes in the internal IR and parse them as casts instead. For now, add
logic to the printing and binary writing of RefCast to continue emitting the
legacy instructions to minimize test changes. The few test changes necessary are
because it is no longer valid to perform a ref.as_func on values outside the
func type hierarchy now that ref.as_func is subject to the ref.cast validation
rules.
RefAsExternInternalize, RefAsExternExternalize, and RefAsNonNull are left
unmodified. A future PR may remove RefAsNonNull as well, since it is also
expressible with casts.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r-- | src/passes/Print.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 12c185e69..e0d9a46a3 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2122,6 +2122,23 @@ struct PrintExpressionContents if (curr->safety == RefCast::Unsafe) { printMedium(o, "ref.cast_nop "); } else { + // TODO: These instructions are deprecated. Remove them. + if (auto type = curr->type.getHeapType(); + type.isBasic() && curr->type.isNonNullable()) { + switch (type.getBasic()) { + case HeapType::func: + printMedium(o, "ref.as_func"); + return; + case HeapType::data: + printMedium(o, "ref.as_data"); + return; + case HeapType::i31: + printMedium(o, "ref.as_i31"); + return; + default: + break; + } + } if (curr->type.isNullable()) { printMedium(o, "ref.cast null "); } else { @@ -2329,15 +2346,6 @@ struct PrintExpressionContents case RefAsNonNull: printMedium(o, "ref.as_non_null"); break; - case RefAsFunc: - printMedium(o, "ref.as_func"); - break; - case RefAsData: - printMedium(o, "ref.as_data"); - break; - case RefAsI31: - printMedium(o, "ref.as_i31"); - break; case ExternInternalize: printMedium(o, "extern.internalize"); break; |