Example #1
0
 /// <summary>Private constructor for internal use</summary>
 private State(Tools tools)
 {
     this._tools              = new Tools(tools);
     this._ctx                = new Context(this._tools.Settings); // housekeeping in Dispose();
     this.Solver              = MakeSolver(this._ctx);
     this.Solver_U            = MakeSolver(this._ctx);
     this._branchInfoStore    = new BranchInfoStore(this._ctx);
     this._cached_Reg_Values  = new Dictionary <Rn, Tv[]>();
     this._cached_Flag_Values = new Dictionary <Flags, Tv>();
 }
Example #2
0
 /// <summary>Private constructor for internal use</summary>
 private State(Tools tools)
 {
     this.tools_              = new Tools(tools);
     this.ctx_                = new Context(this.tools_.ContextSettings); // housekeeping in Dispose();
     this.Solver              = MakeSolver(this.ctx_, this.tools_.SolverSetting);
     this.Solver_U            = MakeSolver(this.ctx_, this.tools_.SolverSetting);
     this.branchInfoStore_    = new BranchInfoStore(this.ctx_);
     this.cached_Reg_Values_  = new Dictionary <Rn, Tv[]>();
     this.cached_Flag_Values_ = new Dictionary <Flags, Tv>();
 }
Example #3
0
        public static BranchInfoStore RetrieveSharedBranchInfo(
            BranchInfoStore store1, BranchInfoStore store2, Context ctx)
        {
            if (store1 == null)
            {
                return(store2);
            }

            if (store2 == null)
            {
                return(store1);
            }

            IList <string> sharedKeys = new List <string>();

            if ((store1._branchInfo != null) && (store2._branchInfo != null))
            {
                ICollection <string> keys1 = store1._branchInfo.Keys;
                ICollection <string> keys2 = store2._branchInfo.Keys;

                foreach (string key in keys1)
                {
                    if (keys2.Contains(key))
                    {
                        if (store1._branchInfo[key].BranchTaken != store2._branchInfo[key].BranchTaken)
                        {
                            sharedKeys.Add(key);
                        }
                        else
                        {
                            //Console.WriteLine("INFO: State:RetrieveSharedBranchInfo: key " + key + " is shared but has equal branchTaken " + state1.BranchInfo[key].branchTaken);
                        }
                    }
                }
                Debug.Assert(sharedKeys.Count <= 1);

                if (false)
                {
                    foreach (string key in keys1)
                    {
                        Console.WriteLine("INFO: State:RetrieveSharedBranchInfo: Keys of state1 " + key);
                    }
                    foreach (string key in keys2)
                    {
                        Console.WriteLine("INFO: State:RetrieveSharedBranchInfo: Keys of state2 " + key);
                    }
                    foreach (string key in sharedKeys)
                    {
                        Console.WriteLine("INFO: State:RetrieveSharedBranchInfo: sharedKey " + key);
                    }
                }
            }

            BranchInfoStore mergeBranchStore = new BranchInfoStore(ctx);

            if (sharedKeys.Count == 0)
            {
                if (store1._branchInfo != null)
                {
                    foreach (KeyValuePair <string, BranchInfo> element in store1._branchInfo)
                    {
                        mergeBranchStore.Add(element.Value, true);
                    }
                }
                if (store2._branchInfo != null)
                {
                    foreach (KeyValuePair <string, BranchInfo> element in store2._branchInfo)
                    {
                        if (!mergeBranchStore.ContainsKey(element.Key))
                        {
                            mergeBranchStore.Add(element.Value, true);
                        }
                    }
                }
                //if (!tools.Quiet) Console.WriteLine("INFO: State:RetrieveSharedBranchInfo: the two provided states do not share a branching point. This would happen in loops.");
            }
            else
            {
                //only use the first sharedKey

                string key = sharedKeys[0];
                foreach (KeyValuePair <string, BranchInfo> element in store1._branchInfo)
                {
                    if (!element.Key.Equals(key))
                    {
                        mergeBranchStore.Add(element.Value, true);
                    }
                }
                foreach (KeyValuePair <string, BranchInfo> element in store2._branchInfo)
                {
                    if (!element.Key.Equals(key))
                    {
                        if (!mergeBranchStore.ContainsKey(element.Key))
                        {
                            mergeBranchStore.Add(element.Value, true);
                        }
                    }
                }
            }

            return(mergeBranchStore);
        }
