Esempio n. 1
0
        public static void Compile(string fileName, ReadOnlyCollection <string> otherFileNames, Program dafnyProgram,
                                   PipelineOutcome oc, PipelineStatistics stats, bool verified)
        {
            var resultFileName = DafnyOptions.O.DafnyPrintCompiledFile ?? fileName;

            switch (oc)
            {
            case PipelineOutcome.VerificationCompleted:
                ExecutionEngine.printer.WriteTrailer(stats);
                if ((DafnyOptions.O.Compile && verified && 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;
            }
        }
Esempio n. 2
0
        public static bool BoogieOnce(string baseFile, string moduleName, Bpl.Program boogieProgram, string programId,
                                      out PipelineStatistics stats, out PipelineOutcome oc)
        {
            if (programId == null)
            {
                programId = "main_program_id";
            }
            programId += "_" + moduleName;

            string bplFilename;

            if (CommandLineOptions.Clo.PrintFile != null)
            {
                bplFilename = CommandLineOptions.Clo.PrintFile;
            }
            else
            {
                string baseName = cce.NonNull(Path.GetFileName(baseFile));
                baseName    = cce.NonNull(Path.ChangeExtension(baseName, "bpl"));
                bplFilename = Path.Combine(Path.GetTempPath(), baseName);
            }

            bplFilename = BoogieProgramSuffix(bplFilename, moduleName);
            stats       = null;
            oc          = BoogiePipelineWithRerun(boogieProgram, bplFilename, out stats, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? programId : null);
            return(IsBoogieVerified(oc, stats));
        }
Esempio n. 3
0
        public static bool BoogieOnce(string baseFile, string moduleName, Bpl.Program boogieProgram, string programId,
            out PipelineStatistics stats, out PipelineOutcome oc)
        {
            if (programId == null)
              {
            programId = "main_program_id";
              }
              programId += "_" + moduleName;

              string bplFilename;
              if (CommandLineOptions.Clo.PrintFile != null)
              {
            bplFilename = CommandLineOptions.Clo.PrintFile;
              }
              else
              {
            string baseName = cce.NonNull(Path.GetFileName(baseFile));
            baseName = cce.NonNull(Path.ChangeExtension(baseName, "bpl"));
            bplFilename = Path.Combine(Path.GetTempPath(), baseName);
              }

              bplFilename = BoogieProgramSuffix(bplFilename, moduleName);
              stats = null;
              oc = BoogiePipelineWithRerun(boogieProgram, bplFilename, out stats, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? programId : null);
              return (oc == PipelineOutcome.Done || oc == PipelineOutcome.VerificationCompleted) && stats.ErrorCount == 0 && stats.InconclusiveCount == 0 && stats.TimeoutCount == 0 && stats.OutOfMemoryCount == 0;
        }
Esempio n. 4
0
        public static bool Compile(string fileName, ReadOnlyCollection <string> otherFileNames, Program dafnyProgram,
                                   PipelineOutcome oc, Dictionary <string, PipelineStatistics> statss, bool verified)
        {
            var  resultFileName = DafnyOptions.O.DafnyPrintCompiledFile ?? fileName;
            bool compiled       = true;

            switch (oc)
            {
            case PipelineOutcome.VerificationCompleted:
                WriteStatss(statss);
                if ((DafnyOptions.O.Compile && verified && CommandLineOptions.Clo.ProcsToCheck == null) || DafnyOptions.O.ForceCompile)
                {
                    compiled = CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames, true);
                }
                else if ((2 <= DafnyOptions.O.SpillTargetCode && verified && CommandLineOptions.Clo.ProcsToCheck == null) || 3 <= DafnyOptions.O.SpillTargetCode)
                {
                    compiled = CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames, false);
                }
                break;

            case PipelineOutcome.Done:
                WriteStatss(statss);
                if (DafnyOptions.O.ForceCompile || 3 <= DafnyOptions.O.SpillTargetCode)
                {
                    compiled = CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames, DafnyOptions.O.ForceCompile);
                }
                break;

            default:
                // error has already been reported to user
                break;
            }
            return(compiled);
        }
