コード例 #1
0
ファイル: crabllvm.py プロジェクト: HUST-PLT/crab-llvm
def main (argv):
    os.setpgrp ()
    loadEnv (os.path.join (root, "env.common"))

    ## add directory containing this file to the PATH
    os.environ ['PATH'] =  os.path.dirname (os.path.realpath (__file__)) + \
                           os.pathsep + os.environ['PATH']
    
    args  = parseArgs (argv[1:])
    workdir = createWorkDir (args.temp_dir, args.save_temps)
    in_name = args.file

    if args.preprocess:
        bc_out = defBCName (in_name, workdir)
        if bc_out != in_name:
                extra_args = []
                if args.debug_info: extra_args.append ('-g')
                with stats.timer ('Clang'):
                    clang (in_name, bc_out, arch=args.machine, extra_args=extra_args)
                #stat ('Progress', 'Clang')
        in_name = bc_out

        pp_out = defPPName (in_name, workdir)
        if pp_out != in_name:
            with stats.timer ('CrabLlvmPP'):
                crabpp (in_name, pp_out, args=args, cpu=args.cpu, mem=args.mem)
            #stat ('Progress', 'Crab Llvm preprocessor')
        in_name = pp_out

    if args.L > 0:
        o_out = defOptName (in_name, workdir)
        if o_out != in_name:
            extra_args = []
            with stats.timer ('CrabOptLlvm'):
                optLlvm (in_name, o_out, args, extra_args, cpu=args.cpu, mem=args.mem)
            #stat ('Progress', 'Llvm optimizer')
        in_name = o_out

    pp_out = defOutPPName(in_name, workdir)
    with stats.timer ('CrabLlvm'):
        extra_opts = []
        if not args.analyze:
            extra_opts.append ('-no-crab')
        crabllvm (in_name, pp_out, args, extra_opts, cpu=args.cpu, mem=args.mem)

    if args.dot_cfg: dot(pp_out)
    if args.view_cfg: dot(pp_out, True)
    #stat ('Progress', 'Crab Llvm')

    if args.asm_out_name is not None and args.asm_out_name != pp_out:
        if verbose: print 'cp {0} {1}'.format (pp_out, args.asm_out_name)
        shutil.copy2 (pp_out, args.asm_out_name)

    return 0
コード例 #2
0
def main (argv):
    os.setpgrp ()
    loadEnv (os.path.join (root, "env.common"))

    ## add directory containing this file to the PATH
    os.environ ['PATH'] =  os.path.dirname (os.path.realpath (__file__)) + \
                           os.pathsep + os.environ['PATH']
    
    args  = parseArgs (argv[1:])
    workdir = createWorkDir (args.temp_dir, args.save_temps)
    in_name = args.file

    if args.preprocess:
        bc_out = defBCName (in_name, workdir)
        if bc_out != in_name:
                extra_args = []
                if args.debug_info: extra_args.append ('-g')
                with stats.timer ('Clang'):
                    clang (in_name, bc_out, arch=args.machine, extra_args=extra_args)
                #stat ('Progress', 'Clang')
        in_name = bc_out

        pp_out = defPPName (in_name, workdir)
        if pp_out != in_name:
            with stats.timer ('CrabLlvmPP'):
                crabpp (in_name, pp_out, args=args, cpu=args.cpu, mem=args.mem)
            #stat ('Progress', 'Crab Llvm preprocessor')
        in_name = pp_out

    if args.L > 0:
        o_out = defOptName (in_name, workdir)
        if o_out != in_name:
            extra_args = []
            with stats.timer ('CrabOptLlvm'):
                optLlvm (in_name, o_out, args, extra_args, cpu=args.cpu, mem=args.mem)
            #stat ('Progress', 'Llvm optimizer')
        in_name = o_out

    pp_out = defOutPPName(in_name, workdir)
    with stats.timer ('CrabLlvm'):
        extra_opts = []
        if not args.analyze:
            extra_opts.append ('-no-crab')
        crabllvm (in_name, pp_out, args, extra_opts, cpu=args.cpu, mem=args.mem)

    if args.dot_cfg: dot(pp_out)
    if args.view_cfg: dot(pp_out, True)
    #stat ('Progress', 'Crab Llvm')

    if args.asm_out_name is not None and args.asm_out_name != pp_out:
        if verbose: print 'cp {0} {1}'.format (pp_out, args.asm_out_name)
        shutil.copy2 (pp_out, args.asm_out_name)

    return 0
コード例 #3
0
 def parallelRun(self, smt2_file):
     """
     Job spanner
     """
     ctx = z3.Context()
     fp = z3.Fixedpoint(ctx=ctx)
     jobs = []
     with stats.timer('Parse'):
         self.log.info('Parsing  ... ' + str(smt2_file))
         queries = fp.parse_file(smt2_file)
         stats.stop('Parse')
         self.log.info("Parsing time ... " + str(stats.get('Parse')) +
                       " ms")
         n_function = len(queries)
         n_query = n_function if self.args.func < 0 or self.args.func > n_function else self.args.func
         self.log.info("Number of functions ...  " + str(n_function))
         self.log.info("Number of jobs ... " + str(n_query))
         all_results = ""
         pool_jobs = Pool(processes=n_query)
         try:
             for q in range(n_query):
                 query = queries[q]
                 function_name = self.getFunctionName(query)
                 self.log.info("Checking feasibility of ...  " +
                               str(function_name))
                 #job_result = pool_jobs.apply_async(jobStarter, (self.args, qi, smt2_file, ), callback=self.onReturn)
                 job_result = pool_jobs.apply_async(jobStarter, (
                     self.args,
                     q,
                     smt2_file,
                 ))
                 job_result.wait(timeout=self.args.timeout)
                 if job_result.ready():
                     out = ""
                     try:
                         out = job_result.get()
                         if bench: print out
                     except Exception as e:
                         print str(e)
                         continue
                     all_results += out + "\n-----------------------\n"
                 else:
                     out = out_message % (function_name, "TIMEOUT", "", "",
                                          "", "", "")
                     out = bcolors.WARNING + out + bcolors.ENDC
                     if bench: print out
                     all_results += out + "\n------- ----------------\n"
             pool_jobs.close()
             pool_jobs.terminate()
             pool_jobs.join()
             if self.args.save:
                 f_name = ntpath.basename(smt2_file) + "_feas.txt"
                 with open(f_name, "w") as f:
                     f.write(all_results)
             else:
                 print "\n\t ========= SUMMARY SEAHORN INCONSISTENCY CHECKS   ========"
                 print all_results
         except Exception as e:
             self.log.exception(str(e))
