private void CreateSwitchConstruct(CFGBlockLogicalConstruct switchBlock, ILogicalConstruct parentConstruct, SwitchData switchData, DominatorTree dominatorTree) { List <KeyValuePair <CFGBlockLogicalConstruct, List <int> > > cfgSuccessorToLabelsMap = GetOrderedCFGSuccessorToLabelsMap(switchData); Dictionary <ILogicalConstruct, HashSet <ISingleEntrySubGraph> > validCaseEntryToDominatedNodesMap = GetValidCases(dominatorTree, switchBlock); List <CaseLogicalConstruct> orderedCaseConstructs = new List <CaseLogicalConstruct>(); PairList <List <int>, CFGBlockLogicalConstruct> labelsToCFGSuccessorsList = new PairList <List <int>, CFGBlockLogicalConstruct>(); foreach (KeyValuePair <CFGBlockLogicalConstruct, List <int> > cfgSuccessorToLabelsPair in cfgSuccessorToLabelsMap) { ILogicalConstruct successor; HashSet <ISingleEntrySubGraph> dominatedNodes; if (LogicalFlowUtilities.TryGetParentConstructWithGivenParent(cfgSuccessorToLabelsPair.Key, parentConstruct, out successor) && validCaseEntryToDominatedNodesMap.TryGetValue(successor, out dominatedNodes)) { CaseLogicalConstruct newCaseConstruct = new CaseLogicalConstruct(successor); newCaseConstruct.CaseNumbers.AddRange(cfgSuccessorToLabelsPair.Value); newCaseConstruct.Body.UnionWith(dominatedNodes.Cast <ILogicalConstruct>()); newCaseConstruct.AttachCaseConstructToGraph(); orderedCaseConstructs.Add(newCaseConstruct); } else { labelsToCFGSuccessorsList.Add(cfgSuccessorToLabelsPair.Value, cfgSuccessorToLabelsPair.Key); } } CaseLogicalConstruct defaultCase = null; CFGBlockLogicalConstruct defaultCFGSuccessor = GetCFGLogicalConstructFromBlock(switchData.DefaultCase); ILogicalConstruct defaultSuccessor; HashSet <ISingleEntrySubGraph> defaultCaseNodes; if (LogicalFlowUtilities.TryGetParentConstructWithGivenParent(defaultCFGSuccessor, parentConstruct, out defaultSuccessor) && validCaseEntryToDominatedNodesMap.TryGetValue(defaultSuccessor, out defaultCaseNodes)) { defaultCase = new CaseLogicalConstruct(defaultSuccessor); if (HasSuccessors(defaultCaseNodes)) { defaultCase.Body.UnionWith(defaultCaseNodes.Cast <ILogicalConstruct>()); } defaultCase.AttachCaseConstructToGraph(); } SwitchLogicalConstruct theSwitch = SwitchLogicalConstruct.GroupInSwitchConstruct(switchBlock, orderedCaseConstructs, labelsToCFGSuccessorsList, defaultCase, defaultCFGSuccessor); UpdateDominatorTree(dominatorTree, theSwitch); }
private void UpdateDominatorTree(DominatorTree dominatorTree, SwitchLogicalConstruct theSwitchConstruct) { HashSet <ISingleEntrySubGraph> switchNodes = new HashSet <ISingleEntrySubGraph>(); switchNodes.Add(theSwitchConstruct.Entry); foreach (CaseLogicalConstruct @case in theSwitchConstruct.ConditionCases) { switchNodes.UnionWith(@case.Children); } if (theSwitchConstruct.DefaultCase != null) { switchNodes.UnionWith(theSwitchConstruct.DefaultCase.Children); } dominatorTree.MergeNodes(switchNodes, theSwitchConstruct.Entry, theSwitchConstruct); }
private void CreateSwitchConstruct(CFGBlockLogicalConstruct switchBlock, ILogicalConstruct parentConstruct, SwitchData switchData, DominatorTree dominatorTree) { stackVariable2 = this.GetOrderedCFGSuccessorToLabelsMap(switchData); V_0 = this.GetValidCases(dominatorTree, switchBlock); V_1 = new List <CaseLogicalConstruct>(); V_2 = new PairList <List <int>, CFGBlockLogicalConstruct>(); V_8 = stackVariable2.GetEnumerator(); try { while (V_8.MoveNext()) { V_9 = V_8.get_Current(); if (!LogicalFlowUtilities.TryGetParentConstructWithGivenParent(V_9.get_Key(), parentConstruct, out V_10) || !V_0.TryGetValue(V_10, out V_11)) { V_2.Add(V_9.get_Value(), V_9.get_Key()); } else { V_12 = new CaseLogicalConstruct(V_10); V_12.get_CaseNumbers().AddRange(V_9.get_Value()); V_12.get_Body().UnionWith(V_11.Cast <ILogicalConstruct>()); V_12.AttachCaseConstructToGraph(); V_1.Add(V_12); } } } finally { ((IDisposable)V_8).Dispose(); } V_3 = null; V_4 = this.GetCFGLogicalConstructFromBlock(switchData.get_DefaultCase()); if (LogicalFlowUtilities.TryGetParentConstructWithGivenParent(V_4, parentConstruct, out V_5) && V_0.TryGetValue(V_5, out V_6)) { V_3 = new CaseLogicalConstruct(V_5); if (this.HasSuccessors(V_6)) { V_3.get_Body().UnionWith(V_6.Cast <ILogicalConstruct>()); } V_3.AttachCaseConstructToGraph(); } V_7 = SwitchLogicalConstruct.GroupInSwitchConstruct(switchBlock, V_1, V_2, V_3, V_4); this.UpdateDominatorTree(dominatorTree, V_7); return; }
private void UpdateDominatorTree(DominatorTree dominatorTree, SwitchLogicalConstruct theSwitchConstruct) { V_0 = new HashSet <ISingleEntrySubGraph>(); dummyVar0 = V_0.Add(theSwitchConstruct.get_Entry()); V_1 = theSwitchConstruct.get_ConditionCases(); V_2 = 0; while (V_2 < (int)V_1.Length) { V_0.UnionWith(V_1[V_2].get_Children()); V_2 = V_2 + 1; } if (theSwitchConstruct.get_DefaultCase() != null) { V_0.UnionWith(theSwitchConstruct.get_DefaultCase().get_Children()); } dominatorTree.MergeNodes(V_0, theSwitchConstruct.get_Entry(), theSwitchConstruct); return; }
private void UpdateDominatorTree(DominatorTree dominatorTree, SwitchLogicalConstruct theSwitchConstruct) { HashSet<ISingleEntrySubGraph> switchNodes = new HashSet<ISingleEntrySubGraph>(); switchNodes.Add(theSwitchConstruct.Entry); foreach (CaseLogicalConstruct @case in theSwitchConstruct.ConditionCases) { switchNodes.UnionWith(@case.Children); } if (theSwitchConstruct.DefaultCase != null) { switchNodes.UnionWith(theSwitchConstruct.DefaultCase.Children); } dominatorTree.MergeNodes(switchNodes, theSwitchConstruct.Entry, theSwitchConstruct); }