forked from umnsec/typm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lll.py
59 lines (46 loc) · 1.84 KB
/
lll.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
#!/usr/bin/env python3
import subprocess
import sys
import os
def main():
if len(sys.argv) < 2:
print("Usage: python lll.py <root_dir> <path_to_executable>")
sys.exit(1)
import argparse
parser = argparse.ArgumentParser(description="Process root directory and executable path.")
parser.add_argument("-r", "--root_dir", type=str, help="Root directory path")
parser.add_argument("executable_path", type=str, help="Path to the executable")
parser.add_argument("-f", "--shell_format", action="store_true", help="Add \ when breaking lines for shell")
parser.add_argument("-o", "--output_file", type=str, help="Output file")
parser.add_argument("-c", "--check", action="store_true", help="Check if all the .mlta.ll files exist")
args = parser.parse_args()
root_dir = args.root_dir
executable_path = args.executable_path
# Get the absolute path of root_dir
root_dir = os.path.abspath(root_dir)
src_files = set()
dump_output = subprocess.check_output(["llvm-dwarfdump", "--show-sources", executable_path]).decode('utf-8')
for line in dump_output.splitlines():
if not line.startswith(root_dir) or line.endswith('.h'):
continue
if not os.path.exists(line + ".mlta.ll"):
if args.check:
print(line + ".mlta.ll not found", file=sys.stderr)
sys.exit(1)
else:
src_files.add(line)
output = ""
for src_file in src_files:
if args.shell_format:
output += src_file + ".mlta.ll \\ \n"
else:
output += src_file + ".mlta.ll\n"
if args.shell_format:
output = output[:-4]
if args.output_file:
with open(args.output_file, "w") as f:
f.write(output)
else:
print(output)
if __name__ == '__main__':
main()