-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreduce.py
executable file
·62 lines (48 loc) · 1.77 KB
/
reduce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# -------------------------------------
# ClangBuiltLinux/misc-scripts/reduce
# Author: Justin Stitt <[email protected]
# As Part Of: ClangBuiltLinux and Google LLC
# License: Apache v2.0 -- see ./LICENSE
# -------------------------------------
import argparse
import sys
from src import flags, prep
VERSION = "0.2.1"
def parse_cli_args() -> argparse.Namespace:
"""
Parse out CLI args for top-level script `reduce` other scripts have their
own CLI arg parsing
"""
parser = argparse.ArgumentParser(
prog="reduce",
description=f"reduce v{VERSION}",
usage="python3 reduce.py [prep | flags | -h]",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
subparsers = parser.add_subparsers(required=True)
flags_parser = subparsers.add_parser(
"flags",
description="A script to minimize the CC flags required to reproduce "
"behavior. Use after $ python reduce prep",
)
flags.FlagReducer.setup_argparser(flags_parser)
flags_parser.set_defaults(func=flags.main)
prep_parser = subparsers.add_parser(
"prep",
prog="prepreduce",
description=f"A script to setup testing files (target.i and test.sh) "
"for use in reduction via (cvise, llvm-reduce, reduce flags)",
epilog="Example Usage: $ python3 prepreduce.py -p ~/path/to/linux -Ff "
"-o test2 -- make -j8 LLVM=1 V=1 lib/string",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
prep.setup_argparser(prep_parser)
prep_parser.set_defaults(func=prep.main)
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
return parser.parse_args()
if __name__ == "__main__":
args = parse_cli_args()
args.func(args)