Example #1
0
        public void PrintInfo(TokenTextWriter writer)
        {
            if (writer == null)
            {
                return;
            }

            writer.WriteLine("=================================");
            writer.WriteLine("Here's what we know of the program:");



            writer.Write("Declared globals: ");
            foreach (var g in declaredGlobals)
            {
                writer.Write(g.Key + " ");
            }
            writer.Write("\n");

            writer.Write("Modified globals: ");
            foreach (var g in modifiedGlobals)
            {
                writer.Write(g.Key + " ");
            }
            writer.Write("\n");

            writer.WriteLine("Main procedure: {0}", mainProcName);

            writer.WriteLine("=================================");
        }
Example #2
0
 public void Emit(TokenTextWriter t)
 {
     Console.Write("\t");
     Source.Emit(t, 0);
     if (!Cons.IsTrue())
     {
         t.WriteLine("\t\tPre: ");
         t.Write("\t\t\t");
         Cons.Emit(t);
         t.WriteLine();
     }
     if (Gammas.Count != 0)
     {
         t.WriteLine("\t\tGammas:");
         for (int i = 0; i < Gammas.Count; i++)
         {
             if (Gammas.Count > 1)
             {
                 t.WriteLine("\t\t\t" + i + ": ");
             }
             Gammas[i].Emit(t);
             t.WriteLine("===============");
         }
     }
 }
Example #3
0
            public static void PrintBplFile(string filename, Program program, bool allowPrintDesugaring)
            {
                Contract.Requires(program != null);
                Contract.Requires(filename != null);

                bool oldPrintDesugaring = CommandLineOptions.Clo.PrintDesugarings;

                if (!allowPrintDesugaring)
                {
                    CommandLineOptions.Clo.PrintDesugarings = false;
                }

                using (TokenTextWriter writer = filename == "-" ?
                                                new TokenTextWriter("<console>", Console.Out, false) :
                                                new TokenTextWriter(filename, false))
                {
                    if (CommandLineOptions.Clo.ShowEnv != CommandLineOptions.ShowEnvironment.Never)
                    {
                        writer.WriteLine("// " + CommandLineOptions.Clo.Version);
                        writer.WriteLine("// " + CommandLineOptions.Clo.Environment);
                    }

                    writer.WriteLine();
                    program.Emit(writer);
                }

                CommandLineOptions.Clo.PrintDesugarings = oldPrintDesugaring;
            }
Example #4
0
        private static void setupPrint(PersistentCBAProgram program, ErrorTrace trace, string file)
        {
            // Set output files
            pathFile = file == null ? null : new TokenTextWriter(file + "_trace.txt");
            if (pathFile != null)
            {
                program.writeToFile(file + ".bpl");
            }
            Program prog = program.getProgram();

            // Initialization
            initialize(prog, trace, file == null ? null : file + ".bpl");

            if (pathFile != null)
            {
                if (traceFormat == TraceFormat.ConcurrencyExplorer)
                {
                    pathFile.WriteLine("s");
                    pathFile.WriteLine("#");
                }
                else if (traceFormat == TraceFormat.SDV)
                {
                    pathFile.WriteLine("0 \"?\" 0 false ^ Call \"OS\" \"main\"");
                }
            }
        }
Example #5
0
        // Prints the policy
        public void print(TokenTextWriter writer)
        {
            if (writer == null)
            {
                return;
            }

            writer.WriteLine("=================================");
            writer.WriteLine("The instrumentation policy:");
            writer.Write("  Globals to instrument: ");

            foreach (var s in globalsToInstrument)
            {
                writer.Write("{0}  ", s);
            }

            writer.WriteLine();

            /*
             * writer.Write("  Procedures without implementation: ");
             * foreach (var s in procsWithoutImpl)
             * {
             *  writer.Write("{0}  ", s);
             * }
             * writer.WriteLine();
             *
             * writer.WriteLine("  Atomic-block procedures: {0}  {1}", atomicBeginProcName, atomicEndProcName);
             * writer.WriteLine("  Assertion procedure: {0}", assertNotReachableName);
             */
            writer.WriteLine("=================================");
        }
