Skip to content

Commit 96ffab5

Browse files
committed
WI #2022 Change Review
1 parent 1d7a2b3 commit 96ffab5

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

TypeCobol.Analysis/Cfg/ControlFlowGraphBuilder.CfgAfterIterativePerformProcedureTransformer.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ public partial class ControlFlowGraphBuilder<D>
1212
private class CfgAfterIterativePerformProcedureTransformer : ICfgTransform<Node, D>
1313
{
1414
private HashSet<BasicBlockForNodeGroup> _visitedGroups;
15-
private ControlFlowGraphBuilder<D> Builder;
15+
private ControlFlowGraph<Node, D> _cfg;
1616

1717
/// <summary>
1818
/// Constructor
1919
/// </summary>
2020
/// <param name="builder"></param>
21-
public CfgAfterIterativePerformProcedureTransformer(ControlFlowGraphBuilder<D> builder)
21+
public CfgAfterIterativePerformProcedureTransformer(ControlFlowGraph<Node, D> cfg)
2222
{
23-
this.Builder = builder;
23+
this._cfg = cfg;
2424
}
2525
private bool Callback(BasicBlock<Node, D> block, int incomingEdge, BasicBlock<Node, D> predecessorBlock, ControlFlowGraph<Node, D> cfg)
2626
{
@@ -48,18 +48,20 @@ private bool Callback(BasicBlock<Node, D> block, int incomingEdge, BasicBlock<No
4848
//If an after iterative group has been found, we must break the edge pointing to the PERFORM
4949
//and replace it with a new edge pointing to the first instruction of the group.
5050
if (iterativeGroup != null)
51-
{
51+
{
5252
//Remove incoming edge
5353
block.SuccessorEdges.RemoveAt(removedIndex);
5454

5555
//Create an edge to the first block of the iterative group.
5656
int entranceEdge = cfg.SuccessorEdges.Count;
5757
cfg.SuccessorEdges.Add(iterativeGroup.Group.First.Value);
5858
block.SuccessorEdges.Add(entranceEdge);
59-
if(block.Context != null)
60-
{
61-
((MultiBranchContext)block.Context).ChangeSuccessor(Builder, iterativeGroup, iterativeGroup.Group.First.Value);
62-
}
59+
System.Diagnostics.Debug.Assert(block.Context == null);
60+
//If the assert above fails (it should not be case), then it will be necessay to exeute the commented code bellow.
61+
//if(block.Context != null)
62+
//{
63+
// ((MultiBranchContext)block.Context).ChangeSuccessor(_cfg, iterativeGroup, iterativeGroup.Group.First.Value);
64+
//}
6365
}
6466

6567
//If the current block is a group, we must also traverse blocks of the group

TypeCobol.Analysis/Cfg/ControlFlowGraphBuilder.MultiBranchContext.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ internal MultiBranchContext(Node instruction)
8585
internal void Start(BasicBlockForNode originBlock)
8686
{
8787
this.OriginBlock = originBlock;
88+
this.OriginBlock.Context = this;
8889
}
8990

9091
/// <summary>
@@ -135,9 +136,10 @@ internal void End(ControlFlowGraphBuilder<D> builder, bool branchToNext, BasicBl
135136
/// <summary>
136137
/// Change the successors
137138
/// </summary>
139+
/// <param name="cfg">The target CFG graph</param>
138140
/// <param name="currentSucc">The current Successor</param>
139141
/// <param name="newSucc">The new Successor</param>
140-
internal void ChangeSuccessor(ControlFlowGraphBuilder<D> builder, BasicBlock<Node, D> currentSucc, BasicBlock<Node, D> newSucc)
142+
internal void ChangeSuccessor(ControlFlowGraph<Node, D> cfg, BasicBlock<Node, D> currentSucc, BasicBlock<Node, D> newSucc)
141143
{
142144
if (NextFlowBlock == currentSucc)
143145
NextFlowBlock = newSucc;
@@ -150,12 +152,12 @@ internal void ChangeSuccessor(ControlFlowGraphBuilder<D> builder, BasicBlock<Nod
150152
{
151153
if (branches[i] == currentSucc)
152154
{
153-
System.Diagnostics.Debug.Assert(builder.Cfg.SuccessorEdges[branchIndices[i]] == currentSucc);
155+
System.Diagnostics.Debug.Assert(cfg.SuccessorEdges[branchIndices[i]] == currentSucc);
154156
branches[i] = newSucc;
155157
RootBlockForEnd.SuccessorEdges.Remove(branchIndices[i]);
156-
branchIndices[i] = builder.Cfg.SuccessorEdges.Count;
157-
RootBlockForEnd.SuccessorEdges.Add(builder.Cfg.SuccessorEdges.Count);
158-
builder.Cfg.SuccessorEdges.Add(newSucc);
158+
branchIndices[i] = cfg.SuccessorEdges.Count;
159+
RootBlockForEnd.SuccessorEdges.Add(cfg.SuccessorEdges.Count);
160+
cfg.SuccessorEdges.Add(newSucc);
159161
break;
160162
}
161163
}

TypeCobol.Analysis/Cfg/ControlFlowGraphBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ private void HandlePerformsWithTestAfter()
13331333
{
13341334
//Transform graph to replace edge in performs with test after.
13351335
//Transformation is directly applied to the graph, no new instance created.
1336-
ICfgTransform<Node, D> transform = new CfgAfterIterativePerformProcedureTransformer(this.CurrentProgramCfgBuilder);
1336+
ICfgTransform<Node, D> transform = new CfgAfterIterativePerformProcedureTransformer(this.CurrentProgramCfgBuilder.Cfg);
13371337
transform.Transform(this.CurrentProgramCfgBuilder.Cfg);
13381338
}
13391339
}
@@ -1733,7 +1733,7 @@ protected virtual void LeaveEvaluate(Evaluate evaluate)
17331733
var nextBlock = this.CurrentProgramCfgBuilder.CreateBlock(null, true);
17341734
ctx.End(this.CurrentProgramCfgBuilder, branchToNext, nextBlock);
17351735
this.CurrentProgramCfgBuilder.CurrentBasicBlock = nextBlock;
1736-
}
1736+
}
17371737
}
17381738

17391739
/// <summary>
@@ -2061,7 +2061,7 @@ public virtual void LeaveSearch(Search node)
20612061
else
20622062
{
20632063
ctx.End(this.CurrentProgramCfgBuilder, branchToNext, nextBlock);
2064-
}
2064+
}
20652065
this.CurrentProgramCfgBuilder.CurrentBasicBlock = nextBlock;
20662066
ctx = this.CurrentProgramCfgBuilder.MultiBranchContextStack.Pop();
20672067
}
@@ -2081,7 +2081,7 @@ public virtual void LeaveSearch(Search node)
20812081
var nextBlock = this.CurrentProgramCfgBuilder.CreateBlock(null, true);
20822082
ctx.End(this.CurrentProgramCfgBuilder, branchToNext, nextBlock);
20832083
this.CurrentProgramCfgBuilder.CurrentBasicBlock = nextBlock;
2084-
}
2084+
}
20852085
}
20862086

20872087
/// <summary>

0 commit comments

Comments
 (0)