-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcompile_commands.py
56 lines (45 loc) · 2.1 KB
/
compile_commands.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
import json
import subprocess
from concurrent.futures import ThreadPoolExecutor
from tqdm import tqdm
def preprocess_command(command):
modified_command = command
# Modify the command as needed
flag = ''
flag += ' -mllvm -disable-llvm-optzns'
flag += ' -fno-discard-value-names'
flag += ' -emit-llvm'
flag += ' -w -g -c '
modified_command = modified_command.replace(' -c ', flag)
modified_command = modified_command.replace('.o ', '.bc ')
modified_command = modified_command.replace(' -Os ', ' -O0 ')
modified_command = modified_command.replace(' -O3 ', ' -O0 ')
modified_command = modified_command.replace(' -O2 ', ' -O0 ')
modified_command = modified_command.replace(
' -fno-var-tracking-assignments ', ' ')
modified_command = modified_command.replace(' -fconserve-stack ', ' ')
modified_command = modified_command.replace(' -march=armv8-a+crypto ', ' ')
modified_command = modified_command.replace(' -mno-fp-ret-in-387 ', ' ')
modified_command = modified_command.replace(' -mskip-rax-setup ', ' ')
modified_command = modified_command.replace(
' -ftrivial-auto-var-init=zero ', ' ')
return modified_command
def execute_command(command):
if not command.startswith('clang '):
return
modified_command = preprocess_command(command)
# print(modified_command)
subprocess.run(modified_command, shell=True)
def execute_commands_concurrently(commands, max_workers):
with ThreadPoolExecutor(max_workers=max_workers) as executor:
results = list(tqdm(executor.map(execute_command, commands),
total=len(commands), desc='Executing Commands'))
# Read compile_commands.json file
with open('compile_commands.json', 'r') as file:
compile_commands = json.load(file)
# Extract commands from compile_commands.json
commands = [entry['command'] for entry in compile_commands]
# Adjust the number of concurrent threads
max_workers = 32 # Example: Set the maximum number of concurrent threads to 4
# Execute the commands concurrently with a progress bar
execute_commands_concurrently(commands, max_workers)