mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-12 03:01:32 +00:00
Callvirt fixed. some other changes. simple delegate test. some usage change to il2cpu.exe
This commit is contained in:
parent
dedbd9851b
commit
5b95799f65
6 changed files with 58 additions and 16 deletions
|
|
@ -45,6 +45,8 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<None Include="Tests\Events\CustomDelegate\CustomDelegate.cs" />
|
||||
<None Include="Tests\Events\SimpleCreateDelegate\SimpleCreateDelegate.cs" />
|
||||
<None Include="Tests\ComplexerStructIndexing\ComplexerStructIndexing.cs" />
|
||||
<None Include="Tests\SimpleVCallTest\SimpleVCallTest.cs" />
|
||||
<None Include="Tests\SimpleNewObject\SimpleNewObject.cs" />
|
||||
|
|
@ -172,6 +174,9 @@
|
|||
<None Include="Tests\ComplexerStructIndexing\ComplexerStructIndexing.exe">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Tests\Events\SimpleCreateDelegate\SimpleCreateDelegate.exe">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Content Include="Tests\SimpleForWithIf\SimpleForWithIf.exe">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue