Example #1
0
 public LiveCopyInserter(SsaState ssa)
 {
     this.ssa    = ssa;
     this.ssaIds = ssa.Identifiers;
     this.sla    = new SsaLivenessAnalysis(ssa);
     this.doms   = ssa.Procedure.CreateBlockDominatorGraph();
 }
        private void Prepare(Procedure proc)
        {
            this.proc = proc;
            doms      = proc.CreateBlockDominatorGraph();
            SsaTransform sst = new SsaTransform(
                new ProgramDataFlow(),
                proc,
                null,
                doms,
                new HashSet <RegisterStorage>());
            SsaState ssa = sst.SsaState;

            ssaIds = ssa.Identifiers;

            var arch = new FakeArchitecture();
            var cce  = new ConditionCodeEliminator(ssa, new DefaultPlatform(null, arch));

            cce.Transform();

            DeadCode.Eliminate(proc, ssa);

            var vp = new ValuePropagator(arch, ssa.Identifiers, proc);

            vp.Transform();

            DeadCode.Eliminate(proc, ssa);
        }
        private void Prepare(Procedure proc)
        {
            var listener       = new FakeDecompilerEventListener();
            var importResolver = new Mock <IImportResolver>().Object;

            this.proc = proc;
            doms      = proc.CreateBlockDominatorGraph();
            SsaTransform sst = new SsaTransform(
                new ProgramDataFlow(),
                proc,
                importResolver,
                doms,
                new HashSet <RegisterStorage>());
            SsaState ssa = sst.SsaState;

            ssaIds = ssa.Identifiers;

            var arch = new FakeArchitecture();
            var cce  = new ConditionCodeEliminator(ssa, new DefaultPlatform(null, arch));

            cce.Transform();

            DeadCode.Eliminate(proc, ssa);

            var segmentMap = new SegmentMap(Address.Ptr32(0x00123400));
            var vp         = new ValuePropagator(segmentMap, ssa, new CallGraph(), importResolver, listener);

            vp.Transform();

            DeadCode.Eliminate(proc, ssa);
        }
        private void Prepare(Procedure proc)
        {
            var listener      = new FakeDecompilerEventListener();
            var dynamicLinker = new Mock <IDynamicLinker>().Object;

            doms = proc.CreateBlockDominatorGraph();
            SsaTransform sst = new SsaTransform(
                new Program(),
                proc,
                new HashSet <Procedure>(),
                dynamicLinker,
                new ProgramDataFlow());

            sst.Transform();
            this.ssa = sst.SsaState;

            var arch = new FakeArchitecture();
            var cce  = new ConditionCodeEliminator(ssa, new DefaultPlatform(null, arch), listener);

            cce.Transform();

            DeadCode.Eliminate(ssa);

            var segmentMap = new SegmentMap(Address.Ptr32(0x00123400));
            var vp         = new ValuePropagator(segmentMap, ssa, new CallGraph(), dynamicLinker, listener);

            vp.Transform();

            DeadCode.Eliminate(ssa);
        }
Example #5
0
		public LiveCopyInserter(Procedure proc, SsaIdentifierCollection ssaIds)
		{
			this.proc = proc;
			this.ssaIds = ssaIds;
			this.sla = new SsaLivenessAnalysis(proc, ssaIds);
			this.doms = proc.CreateBlockDominatorGraph();
		}
Example #6
0
 public LiveCopyInserter(Procedure proc, SsaIdentifierCollection ssaIds)
 {
     this.proc   = proc;
     this.ssaIds = ssaIds;
     this.sla    = new SsaLivenessAnalysis(proc, ssaIds);
     this.doms   = proc.CreateBlockDominatorGraph();
 }
Example #7
0
        private void Build(Procedure proc)
        {
            this.proc = proc;
            this.doms = proc.CreateBlockDominatorGraph();
            SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, doms);

            this.ssaIds = sst.SsaState.Identifiers;
        }
        private void Build(Procedure proc)
        {
            this.proc = proc;
            this.doms = proc.CreateBlockDominatorGraph();
            SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, doms);

            this.ssaIds = sst.SsaState.Identifiers;
        }
Example #9
0
 public LinearInductionVariableFinder(SsaState ssa, BlockDominatorGraph doms)
 {
     this.ssa      = ssa;
     this.doms     = doms;
     this.ctx      = new LinearInductionVariableContext();
     this.ivs      = new List <LinearInductionVariable>();
     this.contexts = new Dictionary <LinearInductionVariable, LinearInductionVariableContext>();
 }
