def extract_parse_arguments(argv): usage = '%(prog)s [options] file' description = 'Extract the llvm bitcode generated for a given file' formatter_class = argparse.RawTextHelpFormatter parser = argparse.ArgumentParser(usage=usage, description=description, formatter_class=formatter_class) # Positional arguments parser.add_argument('input', metavar='file', help='Input file') # Optional arguments parser.add_argument('-o', dest='output', metavar='<file>', help='Output file') parser.add_argument('-v', dest='verbosity', help='Increase verbosity', action='count', default=1) parser.add_argument('-q', dest='verbosity', help='Be quiet', action='store_const', const=0) parser.add_argument('--version', action=args.VersionAction, nargs=0, help='Show ikos version') parser.add_argument('--color', dest='color', metavar='', help=args.help('Enable terminal colors:', args.color_choices, args.default_color), choices=args.choices(args.color_choices), default=args.default_color) parser.add_argument('--log', dest='log_level', metavar='', help=args.help('Log level:', args.log_levels, args.default_log_level), choices=args.choices(args.log_levels), default=None) opt = parser.parse_args(argv) # verbosity changes the log level, if --log is not specified if opt.log_level is None: if opt.verbosity <= 0: opt.log_level = 'error' elif opt.verbosity == 1: opt.log_level = 'info' elif opt.verbosity == 2: opt.log_level = 'debug' else: opt.log_level = 'all' return opt
def parse_arguments(argv): usage = '%(prog)s [options] file.db' description = 'Launch ikos view on an output database' formatter_class = argparse.RawTextHelpFormatter parser = argparse.ArgumentParser(usage=usage, description=description, formatter_class=formatter_class) # Positional arguments parser.add_argument('file', metavar='file.db', help='Result database') # Optional arguments parser.add_argument('--version', action=args.VersionAction, nargs=0, help='Show ikos version') parser.add_argument('--color', dest='color', metavar='', help=args.help('Enable terminal colors:', args.color_choices, args.default_color), choices=args.choices(args.color_choices), default=args.default_color) parser.add_argument('--log', dest='log_level', metavar='', help=args.help('Log level:', args.log_levels, args.default_log_level), choices=args.choices(args.log_levels), default='info') parser.add_argument('--port', dest='port', metavar='', help='Listening port', default=8080, type=int) return parser.parse_args(argv)
def parse_arguments(argv): usage = '%(prog)s [options] file[.c|.cpp|.bc|.ll]' description = 'ikos static analyzer' formatter_class = argparse.RawTextHelpFormatter parser = argparse.ArgumentParser(usage=usage, description=description, formatter_class=formatter_class) # Positional arguments parser.add_argument('file', metavar='file[.c|.cpp|.bc|.ll]', help='File to analyze') # Optional arguments parser.add_argument('-o', '--output-db', dest='output_db', metavar='<file>', help='Output database file (default: output.db)', default='output.db') parser.add_argument('-v', dest='verbosity', help='Increase verbosity', action='count', default=1) parser.add_argument('-q', dest='verbosity', help='Be quiet', action='store_const', const=0) parser.add_argument('--version', action=args.VersionAction, nargs=0, help='Show ikos version') # Analysis options analysis = parser.add_argument_group('Analysis Options') analysis.add_argument('-a', '--analyses', dest='analyses', metavar='', help=args.help('Available analyses:', args.analyses, args.default_analyses), action='append') analysis.add_argument('-d', '--domain', dest='domain', metavar='', help=args.help('Available abstract domains:', args.domains, args.default_domain), choices=args.choices(args.domains), default=args.default_domain) analysis.add_argument('-e', '--entry-points', dest='entry_points', metavar='<function>', help='List of program entry points (default: main)', action='append') analysis.add_argument('--globals-init', dest='globals_init', metavar='', help=args.help( 'Policy of initialization for global variables:', args.globals_init_policies, args.default_globals_init_policy), choices=args.choices(args.globals_init_policies), default=args.default_globals_init_policy) analysis.add_argument('--no-init-globals', dest='no_init_globals', metavar='<function>', help='Do not initialize global variables for the ' 'given entry points', action='append') analysis.add_argument('--no-liveness', dest='no_liveness', help='Disable the liveness analysis', action='store_true', default=False) analysis.add_argument('--no-pointer', dest='no_pointer', help='Disable the pointer analysis', action='store_true', default=False) analysis.add_argument('--no-widening-hints', dest='no_widening_hints', help='Disable the widening hint analysis', action='store_true', default=False) analysis.add_argument('--no-fixpoint-cache', dest='no_fixpoint_cache', help='Disable the cache of fixpoints', action='store_true', default=False) analysis.add_argument('--no-checks', dest='no_checks', help='Disable all the checks', action='store_true', default=False) analysis.add_argument('--proc', dest='procedural', metavar='', help=args.help('Procedural:', args.proceduralities, args.default_procedurality), choices=args.choices(args.proceduralities), default=args.default_procedurality) analysis.add_argument('-j', '--jobs', dest='jobs', metavar='', nargs='?', help='Number of threads', type=int, const=0, default=1) analysis.add_argument('--widening-strategy', dest='widening_strategy', metavar='', help=args.help('Strategy for increasing iterations:', args.widening_strategies, args.default_widening_strategy), choices=args.choices(args.widening_strategies), default=args.default_widening_strategy) analysis.add_argument('--narrowing-strategy', dest='narrowing_strategy', metavar='', help=args.help('Strategy for decreasing iterations:', args.narrowing_strategies, args.default_narrowing_strategy), choices=args.choices(args.narrowing_strategies), default=args.default_narrowing_strategy) analysis.add_argument('--widening-delay', dest='widening_delay', metavar='', help='Number of loop iterations before using the' ' widening strategy (default: %d)' % args.default_widening_delay, default=args.default_widening_delay, type=args.Integer(min=0)) analysis.add_argument('--widening-delay-functions', dest='widening_delay_functions', metavar='<function:int>', help='Widening delay for specific functions', action='append') analysis.add_argument('--widening-period', dest='widening_period', metavar='', help='Number of loop iterations between each' ' widening (default: %d)' % args.default_widening_period, default=args.default_widening_period, type=args.Integer(min=1)) analysis.add_argument('--narrowing-iterations', dest='narrowing_iterations', metavar='', help='Perform a fixed number of narrowing' ' iterations', type=args.Integer(min=0)) analysis.add_argument('--partitioning', dest='partitioning', metavar='', help=args.help('Partitioning strategy:', args.partitioning_strategies, args.default_partitioning_strategy), choices=args.choices(args.partitioning_strategies), default=args.default_partitioning_strategy) analysis.add_argument('--hardware-addresses', dest='hardware_addresses', metavar='', action='append', help='Specify ranges (x-y) of hardware addresses' ', separated by a comma') analysis.add_argument('--hardware-addresses-file', dest='hardware_addresses_file', metavar='', help='Specify ranges (x-y) of hardware addresses' ' from a file (one range per line)') analysis.add_argument('--argc', dest='argc', metavar='', help='Specify a value for argc', type=args.Integer(min=0)) # Compile options compiler = parser.add_argument_group('Compile Options') compiler.add_argument('-I', dest='compiler_include_flags', metavar='', help='Add the specified directory to the search ' 'path for include files', action='append') compiler.add_argument('-D', dest='compiler_define_flags', metavar='', help='Add an implicit #define into the source file', action='append') compiler.add_argument('-W', dest='compiler_warning_flags', metavar='', help='Use the specified warning options', action='append') compiler.add_argument('-w', dest='compiler_disable_warnings', help='Suppress all compiler warnings', action='store_true', default=False) compiler.add_argument('-m', dest='compiler_machine_flags', metavar='', help='Use the specified machine options', action='append') # Preprocessing options preprocess = parser.add_argument_group('Preprocessing Options') preprocess.add_argument('--opt', dest='opt_level', metavar='', help=args.help('Optimization level:', args.opt_levels, args.default_opt_level), choices=args.choices(args.opt_levels), default=args.default_opt_level) preprocess.add_argument('--inline-all', dest='inline_all', help='Front-end inline all functions', action='store_true', default=False) preprocess.add_argument('--no-bc-verify', dest='no_bc_verify', help='Do not run the LLVM bitcode verifier', action='store_true', default=False) # Import options imports = parser.add_argument_group('Import Options') imports.add_argument('--no-libc', dest='no_libc', help='Do not use libc intrinsics ' '(malloc, free, etc.)', action='store_true', default=False) imports.add_argument('--no-libcpp', dest='no_libcpp', help='Do not use libcpp intrinsics ' '(__cxa_throw, etc.)', action='store_true', default=False) imports.add_argument('--no-libikos', dest='no_libikos', help='Do not use ikos intrinsics ' '(__ikos_assert, etc.)', action='store_true', default=False) # AR passes options passes = parser.add_argument_group('AR Passes Options') passes.add_argument('--no-type-check', dest='no_type_check', help='Do not run the AR type checker', action='store_true', default=False) passes.add_argument('--no-simplify-cfg', dest='no_simplify_cfg', help='Do not run the simplify-cfg pass', action='store_true', default=False) passes.add_argument('--no-simplify-upcast-comparison', dest='no_simplify_upcast_comparison', help='Do not run the simplify-upcast-comparison pass', action='store_true', default=False) # Debug options debug = parser.add_argument_group('Debug Options') debug.add_argument('--display-llvm', dest='display_llvm', help='Display the LLVM bitcode as text', action='store_true', default=False) debug.add_argument('--display-ar', dest='display_ar', help='Display the Abstract Representation as text', action='store_true', default=False) debug.add_argument('--display-liveness', dest='display_liveness', help='Display liveness analysis results', action='store_true', default=False) debug.add_argument('--display-function-pointer', dest='display_function_pointer', help='Display function pointer analysis results', action='store_true', default=False) debug.add_argument('--display-pointer', dest='display_pointer', help='Display pointer analysis results', action='store_true', default=False) debug.add_argument('--display-fixpoint-parameters', dest='display_fixpoint_parameters', help='Display fixpoint parameters', action='store_true', default=False) debug.add_argument('--display-checks', dest='display_checks', metavar='', help=args.help('Display checks:', args.display_checks_choices, 'no'), choices=args.choices(args.display_checks_choices), default='no') debug.add_argument('--display-inv', dest='display_inv', metavar='', help=args.help('Display computed invariants:', args.display_inv_choices, 'no'), choices=args.choices(args.display_inv_choices), default='no') debug.add_argument('--display-raw-checks', dest='display_raw_checks', help='Display analysis raw checks', action='store_true', default=False) debug.add_argument('--generate-dot', dest='generate_dot', help='Generate a .dot file for each function', action='store_true', default=False) debug.add_argument('--generate-dot-dir', dest='generate_dot_dir', metavar='<directory>', help='Output directory for .dot files', default=None) debug.add_argument('--save-temps', dest='save_temps', help='Do not delete temporary files', action='store_true', default=False) debug.add_argument('--temp-dir', dest='temp_dir', metavar='<directory>', help='Temporary directory', default=None) # Misc. misc = parser.add_argument_group('Miscellaneous') misc.add_argument('--rm-db', dest='remove_db', help='Remove the output database file after use', action='store_true', default=False) misc.add_argument('--color', dest='color', metavar='', help=args.help('Enable terminal colors:', args.color_choices, args.default_color), choices=args.choices(args.color_choices), default=args.default_color) misc.add_argument('--log', dest='log_level', metavar='', help=args.help('Log level:', args.log_levels, args.default_log_level), choices=args.choices(args.log_levels), default=None) misc.add_argument('--progress', dest='progress', metavar='', help=args.help('Progress report:', args.progress_choices, args.default_progress), choices=args.choices(args.progress_choices), default=args.default_progress) # Report options report = parser.add_argument_group('Report Options') report.add_argument('--display-times', dest='display_times', metavar='', help=args.help('Display timing results', args.display_times_choices, 'short'), choices=args.choices(args.display_times_choices), default='short') report.add_argument('--display-summary', dest='display_summary', metavar='', help=args.help('Display the analysis summary', args.display_summary_choices, 'full'), choices=args.choices(args.display_summary_choices), default='full') report.add_argument('-f', '--format', dest='format', metavar='', help=args.help('Available report formats:', args.report_formats, 'auto'), choices=args.choices(args.report_formats), default='auto') report.add_argument('--report-file', dest='report_file', metavar='<file>', help='Write the report into a file (default: stdout)', default=sys.stdout, type=argparse.FileType('w')) report.add_argument('--status-filter', dest='status_filter', metavar='', help=args.help('Available status filters:', args.status_filters, args.default_status_filter), action='append') report.add_argument('--report-verbosity', dest='report_verbosity', metavar='[1-4]', help='Report verbosity (default: 1)', type=args.Integer(min=1, max=4)) # Resource options resource = parser.add_argument_group('Resources Options') resource.add_argument('--cpu', dest='cpu', help='CPU time limit (seconds)', type=args.Integer(min=1)) resource.add_argument('--mem', dest='mem', help='MEM limit (MB)', type=args.Integer(min=1)) opt = parser.parse_args(argv) # parse --analyses opt.analyses = args.parse_argument(parser, 'analyses', choices=args.analyses, groups=None, default=args.default_analyses, value=opt.analyses) # by default, the entry point is main if not opt.entry_points: opt.entry_points = ('main', ) # verbosity changes the log level, if --log is not specified if opt.log_level is None: if opt.verbosity <= 0: opt.log_level = 'error' elif opt.verbosity == 1: opt.log_level = 'info' elif opt.verbosity == 2: opt.log_level = 'debug' else: opt.log_level = 'all' # quiet mode does not display the timing results and the analysis summary if opt.verbosity <= 0: opt.display_times = 'no' opt.display_summary = 'no' # default value for generate-dot-dir if opt.generate_dot and not opt.generate_dot_dir: if opt.temp_dir and opt.save_temps: opt.generate_dot_dir = opt.temp_dir else: opt.generate_dot_dir = '.' # parse --status-filter opt.status_filter = args.parse_argument(parser, 'status-filter', choices=args.status_filters, groups=None, default=args.default_status_filter, value=opt.status_filter) # verbosity changes the report verbosity level, # if --report-verbosity is not specified if opt.report_verbosity is None: opt.report_verbosity = max(opt.verbosity, 1) return opt
def parse_arguments(argv): usage = '%(prog)s [options] command' description = 'python helper to analyze whole C/C++ projects' formatter_class = argparse.RawTextHelpFormatter parser = argparse.ArgumentParser(usage=usage, description=description, formatter_class=formatter_class) # Positional arguments parser.add_argument('args', nargs=argparse.REMAINDER, help=argparse.SUPPRESS) # Optional arguments parser.add_argument('-v', dest='verbosity', help='Increase verbosity', action='count', default=1) parser.add_argument('-q', dest='verbosity', help='Be quiet', action='store_const', const=0) parser.add_argument('--version', action=args.VersionAction, nargs=0, help='Show ikos version') parser.add_argument('--color', dest='color', metavar='', help=args.help('Enable terminal colors:', args.color_choices, args.default_color), choices=args.choices(args.color_choices), default=args.default_color) parser.add_argument('--log', dest='log_level', metavar='', help=args.help('Log level:', args.log_levels, args.default_log_level), choices=args.choices(args.log_levels), default=None) opt = parser.parse_args(argv) # remove leading '--' while opt.args and opt.args[0] == '--': opt.args.pop(0) if not opt.args: parser.error("too few arguments") # verbosity changes the log level, if --log is not specified if opt.log_level is None: if opt.verbosity <= 0: opt.log_level = 'error' elif opt.verbosity == 1: opt.log_level = 'info' elif opt.verbosity == 2: opt.log_level = 'debug' else: opt.log_level = 'all' return opt