Пример #1
0
        public void Exs_Rolc_To_Shl()
        {
            Given_ExpressionSimplifier();
            var expr = m.Fn(rolc_8, foo, m.Byte(1), Constant.False());

            Assert.AreEqual("foo_1 << 1<8>", expr.Accept(simplifier).ToString());
        }
Пример #2
0
        public void StrAnls_NestedWhile()
        {
            var r1 = m.Reg32("r1", 1);
            var r2 = m.Reg32("r2", 2);

            m.Label("head1");
            m.BranchIf(m.Ge(r1, 4), "done1");

            m.Label("body1");
            m.Declare(r2, m.Word32(0));
            m.Label("head2");
            m.BranchIf(m.Ge(r2, 4), "done2");

            m.Label("body2");
            m.Store(m.IAdd(
                        m.Word32(0x1232100),
                        m.IAdd(
                            m.IMul(r1, 4),
                            r2)),
                    m.Byte(0));
            m.Assign(r2, m.IAdd(r2, 1));
            m.Goto("head2");

            m.Label("done2");
            m.Assign(r1, m.IAdd(r1, 1));
            m.Goto("head1");

            m.Label("done1");
            m.Return();

            var sExp =
                #region Expected
                @"    while (r1 < 0x04)
    {
        word32 r2 = 0x00;
        while (r2 < 0x04)
        {
            Mem0[0x01232100 + (r1 * 0x04 + r2):byte] = 0x00;
            r2 = r2 + 0x01;
        }
        r1 = r1 + 0x01;
    }
    return;
";

            #endregion
            RunTest(sExp, m.Procedure);
        }
Пример #3
0
        public void VpUndoSlicingOfSegmentPointerCheckUses()
        {
            var es      = Reg16("es");
            var es_2    = Reg16("es_2");
            var bx      = Reg16("bx");
            var bx_3    = Reg16("bx_3");
            var bx_4    = Reg16("bx_4");
            var es_bx_1 = Reg32("es_bx_1");

            m.Store(SegMem(PrimitiveType.Byte, es, m.IAdd(bx, 4)), m.Byte(3));
            m.Assign(es_bx_1, SegMem(PrimitiveType.Word32, es, bx));
            m.Assign(es_2, m.Slice(PrimitiveType.Word16, es_bx_1, 16));
            m.Assign(bx_3, m.Cast(PrimitiveType.Word16, es_bx_1));
            var instr = m.Assign(bx_4, SegMem(PrimitiveType.Word16, es_2, m.IAdd(bx_3, 4)));

            RunValuePropagator(m);
            Assert.AreEqual("bx_4 = Mem8[es_bx_1 + 0x0004:word16]", instr.ToString());
        }
Пример #4
0
        public void VpUndoUnnecessarySlicingOfSegmentPointer()
        {
            var m     = new ProcedureBuilder();
            var es    = m.Reg16("es", 1);
            var bx    = m.Reg16("bx", 3);
            var es_bx = m.Frame.EnsureSequence(es.Storage, bx.Storage, PrimitiveType.Word32);

            m.Assign(es_bx, m.SegMem(PrimitiveType.Word32, es, bx));
            m.Assign(es, m.Slice(PrimitiveType.Word16, es_bx, 16));
            m.Assign(bx, m.Cast(PrimitiveType.Word16, es_bx));
            m.SStore(es, m.IAdd(bx, 4), m.Byte(3));

            var ssa = RunTest(m);

            var sExp =
                #region Expected
                @"es:es
    def:  def es
    uses: es_bx_3 = Mem0[es:bx:word32]
bx:bx
    def:  def bx
    uses: es_bx_3 = Mem0[es:bx:word32]
Mem0:Global memory
    def:  def Mem0
    uses: es_bx_3 = Mem0[es:bx:word32]
es_bx_3: orig: es_bx
    def:  es_bx_3 = Mem0[es:bx:word32]
    uses: es_4 = SLICE(es_bx_3, word16, 16)
          bx_5 = (word16) es_bx_3
          Mem6[es_bx_3 + 0x0004:byte] = 0x03
es_4: orig: es
    def:  es_4 = SLICE(es_bx_3, word16, 16)
bx_5: orig: bx
    def:  bx_5 = (word16) es_bx_3
Mem6: orig: Mem0
    def:  Mem6[es_bx_3 + 0x0004:byte] = 0x03
// ProcedureBuilder
// Return size: 0
void ProcedureBuilder()
ProcedureBuilder_entry:
	def es
	def bx
	def Mem0
	// succ:  l1
l1:
	es_bx_3 = Mem0[es:bx:word32]
	es_4 = SLICE(es_bx_3, word16, 16)
	bx_5 = (word16) es_bx_3
	Mem6[es_bx_3 + 0x0004:byte] = 0x03
ProcedureBuilder_exit:
";

            #endregion

            AssertStringsEqual(sExp, ssa);
        }
