Exemple #1
0
        public void StrAnls_While_BreakAtTheEndOfBody()
        {
            m.Label("head");
            m.BranchIf(m.Not(m.Fn("next")), "done");

            m.Label("loop");
            m.SideEffect(m.Fn("process"));
            m.BranchIf(m.Fn("cancel"), "done");
            m.Goto("head");

            m.Label("done");
            m.SideEffect(m.Fn("finalize"));
            m.Return(m.Int32(1));

            var sExp =
                @"    while (next())
    {
        process();
        if (cancel())
            break;
    }
    finalize();
    return 0x01;
";

            RunTest(sExp, m.Procedure);
        }
        public void Pdg_PostdominateLoop()
        {
            ProcedureBuilder m = new ProcedureBuilder();

            m.Jump("test");
            m.Label("test");
            m.BranchIf(m.LocalBool("f"), "done");
            m.Label("body");
            m.Store(m.Int32(30), m.Int32(0));
            m.Jump("test");
            m.Label("done");
            m.Return();

            FindPostDominators(m);
            string sExp =
                "body (4): idom test (3)" + nl +
                "done (5): idom ProcedureBuilder_exit (6)" + nl +
                "l1 (2): idom test (3)" + nl +
                "ProcedureBuilder_entry (1): idom l1 (2)" + nl +
                "ProcedureBuilder_exit (6): idom " + nl +
                "test (3): idom done (5)" + nl;

            Console.WriteLine(sw.ToString());
            Assert.AreEqual(sExp, sw.ToString());
        }
 public void Setup()
 {
     m   = new ProcedureBuilder();
     i   = m.Local32("i");
     c   = m.Int32(16);
     off = m.Int32(42);
     r   = m.Local32("r");
     aem = new ArrayExpressionMatcher(PrimitiveType.Pointer32);
 }
        public void Pdg_PostDominateIfElse()
        {
            ProcedureBuilder m = new ProcedureBuilder();

            m.BranchIf(m.Local32("a"), "then");
            m.Assign(m.Local32("b"), m.Int32(0));
            m.Jump("join");
            m.Label("then");
            m.Assign(m.Local32("c"), m.Int32(0));
            m.Label("join");
            m.Return();

            FindPostDominators(m);
        }
        public void Rl_SliceRegister()
        {
            Identifier eax = f.EnsureRegister(Registers.eax);
            Identifier ax  = f.EnsureRegister(Registers.ax);
            Identifier ecx = f.EnsureRegister(Registers.ecx);

            m.MStore(m.Int32(0x01F3004), ax).Instruction.Accept(rl);
            Assert.AreEqual(" ax", Dump(rl.IdentifierLiveness));
            m.Assign(eax, ecx).Accept(rl);
            Assert.AreEqual(16, rl.IdentifierLiveness.DefBitSize);
            Assert.AreEqual(" cx", Dump(rl.IdentifierLiveness));
        }
Exemple #6
0
        public void Const()
        {
            var subst = new Substitutor(ctx.Object);
            var c     = m.Int32(4);
            var c2    = c.Accept(subst);

            Assert.AreSame(c, c2);
        }
Exemple #7
0
        public void SsaOutParamters()
        {
            ProcedureBuilder m  = new ProcedureBuilder("foo");
            Identifier       r4 = m.Register(4);

            m.Store(m.Int32(0x400), m.Fn("foo", m.Out(PrimitiveType.Pointer32, r4)));
            m.Return();

            RunFileTest(m, "Analysis/SsaOutParameters.txt");
        }
Exemple #8
0
        public void CpaConstantPointer()
        {
            ProgramBuilder   prog = new ProgramBuilder();
            ProcedureBuilder m    = new ProcedureBuilder();
            Identifier       r1   = m.Register(1);

            m.Assign(r1, 0x123130);
            m.Store(r1, m.Int32(0x42));
            prog.Add(m);

            RunTest(prog.BuildProgram(), "Typing/CpaConstantPointer.txt");
        }
Exemple #9
0
        public void TrashRegister()
        {
            var r1  = m.Register(1);
            var stm = m.Assign(r1, m.Int32(0));

            trf = CreateTrashedRegisterFinder();
            CreateBlockFlow(m.Block, m.Frame);
            trf.StartProcessingBlock(m.Block);

            stm.Accept(trf);
            Debug.WriteLine(trf.RegisterSymbolicValues[(RegisterStorage)r1.Storage].ToString());
            Assert.IsTrue(trf.IsTrashed(r1.Storage), "r1 should have been marked as trashed.");
        }
Exemple #10
0
        private Procedure BuildSimpleLoop()
        {
            ProcedureBuilder m = new ProcedureBuilder();
            Identifier       p = m.Local32("p");

            m.Assign(p, 0);

            m.Label("loop");
            m.BranchIf(m.Eq(p, 0x4000), "done");
            m.Store(m.IAdd(p, 0x3000), m.Int32(0));
            m.Assign(p, m.IAdd(p, 4));
            m.Jump("loop");

            m.Label("done");
            m.Return();
            return(m.Procedure);
        }
        public void CreateNoincInitialValue()
        {
            ProcedureBuilder m = new ProcedureBuilder();

            ssaIds = new SsaIdentifierCollection();
            SsaId(new Identifier("id0", PrimitiveType.Word32, new TemporaryStorage("id0", 0, PrimitiveType.Word32)), null, null, false);
            SsaId(new Identifier("id1", PrimitiveType.Word32, new TemporaryStorage("id1", 1, PrimitiveType.Word32)), null, null, false);
            LinearInductionVariableFinder liv = new LinearInductionVariableFinder(null, ssaIds, null);

            liv.Context.InitialValue = Constant.Word32(0);
            Identifier id2 = m.Local32("id_2");

            SsaId(id2, new Statement(0, null, null), null, false);
            Assert.AreEqual(3, ssaIds.Count);

            Identifier id3 = m.Local32("id_3");
            Identifier id4 = m.Local32("id_4");

            liv.Context.PhiStatement  = m.Phi(id3, id2, id4);
            liv.Context.PhiIdentifier = id3;
            SsaId(id3, liv.Context.PhiStatement, ((PhiAssignment)liv.Context.PhiStatement.Instruction).Src, false);
            Assert.AreEqual(4, ssaIds.Count);

            Statement use = new Statement(0, null, null);

            ssaIds[id3].Uses.Add(use);

            liv.Context.DeltaValue = m.Int32(1);
            m.Assign(id4, m.IAdd(id3, liv.Context.DeltaValue));
            liv.Context.DeltaStatement = m.Block.Statements.Last;
            ssaIds[id3].Uses.Add(liv.Context.DeltaStatement);

            LinearInductionVariable iv = liv.CreateInductionVariable();

            Assert.AreEqual("(0x00000000 0x00000001 ?)", iv.ToString());
        }
 public void FindNone()
 {
     Assert.AreEqual(0, UsedIdentifierFinder.Find(null, m.Int32(3)).Count);
 }
Exemple #13
0
 public void FindNone()
 {
     Assert.AreEqual(0, ExpressionIdentifierUseFinder.Find(null, m.Int32(3)).Count);
 }