Example #1
0
 public static Bpl.Program Translate(Program dafnyProgram, Resolver r = null)
 {
     Dafny.Translator translator    = new Dafny.Translator(dafnyProgram.reporter);
     Bpl.Program      boogieProgram = translator.Translate(dafnyProgram, r);
     if (CommandLineOptions.Clo.PrintFile != null)
     {
         ExecutionEngine.PrintBplFile(CommandLineOptions.Clo.PrintFile, boogieProgram, false, false, CommandLineOptions.Clo.PrettyPrint);
     }
     return(boogieProgram);
 }
Example #2
0
        private bool Translate()
        {
            var translator = new Dafny.Translator(reporter)
            {
                InsertChecksums = true, UniqueIdPrefix = fname
            };

            boogieProgram = translator.Translate(dafnyProgram); // FIXME how are translation errors reported?
            return(true);
        }
Example #3
0
 private bool Translate()
 {
     var translator = new Dafny.Translator(reporter) { InsertChecksums = true, UniqueIdPrefix = fname };
       boogieProgram = translator.Translate(dafnyProgram); // FIXME how are translation errors reported?
       return true;
 }
Example #4
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);
        }
Example #5
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;
    }
Example #6
0
 public static Bpl.Program Translate(Program dafnyProgram, Resolver r = null)
 {
   Dafny.Translator translator = new Dafny.Translator(dafnyProgram.reporter);
   Bpl.Program boogieProgram = translator.Translate(dafnyProgram, r);
   if (CommandLineOptions.Clo.PrintFile != null)
   {
     ExecutionEngine.PrintBplFile(CommandLineOptions.Clo.PrintFile, boogieProgram, false, false, CommandLineOptions.Clo.PrettyPrint);
   }
   return boogieProgram;
 }