Example #6
0
            public static void DumpExceptionInformation(Exception e)
            {
                if (e.ToString().Contains("An attempt was made to load an assembly from a network location"))
                {
                    Console.Error.WriteLine();
                    Console.Error.WriteLine("GPUVerify has had trouble loading one of its components due to security settings.");
                    Console.Error.WriteLine();
                    Console.Error.WriteLine("In order to run GPUVerify successfully you need to unblock the archive before unzipping it.");
                    Console.Error.WriteLine();
                    Console.Error.WriteLine("To do this:");
                    Console.Error.WriteLine(" - Right click on the .zip file");
                    Console.Error.WriteLine(" - Click \"Properties\"");
                    Console.Error.WriteLine(" - At the bottom of the \"General\" tab you should see:");
                    Console.Error.WriteLine("     Security: This file came from another computer and might be blocked");
                    Console.Error.WriteLine("     to help protect this computer.");
                    Console.Error.WriteLine(" - Click \"Unblock\"");
                    Console.Error.WriteLine(" - Click \"OK\"");
                    Console.Error.WriteLine("Once this is done, unzip GPUVerify afresh and this issue should be resolved.");
                    Environment.Exit((int)ToolExitCodes.INTERNAL_ERROR);
                }

                const string DUMP_FILE = "__gvdump.txt";

                // Give generic internal error message
                Console.Error.WriteLine("\nGPUVerify: an internal error has occurred, details written to " + DUMP_FILE + ".");
                Console.Error.WriteLine();
                Console.Error.WriteLine("Please consult the troubleshooting guide in the GPUVerify documentation");
                Console.Error.WriteLine("for common problems, and if this does not help, raise an issue via the");
                Console.Error.WriteLine("GPUVerify issue tracker:");
                Console.Error.WriteLine();
                Console.Error.WriteLine("  https://github.com/mc-imperial/gpuverify");
                Console.Error.WriteLine();

                // Now try to give the user a specific hint if this looks like a common problem
                if (e is ProverException)
                {
                    Console.Error.WriteLine("Hint: It looks like GPUVerify is having trouble invoking its");
                    Console.Error.WriteLine("supporting theorem prover, which by default is Z3.  Have you");
                    Console.Error.WriteLine("installed Z3?");
                }

                // Write details of the exception to the dump file
                using (TokenTextWriter writer = new TokenTextWriter(DUMP_FILE, false))
                {
                    writer.WriteLine("An exception occured:");
                    writer.WriteLine(e.ToString());
                }
            }
Example #7
0
 public void Emit(TokenTextWriter t)
 {
     t.WriteLine(Source.Label + ":");
     foreach (SymbolicCmd c in SCmds)
     {
         c.Emit(t);
     }
 }
        // Returns file and line of the failing assert. Dumps
        // error trace to disk.
        public Tuple <string, int> PrintErrorTrace(cba.ErrorTrace trace, string filename, List <Tuple <string, int, string> > eeSlicedSourceLines, string failStatus)
        {
            trace = mapBackTrace(trace);

            if (Driver.printTraceMode == Driver.PRINT_TRACE_MODE.Boogie)
            {
                cba.PrintProgramPath.print(input, trace, filename);
                return(null);
            }
            else
            {
                // relevant lines
                cba.PrintSdvPath.relevantLines = null;
                if (eeSlicedSourceLines != null)
                {
                    cba.PrintSdvPath.relevantLines = new HashSet <Tuple <string, int> >();
                    eeSlicedSourceLines.Iter(tup => cba.PrintSdvPath.relevantLines.Add(Tuple.Create(tup.Item1, tup.Item2)));
                }

                cba.PrintSdvPath.failingLocation = null;
                cba.PrintSdvPath.failStatus      = failStatus;


                cba.PrintSdvPath.Print(input.getProgram(), trace, new HashSet <string>(), "",
                                       filename + ".tt", filename + "stack.txt");

                if (cba.PrintSdvPath.abortMessage != null)
                {
                    var am = new TokenTextWriter(filename + ".txt");
                    am.WriteLine(cba.PrintSdvPath.abortMessage);
                    am.Close();
                }


                if (cba.PrintSdvPath.lastDriverLocation == null)
                {
                    return(null);
                }
                cba.PrintSdvPath.failingLocation = Tuple.Create(cba.PrintSdvPath.lastDriverLocation.Item1, cba.PrintSdvPath.lastDriverLocation.Item3);

                cba.PrintSdvPath.Print(input.getProgram(), trace, new HashSet <string>(), "",
                                       filename + ".tt", filename + "stack.txt");

                if (cba.PrintSdvPath.abortMessage != null)
                {
                    var am = new TokenTextWriter(filename + ".txt");
                    am.WriteLine(cba.PrintSdvPath.abortMessage);
                    am.Close();
                }

                cba.PrintSdvPath.relevantLines   = null;
                cba.PrintSdvPath.failingLocation = null;
                cba.PrintSdvPath.failStatus      = null;

                return(Tuple.Create(cba.PrintSdvPath.lastDriverLocation.Item1, cba.PrintSdvPath.lastDriverLocation.Item3));
            }
        }
        private static void setupPrint(PersistentCBAProgram program, ErrorTrace trace, string file)
        {
            // Set output files
            pathFile = file == null ? null : new TokenTextWriter(file + "_trace.txt");
            if (pathFile != null)
            {
                program.writeToFile(file + ".bpl");
            }
            Program prog = program.getProgram();

            // Initialization
            initialize(prog, trace, file == null ? null : file + ".bpl");

            if (pathFile != null)
            {
                pathFile.WriteLine("s");
            }
            if (pathFile != null)
            {
                pathFile.WriteLine("#");
            }
        }
Example #10
0
 public void Emit(TokenTextWriter t)
 {
     t.Write("vtask: (" + Eq.Name + ", " + Left.Name + ", " + Right.Name + ")");
     if (DesiredOutputVars.Count > 0)
     {
         t.Write(" / ");
         foreach (var v in DesiredOutputVars)
         {
             t.Write(v.Name + "; ");
         }
     }
     t.WriteLine();
 }
