-
Notifications
You must be signed in to change notification settings - Fork 147
Cleanup RMC Flags #332
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
Merged
vecchiot-aws
merged 14 commits into
model-checking:main-153-2021-07-15
from
vecchiot-aws:cleanup-rmc-flags
Jul 26, 2021
+182
−72
Merged
Cleanup RMC Flags #332
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c83bb92
Initial draft.
vecchiot-aws 297df83
Add help strings to flags.
vecchiot-aws c5ccf3a
Add copyright.
vecchiot-aws a767aae
PR review updates.
vecchiot-aws c83a854
Switch warn to fail on unsupported flags.
vecchiot-aws b31b916
Added help messages for --wkdir and --srcdir
vecchiot-aws 68abdb4
Add documentation and rearrange error handling.
vecchiot-aws 222952f
Fix incorrect 'exclude_flags' value in cargo-rmc.
vecchiot-aws c34879e
Changes from deep dive.
vecchiot-aws abb630f
Rearrange, and add documentation.
vecchiot-aws 60e922d
Fix typo.
vecchiot-aws ce727b4
Fix formatting of help strings to be consistent.
vecchiot-aws 8cee0fa
Add reasons for excluding flags.
vecchiot-aws d42f987
Sorted flags alphabetically.
vecchiot-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
|
||
| import argparse | ||
|
|
||
| # Add flags related to debugging output. | ||
| def add_loudness_flags(make_group, add_flag, config): | ||
| group = make_group( | ||
| "Loudness flags", "Determine how much textual output to produce.") | ||
| add_flag(group, "--debug", action="store_true", | ||
| help="Produce full debug information") | ||
| add_flag(group, "--quiet", "-q", action="store_true", | ||
| help="Produces no output, just an exit code and requested artifacts; overrides --verbose") | ||
| add_flag(group, "--verbose", "-v", action="store_true", | ||
| help="Output processing stages and commands, along with minor debug information") | ||
|
|
||
| # Add flags which specify configurations for the proof. | ||
| def add_linking_flags(make_group, add_flag, config): | ||
| group = make_group("Linking flags", | ||
| "Provide information about how to link the prover for RMC.") | ||
| add_flag(group, "--c-lib", nargs="*", default=[], action="extend", | ||
| help="Link external C files referenced by Rust code") | ||
| add_flag(group, "--function", default="main", | ||
| help="Entry point for verification") | ||
|
|
||
| # Add flags that produce extra artifacts. | ||
| def add_artifact_flags(make_group, add_flag, config): | ||
| default_target = config["default-target"] | ||
| assert default_target is not None, \ | ||
| f"Missing item in parser config: \"default-target\".\n" \ | ||
| "This is a bug; please report this to https://github.com/model-checking/rmc/issues." | ||
|
|
||
| group = make_group( | ||
| "Artifact flags", "Produce artifacts in addition to a basic RMC report.") | ||
| add_flag(group, "--gen-c", action="store_true", | ||
| help="Generate C file equivalent to inputted program") | ||
| add_flag(group, "--gen-symbols", action="store_true", | ||
| help="Generate a goto symbol table") | ||
| add_flag(group, "--keep-temps", action="store_true", | ||
| help="Keep temporary files generated throughout RMC process") | ||
| add_flag(group, "--target-dir", default=default_target, metavar="DIR", | ||
| help=f"Directory for all generated artifacts; defaults to \"{default_target}\"") | ||
|
|
||
| # Add flags to turn off default checks. | ||
| def add_check_flags(make_group, add_flag, config): | ||
| group = make_group("Check flags", "Disable some or all default checks.") | ||
| add_flag(group, "--no-default-checks", action="store_true", | ||
| help="Disable all default checks") | ||
| add_flag(group, "--no-memory-safety-checks", action="store_true", | ||
| help="Disable default memory safety checks") | ||
| add_flag(group, "--no-overflow-checks", action="store_true", | ||
| help="Disable default overflow checks") | ||
| add_flag(group, "--no-unwinding-checks", action="store_true", | ||
| help="Disable default unwinding checks") | ||
|
|
||
| # Add flags needed only for visualizer. | ||
| def add_visualizer_flags(make_group, add_flag, config): | ||
| group = make_group( | ||
| "Visualizer flags", "Generate an HTML-based UI for the generated RMC report.\nSee https://github.com/awslabs/aws-viewer-for-cbmc.") | ||
| add_flag(group, "--srcdir", default=".", | ||
| help="The source directory: the root of the source tree") | ||
| add_flag(group, "--visualize", action="store_true", | ||
| help="Generate visualizer report to <target-dir>/report/html/index.html") | ||
| add_flag(group, "--wkdir", default=".", | ||
| help=""" | ||
| The working directory: used to determine source locations in output; | ||
| this is generally the location from which rmc is currently being invoked | ||
| """) | ||
|
|
||
| # Add flags for ad-hoc features. | ||
| def add_other_flags(make_group, add_flag, config): | ||
| group = make_group("Other flags") | ||
| add_flag(group, "--allow-cbmc-verification-failure", action="store_true", | ||
| help="Do not produce error return code on CBMC verification failure") | ||
| add_flag(group, "--dry-run", action="store_true", | ||
| help="Print commands instead of running them") | ||
|
|
||
| # Add flags we don't expect end-users to use. | ||
| def add_developer_flags(make_group, add_flag, config): | ||
| group = make_group( | ||
| "Developer flags", "These are generally meant for use by RMC developers, and are not stable.") | ||
| add_flag(group, "--cbmc-args", nargs=argparse.REMAINDER, default=[], | ||
| help="Pass through directly to CBMC; must be the last flag") | ||
| add_flag(group, "--mangler", default="v0", choices=["v0", "legacy"], | ||
| help="Change what mangler is used by the Rust compiler") | ||
|
|
||
| # Adds the flags common to both rmc and cargo-rmc. | ||
| # Allows you to specify flags/groups of flags to not add. | ||
| # This does not return the parser, but mutates the one provided. | ||
| def add_flags(parser, config, exclude_flags=[], exclude_groups=[]): | ||
| # Keep track of what excluded flags and groups we've seen | ||
| # so we can warn for possibly incorrect names passed in. | ||
| excluded_flags = set() | ||
| excluded_groups = set() | ||
|
|
||
| # Add a group to the parser with title/description, and get a handler for it. | ||
| def make_group(title=None, description=None): | ||
| if title in exclude_groups: | ||
| excluded_groups.add(group.title) | ||
| return None | ||
|
|
||
| return parser.add_argument_group(title, description) | ||
|
|
||
| # Add the flag to the group, | ||
| def add_flag(group, flag, *args, **kwargs): | ||
| if group == None: | ||
| return | ||
|
|
||
| if flag in exclude_flags: | ||
| excluded_flags.add(flag) | ||
| return | ||
|
|
||
| group.add_argument(flag, *args, **kwargs) | ||
|
|
||
| add_groups = [ | ||
| add_loudness_flags, | ||
| add_linking_flags, | ||
| add_artifact_flags, | ||
| add_check_flags, | ||
| add_visualizer_flags, | ||
| add_other_flags, | ||
| add_developer_flags | ||
| ] | ||
|
|
||
| for add_group in add_groups: | ||
| add_group(make_group, add_flag, config) | ||
|
|
||
| # Error if any excluded flags/groups don't exist. | ||
| extra_flags = set(exclude_flags) - excluded_flags | ||
| extra_groups = set(exclude_groups) - excluded_groups | ||
| assert len(extra_flags.union(extra_groups)) == 0, \ | ||
| f"Attempt to exclude parser options which don't exist: {extra_groups.union(extra_flags)}\n" \ | ||
| "This is a bug; please report this to https://github.com/model-checking/rmc/issues." |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this specify in the last position?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't have to be in the last position; actually putting it first can avoid issues with flags that take multiple arguments. The only thing that really matters is
--cbmc-argslast, or else some RMC flags might be interpretted as CBMC flags.