Commit TP5b
This commit is contained in:
+8
-1
@@ -84,6 +84,14 @@ class Block:
|
||||
cast(List[Statement], self._instructions) +
|
||||
[self.get_terminator()])
|
||||
|
||||
def get_body_and_terminator(self) -> List[Statement]:
|
||||
"""
|
||||
Return all statements of the block, except phi-nodes
|
||||
(and the label of the block).
|
||||
"""
|
||||
return (cast(List[Statement], self._instructions) +
|
||||
[self.get_terminator()])
|
||||
|
||||
def get_label(self) -> Label:
|
||||
"""Return the label of the block."""
|
||||
return self._label
|
||||
@@ -259,7 +267,6 @@ class CFG:
|
||||
# nodes
|
||||
for name, blk in self._blocks.items():
|
||||
if DF is not None:
|
||||
print(str(name), blk._label)
|
||||
df_str = "{}" if blk not in DF or not len(DF[blk]) else str(DF[blk])
|
||||
df_lab = blk.to_dot() + "\n\nDominance frontier:\n" + df_str
|
||||
else:
|
||||
|
||||
@@ -156,7 +156,9 @@ class Graph(GeneralGraph):
|
||||
"""Print the graph."""
|
||||
color_names = ['red', 'blue', 'green', 'yellow', 'cyan', 'magenta'] + \
|
||||
[f"grey{i}" for i in range(0, 100, 10)]
|
||||
color_shapes = ['ellipse', 'polygon', 'box', 'circle', 'egg', 'pentagon', 'hexagon']
|
||||
color_shapes = ['ellipse', 'box', 'diamond', 'trapezium', 'egg',
|
||||
'parallelogram', 'house', 'triangle', 'pentagon', 'hexagon',
|
||||
'septagon', 'octagon']
|
||||
dot = Digraph(comment='Conflict Graph')
|
||||
for k in self.graph_dict:
|
||||
shape = None
|
||||
@@ -255,6 +257,10 @@ class Graph(GeneralGraph):
|
||||
class DiGraph(GeneralGraph):
|
||||
"""Class for directed graphs."""
|
||||
|
||||
def pred(self, v: Any) -> Set:
|
||||
"""Return all predecessors of the vertex `v` in the graph."""
|
||||
return {src for src, dests in self.graph_dict.items() if v in dests}
|
||||
|
||||
def neighbourhoods(self) -> List[Tuple[Any, Set]]:
|
||||
"""Return all neighbourhoods in the graph."""
|
||||
return list(self.graph_dict.items())
|
||||
|
||||
@@ -52,6 +52,9 @@ class Return(Statement):
|
||||
.format(self))
|
||||
return self
|
||||
|
||||
def is_read_only(self):
|
||||
return True
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class BranchingTerminator(Instruction):
|
||||
@@ -126,7 +129,7 @@ def jump2terminator(j: ConditionalJump | AbsoluteJump | None,
|
||||
return BranchingTerminator(j.cond, j.op1, j.op2, j.label, label_else)
|
||||
case AbsoluteJump():
|
||||
return AbsoluteJump(label=j.label)
|
||||
case None:
|
||||
case _:
|
||||
if next_label:
|
||||
return AbsoluteJump(next_label)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user