Example #11
0
        private static void printLabels(Counterexample cex, TokenTextWriter ttw, int indent)
        {
            for (int numBlock = 0; numBlock < cex.Trace.Count; numBlock++)
            {
                Block b = cex.Trace[numBlock];

                printIndent(ttw, indent);
                ttw.WriteLine(b.Label);

                for (int numInstr = 0; numInstr < b.Cmds.Count; numInstr++)
                {
                    Cmd c   = b.Cmds[numInstr];
                    var loc = new TraceLocation(numBlock, numInstr);
                    if (cex.calleeCounterexamples.ContainsKey(loc))
                    {
                        printIndent(ttw, indent); ttw.WriteLine("call to {0}:", (c as CallCmd).Proc.Name);
                        printLabels(cex.calleeCounterexamples[loc].counterexample, ttw, indent + 1);
                        printIndent(ttw, indent); ttw.WriteLine("return from {0}.", (c as CallCmd).Proc.Name);
                        printIndent(ttw, indent); ttw.WriteLine(b.Label);
                    }
                }
            }
        }
Example #12
0
        public static void Main(string[] args)
        {
            CommandLineOptions.Parse(args);
            Microsoft.Boogie.CommandLineOptions.Install(new OverrideCommandLineOptions());
            string  file = CommandLineOptions.Files[0];
            Program program;
            var     defines = new List <string>()
            {
                "FILE_0"
            };
            int errors = Parser.Parse(file, defines, out program);

            Debug.Assert(errors == 0, String.Format("Parse errors discovered in '{0}'", file));
            errors = program.Resolve();
            errors = program.Typecheck();
            Microsoft.Boogie.CommandLineOptions.Clo.PrintUnstructured = 2;
            using (TokenTextWriter writer = new TokenTextWriter(file + ".unstructured"))
            {
                writer.WriteLine();
                program.Emit(writer);
            }
            Start(program, CommandLineOptions.ThreadID, CommandLineOptions.GroupID, Print.verbose, Print.debug);
        }
Example #13
0
 public override void Emit(TokenTextWriter stream, int level) {
   //Contract.Requires(stream != null);
   stream.WriteLine();
   stream.WriteLine("{0};", Indent(level));
   first.Emit(stream, level + 1);
   second.Emit(stream, level + 1);
 }
Example #14
0
    public override void Emit(TokenTextWriter stream, int level) {
      //Contract.Requires(stream != null);
      stream.Write(this, level, "const ");
      EmitAttributes(stream);
      if (this.Unique) {
        stream.Write(this, level, "unique ");
      }
      EmitVitals(stream, level, false);

      if (Parents != null || ChildrenComplete) {
        stream.Write(this, level, " extends");
        string/*!*/ sep = " ";
        foreach (ConstantParent/*!*/ p in cce.NonNull(Parents)) {
          Contract.Assert(p != null);
          stream.Write(this, level, sep);
          sep = ", ";
          if (p.Unique)
            stream.Write(this, level, "unique ");
          p.Parent.Emit(stream);
        }
        if (ChildrenComplete)
          stream.Write(this, level, " complete");
      }

      stream.WriteLine(";");
    }
Example #15
0
 public void Emit(TokenTextWriter stream, int level) {
   Contract.Requires(stream != null);
   if (Comment != null) {
     stream.WriteLine(this, level, "// " + Comment);
   }
   stream.Write(this, level, "{0}ensures ", Free ? "free " : "");
   Cmd.EmitAttributes(stream, Attributes);
   this.Condition.Emit(stream);
   stream.WriteLine(";");
 }
Example #16
0
 public override void Emit(TokenTextWriter stream, int level)
 {
     if (Label == null) {
     stream.WriteLine(level, "break;");
       } else {
     stream.WriteLine(level, "break {0};", Label);
       }
 }
Example #17
0
        public void Emit(TokenTextWriter stream, int level)
        {
            Contract.Requires(stream != null);
              if (!Anonymous) {
            stream.WriteLine(level, "{0}:",
              CommandLineOptions.Clo.PrintWithUniqueASTIds ? String.Format("h{0}^^{1}", this.GetHashCode(), this.LabelName) : this.LabelName);
              }

              foreach (Cmd/*!*/ c in this.simpleCmds) {
            Contract.Assert(c != null);
            c.Emit(stream, level + 1);
              }

              if (this.ec != null) {
            this.ec.Emit(stream, level + 1);
              } else if (this.tc != null) {
            this.tc.Emit(stream, level + 1);
              }
        }
Example #18
0
        public override void Emit(TokenTextWriter stream, int level)
        {
            stream.Write(this, level, "");

              string/*!*/ sep = "";
              foreach (AssignLhs/*!*/ l in Lhss) {
            Contract.Assert(l != null);
            stream.Write(sep);
            sep = ", ";
            l.Emit(stream);
              }

              stream.Write(" := ");

              sep = "";
              foreach (Expr/*!*/ e in Rhss) {
            Contract.Assert(e != null);
            stream.Write(sep);
            sep = ", ";
            e.Emit(stream);
              }

              stream.WriteLine(";");
        }