Esempio n. 5
0
        public static bool BoogieOnce(string baseFile, string moduleName, Bpl.Program boogieProgram, string programId,
                                      out PipelineStatistics stats, out PipelineOutcome oc)
        {
            if (programId == null)
            {
                programId = "main_program_id";
            }
            programId += "_" + moduleName;

            string bplFilename;

            if (CommandLineOptions.Clo.PrintFile != null)
            {
                bplFilename = CommandLineOptions.Clo.PrintFile;
            }
            else
            {
                string baseName = cce.NonNull(Path.GetFileName(baseFile));
                baseName    = cce.NonNull(Path.ChangeExtension(baseName, "bpl"));
                bplFilename = Path.Combine(Path.GetTempPath(), baseName);
            }

            bplFilename = BoogieProgramSuffix(bplFilename, moduleName);
            stats       = null;
            oc          = BoogiePipelineWithRerun(boogieProgram, bplFilename, out stats, 1 < Microsoft.Armada.ArmadaOptions.Clo.VerifySnapshots ? programId : null);
            return((oc == PipelineOutcome.Done || oc == PipelineOutcome.VerificationCompleted) && stats.ErrorCount == 0 && stats.InconclusiveCount == 0 && stats.TimeoutCount == 0 && stats.OutOfMemoryCount == 0);
        }
Esempio n. 6
0
        public static bool Verify(Dafny.Program dafnyProgram, ResolverTagger resolver, string uniqueIdPrefix, string requestId, ErrorReporterDelegate er)
        {
            Dafny.Translator translator = new Dafny.Translator(dafnyProgram.reporter, er);
            translator.InsertChecksums = true;
            translator.UniqueIdPrefix  = uniqueIdPrefix;
            Bpl.Program boogieProgram = translator.Translate(dafnyProgram, r: resolver.MostRecentResolver);

            //Interpreter.ResetTacnyResultList();
            resolver.ReInitializeVerificationErrors(requestId, boogieProgram.Implementations);

            // TODO(wuestholz): Maybe we should use a fixed program ID to limit the memory overhead due to the program cache in Boogie.
            PipelineOutcome oc = BoogiePipeline(boogieProgram, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? uniqueIdPrefix : null, requestId, er);

            switch (oc)
            {
            case PipelineOutcome.Done:
            case PipelineOutcome.VerificationCompleted:
                // TODO:  This would be the place to proceed to compile the program, if desired
                return(true);

            case PipelineOutcome.FatalError:
            default:
                return(false);
            }
        }
Esempio n. 7
0
        public static bool Boogie(IList <string> dafnyFileNames, Bpl.Program boogieProgram, string programId,
                                  out PipelineStatistics stats, out PipelineOutcome oc)
        {
            if (programId == null)
            {
                programId = "main_program_id";
            }

            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);
            }

            stats = null;
            oc    = BoogiePipelineWithRerun(boogieProgram, bplFilename, out stats, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? programId : null);
            return(stats.ErrorCount == 0 && stats.InconclusiveCount == 0 && stats.TimeoutCount == 0 && stats.OutOfMemoryCount == 0);
        }
Esempio n. 8
0
 public static bool IsBoogieVerified(PipelineOutcome outcome, PipelineStatistics statistics)
 {
     return((outcome == PipelineOutcome.Done || outcome == PipelineOutcome.VerificationCompleted) &&
            statistics.ErrorCount == 0 &&
            statistics.InconclusiveCount == 0 &&
            statistics.TimeoutCount == 0 &&
            statistics.OutOfResourceCount == 0 &&
            statistics.OutOfMemoryCount == 0);
 }
