-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_test.py
More file actions
65 lines (50 loc) · 1.74 KB
/
Copy pathfind_test.py
File metadata and controls
65 lines (50 loc) · 1.74 KB
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
63
64
65
import csv
import sys
def read_csv_columns(file_path):
max_int = sys.maxsize
while True:
try:
csv.field_size_limit(max_int)
break
except OverflowError:
max_int = int(max_int / 10)
with open(file_path, "r", newline="") as csvfile:
reader = csv.reader(csvfile)
col1, col2 = [], []
for row in reader:
if len(row) < 2:
raise ValueError("CSV file must have at least two columns")
col1.append(row[0])
col2.append(row[1])
return col1, col2
def find_mismatch_index(col1, col2):
min_len = min(len(col1), len(col2))
for i in range(min_len):
if col1[i] != col2[i] and i!=0:
return i
# If no mismatch found within the common length, check if lengths are different
if len(col1) != len(col2):
return min_len
return None
def write_columns_to_files(col1, col2, file1_path, file2_path):
with open(file1_path, "w", newline="") as file1:
writer = csv.writer(file1)
for item in col1:
writer.writerow([item])
with open(file2_path, "w", newline="") as file2:
writer = csv.writer(file2)
for item in col2:
writer.writerow([item])
def main():
input_csv = "./dataset/llvm-ir-loop-optimized-llvm-ir-newversion.csv"
col1, col2 = read_csv_columns(input_csv)
mismatch_index = find_mismatch_index(col1, col2)
if mismatch_index is not None:
print(f"Mismatch found at index: {mismatch_index}")
write_columns_to_files(col1, col2, "v1.ll", "v2.ll")
else:
print(
"No mismatch found. The columns are of the same length and have the same content."
)
if __name__ == "__main__":
main()