From 81e4fa33ff413dbbd6cc5c7678609f4dc550eadf Mon Sep 17 00:00:00 2001 From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD> Date: Wed, 5 Sep 2007 15:35:56 +0000 Subject: [PATCH] some small changes --- source/IL2CPU/Program.cs | 2 +- source/Indy.IL2CPU.IL.X86/Pop.cs | 11 ++++++++++- source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs | 2 +- source/Indy.IL2CPU/Engine.cs | 16 +++++++++++++++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/source/IL2CPU/Program.cs b/source/IL2CPU/Program.cs index a81e4a8f1..aa9352739 100644 --- a/source/IL2CPU/Program.cs +++ b/source/IL2CPU/Program.cs @@ -8,7 +8,7 @@ namespace IL2CPU { public class Program { public static void Main(string[] args) { try { - string exeName = "testexe.exe"; + string exeName = "HelloWorldMetal.exe"; if(args.Length ==1 ) { exeName = args[0]; } diff --git a/source/Indy.IL2CPU.IL.X86/Pop.cs b/source/Indy.IL2CPU.IL.X86/Pop.cs index d6682280f..a8378c1b6 100644 --- a/source/Indy.IL2CPU.IL.X86/Pop.cs +++ b/source/Indy.IL2CPU.IL.X86/Pop.cs @@ -7,11 +7,20 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Pop)] public class Pop: Op { + private bool mNeeded = true; public Pop(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { + if (aInstruction.Previous != null && + (aInstruction.Previous.OpCode.Code == Code.Call || + aInstruction.Previous.OpCode.Code == Code.Calli || + aInstruction.Previous.OpCode.Code == Code.Callvirt)) { + mNeeded = false; + } } public override void Assemble() { - Pop("eax"); + if (mNeeded) { + Pop("eax"); + } } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs b/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs index 24d778df9..5d9bfeec4 100644 --- a/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs +++ b/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs @@ -31,7 +31,7 @@ namespace Indy.IL2CPU.IL.X86 { for (int i = 0; i < LocalsCount; i++) { Assembler.Add(new CPU.Pop("ebp")); } - Assembler.Add(new CPU.Ret(TotalArgsSize.ToString())); + Assembler.Add(new CPU.Ret("")); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU/Engine.cs b/source/Indy.IL2CPU/Engine.cs index 8e0a78ec9..628a0783a 100644 --- a/source/Indy.IL2CPU/Engine.cs +++ b/source/Indy.IL2CPU/Engine.cs @@ -176,7 +176,11 @@ namespace Indy.IL2CPU { xOp.Assemble(); } } else { - mAssembler.Add(new Literal("; Method not being generated yet, as it's handled by an iCall")); + if (xCurrentMethod.IsPInvokeImpl) { + HandlePInvoke(xCurrentMethod, xMethodInfo); + } else { + mAssembler.Add(new Literal("; Method not being generated yet, as it's handled by an iCall")); + } } xOp = GetOpFromType(mMap.MethodFooterOp, null, xMethodInfo); xOp.Assembler = mAssembler; @@ -249,5 +253,15 @@ namespace Indy.IL2CPU { mDebugLog(String.Format(aMessage, args)); } } + + private void HandlePInvoke(MethodDefinition aMethod, MethodInformation aMethodInfo) { + mAssembler.Add(new Noop()); + if(aMethodInfo.HasReturnValue) { +// mAssembler.Add(new Pushd("0")); + mAssembler.Add(new Pushd("eax")); + mAssembler.Add(new Move("eax", "0")); + + } + } } } \ No newline at end of file