Esempio n. 1
0
 def runSpacer(self, in_name):
     """ Run Spacer """
     stats = ["fixedpoint.print_statistics=true"] if self.args.stat else []
     utvpi = ["pdr.utvpi=false"] if self.args.stat else []
     spacer_args = [
         self.getSpacer(), "fixedpoint.xform.slice=false",
         "fixedpoint.xform.inline_linear=false",
         "fixedpoint.xform.inline_eager=false",
         "fixedpoint.use_heavy_mev=true",
         "fixedpoint.print_fixedpoint_extensions=false",
         "fixedpoint.pdr.flexible_trace=true",
         "fixedpoint.reset_obligation_queue=true",
         "fixedpoint.print_answer=true", "-v:1", "fixedpoint.engine=spacer"
     ] + stats + utvpi + [in_name]
     if self.args.verbose: print ' '.join(spacer_args)
     utils.stat('Result', 'UNKNOWN')
     result = None
     try:
         p = sub.Popen(spacer_args,
                       shell=False,
                       stdout=sub.PIPE,
                       stderr=sub.STDOUT)
         result, _ = p.communicate()
         with open(in_name + "_result.txt", "w") as f:
             f.write(result)
     except Exception as e:
         print str(e)
Esempio n. 2
0
 def encode(self):
     """generate CHC and not solve"""
     hornFormulas = self.mk_horn()
     if not hornFormulas:
         self.log.error('Problem generating Horn formulae')
         utils.stat('Result', 'ERR')
     else:
         utils.stat('Result', 'SUCCESS')
     return hornFormulas
Esempio n. 3
0
 def sFunction(self):
     """Link the encoding with an externally generated Horn clause"""
     sf = SFunction(self.args)
     if sf.sanityCheck():
         utils.stat('LegacyCode', 'OK')
         self.log.info('Legacy Code is well formed ...')
         sf.getFiller()
         self.encodeAndSolve()
     else:
         utils.stat('LegacyCode', 'KO')
         self.log.error('Legacy Code Horn Clause is NOT well formed ... ')
         return
Esempio n. 4
0
    def encodeAndSolve(self):
        """Generate horn formulas and solve"""
        self.setSolver()
        hornFormulas = self.args.file if self.args.smt2 else self.mk_horn()
        cex = None
        if not hornFormulas:
            self.log.error('Problem generating Horn formulae')
            return
        with utils.stats.timer('Parse'):
            self.log.info('Successful Horn Generation ... ' +
                          str(hornFormulas))
            q = self.fp.parse_file(hornFormulas)
        preds = utils.fp_get_preds(
            self.fp)  # get the predicates before z3 starts playing with them
        if self.args.invs:
            lemmas = z3.parse_smt2_file(args.invs, sorts={}, decls={}, ctx=ctx)
            if z3.is_and(lemmas):
                lemmas = lemmas.children()
            for l in lemmas:
                if self.args.verbose: print l
                fp_add_cover(self.fp, l.arg(0), l.arg(1))
        contract_file, emf_file = None, None
        with utils.stats.timer('Query'):
            res = self.fp.query(q[0])
            if res == z3.sat:
                utils.stat('Result', 'CEX')
                cex = self.mk_cex(preds)
            elif res == z3.unsat:
                utils.stat('Result', 'SAFE')
                if self.args.ri: self.get_raw_invs(preds)
                if self.args.cg:
                    contract_file, emf_file = self.mk_contract(preds)
                    # try:

                    # except Exception as e:
                    #     print e
                    #     self.log.warning('Failed to generate CoCoSpec')
        if not self.args.save:
            self.log.debug("Cleaning up temp files ...")
            try:
                os.remove(self.smt2_file)
                os.remove(self.trace_file)
            except:
                self.log.info('No Cleaning of temp files ...')
        if self.args.xml:
            utils.stats.xml_print(self.args.node, cex, contract_file, emf_file)
        else:
            utils.stats.brunch_print()
Esempio n. 5
0
    def refineDist(self):
        n=1 # This function is in testing.
        for atom, score0 in self.getAtomNameScoreList(n, rev=True):
            left = []
            right = []
            alen = len(atom)
            for name, score in self.getAtomNameScoreList(n+1,  rev=True):
                nlen = len(name)
                if nlen <= alen:
                    continue

                if name.find(atom) == 0:
                    left.append(score)
                    
                if name.rfind(atom) == nlen-alen:               
                    right.append(score)
            all = left + right   
            left.sort()
            right.sort()
            all.sort()
            sum_left = sum(left)
            sum_right = sum(right)
            sum_all = sum(all)
            print "\n====\n%s:" % atom
            print "total: %d %d %f" % (score0, sum_all,  sum_all/score0)
            print "A-len %d sum %d" % (len(all), sum_all)
            if left:
                print "m: %d, v %d" % utils.stat(all)
            print "*" * 20                
            print "L-len %d sum %d" % (len(left), sum_left)
            if left:
                print "m: %d, v %d" % utils.stat(left)
            print "*" * 20
            print "R-len %d sum %d" % (len(right), sum_right)
            if right:
                print "m: %d, v %d" % utils.stat(right)
Esempio n. 6
0
 def solve(self, horn_file):
     """ Solve directly """
     self.setSolver()
     with utils.stats.timer('Parse'):
         q = self.fp.parse_file(horn_file)
     preds = utils.fp_get_preds(self.fp)
     with utils.stats.timer('Query'):
         res = self.fp.query(q[0])
         if res == z3.sat:
             utils.stat('Result', 'CEX')
         elif res == z3.unsat:
             utils.stat('Result', 'SAFE')
             self.printInv(preds)
         else:
             utils.stat('Result', 'UNK')
     stats.brunch_print()
     return
Esempio n. 7
0
 def eldarica(self):
     """Generate horn formulas and solve with Eldarica"""
     self.setSolver()
     hornFormulas = self.mk_horn()
     if not hornFormulas:
         self.log.error('Problem generating Horn formulae')
         return
     with utils.stats.timer('Parse'):
         self.log.info('Successful Horn VC generation ... ' +
                       str(hornFormulas))
         q = self.fp.parse_file(hornFormulas)
         utils.stats.stop('Parse')
         lusFile = self.args.file
         lusFile_dir = os.path.dirname(os.path.abspath(lusFile)) + os.sep
         base = (os.path.splitext(os.path.basename(lusFile)))[0]
         smt2_name = lusFile_dir + base + "_puresmt2.smt2"
         with open(smt2_name, 'w') as sf:
             puresmt2 = self.fp.to_string(q)
             sf.write(puresmt2)
         self.log.info("Running Eldarica ... ")
         with utils.stats.timer('Eldarica'):
             cmd = [self.getEldarica(), '-ssol', '-lbe', smt2_name]
             p = subprocess.Popen(cmd,
                                  shell=False,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.STDOUT)
             eldaricaOut, _ = p.communicate()
             if 'sat' in eldaricaOut:
                 utils.stat('Result', 'SAFE')
             elif 'unsat' in eldaricaOut:
                 utils.stat('Result', 'CEX')
             else:
                 utils.stat('Result', 'UNKNOWN')
         utils.stats.stop('Eldarica')
         if self.args.xml:
             utils.stats.xml_print(self.args.node, cex, None)
         else:
             utils.stats.brunch_print()