public ProjectionFilter(IProcessorArchitecture arch, SsaState ssa, SegmentedAccessClassifier sac)
 {
     this.arch          = arch;
     this.ssa           = ssa;
     this.sac           = sac;
     this.NewStatements = new HashSet <Statement>();
     this.cmp           = new ExpressionValueComparer();
 }
		public void AssociateConsts()
		{
			Identifier ptr = new Identifier("ptr", PrimitiveType.SegmentSelector, null);
			SegmentedAccessClassifier mpc = new SegmentedAccessClassifier(null, null);
			mpc.Associate(ptr, Constant.Word32(3));
			mpc.Associate(ptr, Constant.Word32(4));
			Assert.IsTrue(mpc.IsOnlyAssociatedWithConstants(ptr), "Should only have been associated with constants");
		}
Example #3
0
 public ProjectionFilter(SsaState ssa, Statement stm, SegmentedAccessClassifier sac)
 {
     this.ssa           = ssa;
     this.Statement     = stm;
     this.sac           = sac;
     this.arch          = ssa.Procedure.Architecture;
     this.NewStatements = new HashSet <Statement>();
     this.cmp           = new ExpressionValueComparer();
 }
		public void DisassociateConsts()
		{
			Identifier ptr = new Identifier("ptr", PrimitiveType.SegmentSelector, null);
			Identifier mp =  new Identifier("mp",  PrimitiveType.SegmentSelector, null);
			SegmentedAccessClassifier mpc = new SegmentedAccessClassifier(null, null);
			mpc.Associate(ptr, Constant.Word32(3));
			mpc.Associate(ptr, mp);
			mpc.Associate(ptr, Constant.Word32(4));
			Assert.IsFalse(mpc.IsOnlyAssociatedWithConstants(ptr), "Should have been disassociated");
		}
		public void Disassociate()
		{
			Identifier foo = new Identifier("foo", PrimitiveType.SegmentSelector, null);
			Identifier bar = new Identifier("bar", PrimitiveType.Word16, null);
			Identifier baz = new Identifier("baz", PrimitiveType.Word16, null);
			SegmentedAccessClassifier mpc = new SegmentedAccessClassifier(null, null);
			mpc.Associate(foo, bar);
			mpc.Associate(foo, baz);
			Assert.IsNull(mpc.AssociatedIdentifier(foo), "Bar should no longer be associated");
		}
		public void Associate()
		{
			var foo = new Identifier("foo", PrimitiveType.SegmentSelector, null);
			var bar = new Identifier("bar", PrimitiveType.Word16, null);
			var mpc = new SegmentedAccessClassifier(null, null);
			mpc.Associate(foo, bar);
			Assert.IsNotNull(mpc.AssociatedIdentifier(foo), "Bar should be associated");
			mpc.Associate(foo, bar);
			Assert.IsNotNull(mpc.AssociatedIdentifier(foo), "Bar should still be associated");
		}
Example #7
0
        /// <summary>
        /// This callback is called from the SccFinder, which passes it a list
        /// of Procedures that form a SCC.
        /// </summary>
        /// <param name="procs"></param>
        private void UntangleProcedureScc(IList <Procedure> procs)
        {
            this.sccProcs = procs.ToHashSet();
            flow.CreateFlowsFor(procs);

            // Convert all procedures in the SCC to SSA form and perform
            // value propagation.
            var ssts = procs.Select(ConvertToSsa).ToArray();

            this.ssts.AddRange(ssts);
            DumpWatchedProcedure("After extra stack vars", ssts);

            // At this point, the computation of ProcedureFlow is possible.
            var trf = new TrashedRegisterFinder(program, flow, ssts, this.eventListener);

            trf.Compute();

            // New stack based variables may be available now.
            foreach (var sst in ssts)
            {
                var vp = new ValuePropagator(program.SegmentMap, sst.SsaState, program.CallGraph, dynamicLinker, this.eventListener);
                vp.Transform();
                sst.RenameFrameAccesses = true;
                sst.Transform();
                DumpWatchedProcedure("After extra stack vars", sst.SsaState.Procedure);
            }

            foreach (var ssa in ssts.Select(sst => sst.SsaState))
            {
                RemoveImplicitRegistersFromHellNodes(ssa);
                var sac = new SegmentedAccessClassifier(ssa);
                sac.Classify();
                var prj = new ProjectionPropagator(ssa, sac);
                prj.Transform();
                DumpWatchedProcedure("After projection propagation", ssa.Procedure);
            }

            var uid = new UsedRegisterFinder(flow, procs, this.eventListener);

            foreach (var sst in ssts)
            {
                var ssa = sst.SsaState;
                RemovePreservedUseInstructions(ssa);
                DeadCode.Eliminate(ssa);
                uid.ComputeLiveIn(ssa, true);
                var procFlow = flow[ssa.Procedure];
                RemoveDeadArgumentsFromCalls(ssa.Procedure, procFlow, ssts);
                DumpWatchedProcedure("After dead call argument removal", ssa.Procedure);
            }
            eventListener.Advance(procs.Count);
        }
Example #8
0
 public ProjectionPropagator(SsaState ssa, SegmentedAccessClassifier sac)
 {
     this.ssa = ssa;
     this.sac = sac;
 }
 public ProjectionPropagator(SsaState ssa, SegmentedAccessClassifier sac)
 {
     this.ssa  = ssa;
     this.sac  = sac;
     this.arch = ssa.Procedure.Architecture;
 }
		public void Classify2()
		{
			Prepare(new Mp2());
			SegmentedAccessClassifier mpc = new SegmentedAccessClassifier(proc, ssaIds);
			mpc.Classify();
            Identifier ds = ssaIds.Where(s => s.Identifier.Name == "ds").Single().Identifier;
			Assert.AreEqual("ds", ds.Name);
            Identifier bx = ssaIds.Where(s => s.Identifier.Name == "bx").Single().Identifier;
			Assert.AreEqual("bx", bx.Name);
			Identifier a = mpc.AssociatedIdentifier(ds);
			Assert.AreSame(a, bx);
		}
		public void Classify3()
		{
			Prepare(new Mp3());
			SegmentedAccessClassifier mpc = new SegmentedAccessClassifier(proc, ssaIds);
			mpc.Classify();
            Identifier ds = ssaIds.Where(s => s.Identifier.Name == "ds").Single().Identifier;
			Assert.AreEqual("ds", ds.Name);
            Identifier bx = ssaIds.Where(s => s.Identifier.Name == "bx").Single().Identifier;
			Assert.AreEqual("bx", bx.Name);
			Identifier a = mpc.AssociatedIdentifier(ds);
			Assert.IsNull(a, "ds is used both as ds:[bx+4] and ds:[0x3000], it should't be strongly associated with a register");
		}