Example #10
0
 public WebBuilder(Procedure proc, SsaIdentifierCollection ssaIds, Dictionary <Identifier, LinearInductionVariable> ivs)
 {
     this.proc   = proc;
     this.ssaIds = ssaIds;
     this.ivs    = ivs;
     this.sla    = new SsaLivenessAnalysis(proc, ssaIds);
     this.doms   = proc.CreateBlockDominatorGraph();
     this.webs   = new List <Web>();
 }
 public LinearInductionVariableFinder(Procedure proc, SsaIdentifierCollection ssaIds, BlockDominatorGraph doms)
 {
     this.proc     = proc;
     this.ssaIds   = ssaIds;
     this.doms     = doms;
     this.ctx      = new LinearInductionVariableContext();
     this.ivs      = new List <LinearInductionVariable>();
     this.contexts = new Dictionary <LinearInductionVariable, LinearInductionVariableContext>();
 }
        /// <summary>
        /// Builds a strongly connected component corresponding to:
        /// a1 = 0
        /// a2 = phi(a1, a3)
        /// while (a2 != 10)
        /// {
        ///    a3 = a2 + 4
        /// }
        /// </summary>
        private List <SsaIdentifier> BuildScc()
        {
            var        m = new ProcedureBuilder("test");
            Identifier a = new Identifier("a", PrimitiveType.Word32, null);

            m.Label("b1");
            m.Assign(a, Constant.Word32(0));
            m.Label("b2");
            m.Assign(a, m.IAdd(a, 4));
            m.BranchIf(m.Ne(a, 10), "b2");
            m.Label("b3");
            m.Return();
            this.dom = m.Procedure.CreateBlockDominatorGraph();
            var ssa = new SsaTransform(
                new ProgramDataFlow(),
                m.Procedure,
                null,
                dom,
                new HashSet <RegisterStorage>());

            /*
             *
             * proc = new Procedure("test", new Frame(PrimitiveType.Word32));
             *          Block b1 = proc.AddBlock("b1");
             *          Block b2 = proc.AddBlock("b2");
             *
             *          Identifier a2 = new Identifier("a2", PrimitiveType.Word32, null);
             *          Identifier a3 = new Identifier("a3", PrimitiveType.Word32, null);
             *          PhiFunction phi = new PhiFunction(a1.DataType, new Expression [] { a1, a3 });
             *
             *          Statement stm_a1 = new Statement(0, new Assignment(a1, Constant.Word32(0)), null);
             *          Statement stm_a2 = new Statement(0, new PhiAssignment(a2, new PhiFunction(a1.DataType,  a1, a3 )), null);
             *          Statement stm_ex = new Statement(0, new Branch(new BinaryExpression(Operator.Ne, PrimitiveType.Bool, a2, Constant.Word32(10)), b2), null);
             *          Statement stm_a3 = new Statement(0, new Assignment(a3, new BinaryExpression(Operator.IAdd, a3.DataType, a2, Constant.Word32(4))), null);
             *          b1.Statements.Add(stm_a1);
             *
             *          b2.Statements.Add(stm_a2);
             *          b2.Statements.Add(stm_a3);
             *
             *          SsaIdentifier sid_a1 = new SsaIdentifier(a1, a1, stm_a1, ((Assignment)stm_a1.Instruction).Src, false);
             * SsaIdentifier sid_a2 = new SsaIdentifier(a2, a2, stm_a2, ((PhiAssignment) stm_a2.Instruction).Src, false);
             * SsaIdentifier sid_a3 = new SsaIdentifier(a3, a3, stm_a3, ((Assignment) stm_a3.Instruction).Src, false);
             *          sid_a1.Uses.Add(stm_a2);
             *          ssaIds = new SsaIdentifierCollection();
             *          ssaIds.Add(a1, sid_a1);
             *          ssaIds.Add(a2, sid_a2);
             *          ssaIds.Add(a3, sid_a3);
             */
            ssaIds = ssa.SsaState.Identifiers;
            List <SsaIdentifier> list = new List <SsaIdentifier> {
                ssaIds.Where(i => i.Identifier.Name == "a_0").Single(),
                ssaIds.Where(i => i.Identifier.Name == "a_1").Single(),
                ssaIds.Where(i => i.Identifier.Name == "a_2").Single(),
            };

            return(list);
        }
