public override Implementation VisitImplementation(Implementation node) { //Contract.Requires(node != null); Contract.Ensures(Contract.Result<Implementation>() != null); var impl = base.VisitImplementation((Implementation)node.Clone()); var blockDuplicationMapping = new Dictionary<Block, Block>(); // Compute the mapping between the blocks of the old implementation (node) // and the new implementation (impl). foreach (var blockPair in node.Blocks.Zip(impl.Blocks)) { blockDuplicationMapping.Add(blockPair.Item1, blockPair.Item2); } // The GotoCmds and blocks have now been duplicated. // Resolve GotoCmd targets to the duplicated blocks foreach (GotoCmd gotoCmd in impl.Blocks.Select( bb => bb.TransferCmd).OfType<GotoCmd>()) { var newLabelTargets = new List<Block>(); var newLabelNames = new List<string>(); for (int index = 0; index < gotoCmd.labelTargets.Count; ++index) { var newBlock = blockDuplicationMapping[gotoCmd.labelTargets[index]]; newLabelTargets.Add(newBlock); newLabelNames.Add(newBlock.Label); } gotoCmd.labelTargets = newLabelTargets; gotoCmd.labelNames = newLabelNames; } return impl; }
public override Implementation VisitImplementation(Implementation node) { //Contract.Requires(node != null); Contract.Ensures(Contract.Result<Implementation>() != null); return base.VisitImplementation((Implementation)node.Clone()); }