From 491be780f8d78320bb035b757ebfb6da18a1668d Mon Sep 17 00:00:00 2001 From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD> Date: Tue, 4 Sep 2007 17:16:30 +0000 Subject: [PATCH] doesn't work, see comments. some progress has been made, though --- source/HelloWorldMetal/Program.cs | 72 +++++++++++++-------- source/IL2CPU/IL2CPU.csproj | 4 ++ source/IL2CPU/Program.cs | 2 +- source/Indy.IL2CPU.Assembler/Assembler.cs | 1 - source/Indy.IL2CPU.Assembler/Label.cs | 8 +-- source/Indy.IL2CPU.IL.X86/Call.cs | 5 ++ source/Indy.IL2CPU.IL.X86/LdStr.cs | 10 +-- source/Indy.IL2CPU.IL.X86/Ldloc.cs | 20 +++++- source/Indy.IL2CPU.IL.X86/Ldloc_0.cs | 6 +- source/Indy.IL2CPU.IL.X86/Ldloc_1.cs | 6 +- source/Indy.IL2CPU.IL.X86/Ldloc_2.cs | 6 +- source/Indy.IL2CPU.IL.X86/Ldloc_3.cs | 6 +- source/Indy.IL2CPU.IL.X86/Ldloc_S.cs | 5 +- source/Indy.IL2CPU.IL.X86/Ldloca.cs | 20 +++++- source/Indy.IL2CPU.IL.X86/Ldloca_S.cs | 5 +- source/Indy.IL2CPU.IL.X86/Ldsfld.cs | 8 ++- source/Indy.IL2CPU.IL.X86/Op.cs | 1 + source/Indy.IL2CPU.IL.X86/Pop.cs | 2 +- source/Indy.IL2CPU.IL.X86/Stloc.cs | 20 +++++- source/Indy.IL2CPU.IL.X86/Stloc_0.cs | 9 +-- source/Indy.IL2CPU.IL.X86/Stloc_1.cs | 6 +- source/Indy.IL2CPU.IL.X86/Stloc_2.cs | 6 +- source/Indy.IL2CPU.IL.X86/Stloc_3.cs | 6 +- source/Indy.IL2CPU.IL.X86/Stloc_S.cs | 5 +- source/Indy.IL2CPU.IL/Indy.IL2CPU.IL.csproj | 1 + source/Indy.IL2CPU.IL/Op.cs | 1 + source/Indy.IL2CPU.IL/Utilities.cs | 22 +++++++ source/Indy.IL2CPU/Engine.cs | 4 ++ 28 files changed, 170 insertions(+), 97 deletions(-) create mode 100644 source/Indy.IL2CPU.IL/Utilities.cs diff --git a/source/HelloWorldMetal/Program.cs b/source/HelloWorldMetal/Program.cs index d10fcc09a..27ac1a4fa 100644 --- a/source/HelloWorldMetal/Program.cs +++ b/source/HelloWorldMetal/Program.cs @@ -1,33 +1,49 @@ using System; +using System.Runtime.InteropServices; +using System.Threading; namespace HelloWorldMetal { - // Restrictions for Metal compile is that static members only, and no heap usage - // Basic string support is provided by using c strings in data sections - class Program { - // These would be output in the data section. Since no heap exists, - // all are treated as globals and space is fixed and preallocated - static int Level = 0; - static string StringValue = "Hello"; + // Restrictions for Metal compile is that static members only, and no heap usage + // Basic string support is provided by using c strings in data sections + class Program { + // These would be output in the data section. Since no heap exists, + // all are treated as globals and space is fixed and preallocated + // MtW: + // Don't make them consts, this will copy the value, and produce + // an ldstr, which Creates (which is evil in Metal mode) a new string. + // declaring as follows makes it reuse the code + public static string Message = "Hello, World"; - static void Main() { - // Local variables are ok too, since they are stack based - int i = 0; - // String literals translate to ldstr - these would automatically be pulled out - // and put in the data section. String manipuation not permitted unless the actual - // bytes are modified directly. - // - // Implement the P/Invoke interface. This will allow interfacing to Windows - // and other systems. - // - // Certain statics can have points mapped and replaced with future metal code - // or translations to P/Invokes. - // Such as Console.Write. It can be determined by name and remapped to - // the Win32 calll. - // Console.Write("Hello World"); - // For now - lets stick with P/Invoke only - I want to do some more investigation - // around map replacement - // So the current test would be - declare a P/Invoke for writing to console in Win32 - // then call it below with "HelloWorld" - } - } + static void Main() { + // Local variables are ok too, since they are stack based + int i = 0; + string theMessage = "Hello, World!"; + // String literals translate to ldstr - these would automatically be pulled out + // and put in the data section. String manipuation not permitted unless the actual + // bytes are modified directly. + // + // Implement the P/Invoke interface. This will allow interfacing to Windows + // and other systems. + // + // Certain statics can have points mapped and replaced with future metal code + // or translations to P/Invokes. + // Such as Console.Write. It can be determined by name and remapped to + // the Win32 calll. + // Console.Write("Hello World"); + // For now - lets stick with P/Invoke only - I want to do some more investigation + // around map replacement + // So the current test would be - declare a P/Invoke for writing to console in Win32 + // then call it below with "HelloWorld" + IntPtr xHandle = GetStdHandle(-11); + uint xCharsWritten = 0; + WriteConsole(xHandle, theMessage, 13, out xCharsWritten, IntPtr.Zero); + } + + [DllImport("kernel32.dll")] + static extern IntPtr GetStdHandle(int nStdHandle); + [DllImport("kernel32.dll")] + static extern bool WriteConsole(IntPtr hConsoleOutput, string lpBuffer, + uint nNumberOfCharsToWrite, out uint lpNumberOfCharsWritten, + IntPtr lpReserved); + } } diff --git a/source/IL2CPU/IL2CPU.csproj b/source/IL2CPU/IL2CPU.csproj index 5a0d031c1..c24ab938a 100644 --- a/source/IL2CPU/IL2CPU.csproj +++ b/source/IL2CPU/IL2CPU.csproj @@ -49,6 +49,10 @@ + + {B57BEF6D-48D6-49DD-B4C5-893537E0EBB8} + HelloWorldMetal + {0267F1AE-CA81-4EBD-86CA-C8E22BE9A6F1} HelloWorld diff --git a/source/IL2CPU/Program.cs b/source/IL2CPU/Program.cs index 8ae4efe9e..3d116ebf5 100644 --- a/source/IL2CPU/Program.cs +++ b/source/IL2CPU/Program.cs @@ -14,7 +14,7 @@ namespace IL2CPU { }; using (FileStream fs = new FileStream(@"output.asm", FileMode.Create)) { using (StreamWriter br = new StreamWriter(fs)) { - e.Execute("HelloWorld.exe", TargetPlatformEnum.x86, br); + e.Execute("HelloWorldMetal.exe", TargetPlatformEnum.x86, br); } } } catch (Exception E) { diff --git a/source/Indy.IL2CPU.Assembler/Assembler.cs b/source/Indy.IL2CPU.Assembler/Assembler.cs index 51f5c67cc..fa4a2ea75 100644 --- a/source/Indy.IL2CPU.Assembler/Assembler.cs +++ b/source/Indy.IL2CPU.Assembler/Assembler.cs @@ -118,6 +118,5 @@ namespace Indy.IL2CPU.Assembler { } } } - } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.Assembler/Label.cs b/source/Indy.IL2CPU.Assembler/Label.cs index 43c667f2a..260c6b8c0 100644 --- a/source/Indy.IL2CPU.Assembler/Label.cs +++ b/source/Indy.IL2CPU.Assembler/Label.cs @@ -51,13 +51,7 @@ namespace Indy.IL2CPU.Assembler { xSB.Append("_"); } xSB.Append("__"); - xSB.Replace('.', '_'); - xSB.Replace('+', '_'); - xSB.Replace('*', '_'); - xSB.Replace('[', '_'); - xSB.Replace(']', '_'); - return xSB.ToString(); + return xSB.ToString().Replace('.', '_').Replace('+', '_').Replace('*', '_').Replace('[', '_').Replace(']', '_').Replace('&', '_'); } - } } diff --git a/source/Indy.IL2CPU.IL.X86/Call.cs b/source/Indy.IL2CPU.IL.X86/Call.cs index 8724f77d9..7cd0fe82e 100644 --- a/source/Indy.IL2CPU.IL.X86/Call.cs +++ b/source/Indy.IL2CPU.IL.X86/Call.cs @@ -9,12 +9,17 @@ namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Call)] public class Call: Op { public readonly string LabelName; + public readonly bool HasResult; public Call(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { + HasResult = !((MethodReference)aInstruction.Operand).ReturnType.ReturnType.FullName.Contains("System.Void"); LabelName = new Asm.Label((MethodReference)aInstruction.Operand).Name; } public void Assemble(string aMethod) { Call(aMethod); + if(HasResult) { + Push("EAX"); + } } public override void Assemble() { diff --git a/source/Indy.IL2CPU.IL.X86/LdStr.cs b/source/Indy.IL2CPU.IL.X86/LdStr.cs index e25f422d8..a84761f0c 100644 --- a/source/Indy.IL2CPU.IL.X86/LdStr.cs +++ b/source/Indy.IL2CPU.IL.X86/LdStr.cs @@ -18,7 +18,7 @@ namespace Indy.IL2CPU.IL.X86 { public override void Assemble() { // Make sure the crawler finds string constructors - DoQueueMethod(typeof(String).Assembly.FullName, typeof(String).FullName, ".ctor"); + //DoQueueMethod(typeof(String).Assembly.FullName, typeof(String).FullName, ".ctor"); // todo: see if we need to output trailing bytes 00 00 or 00 01 depending on whether there are bytes >7F string xDataName = Assembler.GetIdentifier("StringLiteral"); var xDataByteArray = new StringBuilder(); @@ -28,10 +28,10 @@ namespace Indy.IL2CPU.IL.X86 { } Assembler.DataMembers.Add(new DataMember(xDataName, "db", xDataByteArray.ToString().TrimEnd(','))); Pushd(xDataName); - new Newobj() { - CtorName = (new Label(typeof(String).FullName, typeof(Char).FullName + "*")).Name, - Assembler = Assembler - }.Assemble(); +// new Newobj() { +// CtorName = (new Label(typeof(String).FullName, typeof(Char).FullName + "*")).Name, +// Assembler = Assembler +// }.Assemble(); } } } \ 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 11d86e285..07b03f363 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldloc.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldloc.cs @@ -7,11 +7,27 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldloc)] public class Ldloc: Op { + private int mOffset; + protected void SetLocalIndex(int aIndex, MethodInformation aMethodInfo) { + mOffset = aMethodInfo.Locals[aIndex].Offset + aMethodInfo.Locals[aIndex].Size + 4; + } public Ldloc(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { + int xLocalIndex; + if (Int32.TryParse((aInstruction.Operand ?? "").ToString(), out xLocalIndex)) { + SetLocalIndex(xLocalIndex, aMethodInfo); + } } - public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + + public int Offset { + get { + return mOffset; + } + } + + public sealed override void Assemble() { + Push("eax"); + Move("eax", "[esp+" + mOffset + "]"); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldloc_0.cs b/source/Indy.IL2CPU.IL.X86/Ldloc_0.cs index 2b04c54f9..6d455ddc9 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldloc_0.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldloc_0.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldloc_0)] - public class Ldloc_0: Op { + public class Ldloc_0: Ldloc { public Ldloc_0(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!"); + SetLocalIndex(0, aMethodInfo); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldloc_1.cs b/source/Indy.IL2CPU.IL.X86/Ldloc_1.cs index 1ebc04d09..5da3111a8 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldloc_1.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldloc_1.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldloc_1)] - public class Ldloc_1: Op { + public class Ldloc_1: Ldloc { public Ldloc_1(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!"); + SetLocalIndex(1, aMethodInfo); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldloc_2.cs b/source/Indy.IL2CPU.IL.X86/Ldloc_2.cs index f25ce318f..08031e57b 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldloc_2.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldloc_2.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldloc_2)] - public class Ldloc_2: Op { + public class Ldloc_2: Ldloc { public Ldloc_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!"); + SetLocalIndex(2, aMethodInfo); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldloc_3.cs b/source/Indy.IL2CPU.IL.X86/Ldloc_3.cs index 482a29da6..0f6a54c56 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldloc_3.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldloc_3.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldloc_3)] - public class Ldloc_3: Op { + public class Ldloc_3: Ldloc { public Ldloc_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!"); + SetLocalIndex(3, aMethodInfo); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldloc_S.cs b/source/Indy.IL2CPU.IL.X86/Ldloc_S.cs index 0b3cb8635..5b1c2453f 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldloc_S.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldloc_S.cs @@ -6,12 +6,9 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldloc_S)] - public class Ldloc_S: Op { + public class Ldloc_S: Ldloc { public Ldloc_S(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!"); - } } } \ 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 ecf515317..63b5a1457 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldloca.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldloca.cs @@ -7,11 +7,27 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldloca)] public class Ldloca: Op { + private int mOffset; + protected void SetLocalIndex(int aIndex, MethodInformation aMethodInfo) { + mOffset = aMethodInfo.Locals[aIndex].Offset + aMethodInfo.Locals[aIndex].Size + 4; + } public Ldloca(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { + int xLocalIndex; + if (Int32.TryParse((aInstruction.Operand ?? "").ToString(), out xLocalIndex)) { + SetLocalIndex(xLocalIndex, aMethodInfo); + } } - public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + + public int Offset { + get { + return mOffset; + } + } + + public sealed override void Assemble() { + Push("eax"); + Move("eax", "[esp+" + mOffset + "]"); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldloca_S.cs b/source/Indy.IL2CPU.IL.X86/Ldloca_S.cs index 5b287a6ac..334b404ab 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldloca_S.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldloca_S.cs @@ -6,12 +6,9 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldloca_S)] - public class Ldloca_S: Op { + public class Ldloca_S: Ldloca { public Ldloca_S(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!"); - } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Ldsfld.cs b/source/Indy.IL2CPU.IL.X86/Ldsfld.cs index c681d1730..923c76f93 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldsfld.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldsfld.cs @@ -7,11 +7,17 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Ldsfld)] public class Ldsfld: Op { + private bool IsIntPtrZero = false; public Ldsfld(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { + IsIntPtrZero = aInstruction.Operand.ToString() == "System.IntPtr System.IntPtr::Zero"; } public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + if(IsIntPtrZero) { + Pushd("0"); + return; + } + throw new NotImplementedException(); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Op.cs b/source/Indy.IL2CPU.IL.X86/Op.cs index 41ff93e2f..1ccf9565c 100644 --- a/source/Indy.IL2CPU.IL.X86/Op.cs +++ b/source/Indy.IL2CPU.IL.X86/Op.cs @@ -2,6 +2,7 @@ using System.Linq; using Indy.IL2CPU.Assembler; using Indy.IL2CPU.Assembler.X86; +using Mono.Cecil; using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { diff --git a/source/Indy.IL2CPU.IL.X86/Pop.cs b/source/Indy.IL2CPU.IL.X86/Pop.cs index d485c7c40..d6682280f 100644 --- a/source/Indy.IL2CPU.IL.X86/Pop.cs +++ b/source/Indy.IL2CPU.IL.X86/Pop.cs @@ -11,7 +11,7 @@ namespace Indy.IL2CPU.IL.X86 { : base(aInstruction, aMethodInfo) { } public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + Pop("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 deaab4d0b..b992e3683 100644 --- a/source/Indy.IL2CPU.IL.X86/Stloc.cs +++ b/source/Indy.IL2CPU.IL.X86/Stloc.cs @@ -7,11 +7,27 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Stloc)] public class Stloc: Op { + private int mOffset; + protected void SetLocalIndex(int aIndex, MethodInformation aMethodInfo) { + mOffset = aMethodInfo.Locals[aIndex].Offset + aMethodInfo.Locals[aIndex].Size + 4; + } public Stloc(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { + int xLocalIndex; + if (Int32.TryParse((aInstruction.Operand ?? "").ToString(), out xLocalIndex)) { + SetLocalIndex(xLocalIndex, aMethodInfo); + } } - public override void Assemble() { - throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!"); + + public int Offset { + get { + return mOffset; + } + } + + public sealed override void Assemble() { + Pop("eax"); + Move("[esp+" + mOffset + "]", "eax"); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Stloc_0.cs b/source/Indy.IL2CPU.IL.X86/Stloc_0.cs index 0fcc6507e..81fb44a45 100644 --- a/source/Indy.IL2CPU.IL.X86/Stloc_0.cs +++ b/source/Indy.IL2CPU.IL.X86/Stloc_0.cs @@ -6,15 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Stloc_0)] - public class Stloc_0: Op { + public class Stloc_0: Stloc { public Stloc_0(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) : base(aInstruction, aMethodInfo) { - } - public override void Assemble() { - Pop("eax"); - Move("[esp+0]", "eax"); - //Move("eax", "[esp + " + (aMethodInfo.Locals[aMethodInfo.Locals.Length - 1].Offset + aMethodInfo.Locals[aMethodInfo.Locals.Length - 1].Size + 4) + "]"); - //Move("[esp + " + (aMethodInfo.Locals[0].Offset + 4) + "]", "eax"); + base.SetLocalIndex(0, aMethodInfo); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Stloc_1.cs b/source/Indy.IL2CPU.IL.X86/Stloc_1.cs index e97689cca..8d9b3cfcf 100644 --- a/source/Indy.IL2CPU.IL.X86/Stloc_1.cs +++ b/source/Indy.IL2CPU.IL.X86/Stloc_1.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Stloc_1)] - public class Stloc_1: Op { + public class Stloc_1: Stloc { public Stloc_1(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!"); + base.SetLocalIndex(1, aMethodInfo); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Stloc_2.cs b/source/Indy.IL2CPU.IL.X86/Stloc_2.cs index 664c5a0ec..b42a8c621 100644 --- a/source/Indy.IL2CPU.IL.X86/Stloc_2.cs +++ b/source/Indy.IL2CPU.IL.X86/Stloc_2.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Stloc_2)] - public class Stloc_2: Op { + public class Stloc_2: Stloc { public Stloc_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!"); + base.SetLocalIndex(2, aMethodInfo); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Stloc_3.cs b/source/Indy.IL2CPU.IL.X86/Stloc_3.cs index aa909f18c..e25917844 100644 --- a/source/Indy.IL2CPU.IL.X86/Stloc_3.cs +++ b/source/Indy.IL2CPU.IL.X86/Stloc_3.cs @@ -6,12 +6,10 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Stloc_3)] - public class Stloc_3: Op { + public class Stloc_3: Stloc { public Stloc_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!"); + base.SetLocalIndex(3, aMethodInfo); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Stloc_S.cs b/source/Indy.IL2CPU.IL.X86/Stloc_S.cs index c06f0b2ad..62d24a63c 100644 --- a/source/Indy.IL2CPU.IL.X86/Stloc_S.cs +++ b/source/Indy.IL2CPU.IL.X86/Stloc_S.cs @@ -6,12 +6,9 @@ using CPU = Indy.IL2CPU.Assembler.X86; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Stloc_S)] - public class Stloc_S: Op { + public class Stloc_S: Stloc { public Stloc_S(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!"); - } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL/Indy.IL2CPU.IL.csproj b/source/Indy.IL2CPU.IL/Indy.IL2CPU.IL.csproj index 3223dd2ec..06ee9d133 100644 --- a/source/Indy.IL2CPU.IL/Indy.IL2CPU.IL.csproj +++ b/source/Indy.IL2CPU.IL/Indy.IL2CPU.IL.csproj @@ -54,6 +54,7 @@ + diff --git a/source/Indy.IL2CPU.IL/Op.cs b/source/Indy.IL2CPU.IL/Op.cs index e3b36c274..6a479a2dd 100644 --- a/source/Indy.IL2CPU.IL/Op.cs +++ b/source/Indy.IL2CPU.IL/Op.cs @@ -10,6 +10,7 @@ using Cil = Mono.Cecil.Cil; namespace Indy.IL2CPU.IL { public abstract class Op { public delegate void QueueMethodHandler(string aAssembly, string aType, string aMethod); + public abstract void Assemble(); public Op(Instruction aInstruction, MethodInformation aMethodInfo) { diff --git a/source/Indy.IL2CPU.IL/Utilities.cs b/source/Indy.IL2CPU.IL/Utilities.cs new file mode 100644 index 000000000..a900885bf --- /dev/null +++ b/source/Indy.IL2CPU.IL/Utilities.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Mono.Cecil; + +namespace Indy.IL2CPU.IL { + public class Utilities { + public static string GetUniqueConstName(FieldDefinition aField) { + StringBuilder xSB = new StringBuilder(); + xSB.Append("const "); + xSB.Append(aField.FieldType.FullName); + xSB.Append(" "); + xSB.Append(aField.Name); + return FixupIdentifierForAsm(xSB.ToString()); + } + + public static string FixupIdentifierForAsm(string aIdentifier) { + return aIdentifier.Replace('.', '_').Replace('+', '_').Replace('*', '_').Replace('[', '_').Replace(']', '_').Replace('&', '_'); + } + } +} \ No newline at end of file diff --git a/source/Indy.IL2CPU/Engine.cs b/source/Indy.IL2CPU/Engine.cs index cd1d3242b..27c9caf92 100644 --- a/source/Indy.IL2CPU/Engine.cs +++ b/source/Indy.IL2CPU/Engine.cs @@ -11,6 +11,10 @@ using Mono.Cecil; using Mono.Cecil.Cil; using Instruction = Mono.Cecil.Cil.Instruction; +ERROR + +We need a special local vars register in the assembly + namespace Indy.IL2CPU { public class MethodDefinitionComparer: IComparer { #region IComparer Members