コード例 #4
0
ファイル: sfunction.py プロジェクト: coco-team/zustre
 def sanityCheck(self):
     self.log.info("Linking with externally generated Horn clauses ... ")
     self.setSolver()
     with stats.timer ('S-Function-Parse'):
         q = self.fp.parse_file (self.args.sfunction)
     self.preds = utils.fp_get_preds(self.fp) # get the predicates before z3 starts playing with them
     res = self.fp.query (q[0])
     return True if res == z3.sat else False
コード例 #5
0
 def sanityCheck(self):
     self.log.info("Linking with externally generated Horn clauses ... ")
     self.setSolver()
     with stats.timer('S-Function-Parse'):
         q = self.fp.parse_file(self.args.sfunction)
     self.preds = utils.fp_get_preds(
         self.fp)  # get the predicates before z3 starts playing with them
     res = self.fp.query(q[0])
     return True if res == z3.sat else False
コード例 #6
0
ファイル: kind2.py プロジェクト: terminiter/zustre
 def validate(self, coco_file):
     self.log.info("Validating Generated CoCoSpec ... " + str(coco_file))
     hornDefs = None
     with stats.timer('Kind2'):
         coco_dir = os.path.dirname(os.path.abspath(coco_file)) + os.sep
         kind2 = self.getKind2();
         z3_bin = self.getZ3Bin();
         cmd = [kind2, "--modular", "true", "--z3_bin", z3_bin, coco_file]
         p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
         validation, _ = p.communicate()
         print validation
