diff options
Diffstat (limited to 'afdo_redaction/remove_indirect_calls.py')
-rwxr-xr-x | afdo_redaction/remove_indirect_calls.py | 87 |
1 files changed, 47 insertions, 40 deletions
diff --git a/afdo_redaction/remove_indirect_calls.py b/afdo_redaction/remove_indirect_calls.py index a72e43b5..6d77ba7a 100755 --- a/afdo_redaction/remove_indirect_calls.py +++ b/afdo_redaction/remove_indirect_calls.py @@ -17,21 +17,22 @@ objects as Chrome, this can become problematic, and lead to NaCl doubling in size (or worse). See crbug.com/1005023 and crbug.com/916130. """ -from __future__ import division, print_function +from __future__ import division +from __future__ import print_function import argparse import re def _remove_indirect_call_targets(lines): - # Lines with indirect call targets look like: - # 1.1: 1234 foo:111 bar:122 - # - # Where 1.1 is the line info/discriminator, 1234 is the total number of - # samples seen for that line/discriminator, foo:111 is "111 of the calls here - # went to foo," and bar:122 is "122 of the calls here went to bar." - call_target_re = re.compile( - r""" + # Lines with indirect call targets look like: + # 1.1: 1234 foo:111 bar:122 + # + # Where 1.1 is the line info/discriminator, 1234 is the total number of + # samples seen for that line/discriminator, foo:111 is "111 of the calls here + # went to foo," and bar:122 is "122 of the calls here went to bar." + call_target_re = re.compile( + r""" ^\s+ # Top-level lines are function records. \d+(?:\.\d+)?: # Line info/discriminator \s+ @@ -39,42 +40,48 @@ def _remove_indirect_call_targets(lines): \s+ ((?:[^\s:]+:\d+\s*)+) # Indirect call target(s) $ - """, re.VERBOSE) - for line in lines: - line = line.rstrip() + """, + re.VERBOSE, + ) + for line in lines: + line = line.rstrip() - match = call_target_re.match(line) - if not match: - yield line + '\n' - continue + match = call_target_re.match(line) + if not match: + yield line + "\n" + continue - group_start, group_end = match.span(1) - assert group_end == len(line) - yield line[:group_start].rstrip() + '\n' + group_start, group_end = match.span(1) + assert group_end == len(line) + yield line[:group_start].rstrip() + "\n" def run(input_stream, output_stream): - for line in _remove_indirect_call_targets(input_stream): - output_stream.write(line) + for line in _remove_indirect_call_targets(input_stream): + output_stream.write(line) def main(): - parser = argparse.ArgumentParser( - description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) - parser.add_argument( - '--input', - default='/dev/stdin', - help='File to read from. Defaults to stdin.') - parser.add_argument( - '--output', - default='/dev/stdout', - help='File to write to. Defaults to stdout.') - args = parser.parse_args() - - with open(args.input) as stdin: - with open(args.output, 'w') as stdout: - run(stdin, stdout) - - -if __name__ == '__main__': - main() + parser = argparse.ArgumentParser( + description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter, + ) + parser.add_argument( + "--input", + default="/dev/stdin", + help="File to read from. Defaults to stdin.", + ) + parser.add_argument( + "--output", + default="/dev/stdout", + help="File to write to. Defaults to stdout.", + ) + args = parser.parse_args() + + with open(args.input) as stdin: + with open(args.output, "w") as stdout: + run(stdin, stdout) + + +if __name__ == "__main__": + main() |