Esempio n. 1
0
        public void Remove_History()
        {
            ISet <string> keep = new HashSet <string>();

            foreach (var v in this._tools.StateConfig.GetFlagOn())
            {
                using (BoolExpr expr = this.Create(v))
                {
                    keep.Add(expr.ToString());
                }
            }
            foreach (var v in this._tools.StateConfig.GetRegOn())
            {
                using (BitVecExpr expr = this.Create(v))
                {
                    keep.Add(expr.ToString());
                }
            }
            if (this._tools.StateConfig.mem)
            {
                using (ArrayExpr expr = Tools.Create_Mem_Key(this.HeadKey, this._ctx))
                {
                    keep.Add(expr.ToString());
                }
            }
            this.Compress(keep);
        }
Esempio n. 2
0
        public BranchInfo(BoolExpr condition, bool taken)
        {
            Contract.Requires(condition != null);

            this.BranchCondition = condition;
            this.Key             = condition.ToString();
            this.BranchTaken     = taken;
        }
Esempio n. 3
0
        /// <summary>
        /// Asserts the theorem constraints on the Z3 context.
        /// </summary>
        /// <param name="context">Z3 context.</param>
        /// <param name="environment">Environment with bindings of theorem variables to Z3 handles.</param>
        /// <typeparam name="T">Theorem environment type.</typeparam>
        private void AssertConstraints <T>(Context context, Solver solver, Environment environment)
        {
            var constraints = _constraints;

            //
            // Global rewriter registered?
            //
            var rewriterAttr = (TheoremGlobalRewriterAttribute)typeof(T).GetCustomAttributes(typeof(TheoremGlobalRewriterAttribute), false).SingleOrDefault();

            if (rewriterAttr != null)
            {
                //
                // Make sure the specified rewriter type implements the ITheoremGlobalRewriter.
                //
                var rewriterType = rewriterAttr.RewriterType;
                if (!typeof(ITheoremGlobalRewriter).IsAssignableFrom(rewriterType))
                {
                    throw new InvalidOperationException("Invalid global rewriter type definition. Did you implement ITheoremGlobalRewriter?");
                }

                //
                // Assume a parameterless public constructor to new up the rewriter.
                //
                var rewriter = (ITheoremGlobalRewriter)Activator.CreateInstance(rewriterType);

                //
                // Do the rewrite.
                //
                constraints = rewriter.Rewrite(constraints);
            }

            //
            // Visit, assert and log.
            //
            foreach (var constraint in constraints)
            {
                BoolExpr c = (BoolExpr)Visit(context, environment, constraint.Body, constraint.Parameters[0]);

                //context.AssertCnstr(c);
                solver.Assert(c);

                //_context.LogWriteLine(context.ToString(c));
                _context.LogWriteLine(c.ToString());
            }
        }
        public static bool isFlowChart(int n, int startIndex, Expr[,] R)
        {
            Trace.WriteLine("-----------------------------");
            Trace.WriteLine($"In 'isFlowChart', n:{n}, startIndex:{startIndex}");

            using (Context ctx = new Context())
            {
                var        s = ctx.MkFixedpoint();
                BoolSort   B = ctx.BoolSort;
                BitVecSort V = ctx.MkBitVecSort(S_BITVEC_SIZE);


                //Function declarations
                FuncDecl edge = ctx.MkFuncDecl("edge", new Sort[] { V, V }, B);
                FuncDecl path = ctx.MkFuncDecl("path", new Sort[] { V, V }, B);


                var x = (BitVecExpr)ctx.MkBound(0, V);
                var y = (BitVecExpr)ctx.MkBound(1, V);
                var z = (BitVecExpr)ctx.MkBound(2, V);

                s.RegisterRelation(edge);
                s.RegisterRelation(path);

                //Recursive reachability rules - edge and path
                //edge[x,y] => path[x,y]
                //path[x,y] && path[y,z] => path[x,z]
                s.AddRule(ctx.MkImplies((BoolExpr)edge[x, y], (BoolExpr)path[x, y]));
                s.AddRule(ctx.MkImplies(ctx.MkAnd((BoolExpr)path[x, y], (BoolExpr)path[y, z]),
                                        (BoolExpr)path[x, z]));

                //Add a edge fact if R[i,j] == 1,
                for (uint i = 0; i < n; i++)
                {
                    for (uint j = 0; j < n; j++)
                    {
                        if (R[i, j].ToString().Equals("1"))
                        {
                            s.AddFact(edge, i, j);
                        }
                    }
                }

                //For every vertex other than startIndex, there
                //should be a path from startIndex to vertex
                BoolExpr start_c = ctx.MkTrue();
                for (int i = 0; i < n; i++)
                {
                    if (i != startIndex)
                    {
                        start_c = ctx.MkAnd((BoolExpr)path[ctx.MkBV(startIndex, S_BITVEC_SIZE), ctx.MkBV(i, S_BITVEC_SIZE)], start_c);
                    }
                }

                Trace.WriteLine(s.ToString());
                Trace.WriteLine(start_c.ToString());
                Trace.WriteLine("-----------------------------");

                var status = s.Query(start_c);
                if (status == Status.SATISFIABLE)
                {
                    return(true);
                }
                else
                {
                    Trace.WriteLine(s.GetAnswer());
                    Trace.WriteLine("fail");
                    return(false);
                }
            }
        }
Esempio n. 5
0
 public BranchInfo(BoolExpr condition, bool taken)
 {
     this.BranchCondition = condition;
     this.Key             = condition.ToString();
     this.BranchTaken     = taken;
 }