Example #19
0
 public override void Emit(TokenTextWriter stream, int level)
 {
     if (this.Comment.Contains("\n")) {
     stream.WriteLine(this, level, "/* {0} */", this.Comment);
       } else {
     stream.WriteLine(this, level, "// {0}", this.Comment);
       }
 }
Example #20
0
    public override void Emit(TokenTextWriter stream, int level) {
      //Contract.Requires(stream != null);
      stream.Write(this, level, "implementation ");
      EmitAttributes(stream);
      stream.Write(this, level, "{0}", TokenTextWriter.SanitizeIdentifier(this.Name));
      EmitSignature(stream, false);
      stream.WriteLine();

      stream.WriteLine(level, "{0}", '{');

      foreach (Variable/*!*/ v in this.LocVars) {
        Contract.Assert(v != null);
        v.Emit(stream, level + 1);
      }

      if (this.StructuredStmts != null && !CommandLineOptions.Clo.PrintInstrumented && !CommandLineOptions.Clo.PrintInlined) {
        if (this.LocVars.Count > 0) {
          stream.WriteLine();
        }
        if (CommandLineOptions.Clo.PrintUnstructured < 2) {
          if (CommandLineOptions.Clo.PrintUnstructured == 1) {
            stream.WriteLine(this, level + 1, "/*** structured program:");
          }
          this.StructuredStmts.Emit(stream, level + 1);
          if (CommandLineOptions.Clo.PrintUnstructured == 1) {
            stream.WriteLine(level + 1, "**** end structured program */");
          }
        }
      }

      if (this.StructuredStmts == null || 1 <= CommandLineOptions.Clo.PrintUnstructured ||
          CommandLineOptions.Clo.PrintInstrumented || CommandLineOptions.Clo.PrintInlined) {
        foreach (Block b in this.Blocks) {
          b.Emit(stream, level + 1);
        }
      }

      stream.WriteLine(level, "{0}", '}');

      stream.WriteLine();
      stream.WriteLine();
    }
Example #21
0
        public static void ProcessCounterexamplesWOSymbolicOut(SDiffCounterexamples errors, List <Variable> globals, List <Variable> eqLocVars,
                                                               Implementation vtLeftProcImpl, Implementation vtRightProcImpl, List <Declaration> consts, List <Model> errModelList,
                                                               string v1Name, string v2Name)
        {
            List <Expr>  constraintExprs = new List <Expr>();
            List <Block> listBlocksV1    = new List <Block>();
            List <Block> listBlocksV2    = new List <Block>();

            Model[] errModelArray = errModelList.ToArray();

            var label = new GotoCmd(Token.NoToken, new List <String>()
            {
                "DONE"
            });

            label.labelNames = new List <string>(); // label.labelTargets = new List<Block>();
            label.labelNames.Add("DONE");           //label.labelTargets.Add("DONE");


            // First block
            var labels = new List <String>();

            for (int j = 0; j < errors.Count; j++)
            {
                labels.Add("Cex" + j);
            }

            labels.Add("ELSE");
            var labelEntry = new GotoCmd(Token.NoToken, labels);

            labelEntry.labelTargets = new List <Block>();

            for (int j = 0; j < errors.Count; j++)
            {
                labelEntry.labelNames.Add("Cex" + j);//labelEntry.labelTargets.Add("Cex" + j);
            }

            for (int i = 0; i < errors.Count; i++)
            {
                var impl  = errors[i].Impl;
                var trace = errors[i].Trace;

                //Log.Out(Log.Normal, "Attempting symbolic execution of [" + i + "] $ " + impl.Name);


                if (Options.GenerateCTrace)
                {
                    Log.Out(Log.Normal, "Constructing metatrace from location annotations");
                    var extractor = new SDiff.SymEx.TraceExtractor();
                    extractor.VisitTrace(trace);
                    //Log.Out(Log.CTrace, CTrace.Make(extractor.metaTrace));
                    var cTrace = CTrace.Make(extractor.metaTrace, consts, errModelArray[i], v1Name, v2Name);
                    //var cTrace = "";
                    if (cTrace.Trim() != "")
                    {
                        //note that the index for cex on the output shows 1,2,..., instead of 0,1,2....
                        var fname  = impl.Name + "_cex_" + (i + 1) + "_out.c";
                        var cexOut = new TokenTextWriter(impl.Name + "_cex_" + (i + 1) + "_out.c", true);
                        cexOut.WriteLine(cTrace);
                        cexOut.Close();
                        Log.Out(Log.CTrace, "n:" + (i + 1) + ":" + fname);
                        Log.Out(Log.CTrace, "w:" + fname);
                    }
                }

                Log.Out(Log.Normal, "Desugaring calls");
                //HACK!!!: changes havoc x; assume (x= uf(..)); --> x := uf(...)
                var deCall = new SDiff.SymEx.DesugarCallCmds();
                trace = deCall.VisitTrace(trace);

                //symbolic constants
                var symInParams = new List <Variable>(impl.InParams);
                foreach (var g in globals)
                {
                    symInParams.Add(g);
                }

                Log.Out(Log.Normal, "Executing trace downward");
                //symbolic stores (look at symex.cs for the datastructure)
                // var sTrace = SDiff.SymEx.Cexecutor.ExecDown(trace, symInParams);
                Log.Out(Log.Normal, "Executing trace upward");
                //looks at each assume to create the path constants
                //clean up the duplication of assignments
                //SDiff.SymEx.Cexecutor.ExecUp(sTrace);

                Log.Out(Log.Normal, "Grabbing final execution values");
                // var lastStore = sTrace.LastSCmd().Gammas.Last();
                // var firstCons = sTrace.FirstSCmd().Cons;

                // constraintExprs.Add(firstCons.Conjoin());

                //#hemr - generating new strategy right here with inlining counterexamples!

                // Second block
                List <Cmd> cmdsV1_Diff_inline = new List <Cmd>();
                List <Cmd> cmdsV2_Diff_inline = new List <Cmd>();

                Substitution replaceScopeV1 = delegate(Variable x)
                {
                    return(replaceScopeGeneric(vtLeftProcImpl, x));
                };

                Substitution replaceScopeV2 = delegate(Variable x)
                {
                    return(replaceScopeGeneric(vtRightProcImpl, x));
                };

                foreach (Block currentBlock in trace)
                {
                    if (currentBlock.ToString().Contains("inline$" + v1Name))
                    {
                        foreach (Cmd currentCmd in currentBlock.Cmds)
                        {
                            Cmd newCmd = Substituter.Apply(replaceScopeV1, currentCmd);
                            cmdsV1_Diff_inline.Add(newCmd);
                        }
                    }
                    else if (currentBlock.ToString().Contains("inline$" + v2Name))
                    {
                        foreach (Cmd currentCmd in currentBlock.Cmds)
                        {
                            Cmd newCmd = Substituter.Apply(replaceScopeV2, currentCmd);
                            cmdsV2_Diff_inline.Add(newCmd);
                        }
                    }
                }

                Block blockV1 = new Block(Token.NoToken, "Cex" + i, cmdsV1_Diff_inline, label);
                Block blockV2 = new Block(Token.NoToken, "Cex" + i, cmdsV2_Diff_inline, label);

                listBlocksV1.Add(blockV1);
                listBlocksV2.Add(blockV2);

                //#hemr - displaying values related to error model (at console level)

                Model currentModel = errModelArray[i];

                //var keys = currentModel.identifierToPartition.Keys;
                var keys = currentModel.Functions.Where(f => f.Arity == 0).Select(f => f.GetConstant());
            }

            Expr disjunctionDiffCond = Expr.False;

            foreach (Expr currentExpr in constraintExprs)
            {
                disjunctionDiffCond = Expr.Or(disjunctionDiffCond, currentExpr);
            }

            ProcessCounterexampleForDiffInliningWOSymbolicOut(eqLocVars, vtLeftProcImpl, vtRightProcImpl, v1Name, v2Name, listBlocksV1, listBlocksV2, labelEntry);
        }
