private void RunTest(string sExp, Program program) { var dfa = new DataFlowAnalysis( program, import.Object, eventListener.Object); var ssts = dfa.RewriteProceduresToSsa(); var uvr = new UnusedOutValuesRemover( program, ssts.Select(sst => sst.SsaState), dfa.ProgramDataFlow, import.Object, eventListener.Object); uvr.Transform(); var sb = new StringWriter(); foreach (var proc in program.Procedures.Values) { proc.Write(false, sb); sb.WriteLine("==="); } var sActual = sb.ToString(); if (sExp != sActual) { Console.WriteLine(sActual); Assert.AreEqual(sExp, sActual); } }
protected override void RunTest(Program program, TextWriter writer) { var eventListener = new FakeDecompilerEventListener(); var sc = new ServiceContainer(); sc.AddService <DecompilerEventListener>(eventListener); var dfa = new DataFlowAnalysis( program, dynamicLinker.Object, sc); program.User.Procedures = userSigs; var usb = new UserSignatureBuilder(program); usb.BuildSignatures(eventListener); IntraBlockDeadRegisters.Apply(program, eventListener); var ssts = dfa.RewriteProceduresToSsa(); // Discover ssaId's that are live out at each call site. // Delete all others. var uvr = new UnusedOutValuesRemover( program, ssts.Select(sst => sst.SsaState), dfa.ProgramDataFlow, dynamicLinker.Object, eventListener); uvr.Transform(); DumpProcedureFlows(program, dfa, writer); }
private void When_RunUnusedOutValuesRemover() { var program = pb.BuildProgram(); var dataFlow = new ProgramDataFlow(program); var uvr = new UnusedOutValuesRemover( program, ssaStates, dataFlow, import.Object, eventListener.Object); uvr.Transform(); }
protected override void RunTest(Program program, TextWriter writer) { var dynamicLinker = new Mock <IDynamicLinker>(); dfa = new DataFlowAnalysis(program, dynamicLinker.Object, sc); var ssts = dfa.RewriteProceduresToSsa(); // Discover ssaId's that are live out at each call site. // Delete all others. var uvr = new UnusedOutValuesRemover( program, ssts.Select(sst => sst.SsaState), dfa.ProgramDataFlow, dynamicLinker.Object, eventListener); uvr.Transform(); foreach (var p in program.Procedures.Values) { p.Dump(true); Debug.Print("===="); } // At this point, the exit blocks contain only live out registers. // We can create signatures from that. CallRewriter.Rewrite(program.Platform, ssts, dfa.ProgramDataFlow, eventListener); foreach (var proc in program.Procedures.Values) { var flow = dfa.ProgramDataFlow[proc]; proc.Signature.Emit(proc.Name, FunctionType.EmitFlags.ArgumentKind, new TextFormatter(writer)); writer.WriteLine(); flow.Emit(program.Architecture, writer); proc.Write(true, writer); writer.Flush(); } ssts.ForEach(sst => sst.SsaState.Validate(s => Assert.Fail(s))); }