diff options
author | wuestholz <unknown> | 2014-04-21 16:07:47 +0200 |
---|---|---|
committer | wuestholz <unknown> | 2014-04-21 16:07:47 +0200 |
commit | 6fe4e73ffcc88953e3b19f5e56d176d67ac9547e (patch) | |
tree | 2db08b5bc061140d3655d55ce7f9c98b31fd8d8e /Source/DafnyDriver | |
parent | f6549ab8d0c6a93afeadbea6ba06694805fc3a6d (diff) |
DafnyExtension: Made it display the compilation output in the VS output pane.
Diffstat (limited to 'Source/DafnyDriver')
-rw-r--r-- | Source/DafnyDriver/DafnyDriver.cs | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/Source/DafnyDriver/DafnyDriver.cs b/Source/DafnyDriver/DafnyDriver.cs index ba4a9d2c..ff2cbc8c 100644 --- a/Source/DafnyDriver/DafnyDriver.cs +++ b/Source/DafnyDriver/DafnyDriver.cs @@ -240,13 +240,19 @@ namespace Microsoft.Dafny #region Compilation
- public static void CompileDafnyProgram(Dafny.Program dafnyProgram, string dafnyProgramName)
+ public static void CompileDafnyProgram(Dafny.Program dafnyProgram, string dafnyProgramName, TextWriter outputWriter = null)
{
Contract.Requires(dafnyProgram != null);
+ if (outputWriter == null)
+ {
+ outputWriter = Console.Out;
+ }
+
// Compile the Dafny program into a string that contains the C# program
StringWriter sw = new StringWriter();
Dafny.Compiler compiler = new Dafny.Compiler(sw);
+ compiler.ErrorWriter = outputWriter;
var hasMain = compiler.HasMain(dafnyProgram);
if (DafnyOptions.O.RunAfterCompile && !hasMain) {
// do no more
@@ -265,11 +271,11 @@ namespace Microsoft.Dafny target.Write(csharpProgram);
if (completeProgram)
{
- Console.WriteLine("Compiled program written to {0}", targetFilename);
+ outputWriter.WriteLine("Compiled program written to {0}", targetFilename);
}
else
{
- Console.WriteLine("File {0} contains the partially compiled program", targetFilename);
+ outputWriter.WriteLine("File {0} contains the partially compiled program", targetFilename);
}
}
}
@@ -281,7 +287,7 @@ namespace Microsoft.Dafny }
else if (!CodeDomProvider.IsDefinedLanguage("CSharp"))
{
- Console.WriteLine("Error: cannot compile, because there is no provider configured for input language CSharp");
+ outputWriter.WriteLine("Error: cannot compile, because there is no provider configured for input language CSharp");
}
else
{
@@ -302,26 +308,26 @@ namespace Microsoft.Dafny var cr = provider.CompileAssemblyFromSource(cp, csharpProgram);
if (DafnyOptions.O.RunAfterCompile && cr.Errors.Count == 0) {
- Console.WriteLine("Program compiled successfully");
- Console.WriteLine("Running...");
- Console.WriteLine();
+ outputWriter.WriteLine("Program compiled successfully");
+ outputWriter.WriteLine("Running...");
+ outputWriter.WriteLine();
var entry = cr.CompiledAssembly.EntryPoint;
try {
entry.Invoke(null, new object[] { new string[0] });
} catch (System.Reflection.TargetInvocationException e) {
- Console.WriteLine("Error: Execution resulted in exception: {0}", e.Message);
- Console.WriteLine(e.InnerException.ToString());
+ outputWriter.WriteLine("Error: Execution resulted in exception: {0}", e.Message);
+ outputWriter.WriteLine(e.InnerException.ToString());
} catch (Exception e) {
- Console.WriteLine("Error: Execution resulted in exception: {0}", e.Message);
- Console.WriteLine(e.ToString());
+ outputWriter.WriteLine("Error: Execution resulted in exception: {0}", e.Message);
+ outputWriter.WriteLine(e.ToString());
}
} else if (cr.Errors.Count == 0) {
- Console.WriteLine("Compiled assembly into {0}", cr.PathToAssembly);
+ outputWriter.WriteLine("Compiled assembly into {0}", cr.PathToAssembly);
} else {
- Console.WriteLine("Errors compiling program into {0}", cr.PathToAssembly);
+ outputWriter.WriteLine("Errors compiling program into {0}", cr.PathToAssembly);
foreach (var ce in cr.Errors) {
- Console.WriteLine(ce.ToString());
- Console.WriteLine();
+ outputWriter.WriteLine(ce.ToString());
+ outputWriter.WriteLine();
}
}
}
|