// Convert stack to a string
        private static string printStack(int tid)
        {
            string ret = "";

            Debug.Assert(threadStacks.ContainsKey(tid));

            if (printConsole)
            {
                // Calculate indent
                var indent = threadStacks[tid].Count + 1;
                for (int i = 0; i < indent; i++)
                {
                    ret = " " + ret;
                }
                var token = threadStacks[tid][0].tok;

                ret += string.Format("{0}({1},{2}): {3}", fileName, token.line, token.col, threadStacks[tid][0].blockName);
                return(ret);
            }

            if (mapCTrace == null)
            {
                foreach (var wi in threadStacks[tid])
                {
                    ret += wi.procName + "|" + fileName + "|" + wi.tok.line + "|";
                }
            }
            else
            {
                var fstwi = threadStacks[tid][0];
                if (!mapCTrace.ContainsKey(new Duple <string, string>(fstwi.procName, fstwi.blockName)))
                {
                    return("");
                }

                foreach (var wi in threadStacks[tid])
                {
                    var key = new Duple <string, string>(wi.procName, wi.blockName);
                    if (!mapCTrace.ContainsKey(key))
                    {
                        continue;
                    }

                    var file = mapCTrace[key].Item1;
                    var line = mapCTrace[key].Item2;
                    //var col = mapCTrace[key].Item3;

                    if (file.Contains("corral_do_not_print"))
                    {
                        return("");
                    }

                    ret += wi.procName + "|" + file + "|" + line + "|";
                }
            }

            return(ret);
        }
        public void setIdentity(string procName, string blockName, List <Cmd> cmds)
        {
            var key = new Duple <string, string>(procName, blockName);

            if (dict.ContainsKey(key))
            {
                dict.Add(key, new BlockTrans());
            }
            dict[key].setIdentity(cmds);
        }
        public void add(string procName, string blockName, InstrTrans itrans)
        {
            var key = new Duple <string, string>(procName, blockName);

            if (!dict.ContainsKey(key))
            {
                dict.Add(key, new BlockTrans());
            }
            dict[key].addInstrTrans(itrans);
        }
        private BlockTrans getBlockTrans(string procName, string blockName)
        {
            var key = new Duple <string, string>(procName, blockName);

            if (dict.ContainsKey(key))
            {
                return(dict[key]);
            }
            else
            {
                return(null);
            }
        }
        private static void updateCLocation(int tid)
        {
            if (mapCTrace == null)
            {
                return;
            }

            var wi  = threadStacks[tid][0];
            var key = new Duple <string, string>(wi.procName, wi.blockName);

            if (!mapCTrace.ContainsKey(key))
            {
                if (lastCLocation != null)
                {
                    mapCTrace.Add(key, lastCLocation);
                }
            }
            else
            {
                lastCLocation = mapCTrace[key];
            }
        }
        private static void gatherCSourceLineInfoImpl(Implementation implementation)
        {
            foreach (var blk in implementation.Blocks)
            {
                List <Cmd> nseq = new List <Cmd>();
                foreach (Cmd cmd in blk.Cmds)
                {
                    string file;
                    int    line, col;
                    bool   keepCmd;

                    var hasInfo = getSourceInfo(cmd, out file, out line, out col, out keepCmd);

                    if (keepCmd)
                    {
                        nseq.Add(cmd);
                    }

                    if (hasInfo)
                    {
                        var key   = new Duple <string, string>(implementation.Name, blk.Label);
                        var value = new Tuple <string, string, string>(file, line.ToString(), col.ToString());
                        mapCTrace.Add(key, value);
                        if (printData == 2)
                        {
                            var capture = new AssumeCmd(Token.NoToken, Expr.True);
                            var par     = new List <object>();
                            par.Add("corral_capture");
                            capture.Attributes = new QKeyValue(Token.NoToken, "captureState", par, null);
                            nseq.Add(capture);
                        }
                    }
                }
                blk.Cmds = nseq;
            }
        }
        private static void getLineAndFile(int tid, out int lineno, out int col, out string filename)
        {
            Debug.Assert(threadStacks.ContainsKey(tid));

            lineno   = threadStacks[tid][0].tok.line;
            col      = threadStacks[tid][0].tok.col;
            filename = threadStacks[tid][0].tok.filename;

            if (printConsole)
            {
                return;
            }

            if (mapCTrace != null)
            {
                var wi  = threadStacks[tid][0];
                var key = new Duple <string, string>(wi.procName, wi.blockName);
                if (!mapCTrace.ContainsKey(key))
                {
                    filename = "";
                    lineno   = 1;
                    return;
                }

                filename = mapCTrace[key].Item1;
                lineno   = Int32.Parse(mapCTrace[key].Item2);
                col      = Int32.Parse(mapCTrace[key].Item3);

                if (filename.Contains("corral_do_not_print"))
                {
                    filename = "";
                    lineno   = 1;
                    col      = 1;
                }
            }
        }
