@@ -145,7 +145,7 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
145145 switch ({op}.Tag) {{
146146 {cases}
147147
148- default: throw new ArgumentException($ "invalid discriminant: {{{ op}}}" );
148+ default: throw new global::System. ArgumentException("invalid discriminant: " + { op});
149149 }}
150150 "#
151151 ) ;
@@ -222,7 +222,7 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
222222 switch ({op}) {{
223223 {cases}
224224
225- default: throw new ArgumentException($ "invalid discriminant: {{{ op}}}" );
225+ default: throw new global::System. ArgumentException("invalid discriminant:" + { op});
226226 }}
227227 "#
228228 ) ;
@@ -363,7 +363,7 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
363363 {{
364364 {cases}
365365
366- default: throw new ArgumentException($"invalid nesting level: {{e.NestingLevel}}");
366+ default: throw new global::System. ArgumentException($"invalid nesting level: {{e.NestingLevel}}");
367367 }}
368368 }}
369369 "#
@@ -400,22 +400,22 @@ impl Bindgen for FunctionBindgen<'_, '_> {
400400 } ) ) ,
401401 Instruction :: I32Load { offset }
402402 | 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( ) ) ) ,
411411 Instruction :: I32Store { offset }
412412 | 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( ) ) ,
414414 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( ) ) ,
419419
420420 Instruction :: I64FromU64 => results. push ( format ! ( "unchecked((long)({}))" , operands[ 0 ] ) ) ,
421421 Instruction :: I32FromChar => results. push ( format ! ( "((int){})" , operands[ 0 ] ) ) ,
@@ -680,7 +680,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
680680 break;
681681 }}
682682
683- default: throw new ArgumentException("invalid discriminant: " + ({op}));
683+ default: throw new global::System. ArgumentException("invalid discriminant: " + ({op}));
684684 }}
685685 "#
686686 ) ;
@@ -748,7 +748,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
748748 uwrite ! (
749749 self . src,
750750 "
751- var {handle} = GCHandle.Alloc({list}, GCHandleType.Pinned);
751+ var {handle} = global::System.Runtime.InteropServices. GCHandle.Alloc({list}, global::System.Runtime.InteropServices. GCHandleType.Pinned);
752752 var {ptr} = {handle}.AddrOfPinnedObject();
753753 cleanups.Add(()=> {handle}.Free());
754754 "
@@ -766,8 +766,8 @@ impl Bindgen for FunctionBindgen<'_, '_> {
766766 self . src,
767767 "
768768 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}));
771771 "
772772 ) ;
773773
@@ -787,7 +787,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
787787 self . src,
788788 "
789789 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}));
791791 "
792792 ) ;
793793
@@ -805,9 +805,9 @@ impl Bindgen for FunctionBindgen<'_, '_> {
805805 uwriteln ! (
806806 self . src,
807807 "
808- var {utf8_bytes} = Encoding.UTF8.GetBytes({op});
808+ var {utf8_bytes} = global::System.Text. Encoding.UTF8.GetBytes({op});
809809 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);
811811 var {str_ptr} = {gc_handle}.AddrOfPinnedObject();
812812 "
813813 ) ;
@@ -825,34 +825,21 @@ impl Bindgen for FunctionBindgen<'_, '_> {
825825 uwriteln ! (
826826 self . src,
827827 "
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}));
832832 "
833833 ) ;
834834 results. push ( format ! ( "(int){str_ptr}" ) ) ;
835835 }
836836
837837 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- }
845838 }
846839
847840 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-
854841 results. push ( format ! (
855- "Encoding.UTF8.GetString((byte*){}, {})" ,
842+ "global::System.Text. Encoding.UTF8.GetString((byte*){}, {})" ,
856843 operands[ 0 ] , operands[ 1 ]
857844 ) ) ;
858845 }
@@ -895,8 +882,8 @@ impl Bindgen for FunctionBindgen<'_, '_> {
895882 else
896883 {{
897884 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}));
900887 }}
901888 "
902889 ) ;
@@ -906,7 +893,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
906893 uwrite ! ( self . src,
907894 "
908895 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});
910897 "
911898 ) ;
912899 }
@@ -948,7 +935,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
948935 uwrite ! (
949936 self . src,
950937 "
951- var {array} = new List<{ty}>({length});
938+ var {array} = new global::System.Collections.Generic. List<{ty}>({length});
952939 for (int {index} = 0; {index} < {length}; ++{index}) {{
953940 nint {base} = {address} + ({index} * {size});
954941 {body}
@@ -1054,7 +1041,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
10541041 }
10551042
10561043 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>();
10581045 " ) ;
10591046
10601047 uwriteln ! ( self . src, "
@@ -1086,11 +1073,11 @@ impl Bindgen for FunctionBindgen<'_, '_> {
10861073
10871074 Instruction :: GuestDeallocate { .. } => {
10881075 // 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 ] ) ;
10901077 }
10911078
10921079 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 ] ) ;
10941081 }
10951082
10961083 Instruction :: GuestDeallocateVariant { blocks } => {
@@ -1150,7 +1137,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
11501137 ) ;
11511138 }
11521139
1153- uwriteln ! ( self . src, r#"NativeMemory.Free((void*){});"# , operands[ 0 ] ) ;
1140+ uwriteln ! ( self . src, r#"global::System.Runtime.InteropServices. NativeMemory.Free((void*){});"# , operands[ 0 ] ) ;
11541141 }
11551142
11561143 Instruction :: HandleLower {
@@ -1387,12 +1374,12 @@ fn list_element_info(ty: &Type) -> (usize, &'static str) {
13871374
13881375fn perform_cast ( op : & String , cast : & Bitcast ) -> String {
13891376 match cast {
1390- Bitcast :: I32ToF32 => format ! ( "BitConverter.Int32BitsToSingle((int){op})" ) ,
1391- Bitcast :: I64ToF32 => format ! ( "BitConverter.Int32BitsToSingle((int){op})" ) ,
1392- Bitcast :: F32ToI32 => format ! ( "BitConverter.SingleToInt32Bits({op})" ) ,
1393- Bitcast :: F32ToI64 => format ! ( "BitConverter.SingleToInt32Bits({op})" ) ,
1394- Bitcast :: I64ToF64 => format ! ( "BitConverter.Int64BitsToDouble({op})" ) ,
1395- Bitcast :: F64ToI64 => format ! ( "BitConverter.DoubleToInt64Bits({op})" ) ,
1377+ Bitcast :: I32ToF32 => format ! ( "global::System. BitConverter.Int32BitsToSingle((int){op})" ) ,
1378+ Bitcast :: I64ToF32 => format ! ( "global::System. BitConverter.Int32BitsToSingle((int){op})" ) ,
1379+ Bitcast :: F32ToI32 => format ! ( "global::System. BitConverter.SingleToInt32Bits({op})" ) ,
1380+ Bitcast :: F32ToI64 => format ! ( "global::System. BitConverter.SingleToInt32Bits({op})" ) ,
1381+ Bitcast :: I64ToF64 => format ! ( "global::System. BitConverter.Int64BitsToDouble({op})" ) ,
1382+ Bitcast :: F64ToI64 => format ! ( "global::System. BitConverter.DoubleToInt64Bits({op})" ) ,
13961383 Bitcast :: I32ToI64 => format ! ( "(long) ({op})" ) ,
13971384 Bitcast :: I64ToI32 => format ! ( "(int) ({op})" ) ,
13981385 Bitcast :: I64ToP64 => format ! ( "{op}" ) ,
0 commit comments