diff --git a/source/IL2CPU.Tests/IL2CPU.Tests.csproj b/source/IL2CPU.Tests/IL2CPU.Tests.csproj
new file mode 100644
index 000000000..be90bd7fd
--- /dev/null
+++ b/source/IL2CPU.Tests/IL2CPU.Tests.csproj
@@ -0,0 +1,97 @@
+
+
+
+ Debug
+ AnyCPU
+ 9.0.20706
+ 2.0
+ {3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}
+ Exe
+ Properties
+ IL2CPU.Tests
+ IL2CPU.Tests
+ v3.5
+ 512
+ SAK
+ SAK
+ SAK
+ SAK
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+ 3.5
+
+
+
+
+
+
+
+
+
+
+
+
+ Always
+
+
+
+
+ {B7E87073-CFFB-4972-BA0B-DCF0C3A0C930}
+ IL2CPU
+
+
+
+
+ Always
+
+
+ Always
+
+
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+
+
+ Always
+
+
+ Always
+
+
+
+
+
\ No newline at end of file
diff --git a/source/IL2CPU.Tests/IL2CPU.Tests.csproj.vspscc b/source/IL2CPU.Tests/IL2CPU.Tests.csproj.vspscc
new file mode 100644
index 000000000..feffdecaa
--- /dev/null
+++ b/source/IL2CPU.Tests/IL2CPU.Tests.csproj.vspscc
@@ -0,0 +1,10 @@
+""
+{
+"FILE_VERSION" = "9237"
+"ENLISTMENT_CHOICE" = "NEVER"
+"PROJECT_FILE_RELATIVE_PATH" = ""
+"NUMBER_OF_EXCLUDED_FILES" = "0"
+"ORIGINAL_PROJECT_FILE_PATH" = ""
+"NUMBER_OF_NESTED_PROJECTS" = "0"
+"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
+}
diff --git a/source/IL2CPU.Tests/Program.cs b/source/IL2CPU.Tests/Program.cs
new file mode 100644
index 000000000..7181e9d33
--- /dev/null
+++ b/source/IL2CPU.Tests/Program.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.IO;
+using System.Text;
+
+namespace IL2CPU.Tests {
+ class Program {
+ public const int TestTimeout_Seconds = 10;
+ public const int TestTimeout_Milliseconds = TestTimeout_Seconds * 1000;
+ static void Main(string[] args) {
+ SortedList xTests = new SortedList();
+ Console.WriteLine("IL2CPU Tester. Please be patient while all tests are executed");
+ Console.WriteLine();
+ string xBaseDir = Path.GetDirectoryName(typeof(Program).Assembly.Location);
+ string xBaseTestsDir = Path.Combine(xBaseDir, "Tests");
+ foreach (string s in Directory.GetFiles(xBaseTestsDir, "*.expected.asm", SearchOption.AllDirectories)) {
+ if (File.Exists(s.Replace(".expected.asm", ".exe"))) {
+ xTests.Add(s.Replace(".expected.asm", ".exe"), null);
+ }
+ }
+ Console.WriteLine("Found {0} tests. Executing now:", xTests.Count);
+ for (int i = 0; i < xTests.Count; i++) {
+ string xTestExe = xTests.Keys[i];
+ string xExpectedResultFile = xTestExe.Substring(0, xTestExe.Length - ".exe".Length) + ".expected.asm";
+ string xActualOutputFile = Path.GetTempFileName();
+ try {
+ ProcessStartInfo xStartInfo = new ProcessStartInfo();
+ xStartInfo.CreateNoWindow = true;
+ xStartInfo.UseShellExecute = false;
+ xStartInfo.FileName = Path.Combine(xBaseDir, "IL2CPU.exe");
+ xStartInfo.Arguments = "\"" + xTestExe + "\" \"" + xActualOutputFile + "\"";
+ Process xProc = Process.Start(xStartInfo);
+ if (!xProc.WaitForExit(TestTimeout_Milliseconds)) {
+ xTests[xTestExe] = null;
+ Console.Write("E");
+ }
+ if (String.Equals(File.ReadAllText(xExpectedResultFile), File.ReadAllText(xActualOutputFile))) {
+ xTests[xTestExe] = true;
+ Console.Write(".");
+ } else {
+ xTests[xTestExe] = false;
+ Console.Write("F");
+ }
+ } finally {
+ File.Delete(xActualOutputFile);
+ }
+ }
+ Console.WriteLine();
+ Console.WriteLine("Test execution done.");
+ if ((from item in xTests
+ where item.Value == false
+ select item.Key).Count() > 0) {
+ Console.WriteLine("Tests Failed:");
+ foreach (string s in (from item in xTests
+ where item.Value == false
+ select item.Key)) {
+ Console.WriteLine("\t" + s);
+ }
+ }
+ if ((from item in xTests
+ where item.Value == null
+ select item.Key).Count() > 0) {
+ Console.WriteLine("Tests Timed out:");
+ foreach (string s in (from item in xTests
+ where item.Value == null
+ select item.Key)) {
+ Console.WriteLine("\t" + s);
+ }
+ }
+ int xPassCount = (from item in xTests
+ where item.Value == true
+ select item).Count();
+ int xFailCount = (from item in xTests
+ where item.Value == false
+ select item).Count();
+ int xTimeoutCount = (from item in xTests
+ where item.Value == null
+ select item).Count();
+ Console.WriteLine("\tTests passed: {0}/{1}", xPassCount, xTests.Count);
+ Console.WriteLine("\tTests failed: {0}/{1}", xFailCount, xTests.Count);
+ Console.WriteLine("\tTests timed out: {0}/{1}", xTimeoutCount, xTests.Count);
+ }
+ }
+}
diff --git a/source/IL2CPU.Tests/Properties/AssemblyInfo.cs b/source/IL2CPU.Tests/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000..e37166f08
--- /dev/null
+++ b/source/IL2CPU.Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("IL2CPU.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("IL2CPU.Tests")]
+[assembly: AssemblyCopyright("Copyright © 2007")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("7be32638-7ce5-4584-a737-ccf459665a54")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/source/IL2CPU.Tests/Tests/EmptyMethod/TestEmptyMethodApp.cs b/source/IL2CPU.Tests/Tests/EmptyMethod/TestEmptyMethodApp.cs
new file mode 100644
index 000000000..e31353398
--- /dev/null
+++ b/source/IL2CPU.Tests/Tests/EmptyMethod/TestEmptyMethodApp.cs
@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace IL2CPU.Tests.Tests {
+ public class TestEmptyMethodApp {
+ public static void Main() {
+ }
+ }
+}
diff --git a/source/IL2CPU.Tests/Tests/EmptyMethod/TestEmptyMethodApp.exe b/source/IL2CPU.Tests/Tests/EmptyMethod/TestEmptyMethodApp.exe
new file mode 100644
index 000000000..280be0637
Binary files /dev/null and b/source/IL2CPU.Tests/Tests/EmptyMethod/TestEmptyMethodApp.exe differ
diff --git a/source/IL2CPU.Tests/Tests/EmptyMethod/TestEmptyMethodApp.expected.asm b/source/IL2CPU.Tests/Tests/EmptyMethod/TestEmptyMethodApp.expected.asm
new file mode 100644
index 000000000..e71f2fed4
--- /dev/null
+++ b/source/IL2CPU.Tests/Tests/EmptyMethod/TestEmptyMethodApp.expected.asm
@@ -0,0 +1,16 @@
+format PE console
+entry ___ENTRYPOINT___
+
+
+section '.code' code readable executable
+
+ ___ENTRYPOINT___:
+ jmp System_Void___IL2CPU_Tests_Tests_TestEmptyMethodApp_Main____
+
+ System_Void___IL2CPU_Tests_Tests_TestEmptyMethodApp_Main____:
+ mov ebp,esp
+ ; IL: Nop
+ nop
+ ; IL: Ret
+ ret
+
diff --git a/source/IL2CPU.Tests/Tests/SimpleMethodCall/SimpleMethodCall.cs b/source/IL2CPU.Tests/Tests/SimpleMethodCall/SimpleMethodCall.cs
new file mode 100644
index 000000000..21dfcb5e4
--- /dev/null
+++ b/source/IL2CPU.Tests/Tests/SimpleMethodCall/SimpleMethodCall.cs
@@ -0,0 +1,12 @@
+using System;
+
+public static class Program
+{
+ public static void Main()
+ {
+ TheMethod();
+ }
+ public static void TheMethod()
+ {
+ }
+}
\ No newline at end of file
diff --git a/source/IL2CPU.Tests/Tests/SimpleMethodCall/SimpleMethodCall.exe b/source/IL2CPU.Tests/Tests/SimpleMethodCall/SimpleMethodCall.exe
new file mode 100644
index 000000000..174b24dab
Binary files /dev/null and b/source/IL2CPU.Tests/Tests/SimpleMethodCall/SimpleMethodCall.exe differ
diff --git a/source/IL2CPU.Tests/Tests/SimpleMethodCall/SimpleMethodCall.expected.asm b/source/IL2CPU.Tests/Tests/SimpleMethodCall/SimpleMethodCall.expected.asm
new file mode 100644
index 000000000..eb09caafa
--- /dev/null
+++ b/source/IL2CPU.Tests/Tests/SimpleMethodCall/SimpleMethodCall.expected.asm
@@ -0,0 +1,27 @@
+format PE console
+entry ___ENTRYPOINT___
+
+
+section '.code' code readable executable
+
+ ___ENTRYPOINT___:
+ jmp System_Void___Program_Main____
+
+ System_Void___Program_Main____:
+ mov ebp,esp
+ ; IL: Nop
+ nop
+ ; IL: Call System.Void Program::TheMethod()
+ call System_Void___Program_TheMethod____
+ ; IL: Nop
+ nop
+ ; IL: Ret
+ ret
+
+ System_Void___Program_TheMethod____:
+ mov ebp,esp
+ ; IL: Nop
+ nop
+ ; IL: Ret
+ ret
+
diff --git a/source/IL2CPU.Tests/Tests/SimpleVar/SimpleVar.cs b/source/IL2CPU.Tests/Tests/SimpleVar/SimpleVar.cs
new file mode 100644
index 000000000..b1b86e1b0
--- /dev/null
+++ b/source/IL2CPU.Tests/Tests/SimpleVar/SimpleVar.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace IL2CPU.Tests.Tests {
+ public class TestEmptyMethodApp {
+ public static void Main() {
+ int TempInt = 5;
+ }
+ }
+}
diff --git a/source/IL2CPU.Tests/Tests/SimpleVar/SimpleVar.exe b/source/IL2CPU.Tests/Tests/SimpleVar/SimpleVar.exe
new file mode 100644
index 000000000..3863a08e4
Binary files /dev/null and b/source/IL2CPU.Tests/Tests/SimpleVar/SimpleVar.exe differ
diff --git a/source/IL2CPU.Tests/Tests/SimpleVar/SimpleVar.expected.asm b/source/IL2CPU.Tests/Tests/SimpleVar/SimpleVar.expected.asm
new file mode 100644
index 000000000..10fab663d
--- /dev/null
+++ b/source/IL2CPU.Tests/Tests/SimpleVar/SimpleVar.expected.asm
@@ -0,0 +1,23 @@
+format PE console
+entry ___ENTRYPOINT___
+
+
+section '.code' code readable executable
+
+ ___ENTRYPOINT___:
+ jmp System_Void___IL2CPU_Tests_Tests_TestEmptyMethodApp_Main____
+
+ System_Void___IL2CPU_Tests_Tests_TestEmptyMethodApp_Main____:
+ mov ebp,esp
+ pushd ebp
+ ; IL: Nop
+ nop
+ ; IL: Ldc_I4_5
+ pushd 5
+ ; IL: Stloc_0
+ pop eax
+ mov [ebp + 12],eax
+ ; IL: Ret
+ pop ebp
+ ret
+
diff --git a/source/IL2CPU.Tests/Tests/SingleMethodWithParam/SingleMethodWithParam.cs b/source/IL2CPU.Tests/Tests/SingleMethodWithParam/SingleMethodWithParam.cs
new file mode 100644
index 000000000..b300c4b16
--- /dev/null
+++ b/source/IL2CPU.Tests/Tests/SingleMethodWithParam/SingleMethodWithParam.cs
@@ -0,0 +1,14 @@
+using System;
+
+public static class Program
+{
+ public static void Main()
+ {
+ TheMethod(2);
+ }
+
+ public static void TheMethod(int aParam)
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/source/IL2CPU.Tests/Tests/SingleMethodWithParam/SingleMethodWithParam.exe b/source/IL2CPU.Tests/Tests/SingleMethodWithParam/SingleMethodWithParam.exe
new file mode 100644
index 000000000..a873d558f
Binary files /dev/null and b/source/IL2CPU.Tests/Tests/SingleMethodWithParam/SingleMethodWithParam.exe differ
diff --git a/source/IL2CPU.Tests/Tests/SingleMethodWithParam/SingleMethodWithParam.expected.asm b/source/IL2CPU.Tests/Tests/SingleMethodWithParam/SingleMethodWithParam.expected.asm
new file mode 100644
index 000000000..156b88348
--- /dev/null
+++ b/source/IL2CPU.Tests/Tests/SingleMethodWithParam/SingleMethodWithParam.expected.asm
@@ -0,0 +1,29 @@
+format PE console
+entry ___ENTRYPOINT___
+
+
+section '.code' code readable executable
+
+ ___ENTRYPOINT___:
+ jmp System_Void___Program_Main____
+
+ System_Void___Program_Main____:
+ mov ebp,esp
+ ; IL: Nop
+ nop
+ ; IL: Ldc_I4_2
+ pushd 2
+ ; IL: Call System.Void Program::TheMethod(System.Int32)
+ call System_Void___Program_TheMethod___System_Int32___
+ ; IL: Nop
+ nop
+ ; IL: Ret
+ ret
+
+ System_Void___Program_TheMethod___System_Int32___:
+ mov ebp,esp
+ ; IL: Nop
+ nop
+ ; IL: Ret
+ ret 4
+
diff --git a/source/IL2CPU.sln b/source/IL2CPU.sln
index 164077e57..ddedc0e41 100644
--- a/source/IL2CPU.sln
+++ b/source/IL2CPU.sln
@@ -21,9 +21,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldAssembler", "Hell
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldMetal", "HelloWorldMetal\HelloWorldMetal.csproj", "{B57BEF6D-48D6-49DD-B4C5-893537E0EBB8}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IL2CPU.Tests", "IL2CPU.Tests\IL2CPU.Tests.csproj", "{3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}"
+EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
- SccNumberOfProjects = 11
+ SccNumberOfProjects = 12
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://tfs04.codeplex.com/
SccLocalPath0 = .
@@ -57,6 +59,9 @@ Global
SccProjectUniqueName10 = HelloWorldMetal\\HelloWorldMetal.csproj
SccProjectName10 = HelloWorldMetal
SccLocalPath10 = HelloWorldMetal
+ SccProjectUniqueName11 = IL2CPU.Tests\\IL2CPU.Tests.csproj
+ SccProjectName11 = IL2CPU.Tests
+ SccLocalPath11 = IL2CPU.Tests
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -103,6 +108,10 @@ Global
{B57BEF6D-48D6-49DD-B4C5-893537E0EBB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B57BEF6D-48D6-49DD-B4C5-893537E0EBB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B57BEF6D-48D6-49DD-B4C5-893537E0EBB8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3A0BAC46-1D4E-4E21-89CA-72903B9FCEB1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/source/IL2CPU/Program.cs b/source/IL2CPU/Program.cs
index aa9352739..839d79459 100644
--- a/source/IL2CPU/Program.cs
+++ b/source/IL2CPU/Program.cs
@@ -9,14 +9,18 @@ namespace IL2CPU {
public static void Main(string[] args) {
try {
string exeName = "HelloWorldMetal.exe";
- if(args.Length ==1 ) {
+ if (args.Length > 0) {
exeName = args[0];
}
+ string outputFileName = @"output.asm";
+ if(args.Length > 1) {
+ outputFileName = args[1];
+ }
Engine e = new Engine();
e.DebugLog += delegate(string aMessage) {
Console.WriteLine(aMessage);
};
- using (FileStream fs = new FileStream(@"output.asm", FileMode.Create)) {
+ using (FileStream fs = new FileStream(outputFileName, FileMode.Create)) {
using (StreamWriter br = new StreamWriter(fs)) {
e.Execute(exeName, TargetPlatformEnum.x86, br);
}
@@ -26,7 +30,6 @@ namespace IL2CPU {
}
Console.WriteLine("");
Console.WriteLine("Completed");
- Console.ReadLine();
}
}
}
\ 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 5d9bfeec4..590778cb2 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(""));
+ Assembler.Add(new CPU.Ret(TotalArgsSize == 0 ? "" : TotalArgsSize.ToString()));
}
}
}
\ No newline at end of file