void Instrument(Implementation impl) { var varDecls = new Dictionary <string, string>(); var cb = new CollectBasePointer(varDecls); cb.VisitImplementation(impl); foreach (var block in impl.Blocks) { var newcmds = new List <Cmd>(); foreach (Cmd cmd in block.Cmds) { if (cmd is AssumeCmd && BoogieUtil.checkAttrExists("nonnull", (cmd as AssumeCmd).Attributes)) { continue; } if (cmd is AssignCmd) { newcmds.AddRange(ProcessAssign(cmd as AssignCmd, varDecls)); } else if (cmd is AssumeCmd) { newcmds.AddRange(ProcessAssume(cmd as AssumeCmd, varDecls)); } else if (cmd is CallCmd) { newcmds.AddRange(ProcessCall(cmd as CallCmd, varDecls)); } else { newcmds.Add(cmd); } } block.Cmds = newcmds; } }
public override Implementation VisitImplementation(Implementation node) { var varDecls = new Dictionary <string, string>(); var cb = new CollectBasePointer(varDecls); cb.VisitImplementation(node); foreach (var b in node.Blocks) { var newCmds = new List <Cmd>(); foreach (var c in b.Cmds) { if (c is AssumeCmd) { var asmCmd = c as AssumeCmd; if (BoogieUtil.checkAttrExists("nonnull", asmCmd.Attributes)) { var expr = asmCmd.Expr as NAryExpr; expr.Args[1] = nil; newCmds.Add(c); continue; } } if (c is AssignCmd) { var asnCmd = c as AssignCmd; var reads = new GatherMemAccesses(); asnCmd.Rhss.Iter(e => reads.VisitExpr(e)); foreach (var tup in reads.accesses) { var ptr = tup.Item2; string basePtr; if (varDecls.TryGetValue(ptr.ToString(), out basePtr)) { newCmds.Add(MkAssume(Expr.Ident(BoogieAstFactory.MkFormal(basePtr, btype.Int, true)))); } else { newCmds.Add(MkAssume(ptr)); } } } newCmds.Add(c); } b.cmds = newCmds; } return(node); }