Skip to content

Commit

Permalink
Reducing duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-marichal committed Jul 18, 2024
1 parent 5a6a494 commit aa051f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,11 @@ public RoslynLvaWalker(RoslynLiveVariableAnalysis lva, DotWriter writer, RoslynC

protected override void WriteEdges(BasicBlock block)
{
var lvaPredecessors = lva.BlockPredecessors[block.Ordinal];
foreach (var predecessor in block.Predecessors)
{
var condition = string.Empty;
if (predecessor.Source.ConditionKind != ControlFlowConditionKind.None)
{
condition = predecessor == predecessor.Source.ConditionalSuccessor ? predecessor.Source.ConditionKind.ToString() : "Else";
}
var semantics = predecessor.Semantics == ControlFlowBranchSemantics.Regular ? null : predecessor.Semantics.ToString();
writer.WriteEdge(BlockId(predecessor.Source), BlockId(block), $"{semantics} {condition}".Trim());
lvaPredecessors.Remove(predecessor.Source);
}
foreach (var predecessor in lvaPredecessors)
foreach (var predecessor in lva.BlockPredecessors[block.Ordinal].Where(x => !block.Predecessors.Any(y => y.Source == x)))
{
writer.WriteEdge(BlockId(predecessor), BlockId(block), "LVA");
}
if (block.FallThroughSuccessor is { Destination: null })
{
writer.WriteEdge(BlockId(block), "NoDestination_" + BlockId(block), block.FallThroughSuccessor.Semantics.ToString());
}
base.WriteEdges(block);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ void Use(int v) {}
cfg0_block3 -> cfg0_block4 [label="LVA"]
cfg0_block4 -> NoDestination_cfg0_block4 [label="StructuredExceptionHandling"]
cfg0_block0 -> cfg0_block1
cfg0_block2 -> cfg0_block5
cfg0_block3 -> cfg0_block5
cfg0_block4 -> cfg0_block5 [label="LVA"]
cfg0_block4 -> cfg0_block5 [label="LVA"]
cfg0_block2 -> cfg0_block5
cfg0_block3 -> cfg0_block5
}

""");
Expand Down Expand Up @@ -166,8 +166,8 @@ void Use(int v) {}
cfg0_block2 -> cfg0_block4 [label="LVA"]
cfg0_block4 -> NoDestination_cfg0_block4 [label="StructuredExceptionHandling"]
cfg0_block0 -> cfg0_block1
cfg0_block2 -> cfg0_block5
cfg0_block4 -> cfg0_block5 [label="LVA"]
cfg0_block2 -> cfg0_block5
}

""");
Expand Down Expand Up @@ -275,8 +275,8 @@ void Use(int v) {}
cfg0_block7 -> NoDestination_cfg0_block7 [label="StructuredExceptionHandling"]
cfg0_block1 -> cfg0_block2
cfg0_block0 -> cfg0_block1
cfg0_block3 -> cfg0_block8 [label="WhenFalse"]
cfg0_block7 -> cfg0_block8 [label="LVA"]
cfg0_block3 -> cfg0_block8 [label="WhenFalse"]
}

""");
Expand Down

0 comments on commit aa051f6

Please sign in to comment.