//traverse down a trace (List<Block>). At each program point: // -Write the new SymbolicStore at each AssignCmd. // -Write the guard condition for each AssumeCmd. //the latter will be overwritten by an ExecUp public static SymbolicTrace ExecDown(List <Block> bs, List <Variable> args) { SymbolicStore curStore = new SymbolicStore(), nextStore; ////initialize args with symbolic values List <Variable> symbolicConstants = new List <Variable>(); for (int i = 0; i < args.Count; i++) { var v = args[i]; symbolicConstants.Add(B.Factory.MakeConstant(v.Name, v.TypedIdent.Type)); curStore.Add(new StoreLhs(v), Expr.Ident(symbolicConstants[i])); } var newTrace = new SymbolicTrace(); foreach (Block b in bs) { var tmp = ExecBlockDown(b, curStore, out nextStore); newTrace.Add(ExecBlockDown(b, curStore, out nextStore)); curStore = nextStore; } return(newTrace); }
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); }