@@ -800,31 +800,33 @@ impl<'a, B: Bindgen> Generator<'a, B> {
800
800
// ... otherwise if parameters are indirect space is
801
801
// allocated from them and each argument is lowered
802
802
// individually into memory.
803
- let ( size , align ) = self
803
+ let info = self
804
804
. bindgen
805
805
. sizes ( )
806
806
. record ( func. params . iter ( ) . map ( |t| & t. 1 ) ) ;
807
807
let ptr = match self . variant {
808
808
// When a wasm module calls an import it will provide
809
809
// space that isn't explicitly deallocated.
810
- AbiVariant :: GuestImport => self . bindgen . return_pointer ( size, align) ,
810
+ AbiVariant :: GuestImport => self
811
+ . bindgen
812
+ . return_pointer ( info. size . size_wasm32 ( ) , info. align . align_wasm32 ( ) ) ,
811
813
// When calling a wasm module from the outside, though,
812
814
// malloc needs to be called.
813
815
AbiVariant :: GuestExport => {
814
816
self . emit ( & Instruction :: Malloc {
815
817
realloc : "cabi_realloc" ,
816
- size,
817
- align,
818
+ size : info . size . size_wasm32 ( ) ,
819
+ align : info . align . align_wasm32 ( ) ,
818
820
} ) ;
819
821
self . stack . pop ( ) . unwrap ( )
820
822
}
821
823
} ;
822
824
let mut offset = 0usize ;
823
825
for ( nth, ( _, ty) ) in func. params . iter ( ) . enumerate ( ) {
824
826
self . emit ( & Instruction :: GetArg { nth } ) ;
825
- offset = align_to ( offset, self . bindgen . sizes ( ) . align ( ty) ) ;
827
+ offset = align_to ( offset, self . bindgen . sizes ( ) . align ( ty) . align_wasm32 ( ) ) ;
826
828
self . write_to_memory ( ty, ptr. clone ( ) , offset as i32 ) ;
827
- offset += self . bindgen . sizes ( ) . size ( ty) ;
829
+ offset += self . bindgen . sizes ( ) . size ( ty) . size_wasm32 ( ) ;
828
830
}
829
831
830
832
self . stack . push ( ptr) ;
@@ -833,8 +835,10 @@ impl<'a, B: Bindgen> Generator<'a, B> {
833
835
// If necessary we may need to prepare a return pointer for
834
836
// this ABI.
835
837
if self . variant == AbiVariant :: GuestImport && sig. retptr {
836
- let ( size, align) = self . bindgen . sizes ( ) . params ( func. results . iter_types ( ) ) ;
837
- let ptr = self . bindgen . return_pointer ( size, align) ;
838
+ let info = self . bindgen . sizes ( ) . params ( func. results . iter_types ( ) ) ;
839
+ let ptr = self
840
+ . bindgen
841
+ . return_pointer ( info. size . size_wasm32 ( ) , info. align . align_wasm32 ( ) ) ;
838
842
self . return_pointer = Some ( ptr. clone ( ) ) ;
839
843
self . stack . push ( ptr) ;
840
844
}
@@ -904,9 +908,9 @@ impl<'a, B: Bindgen> Generator<'a, B> {
904
908
self . emit ( & Instruction :: GetArg { nth : 0 } ) ;
905
909
let ptr = self . stack . pop ( ) . unwrap ( ) ;
906
910
for ( _, ty) in func. params . iter ( ) {
907
- offset = align_to ( offset, self . bindgen . sizes ( ) . align ( ty) ) ;
911
+ offset = align_to ( offset, self . bindgen . sizes ( ) . align ( ty) . align_wasm32 ( ) ) ;
908
912
self . read_from_memory ( ty, ptr. clone ( ) , offset as i32 ) ;
909
- offset += self . bindgen . sizes ( ) . size ( ty) ;
913
+ offset += self . bindgen . sizes ( ) . size ( ty) . size_wasm32 ( ) ;
910
914
}
911
915
}
912
916
@@ -917,12 +921,15 @@ impl<'a, B: Bindgen> Generator<'a, B> {
917
921
// it's been read by the guest we need to deallocate it.
918
922
if let AbiVariant :: GuestExport = self . variant {
919
923
if sig. indirect_params {
920
- let ( size , align ) = self
924
+ let info = self
921
925
. bindgen
922
926
. sizes ( )
923
927
. record ( func. params . iter ( ) . map ( |t| & t. 1 ) ) ;
924
928
self . emit ( & Instruction :: GetArg { nth : 0 } ) ;
925
- self . emit ( & Instruction :: GuestDeallocate { size, align } ) ;
929
+ self . emit ( & Instruction :: GuestDeallocate {
930
+ size : info. size . size_wasm32 ( ) ,
931
+ align : info. align . align_wasm32 ( ) ,
932
+ } ) ;
926
933
}
927
934
}
928
935
@@ -959,9 +966,10 @@ impl<'a, B: Bindgen> Generator<'a, B> {
959
966
// (statically) and then write the result into that
960
967
// memory, returning the pointer at the end.
961
968
AbiVariant :: GuestExport => {
962
- let ( size, align) =
963
- self . bindgen . sizes ( ) . params ( func. results . iter_types ( ) ) ;
964
- let ptr = self . bindgen . return_pointer ( size, align) ;
969
+ let info = self . bindgen . sizes ( ) . params ( func. results . iter_types ( ) ) ;
970
+ let ptr = self
971
+ . bindgen
972
+ . return_pointer ( info. size . size_wasm32 ( ) , info. align . align_wasm32 ( ) ) ;
965
973
self . write_params_to_memory ( func. results . iter_types ( ) , ptr. clone ( ) , 0 ) ;
966
974
self . stack . push ( ptr) ;
967
975
}
@@ -998,6 +1006,7 @@ impl<'a, B: Bindgen> Generator<'a, B> {
998
1006
. sizes ( )
999
1007
. field_offsets ( func. results . iter_types ( ) )
1000
1008
{
1009
+ let offset = offset. size_wasm32 ( ) ;
1001
1010
let offset = i32:: try_from ( offset) . unwrap ( ) ;
1002
1011
self . deallocate ( ty, addr. clone ( ) , offset) ;
1003
1012
}
@@ -1535,8 +1544,12 @@ impl<'a, B: Bindgen> Generator<'a, B> {
1535
1544
tag : Int ,
1536
1545
cases : impl IntoIterator < Item = Option < & ' b Type > > + Clone ,
1537
1546
) {
1538
- let payload_offset =
1539
- offset + ( self . bindgen . sizes ( ) . payload_offset ( tag, cases. clone ( ) ) as i32 ) ;
1547
+ let payload_offset = offset
1548
+ + ( self
1549
+ . bindgen
1550
+ . sizes ( )
1551
+ . payload_offset ( tag, cases. clone ( ) )
1552
+ . size_wasm32 ( ) as i32 ) ;
1540
1553
for ( i, ty) in cases. into_iter ( ) . enumerate ( ) {
1541
1554
self . push_block ( ) ;
1542
1555
self . emit ( & Instruction :: VariantPayloadName ) ;
@@ -1581,6 +1594,7 @@ impl<'a, B: Bindgen> Generator<'a, B> {
1581
1594
. zip ( fields)
1582
1595
{
1583
1596
self . stack . push ( op) ;
1597
+ let field_offset = field_offset. size_wasm32 ( ) ;
1584
1598
self . write_to_memory ( ty, addr. clone ( ) , offset + ( field_offset as i32 ) ) ;
1585
1599
}
1586
1600
}
@@ -1715,8 +1729,12 @@ impl<'a, B: Bindgen> Generator<'a, B> {
1715
1729
) {
1716
1730
self . stack . push ( addr. clone ( ) ) ;
1717
1731
self . load_intrepr ( offset, tag) ;
1718
- let payload_offset =
1719
- offset + ( self . bindgen . sizes ( ) . payload_offset ( tag, cases. clone ( ) ) as i32 ) ;
1732
+ let payload_offset = offset
1733
+ + ( self
1734
+ . bindgen
1735
+ . sizes ( )
1736
+ . payload_offset ( tag, cases. clone ( ) )
1737
+ . size_wasm32 ( ) as i32 ) ;
1720
1738
for ty in cases {
1721
1739
self . push_block ( ) ;
1722
1740
if let Some ( ty) = ty {
@@ -1743,7 +1761,8 @@ impl<'a, B: Bindgen> Generator<'a, B> {
1743
1761
offset : i32 ,
1744
1762
) {
1745
1763
for ( field_offset, ty) in self . bindgen . sizes ( ) . field_offsets ( tys) . iter ( ) {
1746
- self . read_from_memory ( ty, addr. clone ( ) , offset + ( * field_offset as i32 ) ) ;
1764
+ let field_offset = field_offset. size_wasm32 ( ) ;
1765
+ self . read_from_memory ( ty, addr. clone ( ) , offset + ( field_offset as i32 ) ) ;
1747
1766
}
1748
1767
}
1749
1768
@@ -1882,8 +1901,12 @@ impl<'a, B: Bindgen> Generator<'a, B> {
1882
1901
) {
1883
1902
self . stack . push ( addr. clone ( ) ) ;
1884
1903
self . load_intrepr ( offset, tag) ;
1885
- let payload_offset =
1886
- offset + ( self . bindgen . sizes ( ) . payload_offset ( tag, cases. clone ( ) ) as i32 ) ;
1904
+ let payload_offset = offset
1905
+ + ( self
1906
+ . bindgen
1907
+ . sizes ( )
1908
+ . payload_offset ( tag, cases. clone ( ) )
1909
+ . size_wasm32 ( ) as i32 ) ;
1887
1910
for ty in cases {
1888
1911
self . push_block ( ) ;
1889
1912
if let Some ( ty) = ty {
@@ -1895,6 +1918,7 @@ impl<'a, B: Bindgen> Generator<'a, B> {
1895
1918
1896
1919
fn deallocate_fields ( & mut self , tys : & [ Type ] , addr : B :: Operand , offset : i32 ) {
1897
1920
for ( field_offset, ty) in self . bindgen . sizes ( ) . field_offsets ( tys) {
1921
+ let field_offset = field_offset. size_wasm32 ( ) ;
1898
1922
self . deallocate ( ty, addr. clone ( ) , offset + ( field_offset as i32 ) ) ;
1899
1923
}
1900
1924
}
0 commit comments