@@ -113,6 +113,11 @@ def_instruction! {
113
113
/// it, using the specified constant offset.
114
114
F64Load { offset: i32 } : [ 1 ] => [ 1 ] ,
115
115
116
+ /// Like `I32Load` or `I64Load`, but for loading pointer values.
117
+ PointerLoad { offset: i32 } : [ 1 ] => [ 1 ] ,
118
+ /// Like `I32Load` or `I64Load`, but for loading array length values.
119
+ LengthLoad { offset: i32 } : [ 1 ] => [ 1 ] ,
120
+
116
121
/// Pops an `i32` address from the stack and then an `i32` value.
117
122
/// Stores the value in little-endian at the pointer specified plus the
118
123
/// constant `offset`.
@@ -138,6 +143,11 @@ def_instruction! {
138
143
/// constant `offset`.
139
144
F64Store { offset: i32 } : [ 2 ] => [ 0 ] ,
140
145
146
+ /// Like `I32Store` or `I64Store`, but for storing pointer values.
147
+ PointerStore { offset: i32 } : [ 2 ] => [ 0 ] ,
148
+ /// Like `I32Store` or `I64Store`, but for storing array length values.
149
+ LengthStore { offset: i32 } : [ 2 ] => [ 0 ] ,
150
+
141
151
// Scalar lifting/lowering
142
152
143
153
/// Converts an interface type `char` value to a 32-bit integer
@@ -526,6 +536,12 @@ pub enum Bitcast {
526
536
I64ToI32 ,
527
537
I64ToF32 ,
528
538
539
+ // Pointers
540
+ P64ToI64 ,
541
+ I64ToP64 ,
542
+ P64ToP ,
543
+ PToP64 ,
544
+
529
545
None ,
530
546
}
531
547
@@ -1517,9 +1533,9 @@ impl<'a, B: Bindgen> Generator<'a, B> {
1517
1533
// and the length into the high address.
1518
1534
self . lower ( ty) ;
1519
1535
self . stack . push ( addr. clone ( ) ) ;
1520
- self . emit ( & Instruction :: I32Store { offset : offset + 4 } ) ;
1536
+ self . emit ( & Instruction :: LengthStore { offset : offset + 4 } ) ;
1521
1537
self . stack . push ( addr) ;
1522
- self . emit ( & Instruction :: I32Store { offset } ) ;
1538
+ self . emit ( & Instruction :: PointerStore { offset } ) ;
1523
1539
}
1524
1540
1525
1541
fn write_fields_to_memory < ' b > (
@@ -1689,9 +1705,9 @@ impl<'a, B: Bindgen> Generator<'a, B> {
1689
1705
// Read the pointer/len and then perform the standard lifting
1690
1706
// proceses.
1691
1707
self . stack . push ( addr. clone ( ) ) ;
1692
- self . emit ( & Instruction :: I32Load { offset } ) ;
1708
+ self . emit ( & Instruction :: PointerLoad { offset } ) ;
1693
1709
self . stack . push ( addr) ;
1694
- self . emit ( & Instruction :: I32Load { offset : offset + 4 } ) ;
1710
+ self . emit ( & Instruction :: LengthLoad { offset : offset + 4 } ) ;
1695
1711
self . lift ( ty) ;
1696
1712
}
1697
1713
@@ -1742,9 +1758,9 @@ impl<'a, B: Bindgen> Generator<'a, B> {
1742
1758
match * ty {
1743
1759
Type :: String => {
1744
1760
self . stack . push ( addr. clone ( ) ) ;
1745
- self . emit ( & Instruction :: I32Load { offset } ) ;
1761
+ self . emit ( & Instruction :: PointerLoad { offset } ) ;
1746
1762
self . stack . push ( addr) ;
1747
- self . emit ( & Instruction :: I32Load { offset : offset + 4 } ) ;
1763
+ self . emit ( & Instruction :: LengthLoad { offset : offset + 4 } ) ;
1748
1764
self . emit ( & Instruction :: GuestDeallocateString ) ;
1749
1765
}
1750
1766
@@ -1772,9 +1788,9 @@ impl<'a, B: Bindgen> Generator<'a, B> {
1772
1788
self . finish_block ( 0 ) ;
1773
1789
1774
1790
self . stack . push ( addr. clone ( ) ) ;
1775
- self . emit ( & Instruction :: I32Load { offset } ) ;
1791
+ self . emit ( & Instruction :: PointerLoad { offset } ) ;
1776
1792
self . stack . push ( addr) ;
1777
- self . emit ( & Instruction :: I32Load { offset : offset + 4 } ) ;
1793
+ self . emit ( & Instruction :: LengthLoad { offset : offset + 4 } ) ;
1778
1794
self . emit ( & Instruction :: GuestDeallocateList { element } ) ;
1779
1795
}
1780
1796
@@ -1862,7 +1878,12 @@ fn cast(from: WasmType, to: WasmType) -> Bitcast {
1862
1878
use WasmType :: * ;
1863
1879
1864
1880
match ( from, to) {
1865
- ( I32 , I32 ) | ( I64 , I64 ) | ( F32 , F32 ) | ( F64 , F64 ) => Bitcast :: None ,
1881
+ ( I32 , I32 )
1882
+ | ( I64 , I64 )
1883
+ | ( F32 , F32 )
1884
+ | ( F64 , F64 )
1885
+ | ( Pointer , Pointer )
1886
+ | ( Length , Length ) => Bitcast :: None ,
1866
1887
1867
1888
( I32 , I64 ) => Bitcast :: I32ToI64 ,
1868
1889
( F32 , I32 ) => Bitcast :: F32ToI32 ,
@@ -1875,7 +1896,19 @@ fn cast(from: WasmType, to: WasmType) -> Bitcast {
1875
1896
( F32 , I64 ) => Bitcast :: F32ToI64 ,
1876
1897
( I64 , F32 ) => Bitcast :: I64ToF32 ,
1877
1898
1878
- ( F32 , F64 ) | ( F64 , F32 ) | ( F64 , I32 ) | ( I32 , F64 ) => unreachable ! ( ) ,
1899
+ ( I64 , PointerOrI64 ) => Bitcast :: I64ToP64 ,
1900
+ ( PointerOrI64 , I64 ) => Bitcast :: P64ToI64 ,
1901
+ ( Pointer , PointerOrI64 ) => Bitcast :: PToP64 ,
1902
+ ( PointerOrI64 , Pointer ) => Bitcast :: P64ToP ,
1903
+
1904
+ ( Pointer | PointerOrI64 | Length , _)
1905
+ | ( _, Pointer | PointerOrI64 | Length )
1906
+ | ( F32 , F64 )
1907
+ | ( F64 , F32 )
1908
+ | ( F64 , I32 )
1909
+ | ( I32 , F64 ) => {
1910
+ unreachable ! ( )
1911
+ }
1879
1912
}
1880
1913
}
1881
1914
0 commit comments