Example #22
0
        public static void ProcessCounterexamples(SDiffCounterexamples errors, List <Variable> globals, List <Variable> outputVars, Program prog, Implementation vtLeftProcImpl, Implementation vtRightProcImpl)
        {
            List <Expr> constraintExprs = new List <Expr>();

            for (int i = 0; i < errors.Count; i++)
            {
                var impl  = errors[i].Impl;
                var trace = errors[i].Trace;

                Log.Out(Log.Normal, "Attempting symbolic execution of [" + (i + 1) + "] $ " + impl.Name);


                if (Options.GenerateCTrace)
                {
                    Log.Out(Log.Normal, "Constructing metatrace from location annotations");
                    var extractor = new SDiff.SymEx.TraceExtractor();
                    extractor.VisitTrace(trace);
                    //Log.Out(Log.CTrace, CTrace.Make(extractor.metaTrace));
                    var cTrace = CTrace.Make(extractor.metaTrace, null, null, "", "");
                    //var cTrace = "";
                    if (cTrace.Trim() != "")
                    {
                        var fname  = impl.Name + "_cex_" + (i + 1) + "_out.c";
                        var cexOut = new TokenTextWriter(impl.Name + "_cex_" + (i + 1) + "_out.c", true);
                        cexOut.WriteLine(cTrace);
                        cexOut.Close();
                        Log.Out(Log.CTrace, "n:" + (i + 1) + ":" + fname);
                        Log.Out(Log.CTrace, "w:" + fname);
                    }
                }

                Log.Out(Log.Normal, "Desugaring calls");
                //HACK!!!: changes havoc x; assume (x= uf(..)); --> x := uf(...)
                var deCall = new SDiff.SymEx.DesugarCallCmds();
                trace = deCall.VisitTrace(trace);

                //symbolic constants
                var symInParams = new List <Variable>(impl.InParams);
                foreach (var g in globals)
                {
                    symInParams.Add(g);
                }

                Log.Out(Log.Normal, "Executing trace downward");
                //symbolic stores (look at symex.cs for the datastructure)
                var sTrace = SDiff.SymEx.Cexecutor.ExecDown(trace, symInParams);
                Log.Out(Log.Normal, "Executing trace upward");
                //looks at each assume to create the path constants
                //clean up the duplication of assignments
                SDiff.SymEx.Cexecutor.ExecUp(sTrace);

                if (Options.DumpSymTrace)
                {
                    SDiff.SymEx.CexDumper.PrintSymbolicTrace(sTrace);
                }

                //printing the symbolic stores at exit
                //still in SSA form
                Log.Out(Log.Normal, "Grabbing final execution values");
                var lastStore = sTrace.LastSCmd().Gammas.Last();
                var firstCons = sTrace.FirstSCmd().Cons;

                //resolves the outputs to be expressions over uif and symbolic constants only
                Log.Out(Log.Normal, "Resolving result expressions");
                var outSymExprs = new List <Expr>();
                foreach (var v in outputVars)
                {
                    outSymExprs.Add(SymEx.ResolveSymExpr.Resolve(v, lastStore));
                }


                Log.Out(Log.SymEx, "SymEx Results===================================");

                Log.Out(Log.SymEx, "Input constraint");
                if (Options.EraseUFArgumentsOnPrintout) // f(..)
                {
                    var eraser   = new ArgumentParameterEraser();
                    var duper    = new Duplicator();
                    var dupConst = new SDiff.SymEx.Constraint(firstCons, true);
                    foreach (var e in dupConst.Conjuncts)
                    {
                        eraser.VisitExpr(e);
                    }
                    Log.LogEmit(Log.SymEx, 1, dupConst.Emit);
                }
                else
                {
                    Log.LogEmit(Log.SymEx, 1, firstCons.Emit);
                }

                constraintExprs.Add(firstCons.Conjoin());

                Console.WriteLine();


                Log.Out(Log.SymEx, "Symbolic output values");

                var outSymExprsPrintable = outSymExprs;
                if (Options.EraseUFArgumentsOnPrintout) // f(..)
                {
                    outSymExprsPrintable = new List <Expr>();
                    var eraser = new ArgumentParameterEraser();
                    var duper  = new Duplicator();
                    foreach (Expr e in outSymExprs)
                    {
                        var ex = duper.VisitExpr(e);
                        eraser.VisitExpr(ex);
                        outSymExprsPrintable.Add(ex);
                    }
                }

                //if the output variables aren't paired, iterate through normally
                if (outputVars.Count % 2 != 0)
                {
                    for (int j = 0; j < outputVars.Count; j++)
                    {
                        Log.Out(Log.SymEx, "\t" + outputVars[j].ToString() + ": ");
                        Log.LogEmit(Log.SymEx, 2, outSymExprsPrintable[j].Emit);
                        Log.Out(Log.Normal, "");
                    }
                }
                //otherwise don't print a pair if it's syntactically equal
                else
                {
                    for (int j = 0; j < outputVars.Count; j += 2)
                    {
                        if (!outSymExprs[j].StringEquals(outSymExprs[j + 1]))
                        {
                            Log.Out(Log.SymEx, "\t" + outputVars[j].ToString() + ": ");
                            Log.LogEmit(Log.SymEx, 2, outSymExprsPrintable[j].Emit);
                            Log.Out(Log.Normal, "");
                            Log.Out(Log.SymEx, "\t" + outputVars[j + 1].ToString() + ": ");
                            Log.LogEmit(Log.SymEx, 2, outSymExprsPrintable[j + 1].Emit);
                            Log.Out(Log.Normal, "");
                        }
                    }
                }
            }
            Expr disjunctionDiffCond = Expr.False;

            if (Options.PropagateSingleDifference && errors.Count > 1)
            {
                var t = constraintExprs.First();
                disjunctionDiffCond = Expr.Or(disjunctionDiffCond, constraintExprs.First());
            }
            else
            {
                foreach (Expr currentExpr in constraintExprs)
                {
                    disjunctionDiffCond = Expr.Or(disjunctionDiffCond, currentExpr);
                }
            }

            ProcessCounterexampleForDiffInline(errors, vtLeftProcImpl, vtRightProcImpl, disjunctionDiffCond);
        }
