Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
        private void RunValuePropagator(ProcedureBuilder m)
        {
            var ssa = new SsaState(m.Procedure, null);

            foreach (var ssaId in ssaIds)
            {
                ssa.Identifiers.Add(ssaId.Identifier, ssaId);
            }
            ssaIds = ssa.Identifiers;
            var stms = m.Procedure.EntryBlock.Succ[0].Statements;

            stms.ForEach(stm =>
            {
                var ass = stm.Instruction as Assignment;
                if (ass != null)
                {
                    ssaIds[ass.Dst].DefStatement  = stm;
                    ssaIds[ass.Dst].DefExpression = ass.Src;
                }
                var phiAss = stm.Instruction as PhiAssignment;
                if (phiAss != null)
                {
                    ssaIds[phiAss.Dst].DefStatement  = stm;
                    ssaIds[phiAss.Dst].DefExpression = phiAss.Src;
                }
                ssa.AddUses(stm);
            });
            var vp = new ValuePropagator(arch, ssa, listener);

            vp.Transform();
            ssa.CheckUses(s => Assert.Fail(s));
        }
Ejemplo n.º 3
0
        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, program.Architecture);
                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.Architecture, ssa, 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.CheckUses(s => Assert.Fail(s));
            }
        }
Ejemplo n.º 4
0
        private void RunUnitTest(ProcedureBuilder m, string outfile)
        {
            var proc = m.Procedure;
            var sst  = new SsaTransform(
                new ProgramDataFlow(),
                proc,
                null,
                proc.CreateBlockDominatorGraph(),
                new HashSet <RegisterStorage>());

            ssa = sst.SsaState;
            using (var fut = new FileUnitTester(outfile))
            {
                ssa.Write(fut.TextWriter);
                proc.Write(false, fut.TextWriter);
                fut.AssertFilesEqual();
                ssa.CheckUses(s => Assert.Fail(s));
            }
        }