@@ -145,7 +145,7 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
145
145
switch ({op}.Tag) {{
146
146
{cases}
147
147
148
- default: throw new ArgumentException($ "invalid discriminant: {{{ op}}}" );
148
+ default: throw new global::System. ArgumentException("invalid discriminant: " + { op});
149
149
}}
150
150
"#
151
151
) ;
@@ -222,7 +222,7 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
222
222
switch ({op}) {{
223
223
{cases}
224
224
225
- default: throw new ArgumentException($ "invalid discriminant: {{{ op}}}" );
225
+ default: throw new global::System. ArgumentException("invalid discriminant:" + { op});
226
226
}}
227
227
"#
228
228
) ;
@@ -363,7 +363,7 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
363
363
{{
364
364
{cases}
365
365
366
- default: throw new ArgumentException($"invalid nesting level: {{e.NestingLevel}}");
366
+ default: throw new global::System. ArgumentException($"invalid nesting level: {{e.NestingLevel}}");
367
367
}}
368
368
}}
369
369
"#
@@ -400,22 +400,22 @@ impl Bindgen for FunctionBindgen<'_, '_> {
400
400
} ) ) ,
401
401
Instruction :: I32Load { offset }
402
402
| Instruction :: PointerLoad { offset }
403
- | Instruction :: LengthLoad { offset } => results. push ( format ! ( "BitConverter.ToInt32(new Span<byte>((void*)({} + {offset}), 4))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
404
- Instruction :: I32Load8U { offset } => results. push ( format ! ( "new Span<byte>((void*)({} + {offset}), 1)[0]" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
405
- Instruction :: I32Load8S { offset } => results. push ( format ! ( "(sbyte)new Span<byte>((void*)({} + {offset}), 1)[0]" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
406
- Instruction :: I32Load16U { offset } => results. push ( format ! ( "BitConverter.ToUInt16(new Span<byte>((void*)({} + {offset}), 2))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
407
- Instruction :: I32Load16S { offset } => results. push ( format ! ( "BitConverter.ToInt16(new Span<byte>((void*)({} + {offset}), 2))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
408
- Instruction :: I64Load { offset } => results. push ( format ! ( "BitConverter.ToInt64(new Span<byte>((void*)({} + {offset}), 8))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
409
- Instruction :: F32Load { offset } => results. push ( format ! ( "BitConverter.ToSingle(new Span<byte>((void*)({} + {offset}), 4))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
410
- Instruction :: F64Load { offset } => results. push ( format ! ( "BitConverter.ToDouble(new Span<byte>((void*)({} + {offset}), 8))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
403
+ | Instruction :: LengthLoad { offset } => results. push ( format ! ( "global::System. BitConverter.ToInt32(new global::System. Span<byte>((void*)({} + {offset}), 4))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
404
+ Instruction :: I32Load8U { offset } => results. push ( format ! ( "new global::System. Span<byte>((void*)({} + {offset}), 1)[0]" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
405
+ Instruction :: I32Load8S { offset } => results. push ( format ! ( "(sbyte)new global::System. Span<byte>((void*)({} + {offset}), 1)[0]" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
406
+ Instruction :: I32Load16U { offset } => results. push ( format ! ( "global::System. BitConverter.ToUInt16(new global::System. Span<byte>((void*)({} + {offset}), 2))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
407
+ Instruction :: I32Load16S { offset } => results. push ( format ! ( "global::System. BitConverter.ToInt16(new global::System. Span<byte>((void*)({} + {offset}), 2))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
408
+ Instruction :: I64Load { offset } => results. push ( format ! ( "global::System. BitConverter.ToInt64(new global::System. Span<byte>((void*)({} + {offset}), 8))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
409
+ Instruction :: F32Load { offset } => results. push ( format ! ( "global::System. BitConverter.ToSingle(new global::System. Span<byte>((void*)({} + {offset}), 4))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
410
+ Instruction :: F64Load { offset } => results. push ( format ! ( "global::System. BitConverter.ToDouble(new global::System. Span<byte>((void*)({} + {offset}), 8))" , operands[ 0 ] , offset = offset. size_wasm32( ) ) ) ,
411
411
Instruction :: I32Store { offset }
412
412
| Instruction :: PointerStore { offset }
413
- | Instruction :: LengthStore { offset } => uwriteln ! ( self . src, "BitConverter.TryWriteBytes(new Span<byte>((void*)({} + {offset}), 4), {});" , operands[ 1 ] , operands[ 0 ] , offset = offset. size_wasm32( ) ) ,
413
+ | Instruction :: LengthStore { offset } => uwriteln ! ( self . src, "global::System. BitConverter.TryWriteBytes(new global::System. Span<byte>((void*)({} + {offset}), 4), {});" , operands[ 1 ] , operands[ 0 ] , offset = offset. size_wasm32( ) ) ,
414
414
Instruction :: I32Store8 { offset } => uwriteln ! ( self . src, "*(byte*)({} + {offset}) = (byte){};" , operands[ 1 ] , operands[ 0 ] , offset = offset. size_wasm32( ) ) ,
415
- Instruction :: I32Store16 { offset } => uwriteln ! ( self . src, "BitConverter.TryWriteBytes(new Span<byte>((void*)({} + {offset}), 2), (short){});" , operands[ 1 ] , operands[ 0 ] , offset = offset. size_wasm32( ) ) ,
416
- Instruction :: I64Store { offset } => uwriteln ! ( self . src, "BitConverter.TryWriteBytes(new Span<byte>((void*)({} + {offset}), 8), unchecked((long){}));" , operands[ 1 ] , operands[ 0 ] , offset = offset. size_wasm32( ) ) ,
417
- Instruction :: F32Store { offset } => uwriteln ! ( self . src, "BitConverter.TryWriteBytes(new Span<byte>((void*)({} + {offset}), 4), unchecked((float){}));" , operands[ 1 ] , operands[ 0 ] , offset = offset. size_wasm32( ) ) ,
418
- Instruction :: F64Store { offset } => uwriteln ! ( self . src, "BitConverter.TryWriteBytes(new Span<byte>((void*)({} + {offset}), 8), unchecked((double){}));" , operands[ 1 ] , operands[ 0 ] , offset = offset. size_wasm32( ) ) ,
415
+ Instruction :: I32Store16 { offset } => uwriteln ! ( self . src, "global::System. BitConverter.TryWriteBytes(new global::System. Span<byte>((void*)({} + {offset}), 2), (short){});" , operands[ 1 ] , operands[ 0 ] , offset = offset. size_wasm32( ) ) ,
416
+ Instruction :: I64Store { offset } => uwriteln ! ( self . src, "global::System. BitConverter.TryWriteBytes(new global::System. Span<byte>((void*)({} + {offset}), 8), unchecked((long){}));" , operands[ 1 ] , operands[ 0 ] , offset = offset. size_wasm32( ) ) ,
417
+ Instruction :: F32Store { offset } => uwriteln ! ( self . src, "global::System. BitConverter.TryWriteBytes(new global::System. Span<byte>((void*)({} + {offset}), 4), unchecked((float){}));" , operands[ 1 ] , operands[ 0 ] , offset = offset. size_wasm32( ) ) ,
418
+ Instruction :: F64Store { offset } => uwriteln ! ( self . src, "global::System. BitConverter.TryWriteBytes(new global::System. Span<byte>((void*)({} + {offset}), 8), unchecked((double){}));" , operands[ 1 ] , operands[ 0 ] , offset = offset. size_wasm32( ) ) ,
419
419
420
420
Instruction :: I64FromU64 => results. push ( format ! ( "unchecked((long)({}))" , operands[ 0 ] ) ) ,
421
421
Instruction :: I32FromChar => results. push ( format ! ( "((int){})" , operands[ 0 ] ) ) ,
@@ -680,7 +680,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
680
680
break;
681
681
}}
682
682
683
- default: throw new ArgumentException("invalid discriminant: " + ({op}));
683
+ default: throw new global::System. ArgumentException("invalid discriminant: " + ({op}));
684
684
}}
685
685
"#
686
686
) ;
@@ -748,7 +748,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
748
748
uwrite ! (
749
749
self . src,
750
750
"
751
- var {handle} = GCHandle.Alloc({list}, GCHandleType.Pinned);
751
+ var {handle} = global::System.Runtime.InteropServices. GCHandle.Alloc({list}, global::System.Runtime.InteropServices. GCHandleType.Pinned);
752
752
var {ptr} = {handle}.AddrOfPinnedObject();
753
753
cleanups.Add(()=> {handle}.Free());
754
754
"
@@ -766,8 +766,8 @@ impl Bindgen for FunctionBindgen<'_, '_> {
766
766
self . src,
767
767
"
768
768
var {byte_length} = ({size}) * {list}.Length;
769
- var {address} = NativeMemory.Alloc((nuint)({byte_length}));
770
- {list}. AsSpan().CopyTo(new Span<{ty}>({address},{byte_length}));
769
+ var {address} = global::System.Runtime.InteropServices. NativeMemory.Alloc((nuint)({byte_length}));
770
+ global::System.MemoryExtensions. AsSpan({list} ).CopyTo(new global::System. Span<{ty}>({address},{byte_length}));
771
771
"
772
772
) ;
773
773
@@ -787,7 +787,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
787
787
self . src,
788
788
"
789
789
var {array} = new {ty}[{length}];
790
- new Span<{ty}>((void*)({address}), {length}).CopyTo(new Span<{ty}>({array}));
790
+ new global::System. Span<{ty}>((void*)({address}), {length}).CopyTo(new global::System. Span<{ty}>({array}));
791
791
"
792
792
) ;
793
793
@@ -805,9 +805,9 @@ impl Bindgen for FunctionBindgen<'_, '_> {
805
805
uwriteln ! (
806
806
self . src,
807
807
"
808
- var {utf8_bytes} = Encoding.UTF8.GetBytes({op});
808
+ var {utf8_bytes} = global::System.Text. Encoding.UTF8.GetBytes({op});
809
809
var {length} = {utf8_bytes}.Length;
810
- var {gc_handle} = GCHandle.Alloc({utf8_bytes}, GCHandleType.Pinned);
810
+ var {gc_handle} = global::System.Runtime.InteropServices. GCHandle.Alloc({utf8_bytes}, global::System.Runtime.InteropServices. GCHandleType.Pinned);
811
811
var {str_ptr} = {gc_handle}.AddrOfPinnedObject();
812
812
"
813
813
) ;
@@ -825,34 +825,21 @@ impl Bindgen for FunctionBindgen<'_, '_> {
825
825
uwriteln ! (
826
826
self . src,
827
827
"
828
- var {string_span} = {op}. AsSpan();
829
- var {length} = Encoding.UTF8.GetByteCount({string_span});
830
- var {str_ptr} = NativeMemory.Alloc((nuint){length});
831
- Encoding.UTF8.GetBytes({string_span}, new Span<byte>({str_ptr}, {length}));
828
+ var {string_span} = global::System.MemoryExtensions. AsSpan({op} );
829
+ var {length} = global::System.Text. Encoding.UTF8.GetByteCount({string_span});
830
+ var {str_ptr} = global::System.Runtime.InteropServices. NativeMemory.Alloc((nuint){length});
831
+ global::System.Text. Encoding.UTF8.GetBytes({string_span}, new global::System. Span<byte>({str_ptr}, {length}));
832
832
"
833
833
) ;
834
834
results. push ( format ! ( "(int){str_ptr}" ) ) ;
835
835
}
836
836
837
837
results. push ( format ! ( "{length}" ) ) ;
838
- if FunctionKind :: Freestanding == * self . kind || self . interface_gen . direction == Direction :: Export {
839
- self . interface_gen . require_interop_using ( "System.Text" ) ;
840
- self . interface_gen . require_interop_using ( "System.Runtime.InteropServices" ) ;
841
- } else {
842
- self . interface_gen . require_using ( "System.Text" ) ;
843
- self . interface_gen . require_using ( "System.Runtime.InteropServices" ) ;
844
- }
845
838
}
846
839
847
840
Instruction :: StringLift { .. } => {
848
- if FunctionKind :: Freestanding == * self . kind || self . interface_gen . direction == Direction :: Export {
849
- self . interface_gen . require_interop_using ( "System.Text" ) ;
850
- } else {
851
- self . interface_gen . require_using ( "System.Text" ) ;
852
- }
853
-
854
841
results. push ( format ! (
855
- "Encoding.UTF8.GetString((byte*){}, {})" ,
842
+ "global::System.Text. Encoding.UTF8.GetString((byte*){}, {})" ,
856
843
operands[ 0 ] , operands[ 1 ]
857
844
) ) ;
858
845
}
@@ -895,8 +882,8 @@ impl Bindgen for FunctionBindgen<'_, '_> {
895
882
else
896
883
{{
897
884
var {buffer_size} = {size} * (nuint){list}.Count;
898
- {address} = NativeMemory.AlignedAlloc({buffer_size}, {align});
899
- cleanups.Add(() => NativeMemory.AlignedFree({address}));
885
+ {address} = global::System.Runtime.InteropServices. NativeMemory.AlignedAlloc({buffer_size}, {align});
886
+ cleanups.Add(() => global::System.Runtime.InteropServices. NativeMemory.AlignedFree({address}));
900
887
}}
901
888
"
902
889
) ;
@@ -906,7 +893,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
906
893
uwrite ! ( self . src,
907
894
"
908
895
var {buffer_size} = {size} * (nuint){list}.Count;
909
- void* {address} = NativeMemory.AlignedAlloc({buffer_size}, {align});
896
+ void* {address} = global::System.Runtime.InteropServices. NativeMemory.AlignedAlloc({buffer_size}, {align});
910
897
"
911
898
) ;
912
899
}
@@ -948,7 +935,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
948
935
uwrite ! (
949
936
self . src,
950
937
"
951
- var {array} = new List<{ty}>({length});
938
+ var {array} = new global::System.Collections.Generic. List<{ty}>({length});
952
939
for (int {index} = 0; {index} < {length}; ++{index}) {{
953
940
nint {base} = {address} + ({index} * {size});
954
941
{body}
@@ -1054,7 +1041,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
1054
1041
}
1055
1042
1056
1043
if self . needs_cleanup {
1057
- self . src . insert_str ( 0 , "var cleanups = new List<Action>();
1044
+ self . src . insert_str ( 0 , "var cleanups = new global::System.Collections.Generic. List<global::System. Action>();
1058
1045
" ) ;
1059
1046
1060
1047
uwriteln ! ( self . src, "
@@ -1086,11 +1073,11 @@ impl Bindgen for FunctionBindgen<'_, '_> {
1086
1073
1087
1074
Instruction :: GuestDeallocate { .. } => {
1088
1075
// the original alloc here comes from cabi_realloc implementation (wasi-libc in .net)
1089
- uwriteln ! ( self . src, r#"NativeMemory.Free((void*){});"# , operands[ 0 ] ) ;
1076
+ uwriteln ! ( self . src, r#"global::System.Runtime.InteropServices. NativeMemory.Free((void*){});"# , operands[ 0 ] ) ;
1090
1077
}
1091
1078
1092
1079
Instruction :: GuestDeallocateString => {
1093
- uwriteln ! ( self . src, r#"NativeMemory.Free((void*){});"# , operands[ 0 ] ) ;
1080
+ uwriteln ! ( self . src, r#"global::System.Runtime.InteropServices. NativeMemory.Free((void*){});"# , operands[ 0 ] ) ;
1094
1081
}
1095
1082
1096
1083
Instruction :: GuestDeallocateVariant { blocks } => {
@@ -1150,7 +1137,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
1150
1137
) ;
1151
1138
}
1152
1139
1153
- uwriteln ! ( self . src, r#"NativeMemory.Free((void*){});"# , operands[ 0 ] ) ;
1140
+ uwriteln ! ( self . src, r#"global::System.Runtime.InteropServices. NativeMemory.Free((void*){});"# , operands[ 0 ] ) ;
1154
1141
}
1155
1142
1156
1143
Instruction :: HandleLower {
@@ -1385,12 +1372,12 @@ fn list_element_info(ty: &Type) -> (usize, &'static str) {
1385
1372
1386
1373
fn perform_cast ( op : & String , cast : & Bitcast ) -> String {
1387
1374
match cast {
1388
- Bitcast :: I32ToF32 => format ! ( "BitConverter.Int32BitsToSingle((int){op})" ) ,
1389
- Bitcast :: I64ToF32 => format ! ( "BitConverter.Int32BitsToSingle((int){op})" ) ,
1390
- Bitcast :: F32ToI32 => format ! ( "BitConverter.SingleToInt32Bits({op})" ) ,
1391
- Bitcast :: F32ToI64 => format ! ( "BitConverter.SingleToInt32Bits({op})" ) ,
1392
- Bitcast :: I64ToF64 => format ! ( "BitConverter.Int64BitsToDouble({op})" ) ,
1393
- Bitcast :: F64ToI64 => format ! ( "BitConverter.DoubleToInt64Bits({op})" ) ,
1375
+ Bitcast :: I32ToF32 => format ! ( "global::System. BitConverter.Int32BitsToSingle((int){op})" ) ,
1376
+ Bitcast :: I64ToF32 => format ! ( "global::System. BitConverter.Int32BitsToSingle((int){op})" ) ,
1377
+ Bitcast :: F32ToI32 => format ! ( "global::System. BitConverter.SingleToInt32Bits({op})" ) ,
1378
+ Bitcast :: F32ToI64 => format ! ( "global::System. BitConverter.SingleToInt32Bits({op})" ) ,
1379
+ Bitcast :: I64ToF64 => format ! ( "global::System. BitConverter.Int64BitsToDouble({op})" ) ,
1380
+ Bitcast :: F64ToI64 => format ! ( "global::System. BitConverter.DoubleToInt64Bits({op})" ) ,
1394
1381
Bitcast :: I32ToI64 => format ! ( "(long) ({op})" ) ,
1395
1382
Bitcast :: I64ToI32 => format ! ( "(int) ({op})" ) ,
1396
1383
Bitcast :: I64ToP64 => format ! ( "{op}" ) ,
0 commit comments