public static int ThreadMain(string[] args) { Contract.Requires(cce.NonNullElements(args)); ErrorReporter reporter = new ConsoleErrorReporter(); ExecutionEngine.printer = new DafnyConsolePrinter(); // For boogie errors ArmadaOptions.Install(new ArmadaOptions(reporter)); List <DafnyFile> dafnyFiles; List <string> otherFiles; ExitValue exitValue = ProcessCommandLineArguments(args, out dafnyFiles, out otherFiles); if (exitValue == ExitValue.VERIFIED) { exitValue = ProcessFiles(dafnyFiles, otherFiles.AsReadOnly(), reporter); } if (CommandLineOptions.Clo.XmlSink != null) { CommandLineOptions.Clo.XmlSink.Close(); } if (CommandLineOptions.Clo.Wait) { Console.WriteLine("Press Enter to exit."); Console.ReadLine(); } if (!ArmadaOptions.O.CountVerificationErrors && exitValue != ExitValue.PREPROCESSING_ERROR) { return(0); } //Console.ReadKey(); return((int)exitValue); }
static ExitValue ProcessFiles(IList <DafnyFile /*!*/> /*!*/ dafnyFiles, ReadOnlyCollection <string> otherFileNames, ErrorReporter reporter, bool lookForSnapshots = true, string programId = null) { Contract.Requires(cce.NonNullElements(dafnyFiles)); var dafnyFileNames = DafnyFile.fileNames(dafnyFiles); ExitValue exitValue = ExitValue.VERIFIED; if (CommandLineOptions.Clo.VerifySeparately && 1 < dafnyFiles.Count) { foreach (var f in dafnyFiles) { Console.WriteLine(); Console.WriteLine("-------------------- {0} --------------------", f); var ev = ProcessFiles(new List <DafnyFile> { f }, new List <string>().AsReadOnly(), reporter, lookForSnapshots, f.FilePath); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return(exitValue); } if (0 <= CommandLineOptions.Clo.VerifySnapshots && lookForSnapshots) { var snapshotsByVersion = ExecutionEngine.LookForSnapshots(dafnyFileNames); foreach (var s in snapshotsByVersion) { var snapshots = new List <DafnyFile>(); foreach (var f in s) { snapshots.Add(new DafnyFile(f)); } var ev = ProcessFiles(snapshots, new List <string>().AsReadOnly(), reporter, false, programId); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return(exitValue); } Microsoft.Armada.Program dafnyProgram; string programName = dafnyFileNames.Count == 1 ? dafnyFileNames[0] : "the program"; string err = Microsoft.Armada.Main.ParseCheck(dafnyFiles, programName, reporter, out dafnyProgram); if (err != null) { exitValue = ExitValue.DAFNY_ERROR; ExecutionEngine.printer.ErrorWriteLine(Console.Out, err); } else if (dafnyProgram != null && !CommandLineOptions.Clo.NoResolve && !CommandLineOptions.Clo.NoTypecheck && ArmadaOptions.O.DafnyVerify) { var boogiePrograms = Translate(dafnyProgram); Dictionary <string, PipelineStatistics> statss; PipelineOutcome oc; string baseName = cce.NonNull(Path.GetFileName(dafnyFileNames[dafnyFileNames.Count - 1])); var verified = Boogie(baseName, boogiePrograms, programId, out statss, out oc); var compiled = Compile(dafnyFileNames[0], otherFileNames, dafnyProgram, oc, statss, verified); exitValue = verified && compiled ? ExitValue.VERIFIED : !verified ? ExitValue.NOT_VERIFIED : ExitValue.COMPILE_ERROR; } else { // Console.WriteLine("Force compiling!"); Dictionary <string, PipelineStatistics> statss; PipelineOutcome oc; oc = PipelineOutcome.VerificationCompleted; statss = new Dictionary <string, PipelineStatistics>(); var compiled = Compile(dafnyFileNames[0], otherFileNames, dafnyProgram, oc, statss, false); } if (err == null && dafnyProgram != null && ArmadaOptions.O.PrintStats) { Util.PrintStats(dafnyProgram); } if (err == null && dafnyProgram != null && ArmadaOptions.O.PrintFunctionCallGraph) { Util.PrintFunctionCallGraph(dafnyProgram); } return(exitValue); }
static ExitValue ProcessFiles(IList <string /*!*/> /*!*/ dafnyFileNames, ReadOnlyCollection <string> otherFileNames, ErrorReporter reporter, bool lookForSnapshots = true, string programId = null) { Contract.Requires(cce.NonNullElements(dafnyFileNames)); ExitValue exitValue = ExitValue.VERIFIED; if (CommandLineOptions.Clo.VerifySeparately && 1 < dafnyFileNames.Count) { foreach (var f in dafnyFileNames) { string extension = Path.GetExtension(f); if (extension != null) { extension = extension.ToLower(); } if (extension != ".dfy") { continue; } Console.WriteLine(); Console.WriteLine("-------------------- {0} --------------------", f); var ev = ProcessFiles(new List <string> { f }, new List <string>().AsReadOnly(), reporter, lookForSnapshots, f); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return(exitValue); } if (0 <= CommandLineOptions.Clo.VerifySnapshots && lookForSnapshots) { var snapshotsByVersion = ExecutionEngine.LookForSnapshots(dafnyFileNames); foreach (var s in snapshotsByVersion) { var ev = ProcessFiles(new List <string>(s), new List <string>().AsReadOnly(), reporter, false, programId); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return(exitValue); } Dafny.Program dafnyProgram; Resolver r = null; string programName = dafnyFileNames.Count == 1 ? dafnyFileNames[0] : "the program"; //Same as ParseCheck, except for the instance of out Resolver string err = Dafny.Main.Parse(dafnyFileNames, programName, reporter, out dafnyProgram); if (err == null) { err = Dafny.Main.Resolve(dafnyProgram, reporter, out r); } if (err != null) { exitValue = ExitValue.DAFNY_ERROR; ExecutionEngine.printer.ErrorWriteLine(Console.Out, err); } else if (dafnyProgram != null && !CommandLineOptions.Clo.NoResolve && !CommandLineOptions.Clo.NoTypecheck && DafnyOptions.O.DafnyVerify) { Bpl.Program boogieProgram = Translate(dafnyProgram, r); PipelineStatistics stats; PipelineOutcome oc; var verified = Boogie(dafnyFileNames, boogieProgram, programId, out stats, out oc); Compile(dafnyFileNames[0], otherFileNames, dafnyProgram, oc, stats, verified); exitValue = verified ? ExitValue.VERIFIED : ExitValue.NOT_VERIFIED; } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintStats) { Util.PrintStats(dafnyProgram); } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintFunctionCallGraph) { Util.PrintFunctionCallGraph(dafnyProgram); } return(exitValue); }
static ExitValue ProcessFiles(IList <DafnyFile /*!*/> /*!*/ dafnyFiles, ReadOnlyCollection <string> otherFileNames, ErrorReporter reporter, bool lookForSnapshots = true, string programId = null) { Contract.Requires(cce.NonNullElements(dafnyFiles)); var dafnyFileNames = DafnyFile.fileNames(dafnyFiles); ExitValue exitValue = ExitValue.SUCCESS; if (DafnyOptions.O.TestGenOptions.WarnDeadCode) { foreach (var line in DafnyTestGeneration.Main .GetDeadCodeStatistics(dafnyFileNames[0])) { Console.WriteLine(line); } return(exitValue); } if (DafnyOptions.O.TestGenOptions.Mode != TestGenerationOptions.Modes.None) { foreach (var line in DafnyTestGeneration.Main .GetTestClassForProgram(dafnyFileNames[0])) { Console.WriteLine(line); } return(exitValue); } if (CommandLineOptions.Clo.VerifySeparately && 1 < dafnyFiles.Count) { foreach (var f in dafnyFiles) { Console.WriteLine(); Console.WriteLine("-------------------- {0} --------------------", f); var ev = ProcessFiles(new List <DafnyFile> { f }, new List <string>().AsReadOnly(), reporter, lookForSnapshots, f.FilePath); if (exitValue != ev && ev != ExitValue.SUCCESS) { exitValue = ev; } } return(exitValue); } if (0 <= CommandLineOptions.Clo.VerifySnapshots && lookForSnapshots) { var snapshotsByVersion = ExecutionEngine.LookForSnapshots(dafnyFileNames); foreach (var s in snapshotsByVersion) { var snapshots = new List <DafnyFile>(); foreach (var f in s) { snapshots.Add(new DafnyFile(f)); } var ev = ProcessFiles(snapshots, new List <string>().AsReadOnly(), reporter, false, programId); if (exitValue != ev && ev != ExitValue.SUCCESS) { exitValue = ev; } } return(exitValue); } Dafny.Program dafnyProgram; string programName = dafnyFileNames.Count == 1 ? dafnyFileNames[0] : "the_program"; string err = Dafny.Main.ParseCheck(dafnyFiles, programName, reporter, out dafnyProgram); if (err != null) { exitValue = ExitValue.DAFNY_ERROR; ExecutionEngine.printer.ErrorWriteLine(Console.Out, err); } else if (dafnyProgram != null && !CommandLineOptions.Clo.NoResolve && !CommandLineOptions.Clo.NoTypecheck && DafnyOptions.O.DafnyVerify) { var boogiePrograms = Translate(dafnyProgram); Dictionary <string, PipelineStatistics> statss; PipelineOutcome oc; string baseName = cce.NonNull(Path.GetFileName(dafnyFileNames[dafnyFileNames.Count - 1])); var verified = Boogie(baseName, boogiePrograms, programId, out statss, out oc); var compiled = Compile(dafnyFileNames[0], otherFileNames, dafnyProgram, oc, statss, verified); exitValue = verified && compiled ? ExitValue.SUCCESS : !verified ? ExitValue.VERIFICATION_ERROR : ExitValue.COMPILE_ERROR; } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintStats) { Util.PrintStats(dafnyProgram); } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintFunctionCallGraph) { Util.PrintFunctionCallGraph(dafnyProgram); } if (dafnyProgram != null && DafnyOptions.O.ExtractCounterexample && exitValue == ExitValue.VERIFICATION_ERROR) { PrintCounterexample(DafnyOptions.O.ModelViewFile); } return(exitValue); }
public static int ThreadMain(string[] args) { Contract.Requires(cce.NonNullElements(args)); ErrorReporter reporter = new ConsoleErrorReporter(); ExecutionEngine.printer = new DafnyConsolePrinter(); // For boogie errors DafnyOptions.Install(new DafnyOptions(reporter)); ExitValue exitValue = ExitValue.VERIFIED; CommandLineOptions.Clo.RunningBoogieFromCommandLine = true; if (!CommandLineOptions.Clo.Parse(args)) { exitValue = ExitValue.PREPROCESSING_ERROR; goto END; } //CommandLineOptions.Clo.Files = new List<string> { @"C:\dafny\Test\dafny0\Trait\TraitExtend.dfy" }; if (CommandLineOptions.Clo.Files.Count == 0) { ExecutionEngine.printer.ErrorWriteLine(Console.Out, "*** Error: No input files were specified."); exitValue = ExitValue.PREPROCESSING_ERROR; goto END; } if (CommandLineOptions.Clo.XmlSink != null) { string errMsg = CommandLineOptions.Clo.XmlSink.Open(); if (errMsg != null) { ExecutionEngine.printer.ErrorWriteLine(Console.Out, "*** Error: " + errMsg); exitValue = ExitValue.PREPROCESSING_ERROR; goto END; } } if (!CommandLineOptions.Clo.DontShowLogo) { Console.WriteLine(CommandLineOptions.Clo.Version); } if (CommandLineOptions.Clo.ShowEnv == CommandLineOptions.ShowEnvironment.Always) { Console.WriteLine("---Command arguments"); foreach (string arg in args) { Contract.Assert(arg != null); Console.WriteLine(arg); } Console.WriteLine("--------------------"); } var dafnyFiles = new List <string>(); var otherFiles = new List <string>(); foreach (string file in CommandLineOptions.Clo.Files) { Contract.Assert(file != null); string extension = Path.GetExtension(file); if (extension != null) { extension = extension.ToLower(); } if (extension == ".dfy" || extension == ".tacny") { dafnyFiles.Add(file); } else if ((extension == ".cs") || (extension == ".dll")) { otherFiles.Add(file); } else { ExecutionEngine.printer.ErrorWriteLine(Console.Out, "*** Error: '{0}': Filename extension '{1}' is not supported. Input files must be Dafny programs (.dfy) or C# files (.cs) or managed DLLS (.dll)", file, extension == null ? "" : extension); exitValue = ExitValue.PREPROCESSING_ERROR; goto END; } } exitValue = ProcessFiles(dafnyFiles, otherFiles.AsReadOnly(), reporter); END: if (CommandLineOptions.Clo.XmlSink != null) { CommandLineOptions.Clo.XmlSink.Close(); } if (CommandLineOptions.Clo.Wait) { Console.WriteLine("Press Enter to exit."); Console.ReadLine(); } if (!DafnyOptions.O.CountVerificationErrors && exitValue != ExitValue.PREPROCESSING_ERROR) { return(0); } //Console.ReadKey(); return((int)exitValue); }
static ExitValue ProcessFiles(IList <string /*!*/> /*!*/ dafnyFileNames, ReadOnlyCollection <string> otherFileNames, ErrorReporter reporter, bool lookForSnapshots = true, string programId = null) { Contract.Requires(cce.NonNullElements(dafnyFileNames)); if (programId == null) { programId = "main_program_id"; } ExitValue exitValue = ExitValue.VERIFIED; if (CommandLineOptions.Clo.VerifySeparately && 1 < dafnyFileNames.Count) { foreach (var f in dafnyFileNames) { string extension = Path.GetExtension(f); if (extension != null) { extension = extension.ToLower(); } if (extension != ".dfy") { continue; } Console.WriteLine(); Console.WriteLine("-------------------- {0} --------------------", f); var ev = ProcessFiles(new List <string> { f }, new List <string>().AsReadOnly(), reporter, lookForSnapshots, f); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return(exitValue); } if (0 <= CommandLineOptions.Clo.VerifySnapshots && lookForSnapshots) { var snapshotsByVersion = ExecutionEngine.LookForSnapshots(dafnyFileNames); foreach (var s in snapshotsByVersion) { var ev = ProcessFiles(new List <string>(s), new List <string>().AsReadOnly(), reporter, false, programId); if (exitValue != ev && ev != ExitValue.VERIFIED) { exitValue = ev; } } return(exitValue); } using (XmlFileScope xf = new XmlFileScope(CommandLineOptions.Clo.XmlSink, dafnyFileNames[dafnyFileNames.Count - 1])) { Dafny.Program dafnyProgram; string programName = dafnyFileNames.Count == 1 ? dafnyFileNames[0] : "the program"; string err = Dafny.Main.ParseCheck(dafnyFileNames, programName, reporter, out dafnyProgram); if (err != null) { exitValue = ExitValue.DAFNY_ERROR; ExecutionEngine.printer.ErrorWriteLine(Console.Out, err); } else if (dafnyProgram != null && !CommandLineOptions.Clo.NoResolve && !CommandLineOptions.Clo.NoTypecheck && DafnyOptions.O.DafnyVerify) { Dafny.Translator translator = new Dafny.Translator(dafnyProgram.reporter); Bpl.Program boogieProgram = translator.Translate(dafnyProgram); if (CommandLineOptions.Clo.PrintFile != null) { ExecutionEngine.PrintBplFile(CommandLineOptions.Clo.PrintFile, boogieProgram, false, false, CommandLineOptions.Clo.PrettyPrint); } string bplFilename; if (CommandLineOptions.Clo.PrintFile != null) { bplFilename = CommandLineOptions.Clo.PrintFile; } else { string baseName = cce.NonNull(Path.GetFileName(dafnyFileNames[dafnyFileNames.Count - 1])); baseName = cce.NonNull(Path.ChangeExtension(baseName, "bpl")); bplFilename = Path.Combine(Path.GetTempPath(), baseName); } PipelineStatistics stats = null; PipelineOutcome oc = BoogiePipelineWithRerun(boogieProgram, bplFilename, out stats, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? programId : null); var allOk = stats.ErrorCount == 0 && stats.InconclusiveCount == 0 && stats.TimeoutCount == 0 && stats.OutOfMemoryCount == 0; var resultFileName = DafnyOptions.O.DafnyPrintCompiledFile ?? dafnyFileNames[0]; switch (oc) { case PipelineOutcome.VerificationCompleted: ExecutionEngine.printer.WriteTrailer(stats); if ((DafnyOptions.O.Compile && allOk && CommandLineOptions.Clo.ProcsToCheck == null) || DafnyOptions.O.ForceCompile) { CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames); } break; case PipelineOutcome.Done: ExecutionEngine.printer.WriteTrailer(stats); if (DafnyOptions.O.ForceCompile) { CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames); } break; default: // error has already been reported to user break; } exitValue = allOk ? ExitValue.VERIFIED : ExitValue.NOT_VERIFIED; } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintStats) { Util.PrintStats(dafnyProgram); } if (err == null && dafnyProgram != null && DafnyOptions.O.PrintFunctionCallGraph) { Util.PrintFunctionCallGraph(dafnyProgram); } } return(exitValue); }