Esempio n. 9
0
        public static void VerifyResolvedProg(ProofState state, Program program,
                                              List <TacnyInterpreter.VerifyResult> res, List <int> idx,
                                              ErrorReporterDelegate er)
        {
            Contract.Requires <ArgumentNullException>(program != null);

#if _TACTIC_DEBUG_L1
            var printer = new Printer(Console.Out);
            Console.WriteLine("*********************Verifying Tactic Generated Prog*****************");
            printer.PrintProgram(program, true);
            Console.WriteLine("\n*********************Prog END*****************");
#endif


            _verificationCount++;
            Console.WriteLine("Verfication Count: " + _verificationCount);

            IEnumerable <Tuple <string, Bpl.Program> > boogieProg;

            //   try {
            boogieProg = Translator.Translate(program, program.reporter, null);

            foreach (var prog in boogieProg)
            {
                PipelineStatistics      stats;
                List <ErrorInformation> errorList;
                PipelineOutcome         tmp = BoogiePipeline(prog.Item2,
                                                             new List <string> {
                    program.Name
                }, program.Name, er,
                                                             out stats, out errorList, program);

                var curIdx = -1;
                for (var i = 0; i < errorList.Count; i++)
                {
                    var err = errorList[i];
                    if (err.Tok.line < TacnyDriver.TacticCodeTokLine)
                    {
                        curIdx           = 0 - err.Tok.line - 2;
                        res[idx[curIdx]] = TacnyInterpreter.VerifyResult.Failed;
                    }
                }
            }

            /*  } catch {
             *  Console.WriteLine("execption: set verify result as failed.");
             *  for(var i = 0; i < res.Count; i++) {
             *      res[i] = TacnyInterpreter.VerifyResult.Failed;
             *    }
             *  }*/
        }
Esempio n. 10
0
        /// <summary>
        /// Resolve, type check, infer invariants for, and verify the given Boogie program.
        /// The intention is that this Boogie program has been produced by translation from something
        /// else.  Hence, any resolution errors and type checking errors are due to errors in
        /// the translation.
        /// </summary>
        static PipelineOutcome BoogiePipeline(Bpl.Program /*!*/ program, string programId, string requestId, ErrorSink errorSink, ErrorReporterDelegate er)
        {
            Contract.Requires(program != null);

            PipelineOutcome oc = BoogieResolveAndTypecheck(program, errorSink);

            if (oc == PipelineOutcome.ResolvedAndTypeChecked)
            {
                ExecutionEngine.EliminateDeadVariables(program);
                ExecutionEngine.CollectModSets(program);
                ExecutionEngine.CoalesceBlocks(program);
                ExecutionEngine.Inline(program);
                return(ExecutionEngine.InferAndVerify(program, new PipelineStatistics(), programId, er, requestId));
            }
            return(oc);
        }
Esempio n. 11
0
        public static bool VerifyResolvedProg(Program program, ErrorReporterDelegate er)
        {
            Contract.Requires <ArgumentNullException>(program != null);

            var boogieProg = Translate(program, program.Name, er);
            PipelineStatistics      stats;
            List <ErrorInformation> errorList;

            //Console.WriteLine("call verifier in Tacny !!!");
            PipelineOutcome tmp = BoogiePipeline(boogieProg,
                                                 new List <string> {
                program.Name
            }, program.Name, er,
                                                 out stats, out errorList, program);

            return(errorList.Count == 0);
        }