Пример #8
0
 public virtual void Add(Duple <string, string> d)
 {
     values.Add(d);
 }
Пример #9
0
        /// <summary>
        /// Checks if two version of f are equivalnt
        /// Every procedure that is not inlined will be replaced by their specs (even unreachable ones)
        /// </summary>
        /// <param name="f"></param> the index of the fn
        /// <param name="inlinedFns1"></param> list of fns in side1 to inline
        /// <param name="inlinedFns2"></param> list of fns in side2 to inline
        ///  <param name="is_recursive"></param> whether f is recursive (or part of mutual recursion). Should be used for determining whether we can do differential inlining.
        /// <returns></returns>
        public static bool RVTCheckEq(int f, HashSet <int> inlinedFns1, HashSet <int> inlinedFns2, bool is_recursive)
        {
            //name of the function
            string n1Name = fnIndexToName1[f];
            var    n1     = cg.NodeOfName(n1Name);
            var    n2Name = funs.Get(n1.Name);

            if (n1Name == null || n2Name == null)
            {
                return(false);
            }
            var n2 = cg.NodeOfName(n2Name);

            Console.Write("Checking (" + n1.Name + ", " + n2.Name + ").");
            if (is_recursive)
            {
                Console.WriteLine(" These are recursive.");
            }
            else
            {
                Console.WriteLine(" These are non recursive.");
            }

            string eqpName = Transform.mkEqProcName(n1.Name, n2.Name);

            Duple <Procedure, Implementation> eqp = null;
            List <Variable> outputVars            = new List <Variable>();

            if (eqProcsCreated.ContainsKey(eqpName))
            {
                var tmp = eqProcsCreated[eqpName];
                eqp        = tmp.fst;
                outputVars = tmp.snd;
            }
            else
            {
                return(false);
            }

            // if any visible output
            VerificationTask vt;

            if (eqp != null)
            {
                vt = new VerificationTask(eqp.snd, n1.Impl, n2.Impl, outputVars);
            }
            //it may be that these functions have no comparable effect. if so, don't generate a verification task
            else //we'll split their uninterpreted functions, but otherwise don't generate a verification task
            {
                vt        = new VerificationTask(null, n1.Impl, n2.Impl);
                vt.Result = SDiff.VerificationResult.Error;
                SDiff.Boogie.Process.RewriteUninterpretedOnDiseq(vt, SDiff.Boogie.Process.BuildProgramDictionary(mergedProgram.TopLevelDeclarations.ToList()));
            }


            //The inline:spec inlines a procedure with {:inline 1} 1 times and then uses the spec for deeper calls
            var boogieOptions = "-z3multipleErrors /typeEncoding:m -timeLimit:" + Options.Timeout + " -removeEmptyBlocks:0 -inline:spec " + Options.BoogieUserOpts;

            SDiff.Boogie.Process.InitializeBoogie(boogieOptions);
            //VC.ConditionGeneration vcgen = BoogieVerify.InitializeVC(mergedProgram);

            // dictionary of all program AST objects by name
            SDiff.Boogie.Process.BuildProgramDictionary(mergedProgram.TopLevelDeclarations.ToList());


            // Call RVTRunVerification Task
            bool crashed;
            var  result = 1;

            if (eqp != null)
            {
                result = RVTRunVerificationTask(vt, null, mergedProgram, inlinedFns1, inlinedFns2, out crashed);
            }

            return(result == 1);
        }
