Exemplo n.º 1
0
        /// <summary>
        /// Return the counterexample log produced by trying to verify this modified
        /// version of the original boogie program. Return null if this
        /// counterexample does not cover any new SourceModifications.
        /// </summary>
        public virtual string?GetCounterExampleLog()
        {
            var oldOptions = DafnyOptions.O;
            var options    = SetupOptions(procedure);

            DafnyOptions.Install(options);
            var uniqueId = Guid.NewGuid().ToString();

            program.Resolve();
            program.Typecheck();
            ExecutionEngine.EliminateDeadVariables(program);
            ExecutionEngine.CollectModSets(program);
            ExecutionEngine.CoalesceBlocks(program);
            ExecutionEngine.Inline(program);
            var log = Utils.CaptureConsoleOutput(
                () => ExecutionEngine.InferAndVerify(program,
                                                     new PipelineStatistics(), uniqueId,
                                                     _ => { }, uniqueId));

            DafnyOptions.Install(oldOptions);
            // make sure that there is a counterexample (i.e. no parse errors, etc):
            string?line;
            var    stringReader = new StringReader(log);

            while ((line = stringReader.ReadLine()) != null)
            {
                if (line.StartsWith("Block |"))
                {
                    return(log);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a program from the given files.
        /// </summary>
        /// <param name="filesToParse">Files to parse</param>
        /// <param name="program">Program</param>
        /// <param name="rc">ResolutionContext</param>
        private static void CreateProgramFromFiles(List <string> filesToParse,
                                                   out Microsoft.Boogie.Program program, out ResolutionContext rc)
        {
            program = ExecutionEngine.ParseBoogieProgram(filesToParse, false);
            if (program == null)
            {
                Environment.Exit((int)Outcome.ParsingError);
            }

            rc = new ResolutionContext(null);
            program.Resolve(rc);
            if (rc.ErrorCount != 0)
            {
                Output.PrintLine("{0} name resolution errors detected", rc.ErrorCount);
                Environment.Exit((int)Outcome.ParsingError);
            }

            int errorCount = program.Typecheck();

            if (errorCount != 0)
            {
                Output.PrintLine("{0} type checking errors detected", errorCount);
                Environment.Exit((int)Outcome.ParsingError);
            }
        }
        /// <summary>
        /// Prove correctness with Boogie for a single Boogie program.
        /// This will report logical (asserts, ensures, decreases, ...) errors.
        /// </summary>
        private bool BoogieOnce(string moduleName, Bpl.Program boogieProgram)
        {
            ClearModelFile();

            if (boogieProgram.Resolve() != 0 || boogieProgram.Typecheck() != 0)
            {
                return(false);
            }

            ExecutionEngine.EliminateDeadVariables(boogieProgram);
            ExecutionEngine.CollectModSets(boogieProgram);
            ExecutionEngine.CoalesceBlocks(boogieProgram);
            ExecutionEngine.Inline(boogieProgram);

            var ps            = new PipelineStatistics();
            var programId     = "BoogieProgram_" + moduleName;
            var time          = DateTime.UtcNow.Ticks.ToString();
            var boogieOutcome = ExecutionEngine.InferAndVerify(boogieProgram, ps, programId, AddBoogieErrorToList, time);

            bool success = boogieOutcome == PipelineOutcome.Done ||
                           boogieOutcome == PipelineOutcome.VerificationCompleted;

            if (success)
            {
                _status = TranslationStatus.Boogied;
            }
            return(success);
        }
Exemplo n.º 4
0
Arquivo: Utils.cs Projeto: townie/esh
        public static bool ParseProgram(string path, out Program program)
        {
            program = null;
            int errCount;
            try
            {
                errCount = Parser.Parse(path, new List<string>(), out program);
                if (errCount != 0 || program == null)
                {
                    Warning($"Parse errors detected in {path}");
                    return false;
                }
            }
            catch (IOException e)
            {
                Warning($"Error opening file \"{path}\": {e.Message}");
                return false;
            }
            errCount = program.Resolve();
            if (errCount > 0)
            {
                Warning($"Name resolution errors in {path}");
                return false;
            }
            ModSetCollector c = new ModSetCollector();
            c.DoModSetAnalysis(program);

            return true;
        }
Exemplo n.º 5
0
        private bool BoogieOnce(string moduleName, Bpl.Program boogieProgram)
        {
            if (boogieProgram.Resolve() == 0 && boogieProgram.Typecheck() == 0) //FIXME ResolveAndTypecheck?
            {
                ExecutionEngine.EliminateDeadVariables(boogieProgram);
                ExecutionEngine.CollectModSets(boogieProgram);
                ExecutionEngine.CoalesceBlocks(boogieProgram);
                ExecutionEngine.Inline(boogieProgram);

                //NOTE: We could capture errors instead of printing them (pass a delegate instead of null)
                switch (ExecutionEngine.InferAndVerify(boogieProgram, new PipelineStatistics(), "ServerProgram_" + moduleName, null, DateTime.UtcNow.Ticks.ToString()))
                {
                case PipelineOutcome.Done:
                case PipelineOutcome.VerificationCompleted:
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Resolves and type checks the given Boogie program.
        /// Returns:
        ///  - Done if no errors occurred, and command line specified no resolution or no type checking.
        ///  - ResolutionError if a resolution error occurred
        ///  - TypeCheckingError if a type checking error occurred
        ///  - ResolvedAndTypeChecked if both resolution and type checking succeeded
        /// </summary>
        static PipelineOutcome BoogieResolveAndTypecheck(Bpl.Program program, ErrorSink errorSink)
        {
            Contract.Requires(program != null);
            // ---------- Resolve ------------------------------------------------------------
            int errorCount = program.Resolve(errorSink);

            if (errorCount != 0)
            {
                return(PipelineOutcome.ResolutionError);
            }

            // ---------- Type check ------------------------------------------------------------
            errorCount = program.Typecheck(errorSink);
            if (errorCount != 0)
            {
                return(PipelineOutcome.TypeCheckingError);
            }

            return(PipelineOutcome.ResolvedAndTypeChecked);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Resolves and type checks the given Boogie program.  Any errors are reported to the
        /// console.  Returns:
        ///  - Done if no errors occurred, and command line specified no resolution or no type checking.
        ///  - ResolutionError if a resolution error occurred
        ///  - TypeCheckingError if a type checking error occurred
        ///  - ResolvedAndTypeChecked if both resolution and type checking succeeded
        /// </summary>
        public static PipelineOutcome ResolveAndTypecheck(Program program, string bplFileName, out LinearTypeChecker linearTypeChecker, out CivlTypeChecker civlTypeChecker)
        {
            Contract.Requires(program != null);
              Contract.Requires(bplFileName != null);

              linearTypeChecker = null;
              civlTypeChecker = null;

              // ---------- Resolve ------------------------------------------------------------

              if (CommandLineOptions.Clo.NoResolve)
              {
            return PipelineOutcome.Done;
              }

              int errorCount = program.Resolve();
              if (errorCount != 0)
              {
            Console.WriteLine("{0} name resolution errors detected in {1}", errorCount, GetFileNameForConsole(bplFileName));
            return PipelineOutcome.ResolutionError;
              }

              // ---------- Type check ------------------------------------------------------------

              if (CommandLineOptions.Clo.NoTypecheck)
              {
            return PipelineOutcome.Done;
              }

              errorCount = program.Typecheck();
              if (errorCount != 0)
              {
            Console.WriteLine("{0} type checking errors detected in {1}", errorCount, GetFileNameForConsole(bplFileName));
            return PipelineOutcome.TypeCheckingError;
              }

              if (PolymorphismChecker.IsMonomorphic(program))
              {
              CommandLineOptions.Clo.TypeEncodingMethod = CommandLineOptions.TypeEncoding.Monomorphic;
              }

              CollectModSets(program);

              civlTypeChecker = new CivlTypeChecker(program);
              civlTypeChecker.TypeCheck();
              if (civlTypeChecker.errorCount != 0)
              {
              Console.WriteLine("{0} type checking errors detected in {1}", civlTypeChecker.errorCount, GetFileNameForConsole(bplFileName));
              return PipelineOutcome.TypeCheckingError;
              }

              linearTypeChecker = new LinearTypeChecker(program);
              linearTypeChecker.TypeCheck();
              if (linearTypeChecker.errorCount == 0)
              {
            linearTypeChecker.Transform();
              }
              else
              {
            Console.WriteLine("{0} type checking errors detected in {1}", linearTypeChecker.errorCount, GetFileNameForConsole(bplFileName));
            return PipelineOutcome.TypeCheckingError;
              }

              if (CommandLineOptions.Clo.PrintFile != null && CommandLineOptions.Clo.PrintDesugarings)
              {
            // if PrintDesugaring option is engaged, print the file here, after resolution and type checking
            PrintBplFile(CommandLineOptions.Clo.PrintFile, program, true, true, CommandLineOptions.Clo.PrettyPrint);
              }

              return PipelineOutcome.ResolvedAndTypeChecked;
        }