diff --git a/source/HelloWorld/Program.cs b/source/HelloWorld/Program.cs
index 7f29a1cda..dfc915b23 100644
--- a/source/HelloWorld/Program.cs
+++ b/source/HelloWorld/Program.cs
@@ -74,7 +74,8 @@ namespace HelloWorld {
public static void UseArray() {
int[] values = new int[] { 1, 2, 3, 4 };
int total = values[0] + values[1] + values[2] + values[3];
-
+ values[0] = 10;
+ total = total + values[0] + values[1] + values[2] + values[3];
}
public static void DoWriteLines() {
diff --git a/source/IL2CPU.Tests/Tests/TestSimpleArrays/TestSimpleArrays.cs b/source/IL2CPU.Tests/Tests/TestSimpleArrays/TestSimpleArrays.cs
index 02b32396f..30b2bb796 100644
--- a/source/IL2CPU.Tests/Tests/TestSimpleArrays/TestSimpleArrays.cs
+++ b/source/IL2CPU.Tests/Tests/TestSimpleArrays/TestSimpleArrays.cs
@@ -6,5 +6,7 @@ class ConsoleDrv
{
int[] xTestValues = new int[] {1, 2, 3, 4};
int xSum = xTestValues[0] + xTestValues[1] + xTestValues[2] + xTestValues[3];
+ xTestValues[0] = 10;
+ xSum = xSum + xTestValues[0] + xTestValues[1] + xTestValues[2] + xTestValues[3];
}
}
\ No newline at end of file
diff --git a/source/IL2CPU.Tests/Tests/TestSimpleArrays/TestSimpleArrays.exe b/source/IL2CPU.Tests/Tests/TestSimpleArrays/TestSimpleArrays.exe
index f6b422986..7f201c1db 100644
Binary files a/source/IL2CPU.Tests/Tests/TestSimpleArrays/TestSimpleArrays.exe and b/source/IL2CPU.Tests/Tests/TestSimpleArrays/TestSimpleArrays.exe differ
diff --git a/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj b/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj
index 198ecfeb5..317a32da6 100644
--- a/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj
+++ b/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj
@@ -57,7 +57,9 @@
+
+
diff --git a/source/Indy.IL2CPU.Assembler.X86/JumpIfGreaterOrEquals.cs b/source/Indy.IL2CPU.Assembler.X86/JumpIfGreaterOrEquals.cs
new file mode 100644
index 000000000..4f83b5c3f
--- /dev/null
+++ b/source/Indy.IL2CPU.Assembler.X86/JumpIfGreaterOrEquals.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Indy.IL2CPU.Assembler.X86 {
+ [OpCode(0xFFFFFFFF, "jbe")]
+ public class JumpIfGreaterOrEquals: Instruction {
+ public readonly string Address;
+ public JumpIfGreaterOrEquals(string aAddress) {
+ Address = aAddress;
+ }
+
+ public override string ToString() {
+ return "jbe " + Address;
+ }
+ }
+}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.Assembler.X86/JumpIfLessOrEqual.cs b/source/Indy.IL2CPU.Assembler.X86/JumpIfLessOrEqual.cs
new file mode 100644
index 000000000..a654db357
--- /dev/null
+++ b/source/Indy.IL2CPU.Assembler.X86/JumpIfLessOrEqual.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Indy.IL2CPU.Assembler.X86 {
+ ///
+ /// Represents the JLE opcode
+ ///
+ [OpCode(0xFFFFFFFF, "jle")]
+ public class JumpIfLessOrEqual: Instruction {
+ public readonly string Address;
+ public JumpIfLessOrEqual(string aAddress) {
+ Address = aAddress;
+ }
+ public override string ToString() {
+ return "jle " + Address;
+ }
+ }
+}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Beq.cs b/source/Indy.IL2CPU.IL.X86/Beq.cs
index a3a4c22af..2592978d9 100644
--- a/source/Indy.IL2CPU.IL.X86/Beq.cs
+++ b/source/Indy.IL2CPU.IL.X86/Beq.cs
@@ -26,12 +26,8 @@ namespace Indy.IL2CPU.IL.X86 {
Assembler.Add(new CPU.Label(LabelTrue));
Assembler.Add(new CPUx86.Add("esp", "4"));
Assembler.Add(new CPUx86.JumpAlways(TargetLabel));
- // Assembler.Add(new CPUx86.Pop("eax"));
- // Assembler.Add(new CPUx86.Move("[esp]", "eax"));
Assembler.Add(new CPU.Label(LabelFalse));
Assembler.Add(new CPUx86.Add("esp", "4"));
- // Assembler.Add(new CPUx86.Pop("eax"));
- // Assembler.Add(new CPUx86.Move("[esp]", "eax"));
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Bge.cs b/source/Indy.IL2CPU.IL.X86/Bge.cs
index a6c7d7e6a..bd501b410 100644
--- a/source/Indy.IL2CPU.IL.X86/Bge.cs
+++ b/source/Indy.IL2CPU.IL.X86/Bge.cs
@@ -2,16 +2,32 @@ using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
-using CPU = Indy.IL2CPU.Assembler.X86;
+using CPU = Indy.IL2CPU.Assembler;
+using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Bge)]
public class Bge: Op {
+ public readonly string TargetLabel;
+ public readonly string CurInstructionLabel;
public Bge(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
+ TargetLabel = GetInstructionLabel((Instruction)aInstruction.Operand);
+ CurInstructionLabel = GetInstructionLabel(aInstruction);
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ string BaseLabel = CurInstructionLabel + "__";
+ string LabelTrue = BaseLabel + "True";
+ string LabelFalse = BaseLabel + "False";
+ Assembler.Add(new CPUx86.Pop("eax"));
+ Assembler.Add(new CPUx86.Compare("eax", "[esp]"));
+ Assembler.Add(new CPUx86.JumpIfGreaterOrEquals(LabelTrue));
+ Assembler.Add(new CPUx86.JumpAlways(LabelFalse));
+ Assembler.Add(new CPU.Label(LabelTrue));
+ Assembler.Add(new CPUx86.Add("esp", "4"));
+ Assembler.Add(new CPUx86.JumpAlways(TargetLabel));
+ Assembler.Add(new CPU.Label(LabelFalse));
+ Assembler.Add(new CPUx86.Add("esp", "4"));
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Bge_S.cs b/source/Indy.IL2CPU.IL.X86/Bge_S.cs
index 27475e447..78d89b8ec 100644
--- a/source/Indy.IL2CPU.IL.X86/Bge_S.cs
+++ b/source/Indy.IL2CPU.IL.X86/Bge_S.cs
@@ -6,12 +6,9 @@ using CPU = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Bge_S)]
- public class Bge_S: Op {
+ public class Bge_S: Bge {
public Bge_S(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
}
- public override void DoAssemble() {
- 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/Bgt.cs b/source/Indy.IL2CPU.IL.X86/Bgt.cs
index b2083570b..9782f21e8 100644
--- a/source/Indy.IL2CPU.IL.X86/Bgt.cs
+++ b/source/Indy.IL2CPU.IL.X86/Bgt.cs
@@ -2,16 +2,32 @@ using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
-using CPU = Indy.IL2CPU.Assembler.X86;
+using CPU = Indy.IL2CPU.Assembler;
+using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Bgt)]
public class Bgt: Op {
+ public readonly string TargetLabel;
+ public readonly string CurInstructionLabel;
public Bgt(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
+ TargetLabel = GetInstructionLabel((Instruction)aInstruction.Operand);
+ CurInstructionLabel = GetInstructionLabel(aInstruction);
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ string BaseLabel = CurInstructionLabel + "__";
+ string LabelTrue = BaseLabel + "True";
+ string LabelFalse = BaseLabel + "False";
+ Assembler.Add(new CPUx86.Pop("eax"));
+ Assembler.Add(new CPUx86.Compare("eax", "[esp]"));
+ Assembler.Add(new CPUx86.JumpIfGreater(LabelTrue));
+ Assembler.Add(new CPUx86.JumpAlways(LabelFalse));
+ Assembler.Add(new CPU.Label(LabelTrue));
+ Assembler.Add(new CPUx86.Add("esp", "4"));
+ Assembler.Add(new CPUx86.JumpAlways(TargetLabel));
+ Assembler.Add(new CPU.Label(LabelFalse));
+ Assembler.Add(new CPUx86.Add("esp", "4"));
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Bgt_S.cs b/source/Indy.IL2CPU.IL.X86/Bgt_S.cs
index ee00d3ce6..15e2ed6da 100644
--- a/source/Indy.IL2CPU.IL.X86/Bgt_S.cs
+++ b/source/Indy.IL2CPU.IL.X86/Bgt_S.cs
@@ -6,12 +6,9 @@ using CPU = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Bgt_S)]
- public class Bgt_S: Op {
+ public class Bgt_S: Bgt {
public Bgt_S(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
}
- public override void DoAssemble() {
- 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/Ble.cs b/source/Indy.IL2CPU.IL.X86/Ble.cs
index 0a3e3831d..71c4e90c9 100644
--- a/source/Indy.IL2CPU.IL.X86/Ble.cs
+++ b/source/Indy.IL2CPU.IL.X86/Ble.cs
@@ -2,16 +2,32 @@ using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
-using CPU = Indy.IL2CPU.Assembler.X86;
+using CPU = Indy.IL2CPU.Assembler;
+using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Ble)]
public class Ble: Op {
+ public readonly string TargetLabel;
+ public readonly string CurInstructionLabel;
public Ble(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
+ TargetLabel = GetInstructionLabel((Instruction)aInstruction.Operand);
+ CurInstructionLabel = GetInstructionLabel(aInstruction);
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ string BaseLabel = CurInstructionLabel + "__";
+ string LabelTrue = BaseLabel + "True";
+ string LabelFalse = BaseLabel + "False";
+ Assembler.Add(new CPUx86.Pop("eax"));
+ Assembler.Add(new CPUx86.Compare("eax", "[esp]"));
+ Assembler.Add(new CPUx86.JumpIfLessOrEqual(LabelTrue));
+ Assembler.Add(new CPUx86.JumpAlways(LabelFalse));
+ Assembler.Add(new CPU.Label(LabelTrue));
+ Assembler.Add(new CPUx86.Add("esp", "4"));
+ Assembler.Add(new CPUx86.JumpAlways(TargetLabel));
+ Assembler.Add(new CPU.Label(LabelFalse));
+ Assembler.Add(new CPUx86.Add("esp", "4"));
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Ble_S.cs b/source/Indy.IL2CPU.IL.X86/Ble_S.cs
index c527ee387..fad6976fa 100644
--- a/source/Indy.IL2CPU.IL.X86/Ble_S.cs
+++ b/source/Indy.IL2CPU.IL.X86/Ble_S.cs
@@ -6,12 +6,9 @@ using CPU = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Ble_S)]
- public class Ble_S: Op {
+ public class Ble_S: Ble {
public Ble_S(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
}
- public override void DoAssemble() {
- 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/Blt.cs b/source/Indy.IL2CPU.IL.X86/Blt.cs
index 0203cb294..ccdd41775 100644
--- a/source/Indy.IL2CPU.IL.X86/Blt.cs
+++ b/source/Indy.IL2CPU.IL.X86/Blt.cs
@@ -2,16 +2,32 @@ using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
-using CPU = Indy.IL2CPU.Assembler.X86;
+using CPU = Indy.IL2CPU.Assembler;
+using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Blt)]
public class Blt: Op {
+ public readonly string TargetLabel;
+ public readonly string CurInstructionLabel;
public Blt(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
+ TargetLabel = GetInstructionLabel((Instruction)aInstruction.Operand);
+ CurInstructionLabel = GetInstructionLabel(aInstruction);
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ string BaseLabel = CurInstructionLabel + "__";
+ string LabelTrue = BaseLabel + "True";
+ string LabelFalse = BaseLabel + "False";
+ Assembler.Add(new CPUx86.Pop("eax"));
+ Assembler.Add(new CPUx86.Compare("eax", "[esp]"));
+ Assembler.Add(new CPUx86.JumpIfLess(LabelTrue));
+ Assembler.Add(new CPUx86.JumpAlways(LabelFalse));
+ Assembler.Add(new CPU.Label(LabelTrue));
+ Assembler.Add(new CPUx86.Add("esp", "4"));
+ Assembler.Add(new CPUx86.JumpAlways(TargetLabel));
+ Assembler.Add(new CPU.Label(LabelFalse));
+ Assembler.Add(new CPUx86.Add("esp", "4"));
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Blt_S.cs b/source/Indy.IL2CPU.IL.X86/Blt_S.cs
index 1e1ee62b4..b31f15b7f 100644
--- a/source/Indy.IL2CPU.IL.X86/Blt_S.cs
+++ b/source/Indy.IL2CPU.IL.X86/Blt_S.cs
@@ -6,12 +6,9 @@ using CPU = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Blt_S)]
- public class Blt_S: Op {
+ public class Blt_S: Blt {
public Blt_S(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
}
- public override void DoAssemble() {
- 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/Bne_Un.cs b/source/Indy.IL2CPU.IL.X86/Bne_Un.cs
index 33675a804..e3d4bd2e3 100644
--- a/source/Indy.IL2CPU.IL.X86/Bne_Un.cs
+++ b/source/Indy.IL2CPU.IL.X86/Bne_Un.cs
@@ -2,16 +2,32 @@ using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
-using CPU = Indy.IL2CPU.Assembler.X86;
+using CPU = Indy.IL2CPU.Assembler;
+using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Bne_Un)]
public class Bne_Un: Op {
+ public readonly string TargetLabel;
+ public readonly string CurInstructionLabel;
public Bne_Un(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
+ TargetLabel = GetInstructionLabel((Instruction)aInstruction.Operand);
+ CurInstructionLabel = GetInstructionLabel(aInstruction);
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ string BaseLabel = CurInstructionLabel + "__";
+ string LabelTrue = BaseLabel + "True";
+ string LabelFalse = BaseLabel + "False";
+ Assembler.Add(new CPUx86.Pop("eax"));
+ Assembler.Add(new CPUx86.Compare("eax", "[esp]"));
+ Assembler.Add(new CPUx86.JumpIfEquals(LabelTrue));
+ Assembler.Add(new CPUx86.JumpAlways(LabelFalse));
+ Assembler.Add(new CPU.Label(LabelFalse));
+ Assembler.Add(new CPUx86.Add("esp", "4"));
+ Assembler.Add(new CPUx86.JumpAlways(TargetLabel));
+ Assembler.Add(new CPU.Label(LabelTrue));
+ Assembler.Add(new CPUx86.Add("esp", "4"));
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Bne_Un_S.cs b/source/Indy.IL2CPU.IL.X86/Bne_Un_S.cs
index 9cc08412a..aeadbd5f1 100644
--- a/source/Indy.IL2CPU.IL.X86/Bne_Un_S.cs
+++ b/source/Indy.IL2CPU.IL.X86/Bne_Un_S.cs
@@ -6,12 +6,9 @@ using CPU = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Bne_Un_S)]
- public class Bne_Un_S: Op {
+ public class Bne_Un_S: Bne_Un {
public Bne_Un_S(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
}
- public override void DoAssemble() {
- 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/Brfalse.cs b/source/Indy.IL2CPU.IL.X86/Brfalse.cs
index 1d12f91ce..f23afce84 100644
--- a/source/Indy.IL2CPU.IL.X86/Brfalse.cs
+++ b/source/Indy.IL2CPU.IL.X86/Brfalse.cs
@@ -7,11 +7,15 @@ using CPU = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Brfalse)]
public class Brfalse: Op {
+ public readonly string TargetLabel;
public Brfalse(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
+ TargetLabel = GetInstructionLabel((Instruction)aInstruction.Operand);
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ Assembler.Add(new CPU.Popd("eax"));
+ Assembler.Add(new CPU.Compare("eax", "00h"));
+ Assembler.Add(new CPU.JumpIfEquals(TargetLabel));
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Brfalse_S.cs b/source/Indy.IL2CPU.IL.X86/Brfalse_S.cs
index 3c105ff46..c4039b497 100644
--- a/source/Indy.IL2CPU.IL.X86/Brfalse_S.cs
+++ b/source/Indy.IL2CPU.IL.X86/Brfalse_S.cs
@@ -6,12 +6,9 @@ using CPU = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Brfalse_S)]
- public class Brfalse_S: Op {
+ public class Brfalse_S: Brfalse {
public Brfalse_S(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
}
- public override void DoAssemble() {
- 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/Conv_I8.cs b/source/Indy.IL2CPU.IL.X86/Conv_I8.cs
index 78fe14ebe..56926fe0d 100644
--- a/source/Indy.IL2CPU.IL.X86/Conv_I8.cs
+++ b/source/Indy.IL2CPU.IL.X86/Conv_I8.cs
@@ -11,7 +11,8 @@ namespace Indy.IL2CPU.IL.X86 {
: base(aInstruction, aMethodInfo) {
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ // todo: WARNING: not implemented correctly!
+ //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/Conv_U.cs b/source/Indy.IL2CPU.IL.X86/Conv_U.cs
index a35b39e1b..189a471a5 100644
--- a/source/Indy.IL2CPU.IL.X86/Conv_U.cs
+++ b/source/Indy.IL2CPU.IL.X86/Conv_U.cs
@@ -11,7 +11,8 @@ namespace Indy.IL2CPU.IL.X86 {
: base(aInstruction, aMethodInfo) {
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ // todo: check for correctness
+ //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/Endfinally.cs b/source/Indy.IL2CPU.IL.X86/Endfinally.cs
index a2dfee932..df39e39e1 100644
--- a/source/Indy.IL2CPU.IL.X86/Endfinally.cs
+++ b/source/Indy.IL2CPU.IL.X86/Endfinally.cs
@@ -11,7 +11,8 @@ namespace Indy.IL2CPU.IL.X86 {
: base(aInstruction, aMethodInfo) {
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ // TODO: unimplemented
+ //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/Ldelem_Ref.cs b/source/Indy.IL2CPU.IL.X86/Ldelem_Ref.cs
index 8250b9d4c..e184b7b03 100644
--- a/source/Indy.IL2CPU.IL.X86/Ldelem_Ref.cs
+++ b/source/Indy.IL2CPU.IL.X86/Ldelem_Ref.cs
@@ -2,16 +2,29 @@ using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
-using CPU = Indy.IL2CPU.Assembler.X86;
+using CPU = Indy.IL2CPU.Assembler;
+using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Ldelem_Ref, false)]
public class Ldelem_Ref: Op {
- public Ldelem_Ref(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
+ public Ldelem_Ref(Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
}
+
+ public static void Assemble(CPU.Assembler aAssembler) {
+ aAssembler.Add(new CPUx86.Pop("eax"));
+ aAssembler.Add(new CPUx86.Move("edx", "4"));
+ aAssembler.Add(new CPUx86.Multiply("edx"));
+ aAssembler.Add(new CPUx86.Add("eax", "0" + (ObjectImpl.FieldDataOffset + 4).ToString("X") + "h"));
+ aAssembler.Add(new CPUx86.Pop("edx"));
+ aAssembler.Add(new CPUx86.Add("edx", "eax"));
+ aAssembler.Add(new CPUx86.Move("eax", "[edx]"));
+ aAssembler.Add(new CPUx86.Pushd("eax"));
+ }
+
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ Assemble(Assembler);
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Ldelema.cs b/source/Indy.IL2CPU.IL.X86/Ldelema.cs
index 88a0770f6..144139c3b 100644
--- a/source/Indy.IL2CPU.IL.X86/Ldelema.cs
+++ b/source/Indy.IL2CPU.IL.X86/Ldelema.cs
@@ -2,16 +2,28 @@ using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
-using CPU = Indy.IL2CPU.Assembler.X86;
+using CPU = Indy.IL2CPU.Assembler;
+using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Ldelema, false)]
public class Ldelema: Op {
- public Ldelema(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
+ public Ldelema(Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
}
+
+ public static void Assemble(CPU.Assembler aAssembler) {
+ aAssembler.Add(new CPUx86.Pop("eax"));
+ aAssembler.Add(new CPUx86.Move("edx", "4"));
+ aAssembler.Add(new CPUx86.Multiply("edx"));
+ aAssembler.Add(new CPUx86.Add("eax", "0" + (ObjectImpl.FieldDataOffset + 4).ToString("X") + "h"));
+ aAssembler.Add(new CPUx86.Pop("edx"));
+ aAssembler.Add(new CPUx86.Add("edx", "eax"));
+ aAssembler.Add(new CPUx86.Pushd("edx"));
+ }
+
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ Assemble(Assembler);
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Ldnull.cs b/source/Indy.IL2CPU.IL.X86/Ldnull.cs
index cb0dfdfdf..7d99dc714 100644
--- a/source/Indy.IL2CPU.IL.X86/Ldnull.cs
+++ b/source/Indy.IL2CPU.IL.X86/Ldnull.cs
@@ -11,7 +11,7 @@ namespace Indy.IL2CPU.IL.X86 {
: base(aInstruction, aMethodInfo) {
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ Pushd("0");
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Ldobj.cs b/source/Indy.IL2CPU.IL.X86/Ldobj.cs
index 7f12bf192..1f34c7040 100644
--- a/source/Indy.IL2CPU.IL.X86/Ldobj.cs
+++ b/source/Indy.IL2CPU.IL.X86/Ldobj.cs
@@ -11,7 +11,8 @@ namespace Indy.IL2CPU.IL.X86 {
: base(aInstruction, aMethodInfo) {
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ // todo: implement correctly
+ //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/Ldsflda.cs b/source/Indy.IL2CPU.IL.X86/Ldsflda.cs
index 4f5abbb62..ca28cc401 100644
--- a/source/Indy.IL2CPU.IL.X86/Ldsflda.cs
+++ b/source/Indy.IL2CPU.IL.X86/Ldsflda.cs
@@ -7,11 +7,16 @@ using CPU = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Ldsflda)]
public class Ldsflda: Op {
+ private readonly string mDataName;
+
public Ldsflda(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
+ FieldReference xField = (FieldReference)aInstruction.Operand;
+ DoQueueStaticField(xField.DeclaringType.Module.Assembly.Name.Name, xField.DeclaringType.FullName, xField.Name, out mDataName);
}
+
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ Pushd(mDataName);
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Leave.cs b/source/Indy.IL2CPU.IL.X86/Leave.cs
index 5d7368249..b835d82cd 100644
--- a/source/Indy.IL2CPU.IL.X86/Leave.cs
+++ b/source/Indy.IL2CPU.IL.X86/Leave.cs
@@ -6,12 +6,13 @@ using CPU = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Leave)]
- public class Leave: Op {
- public Leave(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
+ public class Leave: Op {public readonly string TargetLabel;
+ public Leave(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
+ TargetLabel = GetInstructionLabel((Instruction)aInstruction.Operand);
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ JumpAlways(TargetLabel);
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Leave_S.cs b/source/Indy.IL2CPU.IL.X86/Leave_S.cs
index 4a04d3a43..7e9f68a37 100644
--- a/source/Indy.IL2CPU.IL.X86/Leave_S.cs
+++ b/source/Indy.IL2CPU.IL.X86/Leave_S.cs
@@ -6,12 +6,9 @@ using CPU = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Leave_S)]
- public class Leave_S: Op {
+ public class Leave_S: Leave {
public Leave_S(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
}
- public override void DoAssemble() {
- 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/Stelem_Ref.cs b/source/Indy.IL2CPU.IL.X86/Stelem_Ref.cs
index 3599b6a08..644f56544 100644
--- a/source/Indy.IL2CPU.IL.X86/Stelem_Ref.cs
+++ b/source/Indy.IL2CPU.IL.X86/Stelem_Ref.cs
@@ -2,7 +2,8 @@ using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
-using CPU = Indy.IL2CPU.Assembler.X86;
+using CPU = Indy.IL2CPU.Assembler;
+using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Stelem_Ref, false)]
@@ -10,8 +11,21 @@ namespace Indy.IL2CPU.IL.X86 {
public Stelem_Ref(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
}
+ public static void Assemble(CPU.Assembler aAssembler) {
+ // stack - 3 == the array
+ // stack - 2 == the index
+ // stack - 1 == the new value
+ aAssembler.Add(new CPUx86.Pop("ecx")); // the new value;
+ aAssembler.Add(new CPUx86.Pop("eax")); // the index
+ aAssembler.Add(new CPUx86.Move("edx", "4"));
+ aAssembler.Add(new CPUx86.Multiply("edx"));
+ aAssembler.Add(new CPUx86.Add("eax", "0" + (ObjectImpl.FieldDataOffset + 4).ToString("X") + "h"));
+ aAssembler.Add(new CPUx86.Pop("edx"));
+ aAssembler.Add(new CPUx86.Add("edx", "eax"));
+ aAssembler.Add(new CPUx86.Move("[edx]", "ecx"));
+ }
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ Assemble(Assembler);
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Throw.cs b/source/Indy.IL2CPU.IL.X86/Throw.cs
index 99427e6b0..3cea6ee21 100644
--- a/source/Indy.IL2CPU.IL.X86/Throw.cs
+++ b/source/Indy.IL2CPU.IL.X86/Throw.cs
@@ -11,7 +11,8 @@ namespace Indy.IL2CPU.IL.X86 {
: base(aInstruction, aMethodInfo) {
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ // TODO: unimplemented
+ Assembler.Add(new CPU.Add("esp", "4"));
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/X86CustomMethodImplementationOp.cs b/source/Indy.IL2CPU.IL.X86/X86CustomMethodImplementationOp.cs
index 4f2788df3..8354bb061 100644
--- a/source/Indy.IL2CPU.IL.X86/X86CustomMethodImplementationOp.cs
+++ b/source/Indy.IL2CPU.IL.X86/X86CustomMethodImplementationOp.cs
@@ -50,29 +50,31 @@ namespace Indy.IL2CPU.IL.X86 {
protected override void Assemble_System_Void___System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray___System_Array__System_RuntimeFieldHandle___() {
// Arguments:
// Array aArray, RuntimeFieldHandle aFieldHandle
- Assembler.Add(new CPUx86.Pushd(MethodInfo.Arguments[0].VirtualAddress));
- Assembler.Add(new CPUx86.Pushd(MethodInfo.Arguments[1].VirtualAddress));
- Op x = new Call(Engine.GetMethodDefinition(Engine.GetTypeDefinition("", "Indy.IL2CPU.CustomImplementation.CompilerServices.RuntimeHelpers"), "InitializeArrayImpl", "System.Int32[]", "System.Int32[]"));
- x.Assembler = Assembler;
- x.Assemble();
-// Assembler.Add(new CPUx86.Move("eax", "0"));
-// Assembler.Add(new CPUx86.Move("edi", "[" + MethodInfo.Arguments[0].VirtualAddress + "]"));
-// Assembler.Add(new CPUx86.Move("esi", "[" + MethodInfo.Arguments[1].VirtualAddress + "]"));
-// Assembler.Add(new CPUx86.Move("ecx", "[esi]"));
-// Assembler.Add(new CPUx86.Add("dword esi", "12"));
-// Assembler.Add(new CPUx86.Add("dword edi", "12"));
-//
-// Assembler.Add(new CPU.Label(".StartLoop"));
-// Assembler.Add(new CPUx86.Move("edx", "[esi]"));
-// Assembler.Add(new CPUx86.Move("[edi]", "edx"));
-// Assembler.Add(new CPUx86.Add("eax", "4"));
-// Assembler.Add(new CPUx86.Add("dword esi", "4"));
-// Assembler.Add(new CPUx86.Add("dword edi", "4"));
-// Assembler.Add(new CPUx86.Compare("eax", "ecx"));
-// Assembler.Add(new CPUx86.JumpIfEquals(".EndLoop"));
-// Assembler.Add(new CPUx86.JumpAlways(".StartLoop"));
-//
-// Assembler.Add(new CPU.Label(".EndLoop"));
+// Assembler.Add(new CPUx86.Pushd(MethodInfo.Arguments[0].VirtualAddress));
+// Assembler.Add(new CPUx86.Pushd(MethodInfo.Arguments[1].VirtualAddress));
+// Op x = new Call(Engine.GetMethodDefinition(Engine.GetTypeDefinition("", "Indy.IL2CPU.CustomImplementation.CompilerServices.RuntimeHelpers"), "InitializeArrayImpl", "System.Int32[]", "System.Int32[]"));
+// x.Assembler = Assembler;
+// x.Assemble();
+ Assembler.Add(new CPU.Literal(";In Pure ASM defined"));
+ Assembler.Add(new CPUx86.Move("eax", "0"));
+ Assembler.Add(new CPUx86.Move("edi", "[" + MethodInfo.Arguments[0].VirtualAddress + "]"));
+ Assembler.Add(new CPUx86.Move("esi", "[" + MethodInfo.Arguments[1].VirtualAddress + "]"));
+ Assembler.Add(new CPUx86.Add("dword esi", "8"));
+ Assembler.Add(new CPUx86.Move("ecx", "[esi]"));
+ Assembler.Add(new CPUx86.Add("dword esi", "4"));
+ Assembler.Add(new CPUx86.Add("dword edi", "12"));
+
+ Assembler.Add(new CPU.Label(".StartLoop"));
+ Assembler.Add(new CPUx86.Move("edx", "[esi]"));
+ Assembler.Add(new CPUx86.Move("[edi]", "edx"));
+ Assembler.Add(new CPUx86.Add("eax", "4"));
+ Assembler.Add(new CPUx86.Add("dword esi", "4"));
+ Assembler.Add(new CPUx86.Add("dword edi", "4"));
+ Assembler.Add(new CPUx86.Compare("eax", "ecx"));
+ Assembler.Add(new CPUx86.JumpIfEquals(".EndLoop"));
+ Assembler.Add(new CPUx86.JumpAlways(".StartLoop"));
+
+ Assembler.Add(new CPU.Label(".EndLoop"));
}
}
}
diff --git a/source/Indy.IL2CPU/CustomImplementation/System/Runtime/CompilerServices/RuntimeHelpers.cs b/source/Indy.IL2CPU/CustomImplementation/System/Runtime/CompilerServices/RuntimeHelpers.cs
index fddc95281..b6713fdc2 100644
--- a/source/Indy.IL2CPU/CustomImplementation/System/Runtime/CompilerServices/RuntimeHelpers.cs
+++ b/source/Indy.IL2CPU/CustomImplementation/System/Runtime/CompilerServices/RuntimeHelpers.cs
@@ -8,7 +8,7 @@ namespace Indy.IL2CPU.CustomImplementation.CompilerServices {
//[DllImport("test.dll")]
//public static extern void InitializeArray(Array aArray, RuntimeFieldHandle aFieldHandle);
public static void InitializeArrayImpl(int[] aArray, int[] aFieldHandle) {
- for (int i = 0; i < aFieldHandle.Length; i++) {
+ for (int i = 0; i < aArray.Length; i++) {
aArray[i] = aFieldHandle[i];
}
}
diff --git a/source/Indy.IL2CPU/Engine.cs b/source/Indy.IL2CPU/Engine.cs
index e16b8f3bf..e920ed44c 100644
--- a/source/Indy.IL2CPU/Engine.cs
+++ b/source/Indy.IL2CPU/Engine.cs
@@ -142,6 +142,9 @@ namespace Indy.IL2CPU {
if (mCurrent == null) {
throw new Exception("No Current engine found!");
}
+ if(aRef.FullName.Contains("modreq")) {
+ aRef = aRef.GetOriginalType();
+ }
if (aRef.FullName.EndsWith("[]")) {
return GetTypeDefinition(aRef.Module.Assembly.Name.Name, aRef.FullName.Substring(0, aRef.FullName.Length - 2));
}
@@ -172,7 +175,7 @@ namespace Indy.IL2CPU {
mCurrent.OnDebugLog("Error: Unhandled scope: " + aRef.Scope == null ? "**NULL**" : aRef.Scope.GetType().FullName);
}
}
- throw new Exception("Could not find TypeDefinition! (" + aRef.FullName + ")");
+ throw new Exception("Could not find TypeDefinition! (" + aRef.FullName + " in assembly " + aRef.Module.Assembly.Name.Name + ")");
}
///
@@ -222,6 +225,9 @@ namespace Indy.IL2CPU {
} else {
if (xCurrentField.InitialValue != null && xCurrentField.InitialValue.Length > 0) {
string xTheData = "";
+ if(xCurrentField.InitialValue.Length>4) {
+ xTheData = "0,0,0,0,2,0,0,0,";
+ }
foreach (byte x in BitConverter.GetBytes(xCurrentField.InitialValue.Length)) {
xTheData += x + ",";
}