Returns the [`Bitcast`] required to move a value of flat type `from` into flat type `to` under the canonical ABI's unification rules. Panics if the pair isn't a legal bitcast per the spec.
(from: WasmType, to: WasmType)
| 2657 | /// `from` into flat type `to` under the canonical ABI's unification |
| 2658 | /// rules. Panics if the pair isn't a legal bitcast per the spec. |
| 2659 | pub fn cast(from: WasmType, to: WasmType) -> Bitcast { |
| 2660 | use WasmType::*; |
| 2661 | |
| 2662 | match (from, to) { |
| 2663 | (I32, I32) |
| 2664 | | (I64, I64) |
| 2665 | | (F32, F32) |
| 2666 | | (F64, F64) |
| 2667 | | (Pointer, Pointer) |
| 2668 | | (PointerOrI64, PointerOrI64) |
| 2669 | | (Length, Length) => Bitcast::None, |
| 2670 | |
| 2671 | (I32, I64) => Bitcast::I32ToI64, |
| 2672 | (F32, I32) => Bitcast::F32ToI32, |
| 2673 | (F64, I64) => Bitcast::F64ToI64, |
| 2674 | |
| 2675 | (I64, I32) => Bitcast::I64ToI32, |
| 2676 | (I32, F32) => Bitcast::I32ToF32, |
| 2677 | (I64, F64) => Bitcast::I64ToF64, |
| 2678 | |
| 2679 | (F32, I64) => Bitcast::F32ToI64, |
| 2680 | (I64, F32) => Bitcast::I64ToF32, |
| 2681 | |
| 2682 | (I64, PointerOrI64) => Bitcast::I64ToP64, |
| 2683 | (Pointer, PointerOrI64) => Bitcast::PToP64, |
| 2684 | (_, PointerOrI64) => { |
| 2685 | Bitcast::Sequence(Box::new([cast(from, I64), cast(I64, PointerOrI64)])) |
| 2686 | } |
| 2687 | |
| 2688 | (PointerOrI64, I64) => Bitcast::P64ToI64, |
| 2689 | (PointerOrI64, Pointer) => Bitcast::P64ToP, |
| 2690 | (PointerOrI64, _) => Bitcast::Sequence(Box::new([cast(PointerOrI64, I64), cast(I64, to)])), |
| 2691 | |
| 2692 | (I32, Pointer) => Bitcast::I32ToP, |
| 2693 | (Pointer, I32) => Bitcast::PToI32, |
| 2694 | (I32, Length) => Bitcast::I32ToL, |
| 2695 | (Length, I32) => Bitcast::LToI32, |
| 2696 | (I64, Length) => Bitcast::I64ToL, |
| 2697 | (Length, I64) => Bitcast::LToI64, |
| 2698 | (Pointer, Length) => Bitcast::PToL, |
| 2699 | (Length, Pointer) => Bitcast::LToP, |
| 2700 | |
| 2701 | (F32, Pointer | Length) => Bitcast::Sequence(Box::new([cast(F32, I32), cast(I32, to)])), |
| 2702 | (Pointer | Length, F32) => Bitcast::Sequence(Box::new([cast(from, I32), cast(I32, F32)])), |
| 2703 | |
| 2704 | (F32, F64) |
| 2705 | | (F64, F32) |
| 2706 | | (F64, I32) |
| 2707 | | (I32, F64) |
| 2708 | | (Pointer | Length, I64 | F64) |
| 2709 | | (I64 | F64, Pointer | Length) => { |
| 2710 | unreachable!("Don't know how to bitcast from {:?} to {:?}", from, to); |
| 2711 | } |
| 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | /// Flatten a component-level type into its canonical-ABI wasm-type |
| 2716 | /// sequence, or return `None` if the result would exceed `max_params`. |
no test coverage detected