40 lines
846 B
Plaintext
40 lines
846 B
Plaintext
|
#!/usr/bin/python3
|
||
|
|
||
|
# Check an llvm bcanalyzer dump for -flto
|
||
|
|
||
|
# This script implements the following command in python
|
||
|
# to avoid PCRE backtrace limits in grep.
|
||
|
# grep -xP '.*\-flto((?!-fno-lto).)*' <input file>
|
||
|
|
||
|
import re
|
||
|
import sys
|
||
|
|
||
|
def open_input_file():
|
||
|
if len(sys.argv) > 1:
|
||
|
f = open(sys.argv[1], "r")
|
||
|
else:
|
||
|
f = sys.stdin
|
||
|
if not f:
|
||
|
raise Exception("Could not open input file")
|
||
|
return f
|
||
|
|
||
|
def match_lto(input_lines):
|
||
|
match_found = False
|
||
|
for line in input_lines:
|
||
|
match = re.match(r"^.*\-flto((?!-fno-lto).)*$", line)
|
||
|
if match:
|
||
|
match_found = True
|
||
|
print(f"{match.group(0)}")
|
||
|
return match_found
|
||
|
|
||
|
def main():
|
||
|
input_file = open_input_file()
|
||
|
input_lines = input_file.readlines()
|
||
|
if input_file != sys.stdin:
|
||
|
input_file.close()
|
||
|
if match_lto(input_lines):
|
||
|
sys.exit(0)
|
||
|
sys.exit(1)
|
||
|
|
||
|
main()
|