コード例 #7
0
ファイル: runner.py プロジェクト: jayhorn/cav_experiments
    def runJar(self):
        try:
            tt = 'TIME-'+str(self.t_n)
            with stats.timer(tt):
                p = subprocess.Popen(self.t_e, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
                result, _ = p.communicate()
                return result

        except Exception as e:
            print str(e)
            return None
コード例 #8
0
ファイル: inc.py プロジェクト: alx441/XSHM
 def checkFeasibility(self, expr_query, function_name):
     done = False
     rounds = 0  # counter for feasibility check
     self.ee_idx = self.ee_vars(expr_query)
     if verbose: print "EE VARS INDEX:", self.ee_idx
     out = ""
     while not done:
         with stats.timer('Query'):
             res = self.fp.query(
                 expr_query
             )  #if round == 0 else self.fp.query_from_lvl(12,expr_query)
             if res == z3.sat:
                 msg = "ENTRY -> EXIT is FEASIBLE" if rounds == 0 else "STILL FEASIBLE: Continue checking ..."
                 if verbose: print "( " + function_name + " ) " + msg
                 expr_query, path = self.cex(expr_query)
                 self.feasible_flag = self.ee_idx
                 rounds += 1
                 if expr_query is None:
                     result = "[%s], Feasible" % function_name
                     stat('Result', result)
                     stat('Rounds', str(rounds))
                     out += out_message % (function_name, "CONSISTENT", "",
                                           str(self.feasible_flag),
                                           str(self.non_feasible_flag))
                     out = bcolors.OKGREEN + out + bcolors.ENDC
                     done = True
             elif res == z3.unsat:
                 result = "[%s], Infeasible" % function_name
                 stat('Result', result)
                 stat('Rounds', str(rounds))
                 msg = "EXIT is not FEASIBLE" if rounds == 0 else "INFEASIBLE BLOCK FOUND"
                 if rounds == 0:
                     self.feasible_flag.append(self.ee_idx[0])
                     self.non_feasible_flag.append(self.ee_idx[1])
                 if verbose: print " ( " + function_name + " ) " + msg
                 inv = "\n"
                 for p in self.preds:
                     lemmas = fp_get_cover_delta(self.fp, p)
                     inv += "\tBasic Block: " + str(p.decl())
                     inv += "\n\tInvariant: " + str(lemmas)
                     inv += "\n\t-----------\n"
                 inv_info = inv if self.args.inv else "(set --inv to get invariants info)"
                 out += out_message % (function_name, "INCONSISTENT",
                                       inv_info, str(self.feasible_flag),
                                       str(self.non_feasible_flag))
                 out = bcolors.FAIL + out + bcolors.ENDC
                 done = True
             stats.stop('Query')
         # debugging purpose
         if self.args.stop != None:
             self.args.stop -= 1
             done = self.args.stop == 0
     return out
コード例 #9
0
ファイル: par_inc.py プロジェクト: edmcman/seahorn
 def parallelRun(self, smt2_file):
     """
     Job spanner
     """
     ctx = z3.Context ()
     fp = z3.Fixedpoint (ctx=ctx)
     jobs = []
     with stats.timer ('Parse'):
         self.log.info('Parsing  ... ' + str(smt2_file))
         queries = fp.parse_file (smt2_file)
         stats.stop('Parse')
         self.log.info("Parsing time ... " + str(stats.get('Parse')) + " ms")
         n_function = len(queries)
         n_query = n_function if self.args.func < 0 or self.args.func > n_function else self.args.func
         self.log.info("Number of functions ...  " + str(n_function))
         self.log.info("Number of jobs ... " + str(n_query))
         all_results = ""
         pool_jobs = Pool(processes=n_query)
         try:
             for q in range(n_query):
                 query = queries[q]
                 function_name  = self.getFunctionName(query)
                 self.log.info("Checking feasibility of ...  " + str(function_name))
                 #job_result = pool_jobs.apply_async(jobStarter, (self.args, qi, smt2_file, ), callback=self.onReturn)
                 job_result = pool_jobs.apply_async(jobStarter, (self.args, q, smt2_file, ))
                 job_result.wait(timeout=self.args.timeout)
                 if job_result.ready():
                     out = ""
                     try:
                         out = job_result.get()
                         if bench: print out
                     except Exception as e:
                         print str(e)
                         continue
                     all_results += out + "\n-----------------------\n"
                 else:
                     out = out_message % (function_name, "TIMEOUT", "", "", "", "", "")
                     out = bcolors.WARNING + out + bcolors.ENDC
                     if bench: print out
                     all_results += out + "\n------- ----------------\n"
             pool_jobs.close()
             pool_jobs.terminate()
             pool_jobs.join()
             if self.args.save:
                 f_name = ntpath.basename(smt2_file)+"_feas.txt"
                 with open (f_name, "w") as f:
                     f.write(all_results)
             else:
                 print "\n\t ========= SUMMARY SEAHORN INCONSISTENCY CHECKS   ========"
                 print all_results
         except Exception as e:
             self.log.exception(str(e))
コード例 #10
0
    def runJar(self):
        try:
            tt = 'TIME-' + str(self.t_n)
            with stats.timer(tt):
                p = subprocess.Popen(self.t_e,
                                     shell=False,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT)
                result, _ = p.communicate()
                return result

        except Exception as e:
            print str(e)
            return None
コード例 #11
0
 def singleRun(self, smt2_file):
     """
     Single run
     """
     ctx = z3.Context()
     fp = z3.Fixedpoint(ctx=ctx)
     with stats.timer('Parse'):
         self.log.info('Parsing  ... ' + str(smt2_file))
         queries = fp.parse_file(smt2_file)
         stats.stop('Parse')
         self.log.info("Parsing time ... " + str(stats.get('Parse')) +
                       " ms")
         n_function = len(queries)
         n_query = n_function if self.args.func < 0 or self.args.func > n_function else self.args.func
         self.log.info("Number of functions ...  " + str(n_function))
         self.log.info("Number of jobs ... " + str(n_query))
         all_results = ""
         try:
             for q in range(n_query):
                 query = queries[q]
                 function_name = self.getFunctionName(query)
                 self.log.info("Checking feasibility of ...  " +
                               str(function_name))
                 out = ""
                 try:
                     p = multiprocessing.Process(target=checkFeas,
                                                 args=(
                                                     self.args,
                                                     q,
                                                     smt2_file,
                                                 ))
                     p.start()
                     p.join(self.args.timeout)
                     if p.is_alive():
                         out = out_message % (function_name, "TIMEOUT", "",
                                              "", "", "", "")
                         out = bcolors.WARNING + out + bcolors.ENDC
                         p.terminate()
                         p.join()
                 except Exception as e:
                     self.log.exception(str(e))
                     continue
                     all_results += out + "\n-----------------------\n"
             if self.args.save:
                 f_name = ntpath.basename(smt2_file) + "_feas.txt"
                 with open(f_name, "w") as f:
                     f.write(all_results)
         except Exception as e:
             self.log.exception(str(e))
コード例 #12
0
ファイル: inc.py プロジェクト: edmcman/seahorn
 def checkFeasibility(self, expr_query, function_name):
     done = False
     rounds = 0 # counter for feasibility check
     self.ee_idx = self.ee_vars(expr_query)
     if verbose: print "EE VARS INDEX:", self.ee_idx
     out = ""
     while not done:
         with stats.timer ('Query'):
             res = self.fp.query (expr_query) #if round == 0 else self.fp.query_from_lvl(12,expr_query)
             if res == z3.sat:
                 msg = "ENTRY -> EXIT is FEASIBLE" if rounds==0 else "STILL FEASIBLE: Continue checking ..."
                 if verbose: print "( " + function_name + " ) " + msg
                 expr_query, path = self.cex(expr_query)
                 self.feasible_flag = self.ee_idx
                 rounds += 1
                 if expr_query is None:
                     result = "[%s], Feasible" % function_name
                     stat('Result', result)
                     stat('Rounds', str(rounds))
                     out += out_message % (function_name, "CONSISTENT", "", str(self.feasible_flag),  str(self.non_feasible_flag))
                     out = bcolors.OKGREEN + out + bcolors.ENDC
                     done = True
             elif res == z3.unsat:
                 result = "[%s], Infeasible" % function_name
                 stat('Result', result)
                 stat('Rounds', str(rounds))
                 msg = "EXIT is not FEASIBLE" if rounds==0 else "INFEASIBLE BLOCK FOUND"
                 if rounds == 0:
                     self.feasible_flag.append(self.ee_idx[0])
                     self.non_feasible_flag.append(self.ee_idx[1])
                 if verbose: print " ( " + function_name + " ) " + msg
                 inv =  "\n"
                 for p in self.preds:
                     lemmas = fp_get_cover_delta (self.fp, p)
                     inv += "\tBasic Block: " + str(p.decl())
                     inv += "\n\tInvariant: " + str(lemmas)
                     inv += "\n\t-----------\n"
                 inv_info = inv if self.args.inv else "(set --inv to get invariants info)"
                 out += out_message % (function_name, "INCONSISTENT", inv_info, str(self.feasible_flag),  str(self.non_feasible_flag))
                 out = bcolors.FAIL + out + bcolors.ENDC
                 done = True
             stats.stop('Query')
         # debugging purpose
         if self.args.stop != None:
             self.args.stop -=1
             done = self.args.stop==0
     return out
コード例 #13
0
def main(argv):
    ## add directory containing this file to the PATH
    os.environ ['PATH'] =  os.path.dirname (os.path.realpath (__file__)) + \
                           os.pathsep + os.environ['PATH']

    returncode = 13
    args = parseArgs(argv[1:])
    stat('Result', 'UNKNOWN')

    z3_args = compute_z3_args(args)
    print z3_args

    if args.no_z3: return returncode

    stat('File', args.file)
    stat('base', os.path.basename(args.file))

    cmd = RunCmd(z3_args.split(), args.cpu, args.mem)
    with stats.timer('Query'):
        returncode = cmd.Run()
    res = cmd.stdout

    if res is None:
        res = 'unknown'
    elif 'unsat' in res:
        res = 'unsat'
    elif 'sat' in res:
        res = 'sat'
    else:
        res = 'unknown'

    print 'Result:', res

    if res == 'sat':
        if args.smt2lib: stat('Result', 'SAFE')
        else: stat('Result', 'CEX')
    elif res == 'unsat':
        if args.smt2lib: stat('Result', 'CEX')
        else: stat('Result', 'SAFE')

    # set returncode
    stat('Status', returncode)

    return returncode
コード例 #14
0
ファイル: inc.py プロジェクト: alx441/XSHM
 def solve(self, smt2_file):
     """
     Start solving
     """
     self.fp.set(engine='spacer')
     if self.args.stat:
         self.fp.set('print_statistics', True)
     if self.args.z3_verbose:
         z3.set_option(verbose=1)
     self.fp.set('use_heavy_mev', True)
     self.fp.set('pdr.flexible_trace', True)
     self.fp.set('reset_obligation_queue', False)
     self.fp.set('spacer.elim_aux', False)
     if self.args.utvpi: self.fp.set('pdr.utvpi', False)
     if not self.args.pp:
         self.fp.set('xform.slice', False)
         self.fp.set('xform.inline_linear', False)
         self.fp.set('xform.inline_eager', False)
     with stats.timer('Parse'):
         queries = self.fp.parse_file(smt2_file)
         stats.stop('Parse')
         self.preds = get_preds(self.fp)
         n_function = len(queries)
         stat("Function_Numbers", n_function)
         # TODO: Put them in a multithreading function
         all_results = ""
         for q in queries:
             if z3.is_quantifier(q):
                 decl = q.body().decl()
                 function_name = str(decl).split("@")[0]
                 try:
                     out = self.checkFeasibility(q, function_name)
                     all_results += out + "\n-----------------------\n"
                 except Exception as e:
                     print "Solving " + function_name
             else:
                 function_name = str(q.decl()).split("@")[0]
                 out = out_message % (function_name, "CONSISTENT", "",
                                      "Trivial", "")
                 all_results += bcolors.OKGREEN + out + bcolors.ENDC
         print "\n\t ========= SEAHORN INCONSISTENCY RESULTS ========"
         print all_results
コード例 #15
0
ファイル: inc.py プロジェクト: edmcman/seahorn
 def solve(self, smt2_file):
     """
     Start solving
     """
     self.fp.set (engine='spacer')
     if self.args.stat:
         self.fp.set('print_statistics',True)
     if self.args.z3_verbose:
         z3.set_option (verbose=1)
     self.fp.set('use_heavy_mev',True)
     self.fp.set('pdr.flexible_trace',True)
     self.fp.set('reset_obligation_queue',False)
     self.fp.set('spacer.elim_aux',False)
     if self.args.utvpi: self.fp.set('pdr.utvpi', False)
     if not self.args.pp:
         self.fp.set ('xform.slice', False)
         self.fp.set ('xform.inline_linear',False)
         self.fp.set ('xform.inline_eager',False)
     with stats.timer ('Parse'):
         queries = self.fp.parse_file (smt2_file)
         stats.stop('Parse')
         self.preds = get_preds(self.fp)
         n_function = len(queries)
         stat("Function_Numbers", n_function)
         # TODO: Put them in a multithreading function
         all_results = ""
         for q in queries:
             if z3.is_quantifier(q):
                 decl = q.body().decl()
                 function_name = str(decl).split("@")[0]
                 try:
                     out = self.checkFeasibility(q, function_name)
                     all_results += out + "\n-----------------------\n"
                 except Exception as e:
                     print "Solving " + function_name
             else:
                 function_name = str(q.decl()).split("@")[0]
                 out = out_message % (function_name, "CONSISTENT", "", "Trivial", "")
                 all_results += bcolors.OKGREEN + out + bcolors.ENDC
         print "\n\t ========= SEAHORN INCONSISTENCY RESULTS ========"
         print all_results
コード例 #16
0
ファイル: par_inc.py プロジェクト: edmcman/seahorn
 def singleRun(self, smt2_file):
     """
     Single run
     """
     ctx = z3.Context ()
     fp = z3.Fixedpoint (ctx=ctx)
     with stats.timer ('Parse'):
         self.log.info('Parsing  ... ' + str(smt2_file))
         queries = fp.parse_file (smt2_file)
         stats.stop('Parse')
         self.log.info("Parsing time ... " + str(stats.get('Parse')) + " ms")
         n_function = len(queries)
         n_query = n_function if self.args.func < 0 or self.args.func > n_function else self.args.func
         self.log.info("Number of functions ...  " + str(n_function))
         self.log.info("Number of jobs ... " + str(n_query))
         all_results = ""
         try:
             for q in range(n_query):
                 query = queries[q]
                 function_name  = self.getFunctionName(query)
                 self.log.info("Checking feasibility of ...  " + str(function_name))
                 out = ""
                 try:
                     p = multiprocessing.Process(target=checkFeas, args=(self.args, q, smt2_file, ))
                     p.start()
                     p.join(self.args.timeout)
                     if p.is_alive():
                         out = out_message % (function_name, "TIMEOUT", "", "", "", "", "")
                         out = bcolors.WARNING + out + bcolors.ENDC
                         p.terminate()
                         p.join()
                 except Exception as e:
                     self.log.exception(str(e))
                     continue
                     all_results += out + "\n-----------------------\n"
             if self.args.save:
                 f_name = ntpath.basename(smt2_file)+"_feas.txt"
                 with open (f_name, "w") as f:
                     f.write(all_results)
         except Exception as e:
             self.log.exception(str(e))
コード例 #17
0
ファイル: termination.py プロジェクト: edmcman/seahorn
def seaTerm(smt_file, rank_function):
    try:
        stat ('Result','UNKNOWN')
        stat ('Ranking_Function', rank_function)
        fp = z3.Fixedpoint()
        fp.set(engine='spacer')
        fp.set('xform.inline_eager', False)
        fp.set('xform.slice', False)
        fp.set('xform.inline_linear', False)
        fp.set('pdr.utvpi', False)
        fp.set('xform.karr', True)
        query = fp.parse_file(smt_file)
        with stats.timer('Termination'):
            if rank_function == 'max':
                piecewise(fp)
            elif rank_function == 'lex':
                lexicographic(fp)
            else:
                raise IOError('unknown ranking function template')
    except Exception as e:
        raise IOError(str(e))
    finally:
        stats.brunch_print()
コード例 #18
0
def seaTerm(smt_file, rank_function):
    try:
        stat('Result', 'UNKNOWN')
        stat('Ranking_Function', rank_function)
        fp = z3.Fixedpoint()
        fp.set(engine='spacer')
        fp.set('xform.inline_eager', False)
        fp.set('xform.slice', False)
        fp.set('xform.inline_linear', False)
        fp.set('pdr.utvpi', False)
        fp.set('xform.karr', True)
        query = fp.parse_file(smt_file)
        with stats.timer('Termination'):
            if rank_function == 'max':
                piecewise(fp)
            elif rank_function == 'lex':
                lexicographic(fp)
            else:
                raise IOError('unknown ranking function template')
    except Exception as e:
        raise IOError(str(e))
    finally:
        stats.brunch_print()
コード例 #19
0
ファイル: par_inc.py プロジェクト: edmcman/seahorn
    def checkFeas(self, expr_query):
        done = False # flag to stop the feasibility checking
        rounds = 1 # counter for feasibility check
        self.ee_idx = self.ee_vars(expr_query) #entr/exit vars
        self.log.info("EE VARS INDEX ..." + str(self.ee_idx))
        out = ""
        function_name = self.function_name
        while not done:
            with stats.timer ('Query'):
                #if round == 0 else self.fp.query_from_lvl(12, expr_query)
                res = self.fp.query (expr_query)
                stats.stop('Query')
                self.query_times.append(str(stats.get('Query')))
                if bench: print "Query | Round [" + str(rounds) + "] | time  [" + str(stats.get('Query')) + " ms]"
                if res == z3.sat:
                    msg = "ENTRY -> EXIT is FEASIBLE" if rounds==1 else "STILL FEASIBLE: Continue checking ..."
                    self.log.info("( " + function_name + " ) " + msg)
                    self.feasible_flag |= set(self.ee_idx)
                    expr_query, path = self.cex(expr_query)
                    rounds += 1
                    if expr_query is None:
                        feas = list(self.feasible_flag)
                        infeas = ";".join([str(x) for x in list(self.non_feasible_flag)])
                        q_times = [float(x) for x in self.query_times]
                        q_average = sum(q_times) / len(q_times)
                        out += out_message % (function_name, "FEASIBLE", "", str(feas),  infeas, str(rounds), str(q_average))
                        out = bcolors.OKGREEN + out + bcolors.ENDC
                        done = True
                elif res == z3.unsat:
                    inv =  "\n-----------\n"
                    for p in self.preds:
                        lemmas = fp_get_cover_delta (self.fp, p)
                        inv += "\tBasic Block: " + str(p.decl())
                        inv += "\n\tInvariant: " + str(lemmas)
                        inv += "\n-----------\n"
                    inv_info = inv if self.args.inv else "(set --inv to get invariants info)"

                    if len(list(self.feasible_flag)) == self.flags:
                        self.log.info(" ( " + function_name + " ) FEASIBLE")
                        feas = list(self.feasible_flag)
                        q_times = [float(x) for x in self.query_times]
                        q_average = sum(q_times) / len(q_times)
                        out += out_message % (function_name, "FEASIBLE", inv_info, str(feas), "", str(rounds), str(q_average))
                        out = bcolors.OKGREEN + out + bcolors.ENDC
                    else:
                        msg = "EXIT is not FEASIBLE" if rounds==1 else "INFEASIBLE BLOCK FOUND"
                        self.feasOut()
                        if rounds == 1:
                            self.feasible_flag.add(self.ee_idx[0])
                            self.non_feasible_flag.add(self.ee_idx[1])
                        self.log.info(" ( " + function_name + " ) " + msg)
                        feas, infeas = self.feasOut()
                        q_times = [float(x) for x in self.query_times]
                        q_average = sum(q_times) / len(q_times)
                        infeas_str = ";".join([str(x) for x in infeas])
                        out += out_message % (function_name, "INFEASIBLE", inv_info, str(feas), infeas_str, str(rounds), str(q_average))
                        out = bcolors.FAIL + out + bcolors.ENDC
                    done = True
                else:
                    out += out_message % (function_name, "UNKNOWN", "", "", "", "", "")
                    done = True
        return out
コード例 #20
0
ファイル: clam.py プロジェクト: LinerSu/clam
def main(argv):
    #def stat(key, val): stats.put(key, val)
    os.setpgrp()
    loadEnv(os.path.join(root, "env.common"))

    ## add directory containing this file to the PATH
    os.environ ['PATH'] =  os.path.dirname(os.path.realpath(__file__)) + \
                           os.pathsep + os.environ['PATH']

    if '--llvm-version' in argv[1:] or '-llvm-version' in argv[1:]:
        print("LLVM version " + llvm_version)
        return 0

    if '--clang-version' in argv[1:] or '-clang-version' in argv[1:]:
        print("Clang version " + getClangVersion(getClang(False)))
        return 0

    print("Platform: {0} {1}".format(platform.system(), platform.release()))
    print("LLVM version: {0}".format(llvm_version))
    #print("Clam started at {0}\n\n".format(datetime.now().strftime("%H:%M:%S")))

    args = parseArgs(argv[1:])
    workdir = createWorkDir(args.temp_dir, args.save_temps)
    in_name = args.file

    if args.preprocess:
        bc_out = defBCName(in_name, workdir)
        if bc_out != in_name:
            extra_args = []
            if args.debug_info: extra_args.append('-g')
            with stats.timer('Clang'):
                clang(in_name,
                      bc_out,
                      args,
                      arch=args.machine,
                      extra_args=extra_args)
            #stat('Progress', 'Clang')
        in_name = bc_out

        pp_out = defPPName(in_name, workdir)
        if pp_out != in_name:
            with stats.timer('ClamPP'):
                crabpp(in_name, pp_out, args=args, cpu=args.cpu, mem=args.mem)
            #stat('Progress', 'Clam preprocessor')
        in_name = pp_out

    if args.L > 0:
        o_out = defOptName(in_name, workdir)
        if o_out != in_name:
            extra_args = []
            with stats.timer('CrabOptLlvm'):
                optLlvm(in_name,
                        o_out,
                        args,
                        extra_args,
                        cpu=args.cpu,
                        mem=args.mem)
            #stat('Progress', 'Llvm optimizer')
        in_name = o_out

    pp_out = defOutPPName(in_name, workdir)
    with stats.timer('Clam'):
        extra_opts = []
        clam(in_name, pp_out, args, extra_opts, cpu=args.cpu, mem=args.mem)

    #stat('Progress', 'Clam')

    if args.asm_out_name is not None and args.asm_out_name != pp_out:
        if False:  #verbose:
            print('cp {0} {1}'.format(pp_out, args.asm_out_name))
        shutil.copy2(pp_out, args.asm_out_name)

    #print("\nClam finished at {0}\n".format(datetime.now().strftime("%H:%M:%S")))
    return 0
コード例 #21
0
def main(argv):
    args = parseArgs(argv[1:])
    stat('Result', 'UNKNOWN')
    z3.set_option(verbose=args.verbose)
    ctx = z3.Context()
    fp = z3.Fixedpoint(ctx=ctx)

    if not args.slice:
        print 'No slicing'
        fp.set(slice=False)

    if not args.inline:
        print 'No inlining'
        fp.set(inline_linear=False)
        fp.set(inline_eager=False)

    print 'Engine: ', args.engine

    fp.set(validate_result=args.validate)
    fp.set(engine=args.engine, use_farkas=True, generate_proof_trace=False)
    fp.set(use_utvpi=args.use_utvpi)
    fp.set(eager_reach_check=args.eager_reach_check)
    fp.set(validate_theory_core=args.validate_theory_core)
    fp.set(print_statistics=args.print_stats)
    fp.set(bit_blast=args.bit_blast)

    if args.dfs: fp.set(bfs_model_search=False)

    fp.set(order_children=int(args.order_children))

    if args.array_blast:
        fp.set(array_blast=True)

    if args.array_blast_full:
        fp.set(array_blast_full=True)

    if args.use_heavy_mev:
        fp.set(use_heavy_mev=True)

    with stats.timer('Parse'):
        q = fp.parse_file(args.file)

    if len(args.trace) > 0:
        print 'Enable trace: ',
        for t in args.trace.split(':'):
            print t,
            z3.enable_trace(t)
        print
        stats.put('Trace', args.trace)
    #print fp
    with stats.timer('Query'):
        res = fp.query_from_lvl(args.from_lvl, q[0])

    if res == z3.sat: stat('Result', 'CEX')
    elif res == z3.unsat: stat('Result', 'SAFE')

    if args.answer:
        print 'The answer is:'
        print fp.get_answer()

    if res == z3.sat:
        if args.ground_answer:
            print 'A ground answer:'
            print fp.get_ground_sat_answer()
        if args.rules_along_trace:
            print 'Rules along trace:'
            print fp.get_rules_along_trace()
コード例 #22
0
def main (argv):
    stat ('Progress', 'UNKNOWN')
    os.setpgrp ()
    loadEnv (os.path.join (root, "env.common"))

    ## add directory containing this file to the PATH
    os.environ ['PATH'] =  os.path.dirname (os.path.realpath (__file__)) + \
                           os.pathsep + os.environ['PATH']
    
    seahorn_args = filter (is_seahorn_opt, argv [1:])
    z3_args = filter (is_z3_opt, argv [1:])
    argv = filter (is_non_seahorn_opt, argv [1:])

    args  = parseArgs (argv)

    workdir = createWorkDir (args.temp_dir, args.save_temps)

    in_name = args.file

    bc_out = defBCName (in_name, workdir)
    assert bc_out != in_name
    with stats.timer ('Clang'):
        extra_args = []
        if args.debug_info:
            extra_args.append ('-g')
        clang (in_name, bc_out, arch=args.machine, extra_args=extra_args)
    stat ('Progress', 'CLANG')

    in_name = bc_out

    pp_out = defPPName (in_name, workdir)
    assert pp_out != in_name
    with stats.timer ('Seapp'):
        seapp (in_name, pp_out, arch=args.machine, args=args)
    stat ('Progress', 'SEAPP')

    in_name = pp_out

    ms_out = defMSName (in_name, workdir)
    assert ms_out != in_name
    with stats.timer ('Mixed'):
        mixSem (in_name, ms_out, arch=args.machine)
    stat ('Progress', 'MIXED')

    in_name = ms_out

    opt_out = defOPTName (in_name, args.L, workdir)
    with stats.timer ('Opt'):
        llvmOpt (in_name, opt_out,
                 opt_level=args.L, time_passes=args.time_passes)
    stat ('Progress', 'OPT')

    in_name = opt_out

    smt_out = defSMTName(in_name, workdir)
    with stats.timer ('Seahorn'):
        seahorn (in_name, smt_out, seahorn_args, cex=args.cex, cpu=args.cpu, mem=args.mem)
    stat ('Progress', 'SMT2')

    if args.out_name is not None and args.out_name != smt_out:
        if verbose: print 'cp {0} {1}'.format (smt_out, args.out_name)
        shutil.copy2 (smt_out, args.out_name)

    if (args.run_z3):
        if args.use_z3_smt2: runZ3 (smt_out, z3_args)
        else: runSpacer (smt_out, args.engine, cpu=args.cpu)

    return 0
コード例 #23
0
ファイル: clam.py プロジェクト: soWhat1/crab-llvm
def main(argv):
    def stat(key, val):
        stats.put(key, val)

    os.setpgrp()
    loadEnv(os.path.join(root, "env.common"))

    ## add directory containing this file to the PATH
    os.environ ['PATH'] =  os.path.dirname(os.path.realpath(__file__)) + \
                           os.pathsep + os.environ['PATH']

    if '--llvm-version' in argv[1:] or '-llvm-version' in argv[1:]:
        print "LLVM version " + llvm_version
        return 0

    if '--clang-version' in argv[1:] or '-clang-version' in argv[1:]:
        print "Clang version " + getClangVersion(getClang(False))
        return 0

    args = parseArgs(argv[1:])
    workdir = createWorkDir(args.temp_dir, args.save_temps)
    in_name = args.file

    if args.preprocess:
        bc_out = defBCName(in_name, workdir)
        if bc_out != in_name:
            extra_args = []
            if args.debug_info: extra_args.append('-g')
            with stats.timer('Clang'):
                clang(in_name,
                      bc_out,
                      args,
                      arch=args.machine,
                      extra_args=extra_args)
            #stat('Progress', 'Clang')
        in_name = bc_out

        pp_out = defPPName(in_name, workdir)
        if pp_out != in_name:
            with stats.timer('ClamPP'):
                crabpp(in_name, pp_out, args=args, cpu=args.cpu, mem=args.mem)
            #stat('Progress', 'Clam preprocessor')
        in_name = pp_out

    if args.L > 0:
        o_out = defOptName(in_name, workdir)
        if o_out != in_name:
            extra_args = []
            with stats.timer('CrabOptLlvm'):
                optLlvm(in_name,
                        o_out,
                        args,
                        extra_args,
                        cpu=args.cpu,
                        mem=args.mem)
            #stat('Progress', 'Llvm optimizer')
        in_name = o_out

    pp_out = defOutPPName(in_name, workdir)
    with stats.timer('Clam'):
        extra_opts = []
        if args.only_preprocess:
            extra_opts.append('-no-crab')
        if args.dot_cfg:
            extra_opts.append('--clam-llvm-cfg-dot')

        clam(in_name, pp_out, args, extra_opts, cpu=args.cpu, mem=args.mem)

    #stat('Progress', 'Clam')

    if args.asm_out_name is not None and args.asm_out_name != pp_out:
        if verbose: print 'cp {0} {1}'.format(pp_out, args.asm_out_name)
        shutil.copy2(pp_out, args.asm_out_name)

    return 0
コード例 #24
0
    def checkFeas(self, expr_query):
        done = False  # flag to stop the feasibility checking
        rounds = 1  # counter for feasibility check
        self.ee_idx = self.ee_vars(expr_query)  #entr/exit vars
        self.log.info("EE VARS INDEX ..." + str(self.ee_idx))
        out = ""
        function_name = self.function_name
        while not done:
            with stats.timer('Query'):
                #if round == 0 else self.fp.query_from_lvl(12, expr_query)
                res = self.fp.query(expr_query)
                stats.stop('Query')
                self.query_times.append(str(stats.get('Query')))
                if bench:
                    print "Query | Round [" + str(
                        rounds) + "] | time  [" + str(
                            stats.get('Query')) + " ms]"
                if res == z3.sat:
                    msg = "ENTRY -> EXIT is FEASIBLE" if rounds == 1 else "STILL FEASIBLE: Continue checking ..."
                    self.log.info("( " + function_name + " ) " + msg)
                    self.feasible_flag |= set(self.ee_idx)
                    expr_query, path = self.cex(expr_query)
                    rounds += 1
                    if expr_query is None:
                        feas = list(self.feasible_flag)
                        infeas = ";".join(
                            [str(x) for x in list(self.non_feasible_flag)])
                        q_times = [float(x) for x in self.query_times]
                        q_average = sum(q_times) / len(q_times)
                        out += out_message % (function_name, "FEASIBLE", "",
                                              str(feas), infeas, str(rounds),
                                              str(q_average))
                        out = bcolors.OKGREEN + out + bcolors.ENDC
                        done = True
                elif res == z3.unsat:
                    inv = "\n-----------\n"
                    for p in self.preds:
                        lemmas = fp_get_cover_delta(self.fp, p)
                        inv += "\tBasic Block: " + str(p.decl())
                        inv += "\n\tInvariant: " + str(lemmas)
                        inv += "\n-----------\n"
                    inv_info = inv if self.args.inv else "(set --inv to get invariants info)"

                    if len(list(self.feasible_flag)) == self.flags:
                        self.log.info(" ( " + function_name + " ) FEASIBLE")
                        feas = list(self.feasible_flag)
                        q_times = [float(x) for x in self.query_times]
                        q_average = sum(q_times) / len(q_times)
                        out += out_message % (function_name, "FEASIBLE",
                                              inv_info, str(feas), "",
                                              str(rounds), str(q_average))
                        out = bcolors.OKGREEN + out + bcolors.ENDC
                    else:
                        msg = "EXIT is not FEASIBLE" if rounds == 1 else "INFEASIBLE BLOCK FOUND"
                        self.feasOut()
                        if rounds == 1:
                            self.feasible_flag.add(self.ee_idx[0])
                            self.non_feasible_flag.add(self.ee_idx[1])
                        self.log.info(" ( " + function_name + " ) " + msg)
                        feas, infeas = self.feasOut()
                        q_times = [float(x) for x in self.query_times]
                        q_average = sum(q_times) / len(q_times)
                        infeas_str = ";".join([str(x) for x in infeas])
                        out += out_message % (function_name, "INFEASIBLE",
                                              inv_info, str(feas), infeas_str,
                                              str(rounds), str(q_average))
                        out = bcolors.FAIL + out + bcolors.ENDC
                    done = True
                else:
                    out += out_message % (function_name, "UNKNOWN", "", "", "",
                                          "", "")
                    done = True
        return out
コード例 #25
0
def main(argv):
    stat('Progress', 'UNKNOWN')
    os.setpgrp()
    loadEnv(os.path.join(root, "env.common"))

    ## add directory containing this file to the PATH
    os.environ ['PATH'] =  os.path.dirname (os.path.realpath (__file__)) + \
                           os.pathsep + os.environ['PATH']

    seahorn_args = filter(is_seahorn_opt, argv[1:])
    z3_args = filter(is_z3_opt, argv[1:])
    argv = filter(is_non_seahorn_opt, argv[1:])

    args = parseArgs(argv)

    workdir = createWorkDir(args.temp_dir, args.save_temps)

    in_name = args.file

    bc_out = defBCName(in_name, workdir)
    assert bc_out != in_name
    with stats.timer('Clang'):
        extra_args = []
        if args.debug_info:
            extra_args.append('-g')
        clang(in_name, bc_out, arch=args.machine, extra_args=extra_args)
    stat('Progress', 'CLANG')

    in_name = bc_out

    pp_out = defPPName(in_name, workdir)
    assert pp_out != in_name
    with stats.timer('Seapp'):
        seapp(in_name, pp_out, arch=args.machine, args=args)
    stat('Progress', 'SEAPP')

    in_name = pp_out

    ms_out = defMSName(in_name, workdir)
    assert ms_out != in_name
    with stats.timer('Mixed'):
        mixSem(in_name, ms_out, arch=args.machine)
    stat('Progress', 'MIXED')

    in_name = ms_out

    opt_out = defOPTName(in_name, args.L, workdir)
    with stats.timer('Opt'):
        llvmOpt(in_name,
                opt_out,
                opt_level=args.L,
                time_passes=args.time_passes)
    stat('Progress', 'OPT')

    in_name = opt_out

    smt_out = defSMTName(in_name, workdir)
    with stats.timer('Seahorn'):
        seahorn(in_name,
                smt_out,
                seahorn_args,
                cex=args.cex,
                cpu=args.cpu,
                mem=args.mem)
    stat('Progress', 'SMT2')

    if args.out_name is not None and args.out_name != smt_out:
        if verbose: print 'cp {0} {1}'.format(smt_out, args.out_name)
        shutil.copy2(smt_out, args.out_name)

    if (args.run_z3):
        if args.use_z3_smt2: runZ3(smt_out, z3_args)
        else: runSpacer(smt_out, args.engine, cpu=args.cpu)

    return 0
コード例 #26
0
def main (argv):
    args = parseArgs (argv[1:])
    stat ('Result', 'UNKNOWN')

    z3_args = which ('z3')

    if z3_args is None:
        print 'No executable named "z3" found in current directory or PATH'
        return

    z3_args += ' -v:' + str(args.verbose)

    if not args.slice:
        print 'No slicing'
        z3_args += ' fixedpoint.slice=false'

    if not args.inline:
        print 'No inlining'
        z3_args += ' fixedpoint.inline_linear=false'
        z3_args += ' fixedpoint.inline_eager=false'

    print 'Engine: ', args.engine

    if (args.validate):
        z3_args += ' fixedpoint.validate_result=true'

    if (args.answer):
        z3_args += ' fixedpoint.print_answer=true'

    z3_args += ' fixedpoint.engine='
    z3_args += args.engine

    if args.no_utvpi:
        z3_args += ' fixedpoint.use_utvpi=false'

    if args.lazy_reach_check:
        z3_args += ' fixedpoint.eager_reach_check=false'

    if args.validate_theory_core:
        z3_args += ' fixedpoint.validate_theory_core=true'

    if args.print_stats:
        z3_args += ' fixedpoint.print_statistics=true'

    if args.dfs:
        z3_args += ' fixedpoint.bfs_model_search=false'

    if int(args.order_children)==1:
        z3_args += ' fixedpoint.order_children=1'

    if args.array_blast:
        z3_args += ' fixedpoint.array_blast=true'

    if args.array_blast_full:
        z3_args += ' fixedpoint.array_blast_full=true'

    if args.use_heavy_mev:
        z3_args += ' fixedpoint.use_heavy_mev=true'

    if args.flexible_trace:
        z3_args += ' fixedpoint.flexible_trace=true'

    z3_args += ' ' + args.file


    if len(args.trace) > 0:
        print 'Enable trace: ',
        for t in args.trace.split (':'):
            print t,
            z3_args += ' -tr:{}'.format (t)
        print 
        stats.put ('Trace', args.trace)

    print z3_args

    with stats.timer ('Query'):
        popen = subprocess.Popen(z3_args.split (), stdout=subprocess.PIPE)
        popen.wait()
        res = popen.stdout.read()
    if 'unsat' in res:
        res = 'unsat'
    elif 'sat' in res:
        res = 'sat'
    else:
        res = 'unknown'
    print 'Result:', res

    if res == 'sat':
        if args.smt2lib: stat ('Result', 'SAFE')
        else: stat ('Result', 'CEX')
    elif res == 'unsat':
        if args.smt2lib: stat ('Result', 'CEX')
        else: stat ('Result', 'SAFE')