Skip to content

Commit

Permalink
Merge branch 'main' into feature/354.wide-arch
Browse files Browse the repository at this point in the history
# Conflicts:
#	Cesium.Runtime/StdIoFunctions.cs
  • Loading branch information
ForNeVeR committed Nov 17, 2023
2 parents 1a9bf18 + 929ab30 commit 118e2d7
Show file tree
Hide file tree
Showing 48 changed files with 989 additions and 261 deletions.
17 changes: 17 additions & 0 deletions Cesium.CodeGen.Tests/CodeGenArrayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,21 @@ public Task ArrayInitializationWithoutSize() => DoTest(@"int main() {
[Fact]
public Task ArrayParameterPassing() => DoTest(@"
int foo(int ints[]) { return ints[0]; }");

[Fact]
public Task ArrayOverPointer() => DoTest(@"int main(int argc, char** argv) {
char c = argv[0][0];
return argv[1];
}");

[Fact]
public Task PointerArrayIndexing() => DoTest(@"
int f(char*** t) {
char* c = t[2][3];
return c[1];
}
int main() {
return 42;
}");
}
6 changes: 6 additions & 0 deletions Cesium.CodeGen.Tests/CodeGenMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ public Task CanHaveTwoFunctionDeclarations() => DoTest(@"
int console_read(void) { return 0; }");

[Fact]
public Task CanHaveTwoFunctionDeclarationsWithDifferentParameterNames() => DoTest(@"
int console_read(int argc);
int console_read(int __argc) { return 0; }");

[Fact]
public void DoubleDefinition() => DoesNotCompile(@"int console_read() { return 1; }
int console_read() { return 2; }", "Double definition of function console_read.");
Expand Down
4 changes: 2 additions & 2 deletions Cesium.CodeGen.Tests/CodeGenPointersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public void CannotAddPointerTypes() => DoesNotCompile(
"Operator Add is not supported for pointer/pointer operands");

[Fact]
public void CanSubstractPointerTypes() => DoTest("void foo (int *x, int *y) { int d = x - y; }");
public Task CanSubtractPointerTypes() => DoTest("void foo (int *x, int *y) { int d = x - y; }");

[Fact]
public void CanSubstractPointerWithConstTypes() => DoTest("void foo (int *x, const int *y) { int d = x - y; }");
public Task CanSubtractPointerWithConstTypes() => DoTest("void foo (int *x, const int *y) { int d = x - y; }");

[Fact]
public Task CanUseBuiltinOffsetOfOnDeclaredStruct() => DoTest(
Expand Down
7 changes: 7 additions & 0 deletions Cesium.CodeGen.Tests/CodeGenSizeofTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ int main() {
return sizeof(x);
}");

[Fact]
public Task ArraySizeofLong() => DoTest(@"
int main() {
long x[] = { 1,2,3,4,5 };
return sizeof(x);
}");

[Fact]
public Task EnumSizeof() => DoTest(@"
int main() {
Expand Down
7 changes: 7 additions & 0 deletions Cesium.CodeGen.Tests/CodeGenTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,11 @@ typedef struct {

[Fact]
public Task StaticFileScopedVariable() => DoTest(@"static int x = 123;");

[Fact]
public Task StaticStruct() => DoTest(@"struct _foo {
int x[4];
};
static struct _foo foo;");
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.Int32 <Module>::main()
System.Int32 <Module>::main()
Locals:
System.Int32* V_0
IL_0000: ldc.i4.s 16
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.Int32 <Module>::main()
System.Int32 <Module>::main()
Locals:
System.Int32* V_0
System.Int32* V_1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
System.Int32 <Module>::main(System.Int32 argc, System.Byte** argv)
Locals:
System.Byte V_0
IL_0000: ldarg.1
IL_0001: ldc.i4.0
IL_0002: conv.i
IL_0003: ldc.i4 1
IL_0008: mul
IL_0009: add
IL_000a: ldind.i1
IL_000b: sizeof System.Byte*
IL_0011: ldc.i4.0
IL_0012: mul
IL_0013: add
IL_0014: ldind.i
IL_0015: stloc.0
IL_0016: ldarg.1
IL_0017: sizeof System.Byte*
IL_001d: ldc.i4.1
IL_001e: mul
IL_001f: add
IL_0020: ldind.i
IL_0021: ret

System.Int32 <Module>::<SyntheticEntrypoint>(System.String[] args)
Locals:
System.Int32 V_0
System.Byte*[] V_1
System.Byte*[] V_2
System.Byte*[] (pinned) V_3
System.Int32 V_4
IL_0000: ldarg.0
IL_0001: ldlen
IL_0002: ldc.i4.1
IL_0003: add
IL_0004: stloc.0
IL_0005: ldarg.0
IL_0006: call System.Byte*[] Cesium.Runtime.RuntimeHelpers::ArgsToArgv(System.String[])
IL_000b: stloc.1
IL_000c: ldloc.1
IL_000d: ldlen
IL_000e: newarr System.Byte*
IL_0013: stloc.2
IL_0014: ldloc.1
IL_0015: ldloc.2
IL_0016: ldc.i4.0
IL_0017: call System.Void System.Array::CopyTo(System.Array,System.Int32)
IL_001c: ldloc.0
IL_001d: ldloc.2
IL_001e: stloc.3
IL_001f: ldloc.3
IL_0020: ldc.i4.0
IL_0021: ldelema System.Byte*
IL_0026: call System.Int32 <Module>::main(System.Int32,System.Byte**)
IL_002b: stloc.s V_4
IL_002d: ldnull
IL_002e: stloc.3
IL_002f: ldloc.1
IL_0030: call System.Void Cesium.Runtime.RuntimeHelpers::FreeArgv(System.Byte*[])
IL_0035: ldloc.s V_4
IL_0037: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_003c: ldloc.s V_4
IL_003e: ret
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.Void <Module>::.cctor()
System.Void <Module>::.cctor()
IL_0000: ldc.i4.s 16
IL_0002: conv.u
IL_0003: call System.Void* Cesium.Runtime.RuntimeHelpers::AllocateGlobalField(System.UInt32)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.Void <Module>::.cctor()
System.Void <Module>::.cctor()
IL_0000: ldc.i4.s 12
IL_0002: conv.u
IL_0003: call System.Void* Cesium.Runtime.RuntimeHelpers::AllocateGlobalField(System.UInt32)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
System.Int32 <Module>::f(System.Byte*** t)
Locals:
System.Byte* V_0
IL_0000: ldarg.0
IL_0001: ldc.i4.2
IL_0002: conv.i
IL_0003: sizeof System.IntPtr
IL_0009: mul
IL_000a: add
IL_000b: ldind.i
IL_000c: sizeof System.Byte**
IL_0012: ldc.i4.3
IL_0013: mul
IL_0014: add
IL_0015: ldind.i
IL_0016: stloc.0
IL_0017: ldloc.0
IL_0018: ldc.i4.1
IL_0019: ldc.i4.1
IL_001a: mul
IL_001b: add
IL_001c: ldind.i1
IL_001d: ret

System.Int32 <Module>::main()
IL_0000: ldc.i4.s 42
IL_0002: 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
Expand Up @@ -32,31 +32,33 @@ System.Int32 <Module>::<SyntheticEntrypoint>(System.String[] args)
System.Int32 V_4
IL_0000: ldarg.0
IL_0001: ldlen
IL_0002: stloc.0
IL_0003: ldarg.0
IL_0004: call System.Byte*[] Cesium.Runtime.RuntimeHelpers::ArgsToArgv(System.String[])
IL_0009: stloc.1
IL_000a: ldloc.1
IL_000b: ldlen
IL_000c: newarr System.Byte*
IL_0011: stloc.2
IL_0012: ldloc.1
IL_0013: ldloc.2
IL_0014: ldc.i4.0
IL_0015: call System.Void System.Array::CopyTo(System.Array,System.Int32)
IL_001a: ldloc.0
IL_001b: ldloc.2
IL_001c: stloc.3
IL_001d: ldloc.3
IL_001e: ldc.i4.0
IL_001f: ldelema System.Byte*
IL_0024: call System.Int32 <Module>::main(System.Int32,System.Byte**)
IL_0029: stloc.s V_4
IL_002b: ldnull
IL_002c: stloc.3
IL_002d: ldloc.1
IL_002e: call System.Void Cesium.Runtime.RuntimeHelpers::FreeArgv(System.Byte*[])
IL_0033: ldloc.s V_4
IL_0035: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_003a: ldloc.s V_4
IL_003c: ret
IL_0002: ldc.i4.1
IL_0003: add
IL_0004: stloc.0
IL_0005: ldarg.0
IL_0006: call System.Byte*[] Cesium.Runtime.RuntimeHelpers::ArgsToArgv(System.String[])
IL_000b: stloc.1
IL_000c: ldloc.1
IL_000d: ldlen
IL_000e: newarr System.Byte*
IL_0013: stloc.2
IL_0014: ldloc.1
IL_0015: ldloc.2
IL_0016: ldc.i4.0
IL_0017: call System.Void System.Array::CopyTo(System.Array,System.Int32)
IL_001c: ldloc.0
IL_001d: ldloc.2
IL_001e: stloc.3
IL_001f: ldloc.3
IL_0020: ldc.i4.0
IL_0021: ldelema System.Byte*
IL_0026: call System.Int32 <Module>::main(System.Int32,System.Byte**)
IL_002b: stloc.s V_4
IL_002d: ldnull
IL_002e: stloc.3
IL_002f: ldloc.1
IL_0030: call System.Void Cesium.Runtime.RuntimeHelpers::FreeArgv(System.Byte*[])
IL_0035: ldloc.s V_4
IL_0037: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_003c: ldloc.s V_4
IL_003e: ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
System.Int32 <Module>::console_read(System.Int32 argc)
IL_0000: ldc.i4.0
IL_0001: ret
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,33 @@ System.Int32 <Module>::<SyntheticEntrypoint>(System.String[] args)
System.Int32 V_4
IL_0000: ldarg.0
IL_0001: ldlen
IL_0002: stloc.0
IL_0003: ldarg.0
IL_0004: call System.Byte*[] Cesium.Runtime.RuntimeHelpers::ArgsToArgv(System.String[])
IL_0009: stloc.1
IL_000a: ldloc.1
IL_000b: ldlen
IL_000c: newarr System.Byte*
IL_0011: stloc.2
IL_0012: ldloc.1
IL_0013: ldloc.2
IL_0014: ldc.i4.0
IL_0015: call System.Void System.Array::CopyTo(System.Array,System.Int32)
IL_001a: ldloc.0
IL_001b: ldloc.2
IL_001c: stloc.3
IL_001d: ldloc.3
IL_001e: ldc.i4.0
IL_001f: ldelema System.Byte*
IL_0024: call System.Int32 <Module>::main(System.Int32,System.Byte**)
IL_0029: stloc.s V_4
IL_002b: ldnull
IL_002c: stloc.3
IL_002d: ldloc.1
IL_002e: call System.Void Cesium.Runtime.RuntimeHelpers::FreeArgv(System.Byte*[])
IL_0033: ldloc.s V_4
IL_0035: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_003a: ldloc.s V_4
IL_003c: ret
IL_0002: ldc.i4.1
IL_0003: add
IL_0004: stloc.0
IL_0005: ldarg.0
IL_0006: call System.Byte*[] Cesium.Runtime.RuntimeHelpers::ArgsToArgv(System.String[])
IL_000b: stloc.1
IL_000c: ldloc.1
IL_000d: ldlen
IL_000e: newarr System.Byte*
IL_0013: stloc.2
IL_0014: ldloc.1
IL_0015: ldloc.2
IL_0016: ldc.i4.0
IL_0017: call System.Void System.Array::CopyTo(System.Array,System.Int32)
IL_001c: ldloc.0
IL_001d: ldloc.2
IL_001e: stloc.3
IL_001f: ldloc.3
IL_0020: ldc.i4.0
IL_0021: ldelema System.Byte*
IL_0026: call System.Int32 <Module>::main(System.Int32,System.Byte**)
IL_002b: stloc.s V_4
IL_002d: ldnull
IL_002e: stloc.3
IL_002f: ldloc.1
IL_0030: call System.Void Cesium.Runtime.RuntimeHelpers::FreeArgv(System.Byte*[])
IL_0035: ldloc.s V_4
IL_0037: call System.Void Cesium.Runtime.RuntimeHelpers::Exit(System.Int32)
IL_003c: ldloc.s V_4
IL_003e: ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
System.Void <Module>::foo(System.Int32* x, System.Int32* y)
Locals:
System.Int32 V_0
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: sub
IL_0003: ldc.i4.4
IL_0004: div
IL_0005: conv.i4
IL_0006: stloc.0
IL_0007: ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
System.Void <Module>::foo(System.Int32* x, System.Int32* y)
Locals:
System.Int32 V_0
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: sub
IL_0003: ldc.i4.4
IL_0004: div
IL_0005: conv.i4
IL_0006: stloc.0
IL_0007: ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
System.Int32 <Module>::main()
Locals:
System.Int64* V_0
IL_0000: ldc.i4.s 40
IL_0002: conv.u
IL_0003: localloc
IL_0005: stloc.0
IL_0006: ldsflda <ConstantPool>/<ConstantPoolItemType40> <ConstantPool>::ConstDataBuffer0
IL_000b: ldloc V_0
IL_000f: ldc.i4.s 40
IL_0011: conv.u
IL_0012: call System.Void Cesium.Runtime.RuntimeHelpers::InitializeCompound(System.Void*,System.Void*,System.UInt32)
IL_0017: ldc.i4.s 40
IL_0019: 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 118e2d7

Please sign in to comment.