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; }
public static void ProcessFiles(List<string> fileNames, bool lookForSnapshots = true, string programId = null) { Contract.Requires(cce.NonNullElements(fileNames)); if (programId == null) { programId = "main_program_id"; } if (CommandLineOptions.Clo.VerifySeparately && 1 < fileNames.Count) { foreach (var f in fileNames) { ProcessFiles(new List<string> { f }, lookForSnapshots, f); } return; } if (0 <= CommandLineOptions.Clo.VerifySnapshots && lookForSnapshots) { var snapshotsByVersion = LookForSnapshots(fileNames); foreach (var s in snapshotsByVersion) { ProcessFiles(new List<string>(s), false, programId); } return; } using (XmlFileScope xf = new XmlFileScope(CommandLineOptions.Clo.XmlSink, fileNames[fileNames.Count - 1])) { Program program = ParseBoogieProgram(fileNames, false); if (program == null) return; if (CommandLineOptions.Clo.PrintFile != null) { PrintBplFile(CommandLineOptions.Clo.PrintFile, program, false, true, CommandLineOptions.Clo.PrettyPrint); } LinearTypeChecker linearTypeChecker; CivlTypeChecker civlTypeChecker; PipelineOutcome oc = ResolveAndTypecheck(program, fileNames[fileNames.Count - 1], out linearTypeChecker, out civlTypeChecker); if (oc != PipelineOutcome.ResolvedAndTypeChecked) return; if (CommandLineOptions.Clo.PrintCFGPrefix != null) { foreach (var impl in program.Implementations) { using (StreamWriter sw = new StreamWriter(CommandLineOptions.Clo.PrintCFGPrefix + "." + impl.Name + ".dot")) { sw.Write(program.ProcessLoops(impl).ToDot()); } } } if (CommandLineOptions.Clo.StratifiedInlining == 0) { Concurrency.Transform(linearTypeChecker, civlTypeChecker); (new LinearEraser()).VisitProgram(program); if (CommandLineOptions.Clo.CivlDesugaredFile != null) { int oldPrintUnstructured = CommandLineOptions.Clo.PrintUnstructured; CommandLineOptions.Clo.PrintUnstructured = 1; PrintBplFile(CommandLineOptions.Clo.CivlDesugaredFile, program, false, false, CommandLineOptions.Clo.PrettyPrint); CommandLineOptions.Clo.PrintUnstructured = oldPrintUnstructured; } } EliminateDeadVariables(program); CoalesceBlocks(program); Inline(program); var stats = new PipelineStatistics(); oc = InferAndVerify(program, stats, 1 < CommandLineOptions.Clo.VerifySnapshots ? programId : null); switch (oc) { case PipelineOutcome.Done: case PipelineOutcome.VerificationCompleted: printer.WriteTrailer(stats); break; default: break; } } }
public static void ProcessFiles(List<string> fileNames, bool lookForSnapshots = true) { Contract.Requires(cce.NonNullElements(fileNames)); if (CommandLineOptions.Clo.VerifySeparately && 1 < fileNames.Count) { foreach (var f in fileNames) { ProcessFiles(new List<string> { f }, lookForSnapshots); } return; } if (CommandLineOptions.Clo.VerifySnapshots && lookForSnapshots) { var snapshotsByVersion = new List<List<string>>(); for (int version = 0; true; version++) { var nextSnapshot = new List<string>(); foreach (var name in fileNames) { var versionedName = name.Replace(Path.GetExtension(name), ".v" + version + Path.GetExtension(name)); if (File.Exists(versionedName)) { nextSnapshot.Add(versionedName); } } if (nextSnapshot.Any()) { snapshotsByVersion.Add(nextSnapshot); } else { break; } } foreach (var s in snapshotsByVersion) { ProcessFiles(new List<string>(s), false); } return; } using (XmlFileScope xf = new XmlFileScope(CommandLineOptions.Clo.XmlSink, fileNames[fileNames.Count - 1])) { Program program = ParseBoogieProgram(fileNames, false); if (program == null) return; if (CommandLineOptions.Clo.PrintFile != null) { PrintBplFile(CommandLineOptions.Clo.PrintFile, program, false); } LinearTypeChecker linearTypeChecker; MoverTypeChecker moverTypeChecker; PipelineOutcome oc = ResolveAndTypecheck(program, fileNames[fileNames.Count - 1], out linearTypeChecker, out moverTypeChecker); if (oc != PipelineOutcome.ResolvedAndTypeChecked) return; if (CommandLineOptions.Clo.PrintCFGPrefix != null) { foreach (var impl in program.TopLevelDeclarations.OfType<Implementation>()) { using (StreamWriter sw = new StreamWriter(CommandLineOptions.Clo.PrintCFGPrefix + "." + impl.Name + ".dot")) { sw.Write(program.ProcessLoops(impl).ToDot()); } } } EliminateDeadVariables(program); CollectModSets(program); CoalesceBlocks(program); if (CommandLineOptions.Clo.StratifiedInlining == 0) { Concurrency.Transform(linearTypeChecker, moverTypeChecker); var eraser = new LinearEraser(); eraser.VisitProgram(program); if (CommandLineOptions.Clo.OwickiGriesDesugaredOutputFile != null) { int oldPrintUnstructured = CommandLineOptions.Clo.PrintUnstructured; CommandLineOptions.Clo.PrintUnstructured = 1; PrintBplFile(CommandLineOptions.Clo.OwickiGriesDesugaredOutputFile, program, false, false); CommandLineOptions.Clo.PrintUnstructured = oldPrintUnstructured; } } Inline(program); var stats = new PipelineStatistics(); oc = InferAndVerify(program, stats, fileNames.ElementAt(0)); switch (oc) { case PipelineOutcome.Done: case PipelineOutcome.VerificationCompleted: printer.WriteTrailer(stats); break; default: break; } } }