Example #23
0
 public override void Emit(TokenTextWriter stream, int level) {
   //Contract.Requires(stream != null);
   stream.WriteLine();
   stream.WriteLine("{0}[]", Indent(level));
   foreach (RE/*!*/ r in rs) {
     Contract.Assert(r != null);
     r.Emit(stream, level + 1);
   }
 }
Example #24
0
        public override void Emit(TokenTextWriter stream, int level)
        {
            stream.Write(level, "while (");
              if (Guard == null) {
            stream.Write("*");
              } else {
            Guard.Emit(stream);
              }
              stream.WriteLine(")");

              foreach (PredicateCmd inv in Invariants) {
            if (inv is AssumeCmd) {
              stream.Write(level + 1, "free invariant ");
            } else {
              stream.Write(level + 1, "invariant ");
            }
            Cmd.EmitAttributes(stream, inv.Attributes);
            inv.Expr.Emit(stream);
            stream.WriteLine(";");
              }

              stream.WriteLine(level, "{");
              Body.Emit(stream, level + 1);
              stream.WriteLine(level, "}");
        }
Example #25
0
 public override void Emit(TokenTextWriter stream, int level)
 {
     //Contract.Requires(stream != null);
       stream.WriteLine(this, level, "yield;");
 }
Example #26
0
 public override void Emit(TokenTextWriter stream, int level)
 {
     //Contract.Requires(stream != null);
       Contract.Assume(this.labelNames != null);
       stream.Write(this, level, "goto ");
       if (CommandLineOptions.Clo.PrintWithUniqueASTIds) {
     if (labelTargets == null) {
       string sep = "";
       foreach (string name in labelNames) {
     stream.Write("{0}{1}^^{2}", sep, "NoDecl", name);
     sep = ", ";
       }
     } else {
       string sep = "";
       foreach (Block/*!*/ b in labelTargets) {
     Contract.Assert(b != null);
     stream.Write("{0}h{1}^^{2}", sep, b.GetHashCode(), b.Label);
     sep = ", ";
       }
     }
       } else {
     labelNames.Emit(stream);
       }
       stream.WriteLine(";");
 }