Пример #5
0
        public void BlockDoesntTerminate()
        {
            var m = new ProcedureBuilder();

            m.Store(m.Word32(0x1231), m.Byte(0));
            var b = m.Block;

            m.Return();
            var a = new TerminationAnalysis(flow, eventListener);

            program = new Program
            {
                Architecture = new FakeArchitecture()
            };
            flow[b] = CreateBlockFlow(b, m.Frame);
            a.Analyze(b);
            Assert.IsFalse(flow[b].TerminatesProcess);
        }
Пример #6
0
        public void VpUndoUnnecessarySlicingOfSegmentPointer()
        {
            var m     = new ProcedureBuilder();
            var es    = m.Reg16("es", 1);
            var bx    = m.Reg16("bx", 3);
            var es_bx = m.Frame.EnsureSequence(PrimitiveType.Word32, es.Storage, bx.Storage);

            m.Assign(es_bx, m.SegMem(PrimitiveType.Word32, es, bx));
            m.Assign(es, m.Slice(PrimitiveType.Word16, es_bx, 16));
            m.Assign(bx, m.Slice(PrimitiveType.Word16, es_bx, 0));
            m.SStore(es, m.IAdd(bx, 4), m.Byte(3));

            var ssa = RunTest(m);

            var sExp =
                #region Expected
                @"es:es
    def:  def es
    uses: es_bx_4 = Mem0[es:bx:word32]
bx:bx
    def:  def bx
    uses: es_bx_4 = Mem0[es:bx:word32]
Mem0:Mem
    def:  def Mem0
    uses: es_bx_4 = Mem0[es:bx:word32]
es_bx_4: orig: es_bx
    def:  es_bx_4 = Mem0[es:bx:word32]
    uses: es_5 = SLICE(es_bx_4, word16, 16) (alias)
          bx_6 = SLICE(es_bx_4, word16, 0) (alias)
          es_7 = SLICE(es_bx_4, word16, 16)
          bx_8 = SLICE(es_bx_4, word16, 0)
          Mem9[es_bx_4 + 4<16>:byte] = 3<8>
es_5: orig: es
    def:  es_5 = SLICE(es_bx_4, word16, 16) (alias)
bx_6: orig: bx
    def:  bx_6 = SLICE(es_bx_4, word16, 0) (alias)
es_7: orig: es
    def:  es_7 = SLICE(es_bx_4, word16, 16)
bx_8: orig: bx
    def:  bx_8 = SLICE(es_bx_4, word16, 0)
Mem9: orig: Mem0
    def:  Mem9[es_bx_4 + 4<16>:byte] = 3<8>
// ProcedureBuilder
// Return size: 0
define ProcedureBuilder
ProcedureBuilder_entry:
	def es
	def bx
	def Mem0
	// succ:  l1
l1:
	es_bx_4 = Mem0[es:bx:word32]
	es_5 = SLICE(es_bx_4, word16, 16) (alias)
	bx_6 = SLICE(es_bx_4, word16, 0) (alias)
	es_7 = SLICE(es_bx_4, word16, 16)
	bx_8 = SLICE(es_bx_4, word16, 0)
	Mem9[es_bx_4 + 4<16>:byte] = 3<8>
ProcedureBuilder_exit:
";

            #endregion

            AssertStringsEqual(sExp, ssa);
        }