/// <summary> /// Parses the command line options. /// </summary> /// <param name="name">The name of the option.</param> /// <param name="ps">The command line parsing state.</param> /// <returns>True if the parsing was successful.</returns> protected override bool ParseOption(string name, CommandLineParseState ps) { if (name == "detailedLogging") { if (ps.ConfirmArgumentCount(1)) { DetailedLogging = bool.Parse(ps.args[ps.i]); } return(true); } else if (name == "logClauses") { if (ps.ConfirmArgumentCount(1)) { LogClauses = bool.Parse(ps.args[ps.i]); } return(true); } else if (name == "disableInspection") { if (ps.ConfirmArgumentCount(1)) { DisableInspection = bool.Parse(ps.args[ps.i]); } return(true); } else if (name == "useAxioms") { if (ps.ConfirmArgumentCount(1)) { UseAxioms = bool.Parse(ps.args[ps.i]); } return(true); } else if (name == "loopDepthWeight") { if (ps.ConfirmArgumentCount(1)) { LoopDepthWeight = int.Parse(ps.args[ps.i]); } return(true); } else if (name == "gridBarrierWeight") { if (ps.ConfirmArgumentCount(1)) { GridBarrierWeight = int.Parse(ps.args[ps.i]); } return(true); } else if (name == "solverType") { if (ps.ConfirmArgumentCount(1)) { SolverType = (Solver.SolverType)Enum.Parse(typeof(Solver.SolverType), ps.args[ps.i]); } return(true); } return(base.ParseOption(name, ps)); }
/// <summary> /// The entry point of the program. /// </summary> /// <param name="args">The command line arguments.</param> public static void Main(string[] args) { int?statusCode = null; try { // standard command line options for Boogie CommandLineOptions.Install(new GRCommandLineOptions()); if (!CommandLineOptions.Clo.Parse(args)) { return; } CommandLineOptions.Clo.PrintUnstructured = 2; CommandLineOptions.Clo.DoModSetAnalysis = true; CommandLineOptions.Clo.PruneInfeasibleEdges = true; if (!CommandLineOptions.Clo.Files.Any()) { throw new Exception("An input file must be provided!"); } else if (CommandLineOptions.Clo.Files.Count > 1) { throw new Exception("GPURepair can work on only one file at a time!"); } Logger.FileName = CommandLineOptions.Clo.Files.First(); Logger.DetailedLogging = ((GRCommandLineOptions)CommandLineOptions.Clo).DetailedLogging; ClauseLogger.FileName = CommandLineOptions.Clo.Files.First(); ClauseLogger.LogCLauses = ((GRCommandLineOptions)CommandLineOptions.Clo).LogClauses; Barrier.LoopDepthWeight = ((GRCommandLineOptions)CommandLineOptions.Clo).LoopDepthWeight; Barrier.GridBarrierWeight = ((GRCommandLineOptions)CommandLineOptions.Clo).GridBarrierWeight; Dictionary <string, bool> assignments; // repair the program Solver.SolverType solverType = ((GRCommandLineOptions)CommandLineOptions.Clo).SolverType; bool disableInspection = ((GRCommandLineOptions)CommandLineOptions.Clo).DisableInspection; bool useAxioms = ((GRCommandLineOptions)CommandLineOptions.Clo).UseAxioms; Repairer repairer = new Repairer(Logger.FileName, disableInspection, useAxioms); Microsoft.Boogie.Program program = repairer.Repair(solverType, out assignments); SummaryGenerator generator = new SummaryGenerator(); IEnumerable <string> changes = generator.GenerateSummary(assignments, Logger.FileName.Replace(".cbpl", ".summary")); Logger.Log($"Changes;{changes.Count()}"); Console.WriteLine("Number of changes required: {0}.", changes.Count()); if (changes.Any()) { using (TokenTextWriter writer = new TokenTextWriter(Logger.FileName.Replace(".cbpl", ".fixed.cbpl"), true)) program.Emit(writer); } } catch (Exception ex) { Logger.Log($"ExceptionMessage;{ex.Message}"); Console.Error.WriteLine(ex.Message); if (ex is AssertionException) { statusCode = 201; } else if (ex is RepairException) { statusCode = 202; } else if (ex is NonBarrierException) { statusCode = 203; } else if (ex is SummaryGeneratorException) { statusCode = 204; } } if (statusCode != null) { Environment.Exit(statusCode.Value); } }
/// <summary> /// Reapirs the program at the given filePath. /// </summary> /// <param name="defaultType">The default solver to use.</param> /// <param name="assignments">The assignments to the variables.</param> /// <returns>The fixed program if one exists.</returns> public Microsoft.Boogie.Program Repair(Solver.SolverType defaultType, out Dictionary <string, bool> assignments) { List <RepairableError> errors = new List <RepairableError>(); Dictionary <string, bool> solution = null; while (true) { try { Solver.SolverType type = defaultType; Solver solver = new Solver(); if (solution == null) { if (!errors.Any() && disableInspection) { // for the first run, disable all the barriers assignments = new Dictionary <string, bool>(); foreach (string barrierName in ProgramMetadata.Barriers.Keys) { assignments.Add(barrierName, false); } } else { // try finding a solution for the errors encountered so far assignments = solver.Solve(errors, ref type); } } else if (solution.Any(x => x.Value == true)) { // if the tentative solution has any barriers enabled, optimize it assignments = solver.Optimize(errors, solution, out type); } else { // if the tentative solution has no barriers enabled, it is the optimum solution type = Solver.SolverType.Optimizer; assignments = solution; } // skip the verification if the solution wasn't optimized if (type == Solver.SolverType.Optimizer && assignments.Count(x => x.Value == true) == solution.Count(x => x.Value == true)) { return(constraintGenerator.ConstraintProgram(assignments)); } IEnumerable <RepairableError> current_errors = VerifyProgram(assignments); if (type == Solver.SolverType.Optimizer) { Logger.Log($"RunsAfterOpt"); if (current_errors.Any()) { Logger.Log($"FailsAfterOpt"); } } if (!current_errors.Any()) { // unassigned barriers are marked as not needed foreach (string barrierName in ProgramMetadata.Barriers.Keys) { if (!assignments.ContainsKey(barrierName)) { assignments.Add(barrierName, false); } } if (type == Solver.SolverType.MaxSAT || type == Solver.SolverType.Optimizer) { return(constraintGenerator.ConstraintProgram(assignments)); } else { solution = assignments; } } else { solution = null; errors.AddRange(current_errors); } } catch (AssertionException) { assignments = new Dictionary <string, bool>(); foreach (Barrier barrier in ProgramMetadata.Barriers.Values) { assignments.Add(barrier.Name, !barrier.Generated); } IEnumerable <Error> current_errors = VerifyProgram(assignments); if (!current_errors.Any()) { return(constraintGenerator.ConstraintProgram(assignments)); } throw; } } }