From 71ecc7cdf59e2f8e5d36fdab010adaeb4ab85cd8 Mon Sep 17 00:00:00 2001 From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD> Date: Wed, 5 Sep 2007 13:51:29 +0000 Subject: [PATCH] --- source/HelloWorld/Program.cs | 8 +++++++ source/IL2CPU/Program.cs | 6 +++++- source/Indy.IL2CPU.IL.X86/Br_S.cs | 7 ++++++- source/Indy.IL2CPU.IL.X86/Call.cs | 2 +- source/Indy.IL2CPU.IL.X86/Ldc_I4.cs | 21 +++++++++++-------- source/Indy.IL2CPU.IL.X86/Ldc_I4_0.cs | 2 +- source/Indy.IL2CPU.IL.X86/Ldc_I4_1.cs | 2 +- source/Indy.IL2CPU.IL.X86/Ldc_I4_2.cs | 6 ++---- source/Indy.IL2CPU.IL.X86/Ldc_I4_3.cs | 6 ++---- source/Indy.IL2CPU.IL.X86/Ldc_I4_4.cs | 6 ++---- source/Indy.IL2CPU.IL.X86/Ldc_I4_5.cs | 6 ++---- source/Indy.IL2CPU.IL.X86/Ldc_I4_6.cs | 6 ++---- source/Indy.IL2CPU.IL.X86/Ldc_I4_7.cs | 6 ++---- source/Indy.IL2CPU.IL.X86/Ldc_I4_8.cs | 6 ++---- source/Indy.IL2CPU.IL.X86/Ldc_I4_M1.cs | 6 ++---- source/Indy.IL2CPU.IL.X86/Ldc_I4_S.cs | 8 +------ source/Indy.IL2CPU.IL.X86/Ldloc.cs | 4 ++-- source/Indy.IL2CPU.IL.X86/Ldloca.cs | 4 ++-- source/Indy.IL2CPU.IL.X86/Newobj.cs | 2 +- source/Indy.IL2CPU.IL.X86/Ret.cs | 6 +++++- source/Indy.IL2CPU.IL.X86/Stloc.cs | 10 ++++----- .../Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs | 9 ++++++++ .../Indy.IL2CPU.IL.X86/X86MethodHeaderOp.cs | 3 ++- source/Indy.IL2CPU.IL/MethodInformation.cs | 6 +++++- source/Indy.IL2CPU/Engine.cs | 6 +++--- 25 files changed, 85 insertions(+), 69 deletions(-) diff --git a/source/HelloWorld/Program.cs b/source/HelloWorld/Program.cs index 695c04c9c..8179ddacb 100644 --- a/source/HelloWorld/Program.cs +++ b/source/HelloWorld/Program.cs @@ -19,7 +19,15 @@ namespace HelloWorld { object x = "Hello, World!"; } + public static void EmptyMethod() { + } + + public static void CallEmptyMethod() { + EmptyMethod(); + } + public static void Main() { + CallEmptyMethod(); CallInteger(); Integer(); StringViaCtor(); diff --git a/source/IL2CPU/Program.cs b/source/IL2CPU/Program.cs index 3d116ebf5..aa9352739 100644 --- a/source/IL2CPU/Program.cs +++ b/source/IL2CPU/Program.cs @@ -8,13 +8,17 @@ namespace IL2CPU { public class Program { public static void Main(string[] args) { try { + string exeName = "HelloWorldMetal.exe"; + if(args.Length ==1 ) { + exeName = args[0]; + } Engine e = new Engine(); e.DebugLog += delegate(string aMessage) { Console.WriteLine(aMessage); }; using (FileStream fs = new FileStream(@"output.asm", FileMode.Create)) { using (StreamWriter br = new StreamWriter(fs)) { - e.Execute("HelloWorldMetal.exe", TargetPlatformEnum.x86, br); + e.Execute(exeName, TargetPlatformEnum.x86, br); } } } catch (Exception E) { diff --git a/source/Indy.IL2CPU.IL.X86/Br_S.cs b/source/Indy.IL2CPU.IL.X86/Br_S.cs index 2d9f06c86..38eec75b7 100644 --- a/source/Indy.IL2CPU.IL.X86/Br_S.cs +++ b/source/Indy.IL2CPU.IL.X86/Br_S.cs @@ -7,11 +7,16 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Br_S)] public class Br_S: Op { + private bool mIsFake; public Br_S(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { + // next physical opcode is +2, because the opcode is singlebyte, and has a byte as param + mIsFake = aInstruction.Next.Offset == (aInstruction.Offset + 2); } public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + if (!mIsFake) { + throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + } } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Call.cs b/source/Indy.IL2CPU.IL.X86/Call.cs index 7cd0fe82e..bdfd7ac3d 100644 --- a/source/Indy.IL2CPU.IL.X86/Call.cs +++ b/source/Indy.IL2CPU.IL.X86/Call.cs @@ -18,7 +18,7 @@ namespace Indy.IL2CPU.IL.X86 { public void Assemble(string aMethod) { Call(aMethod); if(HasResult) { - Push("EAX"); + // Push("EAX"); } } diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4.cs index 85d7b69ed..95a33a6cd 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4.cs @@ -7,26 +7,29 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldc_I4)] public class Ldc_I4: Op { - private int mOffset; - protected void SetLocalIndex(int aIndex, MethodInformation aMethodInfo) { - mOffset = aMethodInfo.Locals[aIndex].Offset + aMethodInfo.Locals[aIndex].Size + 4; + private string mValue; + protected void SetValue(int aValue) { + SetValue(aValue.ToString()); + } + + protected void SetValue(string aValue) { + mValue = aValue; } public Ldc_I4(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - int xLocalIndex; - if(Int32.TryParse((aInstruction.Operand ?? "").ToString(), out xLocalIndex)) { - SetLocalIndex(xLocalIndex, aMethodInfo); + if(aInstruction.Operand != null) { + SetValue(aInstruction.Operand.ToString()); } } - public int Offset { + public string Value { get { - return mOffset; + return mValue; } } public override sealed void Assemble() { - Pushd("[esp + " + mOffset + "]"); + Pushd(Value); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4_0.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4_0.cs index 8e8f6f986..1239b9ede 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4_0.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4_0.cs @@ -9,7 +9,7 @@ namespace Indy.IL2CPU.IL.X86 { public class Ldc_I4_0: Ldc_I4 { public Ldc_I4_0(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - SetLocalIndex(0, aMethodInfo); + SetValue(0); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4_1.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4_1.cs index 76d6da805..279e0c042 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4_1.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4_1.cs @@ -9,7 +9,7 @@ namespace Indy.IL2CPU.IL.X86 { public class Ldc_I4_1: Ldc_I4 { public Ldc_I4_1(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - SetLocalIndex(1, aMethodInfo); + SetValue(1); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4_2.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4_2.cs index a8fc91a1b..06c767657 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4_2.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4_2.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldc_I4_2)] - public class Ldc_I4_2: Op { + public class Ldc_I4_2: Ldc_I4 { public Ldc_I4_2(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - } - public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + SetValue(2); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4_3.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4_3.cs index 623353594..301154c58 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4_3.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4_3.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldc_I4_3)] - public class Ldc_I4_3: Op { + public class Ldc_I4_3: Ldc_I4 { public Ldc_I4_3(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - } - public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + SetValue(3); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4_4.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4_4.cs index 482c998fd..12eb58ea4 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4_4.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4_4.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldc_I4_4)] - public class Ldc_I4_4: Op { + public class Ldc_I4_4: Ldc_I4 { public Ldc_I4_4(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - } - public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + SetValue(3); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4_5.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4_5.cs index 524a41e90..c558238ab 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4_5.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4_5.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldc_I4_5)] - public class Ldc_I4_5: Op { + public class Ldc_I4_5: Ldc_I4 { public Ldc_I4_5(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - } - public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + SetValue(5); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4_6.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4_6.cs index a7e7d2cc6..2a9ca9bc6 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4_6.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4_6.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldc_I4_6)] - public class Ldc_I4_6: Op { + public class Ldc_I4_6: Ldc_I4 { public Ldc_I4_6(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - } - public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + SetValue(6); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4_7.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4_7.cs index a548648b6..af0417315 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4_7.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4_7.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldc_I4_7)] - public class Ldc_I4_7: Op { + public class Ldc_I4_7: Ldc_I4 { public Ldc_I4_7(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - } - public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + SetValue(7); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4_8.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4_8.cs index 3bd441ff7..9c0fd1243 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4_8.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4_8.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldc_I4_8)] - public class Ldc_I4_8: Op { + public class Ldc_I4_8: Ldc_I4 { public Ldc_I4_8(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - } - public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + SetValue(8); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4_M1.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4_M1.cs index 1f925e437..d04865706 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4_M1.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4_M1.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldc_I4_M1)] - public class Ldc_I4_M1: Op { + public class Ldc_I4_M1: Ldc_I4 { public Ldc_I4_M1(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - } - public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + SetValue(-1); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4_S.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4_S.cs index 91fc0cb2f..372392a35 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4_S.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4_S.cs @@ -6,15 +6,9 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldc_I4_S)] - public class Ldc_I4_S: Op { - public readonly string Value; + public class Ldc_I4_S: Ldc_I4 { public Ldc_I4_S(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - Value = (aInstruction.Operand ?? "").ToString(); - } - - public override void Assemble() { - Pushd(Value); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldloc.cs b/source/Indy.IL2CPU.IL.X86/Ldloc.cs index 07b03f363..ea6287d0c 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldloc.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldloc.cs @@ -9,7 +9,7 @@ namespace Indy.IL2CPU.IL.X86 { public class Ldloc: Op { private int mOffset; protected void SetLocalIndex(int aIndex, MethodInformation aMethodInfo) { - mOffset = aMethodInfo.Locals[aIndex].Offset + aMethodInfo.Locals[aIndex].Size + 4; + mOffset = aMethodInfo.Locals[aIndex].Offset + aMethodInfo.Locals[aIndex].Size + 8; } public Ldloc(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { @@ -27,7 +27,7 @@ namespace Indy.IL2CPU.IL.X86 { public sealed override void Assemble() { Push("eax"); - Move("eax", "[esp+" + mOffset + "]"); + Move("eax", "[ebp+" + mOffset + "]"); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldloca.cs b/source/Indy.IL2CPU.IL.X86/Ldloca.cs index 63b5a1457..c8b434004 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldloca.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldloca.cs @@ -9,7 +9,7 @@ namespace Indy.IL2CPU.IL.X86 { public class Ldloca: Op { private int mOffset; protected void SetLocalIndex(int aIndex, MethodInformation aMethodInfo) { - mOffset = aMethodInfo.Locals[aIndex].Offset + aMethodInfo.Locals[aIndex].Size + 4; + mOffset = aMethodInfo.Locals[aIndex].Offset + aMethodInfo.Locals[aIndex].Size + 84; } public Ldloca(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { @@ -27,7 +27,7 @@ namespace Indy.IL2CPU.IL.X86 { public sealed override void Assemble() { Push("eax"); - Move("eax", "[esp+" + mOffset + "]"); + Move("eax", "[ebp+" + mOffset + "]"); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Newobj.cs b/source/Indy.IL2CPU.IL.X86/Newobj.cs index 4b1060504..a9b21773c 100644 --- a/source/Indy.IL2CPU.IL.X86/Newobj.cs +++ b/source/Indy.IL2CPU.IL.X86/Newobj.cs @@ -15,7 +15,7 @@ namespace Indy.IL2CPU.IL.X86 { public Newobj(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - CtorName = new Asm.Label(((MethodReference)aInstruction.Operand).Name).Name; + CtorName = new Asm.Label((MethodReference)aInstruction.Operand).Name; } public override void Assemble() { diff --git a/source/Indy.IL2CPU.IL.X86/Ret.cs b/source/Indy.IL2CPU.IL.X86/Ret.cs index 180d5efd4..8227dbe45 100644 --- a/source/Indy.IL2CPU.IL.X86/Ret.cs +++ b/source/Indy.IL2CPU.IL.X86/Ret.cs @@ -7,11 +7,15 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ret)] public class Ret: Op { + private bool mHasReturn; public Ret(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { + mHasReturn = aMethodInfo.HasReturnValue; } public override void Assemble() { - //Ret(); + if (mHasReturn) { + //Push("eax"); + } } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Stloc.cs b/source/Indy.IL2CPU.IL.X86/Stloc.cs index b992e3683..de4bc8794 100644 --- a/source/Indy.IL2CPU.IL.X86/Stloc.cs +++ b/source/Indy.IL2CPU.IL.X86/Stloc.cs @@ -7,9 +7,9 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Stloc)] public class Stloc: Op { - private int mOffset; + private string mAddress; protected void SetLocalIndex(int aIndex, MethodInformation aMethodInfo) { - mOffset = aMethodInfo.Locals[aIndex].Offset + aMethodInfo.Locals[aIndex].Size + 4; + mAddress = aMethodInfo.Locals[aIndex].VirtualAddress; } public Stloc(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { @@ -19,15 +19,15 @@ namespace Indy.IL2CPU.IL.X86 { } } - public int Offset { + public string Address { get { - return mOffset; + return mAddress; } } public sealed override void Assemble() { Pop("eax"); - Move("[esp+" + mOffset + "]", "eax"); + Move("[" + mAddress + "]", "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 50d93a115..7f52fb8a0 100644 --- a/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs +++ b/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs @@ -9,6 +9,7 @@ namespace Indy.IL2CPU.IL.X86 { public class X86MethodFooterOp: MethodFooterOp { public readonly int TotalLocalsSize = 0; public readonly int TotalArgsSize = 0; + public readonly int LocalsCount = 0; public X86MethodFooterOp(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { if (aMethodInfo.Arguments.Length > 0) { @@ -17,10 +18,18 @@ namespace Indy.IL2CPU.IL.X86 { if (aMethodInfo.Locals.Length > 0) { TotalLocalsSize += aMethodInfo.Locals[aMethodInfo.Locals.Length - 1].Offset + aMethodInfo.Locals[aMethodInfo.Locals.Length - 1].Size; } + LocalsCount = aMethodInfo.Locals.Length; + if(aMethodInfo.HasReturnValue) { + TotalLocalsSize += 4; + LocalsCount++; + } } public override void Assemble() { Assembler.Add(new CPU.Add("esp", TotalLocalsSize.ToString())); + for (int i = 0; i < LocalsCount; i++) { + Assembler.Add(new CPU.Pop("ebp")); + } Assembler.Add(new CPU.Ret(TotalArgsSize.ToString())); } } diff --git a/source/Indy.IL2CPU.IL.X86/X86MethodHeaderOp.cs b/source/Indy.IL2CPU.IL.X86/X86MethodHeaderOp.cs index 8e4f620bf..8c892840c 100644 --- a/source/Indy.IL2CPU.IL.X86/X86MethodHeaderOp.cs +++ b/source/Indy.IL2CPU.IL.X86/X86MethodHeaderOp.cs @@ -18,8 +18,9 @@ namespace Indy.IL2CPU.IL.X86 { public override void Assemble() { // TODO: add support for variables with a diff datasize, other than 32bit Assembler.Add(new CPU.Label(LabelName)); + Assembler.Add(new CPUx86.Move("ebp", "esp")); for (int i = 0; i < LocalsCount; i++) { - Assembler.Add(new CPUx86.Pushd(" 0")); + Assembler.Add(new CPUx86.Pushd("ebp")); } } } diff --git a/source/Indy.IL2CPU.IL/MethodInformation.cs b/source/Indy.IL2CPU.IL/MethodInformation.cs index 9feea603f..ec09e54f3 100644 --- a/source/Indy.IL2CPU.IL/MethodInformation.cs +++ b/source/Indy.IL2CPU.IL/MethodInformation.cs @@ -9,9 +9,11 @@ namespace Indy.IL2CPU.IL { public Variable(int aOffset, int aSize) { Offset = aOffset; Size = aSize; + VirtualAddress = "ebp + " + (Offset + Size + 8); } public readonly int Offset; public readonly int Size; + public readonly string VirtualAddress; } public struct Argument { @@ -24,14 +26,16 @@ namespace Indy.IL2CPU.IL { public readonly int Offset; } - public MethodInformation(string aLabelName, Variable[] aLocals, Argument[] aArguments) { + public MethodInformation(string aLabelName, Variable[] aLocals, Argument[] aArguments, bool aHasReturnValue) { Locals = aLocals; LabelName = aLabelName; Arguments = aArguments; + HasReturnValue = aHasReturnValue; } public readonly string LabelName; public readonly Variable[] Locals; public readonly Argument[] Arguments; + public readonly bool HasReturnValue; } } \ No newline at end of file diff --git a/source/Indy.IL2CPU/Engine.cs b/source/Indy.IL2CPU/Engine.cs index 27c9caf92..8e0a78ec9 100644 --- a/source/Indy.IL2CPU/Engine.cs +++ b/source/Indy.IL2CPU/Engine.cs @@ -11,9 +11,9 @@ using Mono.Cecil; using Mono.Cecil.Cil; using Instruction = Mono.Cecil.Cil.Instruction; -ERROR +//ERROR -We need a special local vars register in the assembly +//We need a special local vars register in the assembly namespace Indy.IL2CPU { public class MethodDefinitionComparer: IComparer { @@ -122,7 +122,7 @@ namespace Indy.IL2CPU { xArgs[i] = new MethodInformation.Argument(xArgSize, xCurOffset); xCurOffset += xArgSize; } - xMethodInfo = new MethodInformation(new Label(xCurrentMethod).Name, xVars, xArgs); + xMethodInfo = new MethodInformation(new Label(xCurrentMethod).Name, xVars, xArgs, !xCurrentMethod.ReturnType.ReturnType.FullName.Contains("System.Void")); } IL.Op xOp = GetOpFromType(mMap.MethodHeaderOp, null, xMethodInfo); xOp.Assembler = mAssembler;