Esempio n. 12
0
        /// <summary>
        /// Resolve, type check, infer invariants for, and verify the given Boogie program.
        /// The intention is that this Boogie program has been produced by translation from something
        /// else.  Hence, any resolution errors and type checking errors are due to errors in
        /// the translation.
        /// The method prints errors for resolution and type checking errors, but still returns
        /// their error code.
        /// </summary>
        static PipelineOutcome BoogiePipelineWithRerun(Bpl.Program /*!*/ program, string /*!*/ bplFileName,
                                                       out PipelineStatistics stats, string programId)
        {
            Contract.Requires(program != null);
            Contract.Requires(bplFileName != null);
            Contract.Ensures(0 <= Contract.ValueAtReturn(out stats).InconclusiveCount&& 0 <= Contract.ValueAtReturn(out stats).TimeoutCount);

            stats = new PipelineStatistics();
            LinearTypeChecker ltc;
            CivlTypeChecker   ctc;
            PipelineOutcome   oc = ExecutionEngine.ResolveAndTypecheck(program, bplFileName, out ltc, out ctc);

            switch (oc)
            {
            case PipelineOutcome.Done:
                return(oc);

            case PipelineOutcome.ResolutionError:
            case PipelineOutcome.TypeCheckingError:
            {
                ExecutionEngine.PrintBplFile(bplFileName, program, false, false, CommandLineOptions.Clo.PrettyPrint);
                Console.WriteLine();
                Console.WriteLine("*** Encountered internal translation error - re-running Boogie to get better debug information");
                Console.WriteLine();

                List <string /*!*/> /*!*/ fileNames = new List <string /*!*/>();
                fileNames.Add(bplFileName);
                Bpl.Program reparsedProgram = ExecutionEngine.ParseBoogieProgram(fileNames, true);
                if (reparsedProgram != null)
                {
                    ExecutionEngine.ResolveAndTypecheck(reparsedProgram, bplFileName, out ltc, out ctc);
                }
            }
                return(oc);

            case PipelineOutcome.ResolvedAndTypeChecked:
                ExecutionEngine.EliminateDeadVariables(program);
                ExecutionEngine.CollectModSets(program);
                ExecutionEngine.CoalesceBlocks(program);
                ExecutionEngine.Inline(program);
                return(ExecutionEngine.InferAndVerify(program, stats, programId));

            default:
                Contract.Assert(false); throw new cce.UnreachableException(); // unexpected outcome
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Pipeline the boogie program to Dafny where it is valid
        /// </summary>
        /// <returns>Exit value</returns>
        public static PipelineOutcome BoogiePipeline(Bpl.Program program, IList <string> fileNames, string programId, ErrorReporterDelegate er, out PipelineStatistics stats, out List <ErrorInformation> errorList, Program tmpDafnyProgram = null)
        {
            Contract.Requires(program != null);
            Contract.Ensures(0 <= Contract.ValueAtReturn(out stats).InconclusiveCount&& 0 <= Contract.ValueAtReturn(out stats).TimeoutCount);

            LinearTypeChecker ltc;
            CivlTypeChecker   ctc;
            string            baseName = cce.NonNull(Path.GetFileName(fileNames[fileNames.Count - 1]));

            baseName = cce.NonNull(Path.ChangeExtension(baseName, "bpl"));
            string bplFileName = Path.Combine(Path.GetTempPath(), baseName);

            errorList = new List <ErrorInformation>();
            stats     = new PipelineStatistics();



            PipelineOutcome oc = ExecutionEngine.ResolveAndTypecheck(program, bplFileName, out ltc, out ctc);

            switch (oc)
            {
            case PipelineOutcome.ResolvedAndTypeChecked:
                ExecutionEngine.EliminateDeadVariables(program);
                ExecutionEngine.CollectModSets(program);
                ExecutionEngine.CoalesceBlocks(program);
                ExecutionEngine.Inline(program);
                errorList = new List <ErrorInformation>();
                var tmp = new List <ErrorInformation>();

                oc = ExecutionEngine.InferAndVerify(program, stats, programId, errorInfo =>
                {
                    tmp.Add(errorInfo);
                    er?.Invoke(new CompoundErrorInformation(errorInfo.Tok, errorInfo.Msg, errorInfo, tmpDafnyProgram));
                });
                errorList.AddRange(tmp);

                return(oc);

            default:
                Contract.Assert(false); throw new cce.UnreachableException(); // unexpected outcome
            }
        }
Esempio n. 14
0
        public static bool Boogie(string baseName, IEnumerable<Tuple<string, Bpl.Program>> boogiePrograms, string programId, out Dictionary<string, PipelineStatistics> statss, out PipelineOutcome oc)
        {
            bool isVerified = true;
              oc = PipelineOutcome.VerificationCompleted;
              statss = new Dictionary<string, PipelineStatistics>();

              Stopwatch watch = new Stopwatch();
              watch.Start();

              foreach (var prog in boogiePrograms) {
            PipelineStatistics newstats;
            PipelineOutcome newoc;

            if (DafnyOptions.O.SeparateModuleOutput) {
              ExecutionEngine.printer.AdvisoryWriteLine("For module: {0}", prog.Item1);
            }

            isVerified = BoogieOnce(baseName, prog.Item1, prog.Item2, programId, out newstats, out newoc) && isVerified;

            watch.Stop();

            if ((oc == PipelineOutcome.VerificationCompleted || oc == PipelineOutcome.Done) && newoc != PipelineOutcome.VerificationCompleted) {
              oc = newoc;
            }

            if (DafnyOptions.O.SeparateModuleOutput) {
              TimeSpan ts = watch.Elapsed;
              string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}",
            ts.Hours, ts.Minutes, ts.Seconds);

              ExecutionEngine.printer.AdvisoryWriteLine("Elapsed time: {0}", elapsedTime);
              ExecutionEngine.printer.WriteTrailer(newstats);
            }

            statss.Add(prog.Item1, newstats);
            watch.Restart();
              }
              watch.Stop();

              return isVerified;
        }
