private static bool CollapseInlinedClass14(Statement stat) { bool ret = class14Builder.Match(stat); if (ret) { string class_name = (string)class14Builder.GetVariableValue("$classname$"); AssignmentExprent assignment = (AssignmentExprent)class14Builder.GetVariableValue ("$assignfield$"); FieldExprent fieldExpr = (FieldExprent)class14Builder.GetVariableValue("$field$"); assignment.ReplaceExprent(assignment.GetRight(), new ConstExprent(VarType.Vartype_Class , class_name, null)); List <Exprent> data = new List <Exprent>(stat.GetFirst().GetExprents()); stat.SetExprents(data); SequenceHelper.DestroyAndFlattenStatement(stat); ClassWrapper wrapper = (ClassWrapper)DecompilerContext.GetProperty(DecompilerContext .Current_Class_Wrapper); if (wrapper != null) { wrapper.GetHiddenMembers().Add(InterpreterUtil.MakeUniqueKey(fieldExpr.GetName(), fieldExpr.GetDescriptor().descriptorString)); } } return(ret); }
public static void EnhanceLoops(Statement root) { while (EnhanceLoopsRec(root)) { } /**/ SequenceHelper.CondenseSequences(root); }
public static bool ExtractLoops(Statement root) { bool res = (ExtractLoopsRec(root) != 0); if (res) { SequenceHelper.CondenseSequences(root); } return(res); }
public static bool MergeAllIfs(RootStatement root) { bool res = MergeAllIfsRec(root, new HashSet <int>()); if (res) { SequenceHelper.CondenseSequences(root); } return(res); }
public static bool InlineSingleBlocks(RootStatement root) { bool res = InlineSingleBlocksRec(root); if (res) { SequenceHelper.CondenseSequences(root); } return(res); }
public static bool CondenseExits(RootStatement root) { int changed = IntegrateExits(root); if (changed > 0) { CleanUpUnreachableBlocks(root); SequenceHelper.CondenseSequences(root); } return(changed > 0); }
public static RootStatement ParseGraph(ControlFlowGraph graph) { RootStatement root = GraphToStatement(graph); if (!ProcessStatement(root, new Dictionary <int, HashSet <int> >())) { // try { // DotExporter.toDotFile(root.getFirst().getStats().get(13), new File("c:\\Temp\\stat1.dot")); // } catch (Exception ex) { // ex.printStackTrace(); // } throw new Exception("parsing failure!"); } LabelHelper.LowContinueLabels(root, new HashSet <StatEdge>()); SequenceHelper.CondenseSequences(root); root.BuildMonitorFlags(); // build synchronized statements BuildSynchronized(root); return(root); }
public virtual void SimplifyStackVars(RootStatement root, StructMethod mt, StructClass cl) { HashSet <int> setReorderedIfs = new HashSet <int>(); SSAUConstructorSparseEx ssau = null; while (true) { bool found = false; SSAConstructorSparseEx ssa = new SSAConstructorSparseEx(); ssa.SplitVariables(root, mt); SimplifyExprentsHelper sehelper = new SimplifyExprentsHelper(ssau == null); while (sehelper.SimplifyStackVarsStatement(root, setReorderedIfs, ssa, cl)) { found = true; } SetVersionsToNull(root); SequenceHelper.CondenseSequences(root); ssau = new SSAUConstructorSparseEx(); ssau.SplitVariables(root, mt); if (IterateStatements(root, ssau)) { found = true; } SetVersionsToNull(root); if (!found) { break; } } // remove unused assignments ssau = new SSAUConstructorSparseEx(); ssau.SplitVariables(root, mt); IterateStatements(root, ssau); SetVersionsToNull(root); }
private static bool BuildIff(Statement stat, SSAConstructorSparseEx ssa) { if (stat.type == Statement.Type_If && stat.GetExprents() == null) { IfStatement statement = (IfStatement)stat; Exprent ifHeadExpr = statement.GetHeadexprent(); HashSet <int> ifHeadExprBytecode = (ifHeadExpr == null ? null : ifHeadExpr.bytecode ); if (statement.iftype == IfStatement.Iftype_Ifelse) { Statement ifStatement = statement.GetIfstat(); Statement elseStatement = statement.GetElsestat(); if (ifStatement.GetExprents() != null && ifStatement.GetExprents().Count == 1 && elseStatement.GetExprents() != null && elseStatement.GetExprents().Count == 1 && ifStatement.GetAllSuccessorEdges().Count == 1 && elseStatement.GetAllSuccessorEdges ().Count == 1 && ifStatement.GetAllSuccessorEdges()[0].GetDestination() == elseStatement .GetAllSuccessorEdges()[0].GetDestination()) { Exprent ifExpr = ifStatement.GetExprents()[0]; Exprent elseExpr = elseStatement.GetExprents()[0]; if (ifExpr.type == Exprent.Exprent_Assignment && elseExpr.type == Exprent.Exprent_Assignment) { AssignmentExprent ifAssign = (AssignmentExprent)ifExpr; AssignmentExprent elseAssign = (AssignmentExprent)elseExpr; if (ifAssign.GetLeft().type == Exprent.Exprent_Var && elseAssign.GetLeft().type == Exprent.Exprent_Var) { VarExprent ifVar = (VarExprent)ifAssign.GetLeft(); VarExprent elseVar = (VarExprent)elseAssign.GetLeft(); if (ifVar.GetIndex() == elseVar.GetIndex() && ifVar.IsStack()) { // ifVar.getIndex() >= VarExprent.STACK_BASE) { bool found = false; foreach (KeyValuePair <VarVersionPair, FastSparseSetFactory <int> .FastSparseSet <int> > ent in ssa.GetPhi()) { if (ent.Key.var == ifVar.GetIndex()) { if (ent.Value.Contains(ifVar.GetVersion()) && ent.Value.Contains(elseVar.GetVersion ())) { found = true; break; } } } if (found) { List <Exprent> data = new List <Exprent>(statement.GetFirst().GetExprents()); List <Exprent> operands = Sharpen.Arrays.AsList(statement.GetHeadexprent().GetCondition (), ifAssign.GetRight(), elseAssign.GetRight()); data.Add(new AssignmentExprent(ifVar, new FunctionExprent(FunctionExprent.Function_Iif , operands, ifHeadExprBytecode), ifHeadExprBytecode)); statement.SetExprents(data); if ((statement.GetAllSuccessorEdges().Count == 0)) { StatEdge ifEdge = ifStatement.GetAllSuccessorEdges()[0]; StatEdge edge = new StatEdge(ifEdge.GetType(), statement, ifEdge.GetDestination() ); statement.AddSuccessor(edge); if (ifEdge.closure != null) { ifEdge.closure.AddLabeledEdge(edge); } } SequenceHelper.DestroyAndFlattenStatement(statement); return(true); } } } } else if (ifExpr.type == Exprent.Exprent_Exit && elseExpr.type == Exprent.Exprent_Exit) { ExitExprent ifExit = (ExitExprent)ifExpr; ExitExprent elseExit = (ExitExprent)elseExpr; if (ifExit.GetExitType() == elseExit.GetExitType() && ifExit.GetValue() != null && elseExit.GetValue() != null && ifExit.GetExitType() == ExitExprent.Exit_Return) { // throw is dangerous, because of implicit casting to a common superclass // e.g. throws IOException and throw true?new RuntimeException():new IOException(); won't work if (ifExit.GetExitType() == ExitExprent.Exit_Throw && !ifExit.GetValue().GetExprType ().Equals(elseExit.GetValue().GetExprType())) { // note: getExprType unreliable at this point! return(false); } // avoid flattening to 'iff' if any of the branches is an 'iff' already if (IsIff(ifExit.GetValue()) || IsIff(elseExit.GetValue())) { return(false); } List <Exprent> data = new List <Exprent>(statement.GetFirst().GetExprents()); data.Add(new ExitExprent(ifExit.GetExitType(), new FunctionExprent(FunctionExprent .Function_Iif, Sharpen.Arrays.AsList(statement.GetHeadexprent().GetCondition(), ifExit.GetValue(), elseExit.GetValue()), ifHeadExprBytecode), ifExit.GetRetType( ), ifHeadExprBytecode)); statement.SetExprents(data); StatEdge retEdge = ifStatement.GetAllSuccessorEdges()[0]; Statement closure = retEdge.closure == statement?statement.GetParent() : retEdge .closure; statement.AddSuccessor(new StatEdge(StatEdge.Type_Break, statement, retEdge.GetDestination (), closure)); SequenceHelper.DestroyAndFlattenStatement(statement); return(true); } } } } } return(false); }