Skip to content

Commit cb406c6

Browse files
authored
Merge pull request #8927 from eeckstein/fix-viewcfg
2 parents b3c2a26 + 4d2128b commit cb406c6

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

utils/viewcfg

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ def main():
9191
return
9292
suffix = sys.argv[1]
9393

94-
blocks = {}
94+
block_list = []
95+
block_map = {}
9596
cur_block = None
9697
sil_block_pattern = re.compile(r'^(\S+)(\(.*\))?: *(\/\/ *Preds:(.*))?$')
9798
llvm_block_pattern1 = re.compile(r'^(\S+): *; *preds =(.*)?$')
98-
llvm_block_pattern2 = re.compile(r'^; <label>:(\d+) *; *preds =(.*)?$')
99+
llvm_block_pattern2 = re.compile(r'^; <label>:(\d+):? *; *preds =(.*)?$')
99100

100101
# Scan the input file.
101102

@@ -118,39 +119,40 @@ def main():
118119
if cur_block is not None:
119120
cur_block.add_line(line)
120121
elif not line[:1].isspace():
121-
if line.startswith('}') and blocks:
122+
if line.startswith('}') and block_map:
122123
break
123124
cur_block = None
124125

125126
if block_name is not None:
126127
cur_block = Block(block_name, preds)
127128
cur_block.add_line(line)
128-
blocks[block_name] = cur_block
129+
block_list.append(cur_block)
130+
block_map[block_name] = cur_block
129131

130132
# Add empty blocks which we didn't see, but which are referenced.
131133
new_blocks = {}
132-
for name, block in blocks.iteritems():
134+
for block in block_list:
133135
for adj_name in (block.preds + block.get_succs()):
134-
if adj_name not in blocks:
136+
if adj_name not in block_map:
135137
new_blocks[adj_name] = Block(adj_name, None)
136138

137-
blocks = dict(blocks.items() + new_blocks.items())
139+
block_map = dict(block_map.items() + new_blocks.items())
138140

139141
# Add missing edges if we didn't see a successor in the terminator
140142
# but the block is mentioned in the pred list of the successor.
141143

142-
for name, block in blocks.iteritems():
144+
for block in block_list:
143145
for pred_name in block.preds:
144-
pred_block = blocks[pred_name]
145-
if name not in pred_block.get_succs():
146-
pred_block.get_succs().append(name)
146+
pred_block = block_map[pred_name]
147+
if block.name not in pred_block.get_succs():
148+
pred_block.get_succs().append(block.name)
147149

148150
# Write the output dot file.
149151

150152
file_name = tempfile.gettempdir() + "/viewcfg" + suffix + ".dot"
151153
with open(file_name, 'w') as out_file:
152154
out_file.write('digraph "CFG" {\n')
153-
for name, block in blocks.iteritems():
155+
for block in block_list:
154156
if block.content is not None:
155157
out_file.write(
156158
"\tNode" + str(block.index) +
@@ -162,7 +164,7 @@ def main():
162164
block.name + "}\"];\n")
163165

164166
for succ_name in block.get_succs():
165-
succ_block = blocks[succ_name]
167+
succ_block = block_map[succ_name]
166168
out_file.write(
167169
"\tNode" + str(block.index) + " -> Node" +
168170
str(succ_block.index) + ";\n")

0 commit comments

Comments
 (0)