Example #27
0
 public override void Emit(TokenTextWriter stream, int level)
 {
     //Contract.Requires(stream != null);
       stream.Write(this, level, "assume ");
       EmitAttributes(stream, Attributes);
       this.Expr.Emit(stream);
       stream.WriteLine(";");
 }
Example #28
0
 public override void Emit(TokenTextWriter stream, int level)
 {
     //Contract.Requires(stream != null);
       stream.Write(this, level, "havoc ");
       Vars.Emit(stream, true);
       stream.WriteLine(";");
 }
Example #29
0
        public void Emit(TokenTextWriter stream, int level)
        {
            Contract.Requires(stream != null);
              stream.WriteLine();
              stream.WriteLine(
            this,
            level,
            "{0}:{1}",
            CommandLineOptions.Clo.PrintWithUniqueASTIds ? String.Format("h{0}^^{1}", this.GetHashCode(), this.Label) : this.Label,
            this.widenBlock ? "  // cut point" : "");

              foreach (Cmd/*!*/ c in this.Cmds) {
            Contract.Assert(c != null);
            c.Emit(stream, level + 1);
              }
              Contract.Assume(this.TransferCmd != null);
              this.TransferCmd.Emit(stream, level + 1);
        }
Example #30
0
        public override void Emit(TokenTextWriter stream, int level)
        {
            stream.Write(level, "if (");
              IfCmd/*!*/ ifcmd = this;
              while (true) {
            if (ifcmd.Guard == null) {
              stream.Write("*");
            } else {
              ifcmd.Guard.Emit(stream);
            }
            stream.WriteLine(")");

            stream.WriteLine(level, "{");
            ifcmd.thn.Emit(stream, level + 1);
            stream.WriteLine(level, "}");

            if (ifcmd.elseIf != null) {
              stream.Write(level, "else if (");
              ifcmd = ifcmd.elseIf;
              continue;
            } else if (ifcmd.elseBlock != null) {
              stream.WriteLine(level, "else");
              stream.WriteLine(level, "{");
              ifcmd.elseBlock.Emit(stream, level + 1);
              stream.WriteLine(level, "}");
            }
            break;
              }
        }
Example #31
0
 public override void Emit(TokenTextWriter stream, int level)
 {
     //Contract.Requires(stream != null);
       stream.Write(this, level, "");
       if (IsFree) {
     stream.Write("free ");
       }
       if (IsAsync) {
     stream.Write("async ");
       }
       stream.Write("call ");
       EmitAttributes(stream, Attributes);
       string sep = "";
       if (Outs.Count > 0) {
     foreach (Expr arg in Outs) {
       stream.Write(sep);
       sep = ", ";
       if (arg == null) {
     stream.Write("*");
       } else {
     arg.Emit(stream);
       }
     }
     stream.Write(" := ");
       }
       stream.Write(TokenTextWriter.SanitizeIdentifier(callee));
       stream.Write("(");
       sep = "";
       foreach (Expr arg in Ins) {
     stream.Write(sep);
     sep = ", ";
     if (arg == null) {
       stream.Write("*");
     } else {
       arg.Emit(stream);
     }
       }
       stream.WriteLine(");");
       base.Emit(stream, level);
 }
Example #32
0
 public override void Emit(TokenTextWriter stream, int level) {
   //Contract.Requires(stream != null);
   stream.Write(this, level, "var ");
   EmitVitals(stream, level, true);
   stream.WriteLine(";");
 }
Example #33
0
    public override void Emit(TokenTextWriter stream, int level) {
      //Contract.Requires(stream != null);
      stream.Write(this, level, "procedure ");
      EmitAttributes(stream);
      stream.Write(this, level, "{0}", TokenTextWriter.SanitizeIdentifier(this.Name));
      EmitSignature(stream, false);
      stream.WriteLine(";");

      level++;

      foreach (Requires/*!*/ e in this.Requires) {
        Contract.Assert(e != null);
        e.Emit(stream, level);
      }

      if (this.Modifies.Count > 0) {
        stream.Write(level, "modifies ");
        this.Modifies.Emit(stream, false);
        stream.WriteLine(";");
      }

      foreach (Ensures/*!*/ e in this.Ensures) {
        Contract.Assert(e != null);
        e.Emit(stream, level);
      }

      if (!CommandLineOptions.Clo.IntraproceduralInfer) {
        for (int s = 0; s < this.Summary.Count; s++) {
          ProcedureSummaryEntry/*!*/ entry = cce.NonNull(this.Summary[s]);
          stream.Write(level + 1, "// ");
          stream.WriteLine();
        }
      }

      stream.WriteLine();
      stream.WriteLine();
    }
