Beispiel #1
0
 def solve_all_synth(self, model, program, threads):
     timer = Logger.start_timer("CVC4 intersect")
     (ao_execs,
      executions) = self.find_all_intersect(model, program, threads)
     Logger.stop_timer(timer)
     timer = Logger.start_timer("CVC4 prune equivalent")
     ret = self.prune_not_eq(ao_execs, executions, model, program, threads)
     Logger.stop_timer(timer)
     return ret
Beispiel #2
0
 def solve_all_synth_hybrid(self, cvc4model, alloymodel, program, threads):
     timer = Logger.start_timer("Alloy intersect")
     (ao_execs, executions) = self.alloy_synth.find_all_intersect(
         alloymodel, program, 1)
     Logger.stop_timer(timer)
     timer = Logger.start_timer("CVC4 prune equivalent")
     ret = self.cvc4_synth.prune_not_eq(ao_execs, executions, cvc4model,
                                        program, threads)
     Logger.stop_timer(timer)
     return ret
Beispiel #3
0
 def solve_all_alloy(self, model, program=None, nexecs=-1, threads=1):
     self.alloy_vexecsmanager.program = program
     if program.has_conditions:
         self.alloy_vexecsmanager.set_additional_variables(
             program.get_conditions())
     model += self.alloyencoder.print_run_condition(program)
     timer = Logger.start_timer("Alloy solve all")
     ret = self.alloysolver.solve_allsmt(model, self.alloy_vexecsmanager,
                                         nexecs, threads)
     Logger.stop_timer(timer)
     return len(ret)
Beispiel #4
0
    def solve_all_cvc4(self, model, program=None, nexecs=-1, threads=1):
        self.cvc4_vexecsmanager.program = program
        if program.has_conditions:
            self.cvc4_vexecsmanager.set_additional_variables(
                program.get_conditions())

        timer = Logger.start_timer("CVC4 solve all")
        ret = self.c4solver.solve_allsmt(model, self.cvc4_vexecsmanager,
                                         nexecs, threads)
        Logger.stop_timer(timer)
        return len(ret)
Beispiel #5
0
    def analyze_constraints(self, program, model, jsengine, runs, threads,
                            jsprogram, use_alloy):
        matched = None
        unmatched = None

        config = Config()
        config.command = jsengine
        config.input_file = jsprogram
        config.threads = threads
        config.number = runs
        config.silent = True
        config.models = True

        if use_alloy:
            labelling_vars = [y[2] for y in [x.split(" ") for x in model.split("\n") if len(x.split(" "))>2] \
                              if y[2][:len(LABELLING_VAR_PREF)] == LABELLING_VAR_PREF]
        else:
            labelling_vars = [x.split(" ")[0] for x in model.split("\n") \
                              if x[:len(LABELLING_VAR_PREF)] == LABELLING_VAR_PREF]

        if len(labelling_vars) == 0:
            Logger.error("No labelling vars defined")
            return None

        if use_alloy:
            self.al_consamanager.labelling_vars = labelling_vars
        else:
            self.c4_consamanager.labelling_vars = labelling_vars

        (matched, unmatched) = self.__load_outputs(config.number, self.outfile,
                                                   jsengine)

        if (matched is None) and (unmatched is None):
            timer = Logger.start_timer("Run Litmus")
            (matched, unmatched) = run_litmus(config)
            Logger.stop_timer(timer)
            self.__save_outputs(config.number, self.outfile, jsengine, matched,
                                unmatched)

        timer = Logger.start_timer("Analyze output")

        parser = BeParser()
        mexecs = parser.executions_from_string("\n".join(matched), program)
        uexecs = parser.executions_from_string("\n".join(unmatched), program)

        Logger.log(" -> Found %s matched models" % (len(matched)), 0)
        Logger.log(" -> Found %s unmatched models" % (len(unmatched)), 0)

        if len(unmatched) == 0:
            Logger.error("No unmatched models")
            Logger.stop_timer(timer)
            return None

        rels = [x for x in RELATIONS if x != AO]

        matched = self.al_encoder.print_assert_exl_execs(mexecs, rels) if use_alloy else \
                  self.c4_encoder.print_assert_exl_execs(mexecs, rels)
        unmatched = self.al_encoder.print_assert_exl_execs(uexecs, rels) if use_alloy else \
                    self.c4_encoder.print_assert_exl_execs(uexecs, rels)

        objs = []
        Logger.log("\nMatched models analysis", 0)
        Logger.msg("Solving... ", 0)

        if use_alloy:
            vmodel = "\n".join([
                model, matched,
                self.al_encoder.print_run_condition(program, True)
            ])
            objs = self.al_solver.compute_models(vmodel, self.al_consamanager,
                                                 objs)
            mmodels = " | ".join([x[1] for x in objs])
        else:
            vmodel = "%s\n%s" % (model, matched)
            objs = self.c4_solver.compute_models(vmodel, self.c4_consamanager,
                                                 objs)
            mmodels = " | ".join(objs)

        Logger.log(" DONE", 0)
        mmodels = self.bsolver.simplify(mmodels, True)
        self.__print_models(mmodels)

        objs = []
        Logger.log("Unmatched models analysis", 0)
        Logger.msg("Solving... ", 0)

        if use_alloy:
            vmodel = "\n".join([
                model, unmatched,
                self.al_encoder.print_run_condition(program, True)
            ])
            objs = self.al_solver.compute_models(vmodel, self.al_consamanager,
                                                 objs)
            nmodels = " | ".join([x[1] for x in objs])
        else:
            vmodel = "%s\n%s" % (model, unmatched)
            objs = self.c4_solver.compute_models(vmodel, self.c4_consamanager,
                                                 objs)
            nmodels = " | ".join(objs)

        Logger.log(" DONE", 0)
        nmodels = self.bsolver.simplify(nmodels, True)
        self.__print_models(nmodels)

        Logger.log("Difference analysis (exist support(matched) in unmatched)",
                   0)
        diffmodels = self.bsolver.support_exist(" | ".join(mmodels),
                                                " | ".join(nmodels), True)
        self.__print_models(diffmodels)

        self.user_defined_analyses(mmodels, nmodels)

        Logger.stop_timer(timer)
        return (mmodels, nmodels, diffmodels)