Example #4
0
        /// <summary>Merge Constructor Method</summary>
        private void MergeConstructor(State state1, State state2)
        {
            #region Handle Inconsistent states
            {
                bool consistent1 = state1.IsConsistent == Tv.ONE;
                bool consistent2 = state2.IsConsistent == Tv.ONE;

                if (!consistent1 && !consistent2)
                {
                    Console.WriteLine("WARNING: State: merge constructor: states have to be consistent. state1 consistent = " + consistent1 + "; state2 consistent = " + consistent2);
                }
                if (!consistent1)
                {
                    lock (this._ctxLock)
                    {
                        state2.Copy(this);
                    }

                    return;
                }
                if (!consistent2)
                {
                    lock (this._ctxLock)
                    {
                        state1.Copy(this);
                    }

                    return;
                }
            }
            #endregion

            #region Prepare States
            state1.UndefGrounding = false;
            state2.UndefGrounding = false;

            state1.Simplify();
            state2.Simplify();
            #endregion

            lock (this._ctxLock)
            {
                Context ctx = this._ctx;

                this._branchInfoStore = BranchInfoStore.RetrieveSharedBranchInfo(state1.BranchInfoStore, state2.BranchInfoStore, ctx);

                // merge the contents of both solvers
                {
                    ISet <BoolExpr> mergedContent = new HashSet <BoolExpr>();
#pragma warning disable DisposableFixer // Undisposed ressource.
                    foreach (BoolExpr b in state1.Solver.Assertions)
                    {
                        mergedContent.Add(b.Translate(ctx) as BoolExpr);
                    }

                    foreach (BoolExpr b in state2.Solver.Assertions)
                    {
                        mergedContent.Add(b.Translate(ctx) as BoolExpr);
                    }

                    foreach (BoolExpr b in mergedContent)
                    {
                        this.Solver.Assert(b);
                    }

                    ISet <BoolExpr> mergedContent_U = new HashSet <BoolExpr>();
                    foreach (BoolExpr b in state1.Solver_U.Assertions)
                    {
                        mergedContent_U.Add(b.Translate(ctx) as BoolExpr);
                    }

                    foreach (BoolExpr b in state2.Solver_U.Assertions)
                    {
                        mergedContent_U.Add(b.Translate(ctx) as BoolExpr);
                    }

                    foreach (BoolExpr b in mergedContent_U)
                    {
                        this.Solver_U.Assert(b);
                    }
#pragma warning restore DisposableFixer // Undisposed resource.
                }

                // merge the head and tail
                {
                    if (state1.HeadKey == state2.HeadKey)
                    {
                        this.HeadKey = state1.HeadKey;
                    }
                    else
                    {
                        this.HeadKey = Tools.CreateKey(this.Tools.Rand);
                        string head1 = state1.HeadKey;
                        string head2 = state2.HeadKey;

                        using (StateUpdate stateUpdateForward = new StateUpdate("!ERROR_1", this.HeadKey, this.Tools))
                        {
                            BoolExpr dummyBranchCondttion = ctx.MkBoolConst("DymmyBC" + this.HeadKey);
                            foreach (Rn reg in this.Tools.StateConfig.GetRegOn())
                            {
                                stateUpdateForward.Set(reg, ctx.MkITE(dummyBranchCondttion, Tools.Create_Key(reg, head1, ctx), Tools.Create_Key(reg, head2, ctx)) as BitVecExpr);
                            }
                            foreach (Flags flag in this.Tools.StateConfig.GetFlagOn())
                            {
                                stateUpdateForward.Set(flag, ctx.MkITE(dummyBranchCondttion, Tools.Create_Key(flag, head1, ctx), Tools.Create_Key(flag, head2, ctx)) as BoolExpr);
                            }
                            stateUpdateForward.Set_Mem(ctx.MkITE(dummyBranchCondttion, Tools.Create_Mem_Key(head1, ctx), Tools.Create_Mem_Key(head2, ctx)) as ArrayExpr);

                            this.Update_Forward(stateUpdateForward);
                        }
                    }
                    if (state1.TailKey == state2.TailKey)
                    {
                        this.TailKey = state1.TailKey;
                    }
                    else
                    {
                        this.TailKey = Tools.CreateKey(this.Tools.Rand);
                        //TODO does merging the tail make any sense?
                    }
                }
            }
        }