/// <summary> /// Compiles, optimizes and runs a file at a particular location. /// </summary> /// <param name="fileName"> /// The name of the file to compile, optimize and run. /// </param> /// <param name="csharpFlags"> /// Additional flags to pass to C# compiler. /// </param> /// <param name="runCommand"> /// Runs a command, taking the command itself, a /// path to an executable and a Boolean specifying whether /// the executable should be run by the CLR as arguments. /// </param> public static void CompileAndRun( string fileName, string csharpFlags, Func <ToolCommand, string, bool, string> runCommand) { var prefix = ILOptTests.CreateTemporaryPath(); var exePath = prefix + ".exe"; var irPath = prefix + ".ll"; var outPath = prefix + ".out"; try { ILOptTests.CompileCSharp(fileName, exePath, csharpFlags); CompileILToLLVM(exePath, irPath); CompileLLVM(irPath, outPath, ""); var commands = ILOptTests.ReadCommands(fileName); foreach (var command in commands) { var regularOutput = runCommand(command, exePath, true); var optOutput = runCommand(command, outPath, false); Assert.AreEqual(regularOutput, optOutput); } } finally { File.Delete(exePath); File.Delete(irPath); File.Delete(outPath); } }
/// <summary> /// Compiles, optimizes and runs a file at a particular location. /// </summary> /// <param name="fileName"> /// The name of the file to compile, optimize and run. /// </param> /// <param name="runCommand"> /// Runs a command, taking the command itself and a /// path to an executable as arguments. /// </param> public static void CompileOptimizeAndRun( string fileName, Func <ToolCommand, string, string> runCommand) { var prefix = ILOptTests.CreateTemporaryPath(); var exePath = prefix + ".exe"; try { CompileBrainfuck(fileName, exePath); var commands = ILOptTests.ReadCommands(fileName); foreach (var command in commands) { runCommand(command, exePath); } } finally { File.Delete(exePath); } }