Example #34
0
 // prints the list of statements, not the surrounding curly braces
 public void Emit(TokenTextWriter stream, int level)
 {
     Contract.Requires(stream != null);
       bool needSeperator = false;
       foreach (BigBlock b in BigBlocks) {
     Contract.Assert(b != null);
     Contract.Assume(cce.IsPeerConsistent(b));
     if (needSeperator) {
       stream.WriteLine();
     }
     b.Emit(stream, level);
     needSeperator = true;
       }
 }
Example #35
0
 public override void Emit(TokenTextWriter stream, int level) {
   //Contract.Requires(stream != null);
   if (Comment != null) {
     stream.WriteLine(this, level, "// " + Comment);
   }
   stream.Write(this, level, "function ");
   EmitAttributes(stream);
   if (Body != null && !QKeyValue.FindBoolAttribute(Attributes, "inline")) {
     // Boogie inlines any function whose .Body field is non-null.  The parser populates the .Body field
     // is the :inline attribute is present, but if someone creates the Boogie file directly as an AST, then
     // the :inline attribute may not be there.  We'll make sure it's printed, so one can see that this means
     // that the body will be inlined.
     stream.Write("{:inline} ");
   }
   if (CommandLineOptions.Clo.PrintWithUniqueASTIds) {
     stream.Write("h{0}^^{1}", this.GetHashCode(), TokenTextWriter.SanitizeIdentifier(this.Name));
   } else {
     stream.Write("{0}", TokenTextWriter.SanitizeIdentifier(this.Name));
   }
   EmitSignature(stream, true);
   if (Body != null) {
     stream.WriteLine();
     stream.WriteLine("{");
     stream.Write(level + 1, "");
     Body.Emit(stream);
     stream.WriteLine();
     stream.WriteLine("}");
   } else {
     stream.WriteLine(";");
   }
 }
Example #36
0
 public override void Emit(TokenTextWriter stream, int level)
 {
     //Contract.Requires(stream != null);
       if (CommandLineOptions.Clo.PrintDesugarings) {
     stream.WriteLine(this, level, "/*** desugaring:");
     Desugaring.Emit(stream, level);
     stream.WriteLine(level, "**** end desugaring */");
       }
 }
Example #37
0
 public override void Emit(TokenTextWriter stream, int level) {
   //Contract.Requires(stream != null);
   stream.Write(this, level, "type ");
   EmitAttributes(stream);
   stream.Write("{0}", TokenTextWriter.SanitizeIdentifier(Name));
   for (int i = 0; i < Arity; ++i)
     stream.Write(" _");
   stream.WriteLine(";");
 }
Example #38
0
 public static void Emit(this List<Declaration/*!*/>/*!*/ decls, TokenTextWriter stream) {
   Contract.Requires(stream != null);
   Contract.Requires(cce.NonNullElements(decls));
   bool first = true;
   foreach (Declaration d in decls) {
     if (d == null)
       continue;
     if (first) {
       first = false;
     } else {
       stream.WriteLine();
     }
     d.Emit(stream, 0);
   }
 }
Example #39
0
 public override void Emit(TokenTextWriter stream, int level)
 {
     //Contract.Requires(stream != null);
       stream.Write(this, level, "return ");
       this.Expr.Emit(stream);
       stream.WriteLine(";");
 }
Example #40
0
 public override void Emit(TokenTextWriter stream, int level) {
   //Contract.Requires(stream != null);
   stream.Write(this, level, "type ");
   EmitAttributes(stream);
   stream.Write("{0}", TokenTextWriter.SanitizeIdentifier(Name));
   if (TypeParameters.Count > 0)
     stream.Write(" ");
   TypeParameters.Emit(stream, " ");
   stream.Write(" = ");
   Body.Emit(stream);
   stream.WriteLine(";");
 }
Example #41
0
 public override void Emit(TokenTextWriter stream, int level)
 {
     //Contract.Requires(stream != null);
       stream.WriteLine(this, level, "{");
       foreach (Variable/*!*/ v in Locals) {
     Contract.Assert(v != null);
     v.Emit(stream, level + 1);
       }
       foreach (Cmd/*!*/ c in Cmds) {
     Contract.Assert(c != null);
     c.Emit(stream, level + 1);
       }
       stream.WriteLine(level, "}");
 }
Example #42
0
 public override void Emit(TokenTextWriter stream, int level) {
   //Contract.Requires(stream != null);
   if (Comment != null) {
     stream.WriteLine(this, level, "// " + Comment);
   }
   stream.Write(this, level, "axiom ");
   EmitAttributes(stream);
   this.Expr.Emit(stream);
   stream.WriteLine(";");
 }