diff --git a/source/IL2CPU.Tests/IL2CPU.Tests.csproj b/source/IL2CPU.Tests/IL2CPU.Tests.csproj index 39575afc1..20f31dd58 100644 --- a/source/IL2CPU.Tests/IL2CPU.Tests.csproj +++ b/source/IL2CPU.Tests/IL2CPU.Tests.csproj @@ -45,6 +45,8 @@ + + @@ -172,6 +174,9 @@ Always + + Always + Always diff --git a/source/IL2CPU.Tests/Tests/Events/CustomDelegate/CustomDelegate.cs b/source/IL2CPU.Tests/Tests/Events/CustomDelegate/CustomDelegate.cs new file mode 100644 index 000000000..c114d14a3 --- /dev/null +++ b/source/IL2CPU.Tests/Tests/Events/CustomDelegate/CustomDelegate.cs @@ -0,0 +1,18 @@ +using System; + +namespace IL2CPU.Tests.Tests.Events.CustomDelegate { + public delegate void OurDelegateTest(int aValue); + public static class CustomDelegate { + private static int ReturnCode; + private static void Handler(int aValue) { + ReturnCode -= aValue; + } + + static int Main() { + ReturnCode = 5; + OurDelegateTest xHandler = Handler; + xHandler(5); + return ReturnCode; + } + } +} \ No newline at end of file diff --git a/source/IL2CPU.Tests/Tests/Events/SimpleCreateDelegate/SimpleCreateDelegate.cs b/source/IL2CPU.Tests/Tests/Events/SimpleCreateDelegate/SimpleCreateDelegate.cs new file mode 100644 index 000000000..b2f4cfd97 --- /dev/null +++ b/source/IL2CPU.Tests/Tests/Events/SimpleCreateDelegate/SimpleCreateDelegate.cs @@ -0,0 +1,17 @@ +using System; + +namespace IL2CPU.Tests.Tests.Events.SimpleCreateDelegate { + public class SimpleCreateDelegate { + public static void MyHandler(object sender, EventArgs e) { + ReturnCode = 0; + } + + private static int ReturnCode; + static int Main() { + ReturnCode = 1; + EventHandler xDelegate = MyHandler; + xDelegate(null, null); + return ReturnCode; + } + } +} diff --git a/source/IL2CPU.Tests/Tests/Events/SimpleCreateDelegate/SimpleCreateDelegate.exe b/source/IL2CPU.Tests/Tests/Events/SimpleCreateDelegate/SimpleCreateDelegate.exe new file mode 100644 index 000000000..7f0f447a1 Binary files /dev/null and b/source/IL2CPU.Tests/Tests/Events/SimpleCreateDelegate/SimpleCreateDelegate.exe differ diff --git a/source/IL2CPU/Program.cs b/source/IL2CPU/Program.cs index d35c7f8d1..137b970ac 100644 --- a/source/IL2CPU/Program.cs +++ b/source/IL2CPU/Program.cs @@ -34,7 +34,6 @@ namespace IL2CPU { xArgParts[1] = xArg.Substring(xArg.IndexOfAny(new char[] { '=', ':' }) + 1); } switch (xArgParts[0].ToLower()) { - case "input": case "in": { InputFile = xArgParts[1]; if (InputFile.StartsWith("\"") && InputFile.EndsWith("\"")) { @@ -42,7 +41,6 @@ namespace IL2CPU { } break; } - case "output": case "out": { OutputFile = xArgParts[1]; if (OutputFile.StartsWith("\"") && OutputFile.EndsWith("\"")) { @@ -54,8 +52,7 @@ namespace IL2CPU { AsmFile = xArgParts[1]; break; } - case "metal": - case "metalmode": { + case "metal": { if (String.IsNullOrEmpty(xArgParts[1])) { MetalMode = true; } else { @@ -66,7 +63,6 @@ namespace IL2CPU { } break; } - case "targetplatform": case "platform": { try { TargetPlatform = (TargetPlatformEnum)Enum.Parse(typeof(TargetPlatformEnum), xArgParts[1], true); diff --git a/source/Indy.IL2CPU.IL.X86/Callvirt.cs b/source/Indy.IL2CPU.IL.X86/Callvirt.cs index 4fcdc2009..b51f8a48b 100644 --- a/source/Indy.IL2CPU.IL.X86/Callvirt.cs +++ b/source/Indy.IL2CPU.IL.X86/Callvirt.cs @@ -8,11 +8,12 @@ using CPUx86 = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Callvirt, true)] public class Callvirt: Op { - private int mMethodIdentifier; - private bool mHasReturn; - private string mNormalAddress; - private string mMethodDescription; - private string[] mThisAddresses; + private readonly int mMethodIdentifier; + private readonly bool mHasReturn; + private readonly string mNormalAddress; + private readonly string mMethodDescription; + private readonly string[] mThisAddresses; + private readonly int mThisOffset; public Callvirt(Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { int xThisOffSet = (from item in aMethodInfo.Locals @@ -23,6 +24,9 @@ namespace Indy.IL2CPU.IL.X86 { } MethodDefinition xMethodDef = Engine.GetDefinitionFromMethodReference(xMethod); mMethodDescription = new CPU.Label(xMethodDef).Name; + if (mMethodDescription == "System_Void___System_EventHandler_Invoke___System_Object__System_EventArgs___") { + System.Diagnostics.Debugger.Break(); + } if (xMethodDef.IsStatic || !xMethodDef.IsVirtual) { mNormalAddress = new CPU.Label(xMethod).Name; mHasReturn = !xMethod.ReturnType.ReturnType.FullName.StartsWith("System.Void"); @@ -33,10 +37,11 @@ namespace Indy.IL2CPU.IL.X86 { MethodInformation xTheMethodInfo = Engine.GetMethodInfo(xMethodDef, xMethodDef, mMethodDescription, null); mHasReturn = xTheMethodInfo.ReturnSize != 0; Console.WriteLine("Debug: " + xTheMethodInfo.ToString()); - mThisAddresses = xTheMethodInfo.Arguments[0].VirtualAddresses; - if (mThisAddresses.Length > 1) { - throw new Exception("In x86, object addresses are 4 bytes. Found different size!"); - } +// mThisAddresses = xTheMethodInfo.Arguments[0].VirtualAddresses; + mThisOffset = xTheMethodInfo.Arguments[0].Offset; +// if (mThisAddresses.Length > 1) { +// throw new Exception("In x86, object addresses are 4 bytes. Found different size!"); +// } } public override void DoAssemble() { @@ -46,8 +51,9 @@ namespace Indy.IL2CPU.IL.X86 { if (Assembler.InMetalMode) { throw new Exception("Virtual methods not supported in Metal mode! (Called method = '" + mMethodDescription + "')"); } - Assembler.Add(new CPUx86.Pop("eax")); - Assembler.Add(new CPUx86.Pushd("eax")); + //Assembler.Add(new CPUx86.Pop("eax")); + //Assembler.Add(new CPUx86.Pushd("eax")); + Assembler.Add(new CPUx86.Move("eax", "[esp + 0x" + mThisOffset.ToString("X") + "]")); Assembler.Add(new CPUx86.Pushd("[eax]")); Assembler.Add(new CPUx86.Pushd("0" + mMethodIdentifier.ToString("X") + "h")); Call(new CPU.Label(VTablesImplRefs.GetMethodAddressForTypeRef).Name);