Esempio n. 15
0
        public bool Verify(Dafny.Program dafnyProgram, ResolverTagger resolver, string uniqueIdPrefix, string requestId, ErrorReporterDelegate er)
        {
            Dafny.Translator translator = new Dafny.Translator(dafnyProgram.reporter);
            var translatorFlags         = new Dafny.Translator.TranslatorFlags()
            {
                InsertChecksums = true, UniqueIdPrefix = uniqueIdPrefix
            };


            var boogiePrograms = Dafny.Translator.Translate(dafnyProgram, dafnyProgram.reporter, translatorFlags);

            var impls = boogiePrograms.SelectMany(p => p.Item2.Implementations);

            resolver.ReInitializeVerificationErrors(requestId, impls);

            bool success   = false;
            var  errorSink = new ErrorSink(this);

            foreach (var kv in boogiePrograms)
            {
                var boogieProgram = kv.Item2;

                // TODO(wuestholz): Maybe we should use a fixed program ID to limit the memory overhead due to the program cache in Boogie.
                PipelineOutcome oc = BoogiePipeline(boogieProgram, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? uniqueIdPrefix : null, requestId, errorSink, er);
                switch (oc)
                {
                case PipelineOutcome.Done:
                case PipelineOutcome.VerificationCompleted:
                    // TODO:  This would be the place to proceed to compile the program, if desired
                    success = true;
                    break;

                case PipelineOutcome.FatalError:
                default:
                    return(false);
                }
            }
            return(success);
        }
Esempio n. 16
0
        public static bool Compile(string fileName, ReadOnlyCollection <string> otherFileNames, Program dafnyProgram,
                                   PipelineOutcome oc, Dictionary <string, PipelineStatistics> statss, bool verified)
        {
            var  resultFileName = ArmadaOptions.O.DafnyPrintCompiledFile ?? fileName;
            bool compiled       = true;

            switch (oc)
            {
            case PipelineOutcome.VerificationCompleted:
                // WriteStatss(statss);
                if ((ArmadaOptions.O.Compile && verified && CommandLineOptions.Clo.UserConstrainedProcsToCheck) || ArmadaOptions.O.ForceCompile)
                {
                    Console.WriteLine("Invoke Compiler = True");
                    compiled = CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames, true);
                }
                else if ((2 <= ArmadaOptions.O.SpillTargetCode && verified && !CommandLineOptions.Clo.UserConstrainedProcsToCheck) || 3 <= ArmadaOptions.O.SpillTargetCode)
                {
                    Console.WriteLine("Invoke Compiler = False");
                    compiled = CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames, false);
                }
                break;

            case PipelineOutcome.Done:
                // Console.WriteLine("Done");
                // WriteStatss(statss);
                if (ArmadaOptions.O.ForceCompile || 3 <= ArmadaOptions.O.SpillTargetCode)
                {
                    compiled = CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames, ArmadaOptions.O.ForceCompile);
                }
                break;

            default:
                // error has already been reported to user
                break;
            }
            return(compiled);
        }
