Beispiel #1
0
        //completely clobbers all the existing SCmd constraints
        public static Constraint ExecBlockUp(SymbolicBlock sb, Constraint consIntoBlock)
        {
            var curCons = consIntoBlock;

            for (int i = sb.SCmds.Count - 1; i >= 0; i--)
            {
                var curCmd = sb.SCmds[i];

                var assume = curCmd.Source as AssumeCmd;
                if (assume != null)
                {
                    curCmd.Cons = new Constraint(curCons, false);
                    curCmd.Cons.Add(assume.Expr);
                }

                var assign = curCmd.Source as AssignCmd;
                if (assign != null)
                {
                    curCmd.Cons = new Constraint(curCons, true);

                    for (int j = 0; j < assign.Lhss.Count; j++)
                    {
                        var lhs   = assign.Lhss[j];
                        var gamma = curCmd.Gammas[j];

                        var vToReplace = lhs.DeepAssignedVariable;
                        var rExpr      = gamma.Get(new StoreLhs(vToReplace));
                        curCmd.Cons =
                            new Constraint(curCmd.Cons.Conjuncts.Map(y => Substituter.Apply(x => (x == vToReplace) ? rExpr : null, y)).ToArray());
                    }
                }

                if (assign == null && assume == null)
                {
                    curCmd.Cons = new Constraint(curCons, true);
                }
                else
                {
                    curCons = curCmd.Cons;
                }
            }

            return(curCons);
        }
Beispiel #2
0
        public static SymbolicBlock ExecBlockDown(Block b, SymbolicStore gammaIntoBlock, out SymbolicStore gammaOutOfBlock)
        {
            var duper = new Duplicator();
            var sb    = new SymbolicBlock(b);

            SymbolicStore gammaIntoCmd = gammaIntoBlock;

            foreach (Cmd c in b.Cmds)
            {
                var sc = new SymbolicCmd(c);
                if (c is AssumeCmd)
                {
                    if (!((AssumeCmd)c).Expr.Equals(Expr.True))
                    {
                        var tmp = ((AssumeCmd)c).Expr;
                        sc.AddCons(((AssumeCmd)c).Expr);
                    }
                }
                else if (c is AssignCmd)
                {
                    SymbolicStore newGamma; //= new SymbolicStore(gammaIntoCmd);

                    AssignCmd assgn = c as AssignCmd;
                    if (assgn.Lhss.Count != assgn.Rhss.Count)
                    {
                        Console.WriteLine("Bizzare: uneven assignment command in ExecDown");
                        continue;
                    }
                    //each AssignCmd contains a list of assignments
                    for (int i = 0; i < assgn.Lhss.Count; i++)
                    {
                        var lhsrhs = StoreLhs.Make(assgn.Lhss[i], assgn.Rhss[i]);
                        var lhs    = lhsrhs.fst;
                        var rhs    = lhsrhs.snd;

                        Expr oldrhs;
                        gammaIntoCmd.TryGetValue(lhs, out oldrhs);

                        //if lhs was uninitialized, we just add the new binding to the old gamma
                        if (oldrhs == null)
                        {
                            newGamma = new SymbolicStore(gammaIntoCmd);
                            newGamma.Add(lhs, rhs);
                        }
                        //otherwise we have to do substitution over everything
                        else
                        {
                            newGamma = new SymbolicStore();
                            newGamma.Add(lhs, Substituter.Apply(x => (x == lhs.Var) ? duper.VisitExpr(oldrhs) : null, rhs));

                            //otherwise, we need to substitute the old value for lhs into Gamma
                            foreach (var entry in gammaIntoCmd)
                            {
                                if (!entry.Key.Equals(lhs))
                                {
                                    newGamma.Add(entry.Key, Substituter.Apply(x => (x == lhs.Var) ? duper.VisitExpr(oldrhs) : null, entry.Value));
                                }
                            }
                        }
                        gammaIntoCmd = newGamma;
                        sc.AddGamma(newGamma);
                    }
                }
                else if (c is HavocCmd)
                {
                    Log.Out(Log.Warning, "Help! HavocCmd in ExecBlockDown!");
                }

                // if(sc.Gammas.Count != 0)
                sb.SCmds.Add(sc);
            }

            gammaOutOfBlock = gammaIntoCmd;
            return(sb);
        }