/// <summary> /// Apply the assignments in the form of axioms. /// </summary> /// <param name="program">The program.</param> /// <param name="assignments">The assignments provided by the solver.</param> private void ApplyAssignments(Microsoft.Boogie.Program program, Dictionary <string, bool> assignments) { // remove existing axioms List <Axiom> axioms = new List <Axiom>(); foreach (Axiom axiom in program.Axioms.Where(x => x.Comment == "repair_constraint")) { axioms.Add(axiom); } axioms.ForEach(x => program.RemoveTopLevelDeclaration(x)); // add the axioms corresponding to the assignments foreach (KeyValuePair <string, bool> assignment in assignments) { Expr identifier = new IdentifierExpr(Token.NoToken, assignment.Key, Type.Bool); Expr literal = new LiteralExpr(Token.NoToken, assignment.Value); BinaryOperator _operator = new BinaryOperator(Token.NoToken, BinaryOperator.Opcode.Iff); NAryExpr expr = new NAryExpr(Token.NoToken, _operator, new List <Expr> { identifier, literal }); Axiom axiom = new Axiom(Token.NoToken, expr, "repair_constraint"); program.AddTopLevelDeclaration(axiom); } }
public bool RunOn(Microsoft.Boogie.Program prog, PassInfo passInfo) { var toRemove = new HashSet <Declaration>(); var implToFalsify = new List <Implementation>(); var procToKeep = new HashSet <Declaration>(); // Check there is at least one entry point bool containsEntryPoint = false; foreach (var impl in prog.TopLevelDeclarations.OfType <Implementation>()) { if (IsEntryPoint(impl)) { containsEntryPoint = true; break; } } if (!containsEntryPoint) { throw new EntryPointNotFoundException(); } // Determine which implementation we want to remove and // which implementations we will need to keep foreach (var decl in prog.TopLevelDeclarations) { var declAsImplementation = decl as Implementation; if (declAsImplementation == null) { continue; } if (!IsEntryPoint(declAsImplementation)) { // We want to remove this implementation toRemove.Add(declAsImplementation); } else { implToFalsify.Add(declAsImplementation); Debug.Assert(declAsImplementation.Proc != null); procToKeep.Add(declAsImplementation.Proc); } } // Determine which procedures we should remove foreach (var decl in prog.TopLevelDeclarations) { var declAsProc = decl as Procedure; if (declAsProc == null) { continue; } if (!procToKeep.Contains(declAsProc)) { toRemove.Add(declAsProc); } } // Now remove the procedures and implementations we don't need foreach (var decl in toRemove) { prog.RemoveTopLevelDeclaration(decl); } // Now change entry point bodies to just contain an "assert false" foreach (var impl in implToFalsify) { // Remove any ensures. We probably aren't maintaining it // any more if we remove the body. impl.Proc.Ensures.Clear(); // The body won't be modifying anything so clear the modset impl.Proc.Modifies.Clear(); // Remove existing blocks impl.Blocks.Clear(); // Add block that asserts false and then returns var newBlock = new Block(Token.NoToken, "entry", new List <Cmd>() { new AssertCmd(Token.NoToken, Expr.False) }, new ReturnCmd(Token.NoToken)); impl.Blocks.Add(newBlock); } return((toRemove.Count + implToFalsify.Count) > 0); }