protected override void RunTest(Program program, TextWriter writer) { var dfa = new DataFlowAnalysis(program, importResolver, new FakeDecompilerEventListener()); dfa.UntangleProcedures(); foreach (Procedure proc in program.Procedures.Values) { writer.WriteLine("= {0} ========================", proc.Name); var gr = proc.CreateBlockDominatorGraph(); Aliases alias = new Aliases(proc); alias.Transform(); SsaTransform sst = new SsaTransform(dfa.ProgramDataFlow, proc, importResolver, gr, new HashSet <RegisterStorage>()); SsaState ssa = sst.SsaState; var cce = new ConditionCodeEliminator(ssa, program.Platform); cce.Transform(); ssa.Write(writer); proc.Write(false, writer); writer.WriteLine(); ValuePropagator vp = new ValuePropagator(program.SegmentMap, ssa, listener); vp.Transform(); ssa.Write(writer); proc.Write(false, writer); } }
protected override void RunTest(Program prog, TextWriter writer) { var dfa = new DataFlowAnalysis(prog, null, new FakeDecompilerEventListener()); dfa.UntangleProcedures(); foreach (Procedure proc in prog.Procedures.Values) { writer.WriteLine("= {0} ========================", proc.Name); var gr = proc.CreateBlockDominatorGraph(); Aliases alias = new Aliases(proc, prog.Architecture); alias.Transform(); SsaTransform sst = new SsaTransform(dfa.ProgramDataFlow, proc, null, gr); SsaState ssa = sst.SsaState; var cce = new ConditionCodeEliminator(ssa.Identifiers, prog.Platform); cce.Transform(); ssa.Write(writer); proc.Write(false, writer); writer.WriteLine(); ValuePropagator vp = new ValuePropagator(prog.Architecture, ssa.Identifiers, proc); vp.Transform(); ssa.Write(writer); proc.Write(false, writer); } }
protected override void RunTest(Program program, TextWriter writer) { var dfa = new DataFlowAnalysis( program, dynamicLinker.Object, new FakeDecompilerEventListener()); foreach (Procedure proc in ProceduresInSccOrder(program)) { writer.WriteLine("= {0} ========================", proc.Name); SsaTransform sst = new SsaTransform( program, proc, new HashSet <Procedure>(), dynamicLinker.Object, dfa.ProgramDataFlow); sst.Transform(); SsaState ssa = sst.SsaState; var cce = new ConditionCodeEliminator(ssa, program.Platform, listener); cce.Transform(); ssa.Write(writer); proc.Write(false, writer); writer.WriteLine(); var vp = new ValuePropagator(program.SegmentMap, ssa, program.CallGraph, dynamicLinker.Object, listener); vp.Transform(); sst.RenameFrameAccesses = true; sst.Transform(); ssa.Write(writer); proc.Write(false, writer); } }
protected override void RunTest(Program program, TextWriter fut) { InitProgram(program); IImportResolver importResolver = null; var eventListener = new FakeDecompilerEventListener(); DataFlowAnalysis dfa = new DataFlowAnalysis( program, importResolver, eventListener); dfa.UntangleProcedures(); foreach (Procedure proc in program.Procedures.Values) { SsaTransform sst = new SsaTransform( dfa.ProgramDataFlow, proc, importResolver, proc.CreateBlockDominatorGraph(), new HashSet <RegisterStorage>()); SsaState ssa = sst.SsaState; var icrw = new IndirectCallRewriter( program, ssa, eventListener); icrw.Rewrite(); ssa.Write(fut); proc.Write(false, fut); fut.WriteLine(); } }
protected override void RunTest(Program prog, TextWriter fut) { IImportResolver importResolver = null; DataFlowAnalysis dfa = new DataFlowAnalysis(prog, importResolver, new FakeDecompilerEventListener()); dfa.UntangleProcedures(); foreach (Procedure proc in prog.Procedures.Values) { Aliases alias = new Aliases(proc, prog.Architecture); alias.Transform(); SsaTransform sst = new SsaTransform(dfa.ProgramDataFlow, proc, importResolver, proc.CreateBlockDominatorGraph()); SsaState ssa = sst.SsaState; ConditionCodeEliminator cce = new ConditionCodeEliminator(ssa.Identifiers, prog.Platform); cce.Transform(); DeadCode.Eliminate(proc, ssa); ValuePropagator vp = new ValuePropagator(prog.Architecture, ssa.Identifiers, proc); vp.Transform(); DeadCode.Eliminate(proc, ssa); Coalescer co = new Coalescer(proc, ssa); co.Transform(); ssa.Write(fut); proc.Write(false, fut); fut.WriteLine(); } }
protected override void RunTest(Program program, TextWriter fut) { IImportResolver importResolver = null; var listener = new FakeDecompilerEventListener(); DataFlowAnalysis dfa = new DataFlowAnalysis(program, importResolver, listener); dfa.UntangleProcedures(); foreach (Procedure proc in program.Procedures.Values) { Aliases alias = new Aliases(proc); alias.Transform(); SsaTransform sst = new SsaTransform(dfa.ProgramDataFlow, proc, importResolver, proc.CreateBlockDominatorGraph(), new HashSet <RegisterStorage>()); SsaState ssa = sst.SsaState; ConditionCodeEliminator cce = new ConditionCodeEliminator(ssa, program.Platform); cce.Transform(); DeadCode.Eliminate(proc, ssa); ValuePropagator vp = new ValuePropagator(program.SegmentMap, ssa, program.CallGraph, importResolver, listener); vp.Transform(); DeadCode.Eliminate(proc, ssa); Coalescer co = new Coalescer(proc, ssa); co.Transform(); ssa.Write(fut); proc.Write(false, fut); fut.WriteLine(); ssa.Validate(s => Assert.Fail(s)); } }
protected override void RunTest(Program program, TextWriter writer) { DataFlowAnalysis dfa = new DataFlowAnalysis(program, null, new FakeDecompilerEventListener()); dfa.UntangleProcedures(); foreach (Procedure proc in program.Procedures.Values) { Aliases alias = new Aliases(proc); alias.Transform(); SsaTransform sst = new SsaTransform( dfa.ProgramDataFlow, proc, null, proc.CreateBlockDominatorGraph(), program.Platform.CreateImplicitArgumentRegisters()); SsaState ssa = sst.SsaState; ConditionCodeEliminator cce = new ConditionCodeEliminator(ssa, program.Platform); cce.Transform(); DeadCode.Eliminate(proc, ssa); ssa.Write(writer); proc.Write(false, writer); ssa.Validate(s => Assert.Fail(s)); } }
protected override void RunTest(Program prog, TextWriter writer) { DataFlowAnalysis dfa = new DataFlowAnalysis(prog, new FakeDecompilerEventListener()); dfa.UntangleProcedures(); foreach (Procedure proc in prog.Procedures.Values) { var larw = new LongAddRewriter(proc, prog.Architecture); larw.Transform(); Aliases alias = new Aliases(proc, prog.Architecture, dfa.ProgramDataFlow); alias.Transform(); var sst = new SsaTransform(dfa.ProgramDataFlow, proc, proc.CreateBlockDominatorGraph()); SsaState ssa = sst.SsaState; proc.Dump(true); var vp = new ValuePropagator(ssa.Identifiers, proc); vp.Transform(); var cce = new ConditionCodeEliminator(ssa.Identifiers, prog.Platform); cce.Transform(); DeadCode.Eliminate(proc, ssa); ssa.Write(writer); proc.Write(false, writer); writer.WriteLine(); } }
protected override void RunTest(Program prog, TextWriter writer) { var flow = new ProgramDataFlow(prog); var eventListener = new FakeDecompilerEventListener(); var trf = new TrashedRegisterFinder(prog, prog.Procedures.Values, flow, eventListener); trf.Compute(); trf.RewriteBasicBlocks(); Dump(prog.CallGraph); var rl = RegisterLiveness.Compute(prog, flow, eventListener); GlobalCallRewriter.Rewrite(prog, flow); foreach (Procedure proc in prog.Procedures.Values) { Aliases alias = new Aliases(proc, prog.Architecture); alias.Transform(); var gr = proc.CreateBlockDominatorGraph(); SsaTransform sst = new SsaTransform(flow, proc, gr); ssa = sst.SsaState; ssa.Write(writer); proc.Write(false, true, writer); writer.WriteLine(); } }
protected override void RunTest(Program prog, TextWriter writer) { var flow = new ProgramDataFlow(prog); var eventListener = new FakeDecompilerEventListener(); var importResolver = MockRepository.GenerateStub <IImportResolver>(); importResolver.Replay(); var trf = new TrashedRegisterFinder(prog, prog.Procedures.Values, flow, eventListener); trf.Compute(); trf.RewriteBasicBlocks(); Dump(prog.CallGraph); RegisterLiveness.Compute(prog, flow, eventListener); GlobalCallRewriter.Rewrite(prog, flow, eventListener); foreach (Procedure proc in prog.Procedures.Values) { Aliases alias = new Aliases(proc, prog.Architecture); alias.Transform(); var gr = proc.CreateBlockDominatorGraph(); SsaTransform sst = new SsaTransform( flow, proc, importResolver, gr, new HashSet <RegisterStorage>()); ssa = sst.SsaState; ssa.Write(writer); proc.Write(false, true, writer); writer.WriteLine(); ssa.CheckUses(s => Assert.Fail(s)); } }
protected override void RunTest(Program program, TextWriter fut) { IDynamicLinker dynamicLinker = null; var listener = sc.RequireService <DecompilerEventListener>(); DataFlowAnalysis dfa = new DataFlowAnalysis(program, dynamicLinker, sc); var ssts = dfa.UntangleProcedures(); foreach (Procedure proc in program.Procedures.Values) { var sst = ssts.Single(s => s.SsaState.Procedure == proc); SsaState ssa = sst.SsaState; ConditionCodeEliminator cce = new ConditionCodeEliminator(program, ssa, listener); cce.Transform(); DeadCode.Eliminate(ssa); ValuePropagator vp = new ValuePropagator(program.SegmentMap, ssa, program.CallGraph, dynamicLinker, listener); vp.Transform(); DeadCode.Eliminate(ssa); Coalescer co = new Coalescer(ssa); co.Transform(); ssa.Write(fut); proc.Write(false, fut); fut.WriteLine(); ssa.Validate(s => { ssa.Dump(true); Assert.Fail(s); }); } }
protected override void RunTest(Program program, TextWriter writer) { var importResolver = new Mock <IImportResolver>().Object; var listener = new FakeDecompilerEventListener(); var dfa = new DataFlowAnalysis(program, importResolver, listener); dfa.UntangleProcedures(); foreach (Procedure proc in program.Procedures.Values) { var larw = new LongAddRewriter(proc); larw.Transform(); Aliases alias = new Aliases(proc, dfa.ProgramDataFlow); alias.Transform(); var sst = new SsaTransform(dfa.ProgramDataFlow, proc, importResolver, proc.CreateBlockDominatorGraph(), new HashSet <RegisterStorage>()); SsaState ssa = sst.SsaState; var cce = new ConditionCodeEliminator(ssa, program.Platform); cce.Transform(); var vp = new ValuePropagator(program.SegmentMap, ssa, importResolver, listener); vp.Transform(); DeadCode.Eliminate(proc, ssa); ssa.Write(writer); proc.Write(false, writer); writer.WriteLine(); ssa.Validate(s => Assert.Fail(s)); } }
private void RunUnitTest(ProcedureBuilder m, string outfile) { var proc = m.Procedure; var sst = new SsaTransform(new ProgramDataFlow(), proc, null, proc.CreateBlockDominatorGraph()); ssa = sst.SsaState; using (var fut = new FileUnitTester(outfile)) { ssa.Write(fut.TextWriter); proc.Write(false, fut.TextWriter); fut.AssertFilesEqual(); } }
private void AssertExpected(string sExp, SsaState ssa) { var sw = new StringWriter(); ssa.Write(sw); ssa.Procedure.Write(false, sw); var sActual = sw.ToString(); if (sExp != sActual) { Console.WriteLine(sActual); Assert.AreEqual(sExp, sActual); } }
private void AssertStringsEqual(string sExp, SsaState ssa) { var sw = new StringWriter(); ssa.Write(sw); ssa.Procedure.Write(false, sw); var sActual = sw.ToString(); if (sExp != sActual) { Debug.Print("{0}", sActual); Assert.AreEqual(sExp, sActual); } }
protected override void RunTest(Program program, TextWriter writer) { DataFlowAnalysis dfa = new DataFlowAnalysis(program, dynamicLinker.Object, new FakeDecompilerEventListener()); var ssts = dfa.UntangleProcedures(); foreach (var sst in ssts) { SsaState ssa = sst.SsaState; ConditionCodeEliminator cce = new ConditionCodeEliminator(ssa, program.Platform); cce.Transform(); DeadCode.Eliminate(ssa); ssa.Write(writer); ssa.Procedure.Write(false, writer); } }
protected override void RunTest(Program prog, FileUnitTester fut) { foreach (Procedure proc in prog.Procedures.Values) { DominatorGraph gr = new DominatorGraph(proc); Aliases alias = new Aliases(proc, prog.Architecture); alias.Transform(); SsaTransform sst = new SsaTransform(proc, gr, true); SsaState ssa = sst.SsaState; DeadCode.Eliminate(proc, ssa); ValueNumbering vn = new ValueNumbering(ssa.Identifiers); ssa.Write(fut.TextWriter); proc.Write(false, fut.TextWriter); vn.Write(fut.TextWriter); } }
protected override void RunTest(Program prog, TextWriter writer) { DataFlowAnalysis dfa = new DataFlowAnalysis(prog, null, new FakeDecompilerEventListener()); dfa.UntangleProcedures(); foreach (Procedure proc in prog.Procedures.Values) { Aliases alias = new Aliases(proc, prog.Architecture); alias.Transform(); SsaTransform sst = new SsaTransform(dfa.ProgramDataFlow, proc, null, proc.CreateBlockDominatorGraph()); SsaState ssa = sst.SsaState; ConditionCodeEliminator cce = new ConditionCodeEliminator(ssa.Identifiers, prog.Platform); cce.Transform(); DeadCode.Eliminate(proc, ssa); ssa.Write(writer); proc.Write(false, writer); } }
protected override void RunTest(Program program, TextWriter writer) { var listener = new FakeDecompilerEventListener(); var sc = new ServiceContainer(); sc.AddService <DecompilerEventListener>(listener); DataFlowAnalysis dfa = new DataFlowAnalysis(program, dynamicLinker.Object, sc); var ssts = dfa.UntangleProcedures(); foreach (var sst in ssts) { SsaState ssa = sst.SsaState; ConditionCodeEliminator cce = new ConditionCodeEliminator(program, ssa, listener); cce.Transform(); DeadCode.Eliminate(ssa); ssa.Write(writer); ssa.Validate(s => writer.WriteLine("*** SSA state invalid: {0}", s)); ssa.Procedure.Write(false, writer); } }
private void RunUnitTest(ProcedureBuilder m, string outfile) { var flow = new ProgramDataFlow(); var dynamicLinker = new Mock <IDynamicLinker>(); var proc = m.Procedure; var platform = new FakePlatform(null, m.Architecture) { Test_CreateTrashedRegisters = () => new HashSet <RegisterStorage>() { (RegisterStorage)r1.Storage, (RegisterStorage)r2.Storage, } }; var program = new Program() { Architecture = m.Architecture, Platform = platform, }; var sst = new SsaTransform( program, proc, new HashSet <Procedure>(), dynamicLinker.Object, flow); sst.Transform(); ssa = sst.SsaState; using (var fut = new FileUnitTester(outfile)) { ssa.Write(fut.TextWriter); proc.Write(false, fut.TextWriter); fut.AssertFilesEqual(); ssa.Validate(s => Assert.Fail(s)); } }
protected override void RunTest(Program program, TextWriter writer) { var flow = new ProgramDataFlow(); var dynamicLinker = new Mock <IDynamicLinker>(); foreach (Procedure proc in program.Procedures.Values) { var sst = new SsaTransform( program, proc, new HashSet <Procedure>(), dynamicLinker.Object, flow); sst.Transform(); sst.AddUsesToExitBlock(); sst.RemoveDeadSsaIdentifiers(); Debug.Print("SsaTest: {0}", new StackFrame(3).GetMethod().Name); ssa = sst.SsaState; ssa.Write(writer); proc.Write(false, true, writer); writer.WriteLine(); ssa.Validate(s => Assert.Fail(s)); } }
private void DumpProc(Procedure proc, SsaState ssa, TextWriter writer) { ssa.Write(writer); proc.Write(false, writer); }