Skip to content

Commit

Permalink
Add tests for pointer operations
Browse files Browse the repository at this point in the history
That's taken from ForNeVeR#356 in attempt to take what's good and unblock other work if possible
  • Loading branch information
kant2002 authored and ForNeVeR committed Apr 10, 2023
1 parent 9db29d4 commit 8b150a0
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 182 deletions.
27 changes: 25 additions & 2 deletions Cesium.CodeGen.Tests/ArchitectureDependentCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public class ArchitectureDependentCodeTests : CodeGenTestBase
private static Task DoTest(TargetArchitectureSet arch, string source)
{
var assembly = GenerateAssembly(runtime: default, arch: arch, sources: source);
var moduleType = assembly.Modules.Single().GetType("<Module>");
return VerifyMethods(moduleType, arch);
return VerifyTypes(assembly, arch);
}

[Theory]
Expand Down Expand Up @@ -51,5 +50,29 @@ int main(void)
foo x[3];
return 0;
}
""");

[Theory]
[InlineData(TargetArchitectureSet.Dynamic)]
[InlineData(TargetArchitectureSet.Bit64)]
[InlineData(TargetArchitectureSet.Bit32)]
public Task PointerArrayMemberAssign(TargetArchitectureSet arch) => DoTest(arch, """
int main(void)
{
void *x[3];
x[2] = 0;
x[0] = x[2];
}
""");

[Theory]
[InlineData(TargetArchitectureSet.Dynamic)]
[InlineData(TargetArchitectureSet.Bit64)]
[InlineData(TargetArchitectureSet.Bit32)]
public Task PointerFunctionSignature(TargetArchitectureSet arch) => DoTest(arch, """
int foo(void *x)
{
return 0;
}
""");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Module: Primary
Type: <Module>
Methods:
System.Int32 <Module>::main()
Locals:
System.Void* V_0
IL_0000: ldc.i4.s 12
IL_0002: conv.u
IL_0003: localloc
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: conv.u
IL_0008: ldc.i4.4
IL_0009: ldc.i4.2
IL_000a: mul
IL_000b: conv.i
IL_000c: add
IL_000d: ldc.i4.0
IL_000e: stind.i
IL_000f: ldloc.0
IL_0010: conv.u
IL_0011: ldc.i4.4
IL_0012: ldc.i4.0
IL_0013: mul
IL_0014: conv.i
IL_0015: add
IL_0016: ldloc.0
IL_0017: conv.u
IL_0018: ldc.i4.4
IL_0019: ldc.i4.2
IL_001a: mul
IL_001b: conv.i
IL_001c: add
IL_001d: ldind.i
IL_001e: stind.i
IL_001f: ldc.i4.0
IL_0020: ret

System.Int32 <Module>::<SyntheticEntrypoint>()
Locals:
System.Int32 V_0
IL_0000: call System.Int32 <Module>::main()
IL_0005: stloc.s V_0
IL_0007: ldloc.s V_0
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_000e: ldloc.s V_0
IL_0010: ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Module: Primary
Type: <Module>
Methods:
System.Int32 <Module>::main()
Locals:
System.Void* V_0
IL_0000: ldc.i4.s 24
IL_0002: conv.u
IL_0003: localloc
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: conv.u
IL_0008: ldc.i4.8
IL_0009: ldc.i4.2
IL_000a: mul
IL_000b: conv.i
IL_000c: add
IL_000d: ldc.i4.0
IL_000e: stind.i
IL_000f: ldloc.0
IL_0010: conv.u
IL_0011: ldc.i4.8
IL_0012: ldc.i4.0
IL_0013: mul
IL_0014: conv.i
IL_0015: add
IL_0016: ldloc.0
IL_0017: conv.u
IL_0018: ldc.i4.8
IL_0019: ldc.i4.2
IL_001a: mul
IL_001b: conv.i
IL_001c: add
IL_001d: ldind.i
IL_001e: stind.i
IL_001f: ldc.i4.0
IL_0020: ret

System.Int32 <Module>::<SyntheticEntrypoint>()
Locals:
System.Int32 V_0
IL_0000: call System.Int32 <Module>::main()
IL_0005: stloc.s V_0
IL_0007: ldloc.s V_0
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_000e: ldloc.s V_0
IL_0010: ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Module: Primary
Type: <Module>
Methods:
System.Int32 <Module>::main()
Locals:
System.Void* V_0
IL_0000: sizeof System.Void*
IL_0006: ldc.i4.3
IL_0007: mul
IL_0008: conv.u
IL_0009: localloc
IL_000b: stloc.0
IL_000c: ldloc.0
IL_000d: conv.u
IL_000e: sizeof System.Void*
IL_0014: ldc.i4.2
IL_0015: mul
IL_0016: conv.i
IL_0017: add
IL_0018: ldc.i4.0
IL_0019: stind.i
IL_001a: ldloc.0
IL_001b: conv.u
IL_001c: sizeof System.Void*
IL_0022: ldc.i4.0
IL_0023: mul
IL_0024: conv.i
IL_0025: add
IL_0026: ldloc.0
IL_0027: conv.u
IL_0028: sizeof System.Void*
IL_002e: ldc.i4.2
IL_002f: mul
IL_0030: conv.i
IL_0031: add
IL_0032: ldind.i
IL_0033: stind.i
IL_0034: ldc.i4.0
IL_0035: ret

System.Int32 <Module>::<SyntheticEntrypoint>()
Locals:
System.Int32 V_0
IL_0000: call System.Int32 <Module>::main()
IL_0005: stloc.s V_0
IL_0007: ldloc.s V_0
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_000e: ldloc.s V_0
IL_0010: ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Module: Primary
Type: <Module>
Methods:
System.Int32 <Module>::foo(System.Void* x)
IL_0000: ldc.i4.0
IL_0001: ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Module: Primary
Type: <Module>
Methods:
System.Int32 <Module>::foo(System.Void* x)
IL_0000: ldc.i4.0
IL_0001: ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Module: Primary
Type: <Module>
Methods:
System.Int32 <Module>::foo(System.Void* x)
IL_0000: ldc.i4.0
IL_0001: ret
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
System.Int32 <Module>::main()
Locals:
System.Int32* V_0
IL_0000: ldc.i4 1200
IL_0005: conv.u
IL_0006: localloc
IL_0008: stloc.0
IL_0009: ldloc.0
IL_000a: conv.u
IL_000b: ldc.i4.4
IL_000c: ldc.i4 299
IL_0011: mul
IL_0012: conv.i
IL_0013: add
IL_0014: ldc.i4.0
IL_0015: stind.i
IL_0016: ldloc.0
IL_0017: conv.u
IL_0018: ldc.i4.4
IL_0019: ldc.i4 299
IL_001e: mul
IL_001f: conv.i
IL_0020: add
IL_0021: ldind.i
IL_0022: ret
Module: Primary
Type: <Module>
Methods:
System.Int32 <Module>::main()
Locals:
System.Int32* V_0
IL_0000: ldc.i4 1200
IL_0005: conv.u
IL_0006: localloc
IL_0008: stloc.0
IL_0009: ldloc.0
IL_000a: conv.u
IL_000b: ldc.i4.4
IL_000c: ldc.i4 299
IL_0011: mul
IL_0012: conv.i
IL_0013: add
IL_0014: ldc.i4.0
IL_0015: stind.i
IL_0016: ldloc.0
IL_0017: conv.u
IL_0018: ldc.i4.4
IL_0019: ldc.i4 299
IL_001e: mul
IL_001f: conv.i
IL_0020: add
IL_0021: ldind.i
IL_0022: ret

System.Int32 <Module>::<SyntheticEntrypoint>()
Locals:
System.Int32 V_0
IL_0000: call System.Int32 <Module>::main()
IL_0005: stloc.s V_0
IL_0007: ldloc.s V_0
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_000e: ldloc.s V_0
IL_0010: ret
System.Int32 <Module>::<SyntheticEntrypoint>()
Locals:
System.Int32 V_0
IL_0000: call System.Int32 <Module>::main()
IL_0005: stloc.s V_0
IL_0007: ldloc.s V_0
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_000e: ldloc.s V_0
IL_0010: ret
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
System.Int32 <Module>::main()
Locals:
System.Int32* V_0
IL_0000: ldc.i4 2400
IL_0005: conv.u
IL_0006: localloc
IL_0008: stloc.0
IL_0009: ldloc.0
IL_000a: conv.u
IL_000b: ldc.i4.8
IL_000c: ldc.i4 299
IL_0011: mul
IL_0012: conv.i
IL_0013: add
IL_0014: ldc.i4.0
IL_0015: stind.i
IL_0016: ldloc.0
IL_0017: conv.u
IL_0018: ldc.i4.8
IL_0019: ldc.i4 299
IL_001e: mul
IL_001f: conv.i
IL_0020: add
IL_0021: ldind.i
IL_0022: ret
Module: Primary
Type: <Module>
Methods:
System.Int32 <Module>::main()
Locals:
System.Int32* V_0
IL_0000: ldc.i4 2400
IL_0005: conv.u
IL_0006: localloc
IL_0008: stloc.0
IL_0009: ldloc.0
IL_000a: conv.u
IL_000b: ldc.i4.8
IL_000c: ldc.i4 299
IL_0011: mul
IL_0012: conv.i
IL_0013: add
IL_0014: ldc.i4.0
IL_0015: stind.i
IL_0016: ldloc.0
IL_0017: conv.u
IL_0018: ldc.i4.8
IL_0019: ldc.i4 299
IL_001e: mul
IL_001f: conv.i
IL_0020: add
IL_0021: ldind.i
IL_0022: ret

System.Int32 <Module>::<SyntheticEntrypoint>()
Locals:
System.Int32 V_0
IL_0000: call System.Int32 <Module>::main()
IL_0005: stloc.s V_0
IL_0007: ldloc.s V_0
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_000e: ldloc.s V_0
IL_0010: ret
System.Int32 <Module>::<SyntheticEntrypoint>()
Locals:
System.Int32 V_0
IL_0000: call System.Int32 <Module>::main()
IL_0005: stloc.s V_0
IL_0007: ldloc.s V_0
IL_0009: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_000e: ldloc.s V_0
IL_0010: ret
Loading

0 comments on commit 8b150a0

Please sign in to comment.