Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: use argparse to parse CLI options #242

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MichalHe
Copy link
Contributor

Rewrites CLI options parsing from getopt to argparse (based on the FIXME comment above).

@MichalHe
Copy link
Contributor Author

@lzaoral Hi. Could you have a look whether you see something wrong with the patch conceptually, e.g. the FIXME comment about transition to argparse does not hold anymore? I have opened this PR before the migration is fully finished so I can gather your feedback before I invest too much effort into the wrong direction 😸

Copy link
Contributor

@lzaoral lzaoral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks A LOT, @MichalHe for this effort! Minor nits inline. It would be nice to use multiline strings for the help messages (so that you don't have to escape the ' and the newlines are redundant), do some parsing for the comma-separated lists, use metavals for options that take arguments, and maybe group related options into argument groups?

You can look into https://gist.github.com/lzaoral/6872728c1af2eb28d85b85f2baf81d6b for the inspiration (comma-separated list parsing, options you haven't ported yet, some additional kwargs for options you've already ported and maybe some tweaks to the help messages). I've actually started the migration like an year ago but since then I did not have the time or need to finish it so this gist is all I've done.

Comment on lines +337 to +347
arg_parser.add_argument('--verifier', metavar='VERIFIER_TOOL',
choices=['Ceagle', 'KLEE', 'CPAchecker', 'Seahorn', 'Skink', 'Smack'],
help=('Use the tool \'name\'. Default is KLEE, other tools that\n'
'can be integrated are Ceagle, CPAchecker, Seahorn,\n'
'Skink and SMACK.'))

arg_parser.add_argument('--target', metavar='VERIFIER_TOOL',
choices=['Ceagle', 'KLEE', 'CPAchecker', 'Seahorn', 'Skink', 'Smack'],
help=('Use the tool \'name\'. Default is KLEE, other tools that\n'
'can be integrated are Ceagle, CPAchecker, Seahorn,\n'
'Skink and SMACK. Synonymous to --verifier.'))
Copy link
Contributor

@lzaoral lzaoral Dec 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can combine these options into one:

Suggested change
arg_parser.add_argument('--verifier', metavar='VERIFIER_TOOL',
choices=['Ceagle', 'KLEE', 'CPAchecker', 'Seahorn', 'Skink', 'Smack'],
help=('Use the tool \'name\'. Default is KLEE, other tools that\n'
'can be integrated are Ceagle, CPAchecker, Seahorn,\n'
'Skink and SMACK.'))
arg_parser.add_argument('--target', metavar='VERIFIER_TOOL',
choices=['Ceagle', 'KLEE', 'CPAchecker', 'Seahorn', 'Skink', 'Smack'],
help=('Use the tool \'name\'. Default is KLEE, other tools that\n'
'can be integrated are Ceagle, CPAchecker, Seahorn,\n'
'Skink and SMACK. Synonymous to --verifier.'))
arg_parser.add_argument('--target', '--verifier', default='klee', ...)

Also, since KLEE is the default, it should be reflected using the default kwarg. Don't forget to update the help message.

I'm not that familiar with this part of Symbiotic, but the list of all supported verifiers should be stored in the following dictionary, so the current choices in the argument won't actually work (@mchalupa can you please confirm?):

targets = {
'klee': KleeTool,
'ceagle': CeagleTool,
'ikos': IkosTool,
'cbmc': CbmcTool,
'cbmc-svcomp': CbmcSVCOMPTool,
'esbmc': EsbmcTool,
'map2check': Map2CheckTool,
'cpachecker': CpaTool,
'cpa': CpaTool,
'skink': SkinkTool,
'smack': SmackTool,
'seahorn': SeahornTool,
'nidhugg': NidhuggTool,
'divine': DivineTool,
'divine-svcomp': DivineSvcompTool,
'ultimateautomizer': UltimateTool,
'ultimate': UltimateTool,
'uautomizer': UltimateTool,
'ua': UltimateTool,
'svcomp': SVCompTool,
'testcomp': TestCompTool,
'slowbeast': SlowbeastTool,
'sb': SlowbeastTool,
'predatorhp': PredatorHPTool,
'predator': PredatorTool,
'2ls': TwolsTool,
'cc': CCTarget
}

Comment on lines +249 to +253
# TODO(MichalHe): @review maybe it should be more robust to use choices here
arg_parser.add_argument('--no-link', metavar='CATEGORIES',
help=('Do not link missing functions from the given category\n'
'(libc, svcomp, verifier, posix, kernel). The argument\n'
'is a comma-separated list of values.'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, categories would be awesome! The list is the following (without symbitoicpy): https://github.com/staticafi/symbiotic/tree/main/lib

Comment on lines +259 to +260
# TODO(MichalHe): @review Original docs contain a fragment `but continue searching` after the end of sentence.
# maybe a left over?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Yes, that was a leftover from 7e32ff8.

Comment on lines +244 to +247
arg_parser.add_argument('--dump-env', action='store_true',
default=False, help='Only dump environment variables (for debugging)')
arg_parser.add_argument('--dump-env-cmd', action='store_true',
default=False, help='Dump environment variables for using them in command line')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. default values for store_X are redundant.

Comment on lines +277 to +281
arg_parser.add_argument('--malloc-never-fails', action='store_true', default=False,
help='Suppose malloc and calloc never return NULL')
arg_parser.add_argument('--undefines-are-pure', action='store_true', default=False,
help='Suppose that undefined functions have no side-effects')
arg_parser.add_argument('--statistics', action='store_true', default=False, help='Dump statistics about bitcode')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Comment on lines +296 to +298
# # TODO(MichalHe): @review Missing docs.
arg_parser.add_argument('--cc', dest='run_in_cc_mode', default=False,
help='')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mchalupa any ideas? I've never used this option myself.

Comment on lines +300 to +302
# # TODO(MichalHe): @review Docs filled in.
arg_parser.add_argument('--link', default='', metavar='LINKFILES',
help='A comma separated list of extra link files.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to expand the help message with a description of the format these file should be in.

""" Return a tuple (VERSION, versions, llvm_versions) """
""" Return a tuple (VERSION, versions, llvm_versions) """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably committed by a mistake.

@lzaoral lzaoral linked an issue Dec 23, 2022 that may be closed by this pull request
@lzaoral
Copy link
Contributor

lzaoral commented Dec 23, 2022

On a second thought, the argument groups in the linked gist are not really thought through, something like: compilation, slicing, instrumentation, optimization, verification, etc... would be better a better distinction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use argparse for parsing arguments
2 participants