Esempio n. 17
0
    public static bool Boogie(IList<string> dafnyFileNames, Bpl.Program boogieProgram, string programId,
                              out PipelineStatistics stats, out PipelineOutcome oc)
    {
      if (programId == null)
      {
        programId = "main_program_id";
      }

      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);
      }

      stats = null;
      oc = BoogiePipelineWithRerun(boogieProgram, bplFilename, out stats, 1 < Dafny.DafnyOptions.Clo.VerifySnapshots ? programId : null);
      return stats.ErrorCount == 0 && stats.InconclusiveCount == 0 && stats.TimeoutCount == 0 && stats.OutOfMemoryCount == 0;
    }
Esempio n. 18
0
        public static bool Boogie(string baseName, IEnumerable <Tuple <string, Bpl.Program> > boogiePrograms, string programId, out Dictionary <string, PipelineStatistics> statss, out PipelineOutcome oc)
        {
            bool isVerified = true;

            oc     = PipelineOutcome.VerificationCompleted;
            statss = new Dictionary <string, PipelineStatistics>();

            Stopwatch watch = new Stopwatch();

            watch.Start();

            foreach (var prog in boogiePrograms)
            {
                PipelineStatistics newstats;
                PipelineOutcome    newoc;

                if (ArmadaOptions.O.SeparateModuleOutput)
                {
                    ExecutionEngine.printer.AdvisoryWriteLine("For module: {0}", prog.Item1);
                }

                isVerified = BoogieOnce(baseName, prog.Item1, prog.Item2, programId, out newstats, out newoc) && isVerified;

                watch.Stop();

                if ((oc == PipelineOutcome.VerificationCompleted || oc == PipelineOutcome.Done) && newoc != PipelineOutcome.VerificationCompleted)
                {
                    oc = newoc;
                }

                if (ArmadaOptions.O.SeparateModuleOutput)
                {
                    TimeSpan ts          = watch.Elapsed;
                    string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}",
                                                         ts.Hours, ts.Minutes, ts.Seconds);

                    ExecutionEngine.printer.AdvisoryWriteLine("Elapsed time: {0}", elapsedTime);
                    ExecutionEngine.printer.WriteTrailer(newstats);
                }

                statss.Add(prog.Item1, newstats);
                watch.Restart();
            }
            watch.Stop();

            return(isVerified);
        }
Esempio n. 19
0
 public static bool Compile(string fileName, ReadOnlyCollection<string> otherFileNames, Program dafnyProgram,
     PipelineOutcome oc, Dictionary<string, PipelineStatistics> statss, bool verified)
 {
     var resultFileName = DafnyOptions.O.DafnyPrintCompiledFile ?? fileName;
       bool compiled = true;
       switch (oc)
       {
     case PipelineOutcome.VerificationCompleted:
       WriteStatss(statss);
       if ((DafnyOptions.O.Compile && verified && CommandLineOptions.Clo.ProcsToCheck == null) || DafnyOptions.O.ForceCompile)
     compiled = CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames);
       break;
     case PipelineOutcome.Done:
       WriteStatss(statss);
       if (DafnyOptions.O.ForceCompile)
     compiled = CompileDafnyProgram(dafnyProgram, resultFileName, otherFileNames);
       break;
     default:
       // error has already been reported to user
       break;
       }
       return compiled;
 }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
 public static void Compile(string fileName, ReadOnlyCollection<string> otherFileNames, Program dafnyProgram,
                            PipelineOutcome oc, PipelineStatistics stats, bool verified)
 {
   var resultFileName = DafnyOptions.O.DafnyPrintCompiledFile ?? fileName;
   switch (oc)
   {
     case PipelineOutcome.VerificationCompleted:
       ExecutionEngine.printer.WriteTrailer(stats);
       if ((DafnyOptions.O.Compile && verified && 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;
   }
 }