def main(argv): progname = os.path.basename(argv[0]) # parse arguments opt = parse_arguments(argv[1:]) # setup colors and logging colors.setup(opt.color, file=log.out) log.setup(opt.log_level) if not os.path.isfile(opt.file): printf("%s: error: no such file: \'%s\'\n", progname, opt.file, file=sys.stderr) sys.exit(1) try: # open result database db = OutputDatabase(opt.file) v = View(db, port=opt.port) browser_timer = threading.Timer(0.1, open_browser, ['http://localhost:%d/' % opt.port]) browser_timer.start() v.serve() # close database db.close() except sqlite3.DatabaseError as e: printf('%s: error: %s\n', progname, e, file=sys.stderr) sys.exit(1)
def main(argv): progname = os.path.basename(argv[0]) start_date = datetime.datetime.now() # parse arguments opt = parse_arguments(argv[1:]) # setup colors and logging colors.setup(opt.color, file=log.out) log.setup(opt.log_level) if is_apron_domain(opt.domain) and not settings.HAS_APRON: printf( '%s: error: cannot use apron abstract domains.\n' 'ikos was compiled without apron support, ' 'see analyzer/README.md\n', progname, file=sys.stderr) sys.exit(1) # create working directory wd = create_working_directory(opt.temp_dir, opt.save_temps) input_path = opt.file # compile c/c++ code if path_ext(input_path) in c_extensions + cpp_extensions: bc_path = namer(opt.file, '.bc', wd) try: with stats.timer('clang'): clang(bc_path, input_path, opt.compiler_include_flags, opt.compiler_define_flags, opt.compiler_warning_flags, opt.compiler_disable_warnings, opt.compiler_machine_flags, colors.ENABLE) except subprocess.CalledProcessError as e: printf('%s: error while compiling %s, abort.\n', progname, input_path, file=sys.stderr) sys.exit(e.returncode) input_path = bc_path if path_ext(input_path) not in llvm_extensions: printf('%s: error: unexpected file extension.\n', progname, file=sys.stderr) sys.exit(1) # ikos-pp: preprocess llvm bitcode pp_path = namer(opt.file, '.pp.bc', wd) try: with stats.timer('ikos-pp'): ikos_pp(pp_path, input_path, opt.entry_points, opt.opt_level, opt.inline_all, not opt.no_bc_verify) except subprocess.CalledProcessError as e: printf('%s: error while preprocessing llvm bitcode, abort.\n', progname, file=sys.stderr) sys.exit(e.returncode) # display the llvm bitcode, if requested if opt.display_llvm: display_llvm(pp_path) # ikos-analyzer: analyze llvm bitcode try: with stats.timer('ikos-analyzer'): ikos_analyzer(opt.output_db, pp_path, opt) except AnalyzerError as e: printf('%s: error: %s\n', progname, e, file=sys.stderr) sys.exit(e.returncode) # open output database db = OutputDatabase(path=opt.output_db) # insert timing results in the database db.insert_timing_results(stats.rows()) # insert settings in the database settings_rows = [ ('version', settings.VERSION), ('start-date', start_date.isoformat(' ')), ('end-date', datetime.datetime.now().isoformat(' ')), ('working-directory', wd), ('input', opt.file), ('bc-file', input_path), ('pp-bc-file', pp_path), ('clang', settings.clang()), ('ikos-pp', settings.ikos_pp()), ('opt-level', opt.opt_level), ('inline-all', json.dumps(opt.inline_all)), ('use-libc-intrinsics', json.dumps(not opt.no_libc)), ('use-libcpp-intrinsics', json.dumps(not opt.no_libcpp)), ('use-libikos-intrinsics', json.dumps(not opt.no_libikos)), ('use-simplify-cfg', json.dumps(not opt.no_simplify_cfg)), ('use-simplify-upcast-comparison', json.dumps(not opt.no_simplify_upcast_comparison)), ] if opt.cpu: settings_rows.append(('cpu-limit', opt.cpu)) if opt.mem: settings_rows.append(('mem-limit', opt.mem)) db.insert_settings(settings_rows) first = (log.LEVEL >= log.ERROR) # display timing results if opt.display_times != 'no': if not first: printf('\n') report.print_timing_results(db, opt.display_times == 'full') first = False # display summary if opt.display_summary != 'no': if not first: printf('\n') report.print_summary(db, opt.display_summary == 'full') first = False # display raw checks if opt.display_raw_checks: if not first: printf('\n') report.print_raw_checks(db, opt.procedural == 'inter') first = False # start ikos-view if opt.format == 'web': ikos_view(opt, db) return # report if opt.format != 'no': if not first and opt.report_file is sys.stdout: printf('\n' + colors.bold('# Results') + '\n') first = False # setup colors again (in case opt.color = 'auto') colors.setup(opt.color, file=opt.report_file) # generate report rep = report.generate_report(db, status_filter=opt.status_filter, analyses_filter=None) # format report formatter_class = report.formats[opt.format] formatter = formatter_class(opt.report_file, opt.report_verbosity) formatter.format(rep) # close database db.close() if opt.remove_db: os.remove(opt.output_db)