Пример #10
0
        /// <summary>
        /// Create the EQ_f_f' procedure statically (eagerly) to avoid generating it again and again
        /// </summary>
        /// <param name="f"></param>
        /// Outputs the list of synEq functions for stubs that have no bodies on both sides
        private static bool RVTCreateEQProcs(int f, ref List <int> synEq, ref List <int> empty1, ref List <int> empty2)
        {
            //name of the function
            string fname = fnIndexToName1[f];

            var n1     = cg.NodeOfName(fname);
            var n2Name = funs.Get(n1.Name);

            if (n2Name == null)
            {
                Log.Out(Log.Error, "Could not find mapping for " + n1.Name);
                Log.Out(Log.Error, "Dumping config...");
                Log.Out(Log.Error, cfg.ToString());
                return(false);
            }

            var n2 = cg.NodeOfName(n2Name);

            if (n2 == null)
            {
                Log.Out(Log.Error, "ERROR: Could not find " + n2Name + " in ARGS[1]");
                return(false);
            }

            if (n1.Proc == null || n2.Proc == null)
            {
                Log.Out(Log.Error, "Missing procedure for " + n1.Name + " or " + n2.Name + ": skipping...");
                return(false);
            }

            //TODO: currently return false for corner cases...FIX this carefully

            if (n1.Name.EndsWith("nondet_choice"))
            {
                Log.Out(Log.Normal, "skipping nondet_choice");
                return(false);
            }

            if (n1.Impl == null && n2.Impl == null)
            {
                Log.Out(Log.Normal, "No implementation for " + n1.Name + ": skipping...");
                synEq.Add(f);
                empty1.Add(f);
                empty2.Add(fnNameToIndex2[n2.Name]);
                return(true);
            }

            if (n1.Impl == null)
            {
                Log.Out(Log.Error, "!Missing implementation for " + n1.Name);
                empty1.Add(f);
                return(false);
            }

            if (n2.Impl == null)
            {
                Log.Out(Log.Error, "!Missing implementation for " + n2.Name);
                empty2.Add(fnNameToIndex2[n2.Name]);
                return(false);
            }

            var ignores = new HashSet <Variable>(n1.IgnoreSet);

            ignores.UnionWith(n2.IgnoreSet);

            // Creates EQ_f_f' function
            List <Variable> outputVars;
            string          eqpName = Transform.mkEqProcName(n1.Name, n2.Name);

            Duple <Procedure, Implementation> eqp;

            eqp = Transform.EqualityReduction(n1.Impl, n2.Impl, cfg.FindProcedure(n1.Name, n2.Name), ignores, out outputVars);

            // if any visible output
            //VerificationTask vt;
            if (eqp != null)
            {
                mergedProgram.AddTopLevelDeclarations(outputVars.Map(x => x as Declaration));
                mergedProgram.AddTopLevelDeclaration(eqp.fst);
                mergedProgram.AddTopLevelDeclaration(eqp.snd);
            }

            //declare the uninterpreted funcs/canonical set of constants  in merged program
            //mergedProgram.AddTopLevelDeclarations(newDecls);
            var canonicalConst = SDiff.Boogie.ConstantFactory.Get().Constants.Map(x => x as Declaration);

            mergedProgram.AddTopLevelDeclarations(canonicalConst);


            //Log.Out(Log.Normal, "Resolving and Typechecking again..");
            if (BoogieUtils.ResolveAndTypeCheckThrow(mergedProgram, Options.MergedProgramOutputFile))
            {
                Log.LogEmit(Log.Normal, mergedProgram.Emit);
                return(false);
            }

            if (Options.TraceVerify)
            {
                Log.Out(Log.Normal, "merged program with ufs etc");
                Log.LogEmit(Log.Normal, mergedProgram.Emit);
            }

            // callgraph has changed because EQ programs are added
            Log.Out(Log.Normal, "Building callgraphs and computing read and write sets");
            cg = CallGraph.Make(mergedProgram);
            ReadWriteSetDecorator.DoDecorate(cg); //start from scratch to fill in the read/write sets
            var mergedProgramNewDecl = new Program();

            mergedProgram.AddTopLevelDeclarations(mergedProgramNewDecl.TopLevelDeclarations);
            mergedProgram.TopLevelDeclarations = SDiff.Boogie.Process.RemoveDuplicateDeclarations(mergedProgram.TopLevelDeclarations.ToList());

            Duple <Duple <Procedure, Implementation>, List <Variable> > tmp = new Duple <Duple <Procedure, Implementation>, List <Variable> >(eqp, outputVars);

            eqProcsCreated.Add(eqpName, tmp);


            return(true);
        }
Пример #11
0
 public void AddFunction(Duple <HDuple <string>, ParamMap> mapping)
 {
     functionMap.Add(mapping);
 }
Пример #12
0
 public void AddProcedure(Duple <HDuple <string>, ParamMap> mapping)
 {
     procMap.Add(mapping);
 }