Example #13
0
 public WebBuilder(Procedure proc, SsaIdentifierCollection ssaIds, Dictionary<Identifier,LinearInductionVariable> ivs)
 {
     this.proc = proc;
     this.ssaIds = ssaIds;
     this.ivs = ivs;
     this.sla = new SsaLivenessAnalysis(proc, ssaIds);
     this.doms = proc.CreateBlockDominatorGraph();
     this.webs = new List<Web>();
 }
Example #14
0
        public void DiamondDominatorTest()
        {
            Program             prog = RewriteFile("Fragments/diamond.asm");
            Procedure           proc = prog.Procedures.Values[0];
            BlockDominatorGraph doms = proc.CreateBlockDominatorGraph();
            var diamondTop           = proc.ControlGraph.Blocks[2];

            Assert.AreSame(diamondTop, doms.ImmediateDominator(diamondTop.ElseBlock));
            Assert.AreSame(diamondTop, doms.ImmediateDominator(diamondTop.ThenBlock));
        }
Example #15
0
        public void DomDiamondTest()
        {
            Procedure           proc = new DiamondMock().Procedure;
            BlockDominatorGraph doms = proc.CreateBlockDominatorGraph();
            var topDiamond           = proc.ControlGraph.Blocks[2];

            Assert.IsTrue(doms.DominatesStrictly(topDiamond, topDiamond.ElseBlock));
            Assert.IsTrue(doms.DominatesStrictly(topDiamond, topDiamond.ThenBlock));
            Assert.IsTrue(doms.DominatesStrictly(topDiamond, topDiamond.ThenBlock.Succ[0]));
        }
		/// <summary>
		/// Builds a strongly connected component corresponding to:
		/// a1 = 0
		/// a2 = phi(a1, a3)
		/// while (a2 != 10)
		/// {
		///    a3 = a2 + 4
		/// }
		/// </summary>
		private List<SsaIdentifier> BuildScc()
		{
            var m = new ProcedureBuilder("test");
			Identifier a = new Identifier("a", PrimitiveType.Word32, null);
            m.Label("b1");
            m.Assign(a, Constant.Word32(0));
            m.Label("b2");
            m.Assign(a, m.IAdd(a, 4));
            m.BranchIf(m.Ne(a, 10), "b2");
            m.Label("b3");
            m.Return();
            this.dom = m.Procedure.CreateBlockDominatorGraph();
            var ssa = new SsaTransform(
                new ProgramDataFlow(),
                m.Procedure,
                null, 
                dom,
                new HashSet<RegisterStorage>());

            /*
            
            proc = new Procedure("test", new Frame(PrimitiveType.Word32));
			Block b1 = proc.AddBlock("b1");
			Block b2 = proc.AddBlock("b2");

			Identifier a2 = new Identifier("a2", PrimitiveType.Word32, null);
			Identifier a3 = new Identifier("a3", PrimitiveType.Word32, null);
			PhiFunction phi = new PhiFunction(a1.DataType, new Expression [] { a1, a3 });

			Statement stm_a1 = new Statement(0, new Assignment(a1, Constant.Word32(0)), null);
			Statement stm_a2 = new Statement(0, new PhiAssignment(a2, new PhiFunction(a1.DataType,  a1, a3 )), null);
			Statement stm_ex = new Statement(0, new Branch(new BinaryExpression(Operator.Ne, PrimitiveType.Bool, a2, Constant.Word32(10)), b2), null);
			Statement stm_a3 = new Statement(0, new Assignment(a3, new BinaryExpression(Operator.IAdd, a3.DataType, a2, Constant.Word32(4))), null);
			b1.Statements.Add(stm_a1);

			b2.Statements.Add(stm_a2);
			b2.Statements.Add(stm_a3);

			SsaIdentifier sid_a1 = new SsaIdentifier(a1, a1, stm_a1, ((Assignment)stm_a1.Instruction).Src, false);
            SsaIdentifier sid_a2 = new SsaIdentifier(a2, a2, stm_a2, ((PhiAssignment) stm_a2.Instruction).Src, false);
            SsaIdentifier sid_a3 = new SsaIdentifier(a3, a3, stm_a3, ((Assignment) stm_a3.Instruction).Src, false);
			sid_a1.Uses.Add(stm_a2);
			ssaIds = new SsaIdentifierCollection();
			ssaIds.Add(a1, sid_a1);
			ssaIds.Add(a2, sid_a2);
			ssaIds.Add(a3, sid_a3);
            */
            ssaIds = ssa.SsaState.Identifiers;
            List<SsaIdentifier> list = new List<SsaIdentifier> {
                ssaIds.Where(i => i.Identifier.Name == "a_0").Single(),
                ssaIds.Where(i => i.Identifier.Name == "a_1").Single(),
                ssaIds.Where(i => i.Identifier.Name == "a_2").Single(),
            };
			return list;
		}
