aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Device/SizeCalculator.cs
diff options
context:
space:
mode:
authorEmmanuel Hansen <emmausssss@gmail.com>2024-08-31 14:39:26 +0000
committerGitHub <noreply@github.com>2024-08-31 11:39:26 -0300
commit2c5c0392f9ff80a3907bbf376a13f797ebbc12cc (patch)
tree66eac1cb8ec09aae5196520cad19ab8ee6aba241 /src/Ryujinx.Graphics.Device/SizeCalculator.cs
parente0acde04bb032fd056904b909b3fd00c1a6fb996 (diff)
Make HLE project AOT friendly (#7085)1.1.1382
* add hle service generator remove usage of reflection in device state * remove rd.xml generation * make applet manager reflection free * fix typos * fix encoding * fix style report * remove rogue generator reference * remove double assignment
Diffstat (limited to 'src/Ryujinx.Graphics.Device/SizeCalculator.cs')
-rw-r--r--src/Ryujinx.Graphics.Device/SizeCalculator.cs63
1 files changed, 0 insertions, 63 deletions
diff --git a/src/Ryujinx.Graphics.Device/SizeCalculator.cs b/src/Ryujinx.Graphics.Device/SizeCalculator.cs
deleted file mode 100644
index 54820ec36..000000000
--- a/src/Ryujinx.Graphics.Device/SizeCalculator.cs
+++ /dev/null
@@ -1,63 +0,0 @@
1using System;
2using System.Reflection;
3
4namespace Ryujinx.Graphics.Device
5{
6 public static class SizeCalculator
7 {
8 public static int SizeOf(Type type)
9 {
10 // Is type a enum type?
11 if (type.IsEnum)
12 {
13 type = type.GetEnumUnderlyingType();
14 }
15
16 // Is type a pointer type?
17 if (type.IsPointer || type == typeof(IntPtr) || type == typeof(UIntPtr))
18 {
19 return IntPtr.Size;
20 }
21
22 // Is type a struct type?
23 if (type.IsValueType && !type.IsPrimitive)
24 {
25 // Check if the struct has a explicit size, if so, return that.
26 if (type.StructLayoutAttribute.Size != 0)
27 {
28 return type.StructLayoutAttribute.Size;
29 }
30
31 // Otherwise we calculate the sum of the sizes of all fields.
32 int size = 0;
33 var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
34
35 for (int fieldIndex = 0; fieldIndex < fields.Length; fieldIndex++)
36 {
37 size += SizeOf(fields[fieldIndex].FieldType);
38 }
39
40 return size;
41 }
42
43 // Primitive types.
44 return (Type.GetTypeCode(type)) switch
45 {
46 TypeCode.SByte => sizeof(sbyte),
47 TypeCode.Byte => sizeof(byte),
48 TypeCode.Int16 => sizeof(short),
49 TypeCode.UInt16 => sizeof(ushort),
50 TypeCode.Int32 => sizeof(int),
51 TypeCode.UInt32 => sizeof(uint),
52 TypeCode.Int64 => sizeof(long),
53 TypeCode.UInt64 => sizeof(ulong),
54 TypeCode.Char => sizeof(char),
55 TypeCode.Single => sizeof(float),
56 TypeCode.Double => sizeof(double),
57 TypeCode.Decimal => sizeof(decimal),
58 TypeCode.Boolean => sizeof(bool),
59 _ => throw new ArgumentException($"Length for type \"{type.Name}\" is unknown."),
60 };
61 }
62 }
63}