public static string ConditionPathToExpression(List <int> path, ACSESERegion region) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < path.Count - 1; i++) { if (region.decNodes.Contains(path[i]) && region.codeNodes.Contains(path[i + 1])) { bool cond = false; foreach (Edge e in region.graph.edges) { if (e.start == path[i] && e.end == path[i + 1]) { cond = e.text == "true"; break; } } if (sb.Length != 0) { sb.Append(" && "); } sb.Append((cond ? "" : "!") + "Block" + ((CodeBlock)(region.graph.nodes[path[i]].data)).myIndex + "()"); } } return(sb.ToString()); }
public static string PrintAcSESEBlock(ABSBlock block, int tabs) { StringBuilder sb = new StringBuilder(); string t = ""; for (int i = 0; i < tabs; i++) { t += "\t"; } ACSESERegion region = ((ACSESERegion)block.data); Graph gr = region.graph; List <int> order = gr.getTopogicalOrder(); for (int i = 0; i < order.Count - 1; i++) { int idx = order[i]; if (region.codeNodes.Contains(idx)) { List <List <int> > paths = gr.getAllReachingPaths(idx); StringBuilder exp = new StringBuilder(); exp.Append(t + "if("); if (paths.Count == 1) { exp.Append(ConditionPathToExpression(paths[0], region)); exp.AppendLine(")"); } else { StringBuilder sb2 = new StringBuilder(); foreach (List <int> path in paths) { if (sb2.Length != 0) { sb2.AppendLine(" || "); sb2.Append(t + " "); } sb2.Append("(" + ConditionPathToExpression(path, region) + ")"); } exp.AppendLine(sb2.ToString()); exp.AppendLine(t + " )"); } exp.AppendLine(t + "{"); exp.Append(PrintBlock(gr.nodes[idx].data, tabs + 1)); exp.AppendLine(t + "}"); sb.Append(exp.ToString()); } } sb.Append(PrintBlock(region.graph.nodes[order[order.Count - 1]].data, tabs)); return(sb.ToString()); }