Example #17
0
 public WebBuilder(Program program, SsaState ssa, Dictionary <Identifier, LinearInductionVariable> ivs, DecompilerEventListener listener)
 {
     this.program  = program;
     this.ssa      = ssa;
     this.ssaIds   = ssa.Identifiers;
     this.ivs      = ivs;
     this.listener = listener;
     this.sla      = new SsaLivenessAnalysis(ssa);
     this.doms     = ssa.Procedure.CreateBlockDominatorGraph();
     this.webs     = new List <Web>();
 }
Example #18
0
        public void LoopDominatorTest()
        {
            Program             prog = RewriteFile("Fragments/while_loop.asm");
            var                 proc = prog.Procedures.Values[0];
            BlockDominatorGraph doms = proc.CreateBlockDominatorGraph();

            Assert.IsTrue(doms.DominatesStrictly(proc.EntryBlock, proc.EntryBlock.Succ[0]));
            Assert.IsTrue(doms.DominatesStrictly(proc.EntryBlock, proc.EntryBlock.Succ[0].Succ[0]));
            Assert.IsTrue(doms.DominatesStrictly(proc.EntryBlock.Succ[0], proc.EntryBlock.Succ[0].Succ[0]));
            Assert.IsTrue(doms.DominatesStrictly(
                              proc.EntryBlock.Succ[0].Succ[0].Succ[0],
                              proc.EntryBlock.Succ[0].Succ[0].Succ[0].Succ[0]));
        }
Example #19
0
        private void Build(Procedure proc)
        {
            this.proc = proc;
            this.doms = proc.CreateBlockDominatorGraph();

            SsaTransform sst = new SsaTransform(
                new ProgramDataFlow(),
                proc,
                null,
                doms,
                new HashSet <RegisterStorage>());

            this.ssaIds = sst.SsaState.Identifiers;
        }
Example #20
0
		private void Build(Procedure proc)
		{
			this.proc = proc;
			this.doms = proc.CreateBlockDominatorGraph();

			SsaTransform sst = new SsaTransform(
                new ProgramDataFlow(), 
                proc, 
                null, 
                doms,
                new HashSet<RegisterStorage>());
			
			this.ssaIds = sst.SsaState.Identifiers;
		}
        private void Prepare(Procedure proc)
        {
            this.proc = proc;
            doms      = proc.CreateBlockDominatorGraph();
            SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, doms);
            SsaState     ssa = sst.SsaState;

            ssaIds = ssa.Identifiers;

            var cce = new ConditionCodeEliminator(ssaIds, new DefaultPlatform(null, new FakeArchitecture()));

            cce.Transform();

            DeadCode.Eliminate(proc, ssa);

            var vp = new ValuePropagator(ssa.Identifiers, proc);

            vp.Transform();

            DeadCode.Eliminate(proc, ssa);
            proc.Dump(true); //$DEBUG
        }
		private void Prepare(Procedure proc)
		{
			this.proc = proc;
            doms = proc.CreateBlockDominatorGraph();
			SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, doms);
			SsaState ssa = sst.SsaState;
			ssaIds = ssa.Identifiers;

            var arch = new FakeArchitecture();
            var cce = new ConditionCodeEliminator(ssaIds, new DefaultPlatform(null, arch));
			cce.Transform();

			DeadCode.Eliminate(proc, ssa);

			var vp = new ValuePropagator(arch, ssa.Identifiers, proc);
			vp.Transform();

			DeadCode.Eliminate(proc, ssa);
		}
Example #23
0
			public DominatedUseRenamer(BlockDominatorGraph domGraph)
			{
				this.domGraph = domGraph;
			}
Example #24
0
 public DeclarationInserter(SsaIdentifierCollection ssaIds, BlockDominatorGraph doms)
 {
     this.doms = doms;
 }
Example #25
0
		public DeclarationInserter(SsaIdentifierCollection ssaIds, BlockDominatorGraph doms)
		{
			this.doms = doms;
		}
Example #26
0
 public DominatedUseRenamer(BlockDominatorGraph domGraph)
 {
     this.domGraph = domGraph;
 }