Skip to content

Commit 78a1638

Browse files
committed
First attempt to handle parallel edges.
1 parent 7f64286 commit 78a1638

1 file changed

Lines changed: 45 additions & 35 deletions

File tree

cfpq_add_context/load_graph.py

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,36 @@
1111
def load_graph(file_path):
1212
nvertices = 0
1313
number_of_contexts = 0
14-
def get_edge_lbl(data_arr):
14+
def get_edge_lbl(terminal):
15+
data_arr = terminal.split()
1516
_context = 0
1617
nonlocal number_of_contexts
17-
if len(data_arr) == 4:
18-
if "load_r" in data_arr[2]:
19-
return labels.mk_load_r(int(data_arr[3]))
20-
elif "load" in data_arr[2]:
21-
return labels.mk_load(int(data_arr[3]))
22-
elif "store_r" in data_arr[2]:
23-
return labels.mk_store_r(int(data_arr[3]))
18+
if len(data_arr) == 2:
19+
if "load" in data_arr[0]:
20+
return labels.mk_load(int(data_arr[1]))
2421
else:
25-
return labels.mk_store(int(data_arr[3]))
26-
elif data_arr[2] == "assign":
22+
return labels.mk_store(int(data_arr[1]))
23+
elif data_arr[0] == "assign":
2724
return labels.mk_other(labels.ASSIGN)
28-
#elif data_arr[2] == "assign_r":
29-
# return labels.mk_other(labels.ASSIGN_R)
30-
elif data_arr[2] == "alloc":
25+
elif data_arr[0] == "alloc":
3126
return labels.mk_other(labels.ALLOC)
32-
elif data_arr[2] == "alloc_r":
33-
return labels.mk_other(labels.ALLOC_R)
34-
elif "open" in data_arr[2]:
35-
if "_r_" in data_arr[2]:
36-
_context = int(data_arr[2].split('_')[2])
37-
res = labels.mk_open_context_from_ret_r(_context)
38-
else:
39-
_context = int(data_arr[2].split('_')[1])
40-
res = labels.mk_open_context_from_pass(_context)
27+
elif "open" in data_arr[0]:
28+
_context = int(data_arr[0].split('_')[1])
29+
res = labels.mk_open_context_from_pass(_context)
4130

4231
number_of_contexts = max(number_of_contexts, _context)
4332
return res
44-
elif "close" in data_arr[2]:
45-
if "_r_" in data_arr[2]:
46-
_context = int(data_arr[2].split('_')[2])
47-
res = labels.mk_close_context_from_pass_r(_context)
48-
else:
49-
_context = int(data_arr[2].split('_')[1])
50-
res = labels.mk_close_context_from_ret(_context)
51-
33+
elif "close" in data_arr[0]:
34+
_context = int(data_arr[0].split('_')[1])
35+
res = labels.mk_close_context_from_ret(_context)
5236
number_of_contexts = max(number_of_contexts, _context)
5337
return res
54-
else: print("ERROR:", data_arr[2])
38+
else: print("ERROR:", terminal)
5539

56-
def handle_line(line):
40+
def get_raw_edge(line):
5741
nonlocal nvertices
5842
data = line.strip().split()
59-
_lbl = get_edge_lbl(data)
43+
_lbl = " ".join(data[2:])
6044
_from = int(data[0])
6145
_to = int(data[1])
6246

@@ -65,10 +49,36 @@ def handle_line(line):
6549

6650
return (_from, _to, _lbl)
6751

52+
6853
with open (file_path,'r') as file:
69-
edges = [handle_line(line) for line in file if len(line.strip()) > 0 and not("_r") in line]
54+
raw_edges = [get_raw_edge(line) for line in file if len(line.strip()) > 0 and not("_r") in line]
55+
#nvertices = 0
56+
#for (_from, _to, line) in raw_edges:
57+
# _max = max(_from,_to)
58+
# nvertices = max(nvertices, _max)
59+
60+
nvertices = nvertices + 1
61+
62+
edges = {}
63+
assign_lbl = get_edge_lbl("assign")
64+
for (v_from, v_to, terminal) in raw_edges:
65+
if (v_from,v_to) in edges:
66+
v_new = nvertices
67+
nvertices = nvertices + 1
68+
if terminal.startswith("store"):
69+
edges[(v_from, v_new)] = get_edge_lbl(terminal)
70+
edges[(v_new, v_to)] = assign_lbl
71+
else:
72+
edges[(v_from, v_new)] = assign_lbl
73+
edges[(v_new, v_to)] = get_edge_lbl(terminal)
74+
else:
75+
edges[(v_from, v_to)] = get_edge_lbl(terminal)
76+
77+
edges = [(i[0],i[1],edges[i]) for i in edges]
7078
#TODO Remove dup_op! It is a hack to avoid edges duplication.
71-
result = Matrix.from_edgelist(edges, dtype=UINT64, nrows=nvertices + 1, ncols=nvertices + 1, name="graph",dup_op="max")
79+
#result = Matrix.from_edgelist(edges, dtype=UINT64, nrows=nvertices + 1, ncols=nvertices + 1, name="graph",dup_op="max")
80+
81+
result = Matrix.from_edgelist(edges, dtype=UINT64, nrows=nvertices, ncols=nvertices, name="graph")
7282
#print_matrix_to_dot(result, "graph.dot")
7383
return (result, (number_of_contexts + 1))
7484

0 commit comments

Comments
 (0)