Exemplo n.º 1
0
        public static RtlTrace[] Create(FakeArchitecture arch)
        {
            var frame = arch.CreateFrame();
            var r1    = frame.EnsureRegister(arch.GetRegister(1));
            var sp    = frame.EnsureRegister(arch.StackRegister);

            return(new RtlTrace[]
            {
                new RtlTrace(0x1000)    // main
                {
                    m => { m.Assign(r1, 3); },
                    m => { m.Assign(sp, m.ISub(sp, 4)); m.Assign(m.Mem32(sp), r1); },
                    m => { m.Call(Address.Ptr32(0x1200), 4); },
                    m => { m.Assign(r1, 3); },
                    m => { m.Assign(sp, m.ISub(sp, 4)); m.Assign(m.Mem32(sp), r1); },
                    m => { m.Call(Address.Ptr32(0x1100), 4); },
                    m => { m.Return(4, 4); }
                },

                new RtlTrace(0x1100)    // odd
                {
                    m => { m.Assign(r1, m.Mem32(m.IAdd(sp, 4))); },
                    m => { m.Branch(m.Eq0(r1), Address.Ptr32(0x1120), InstrClass.ConditionalTransfer); },
                    m => { m.Assign(r1, m.Mem32(m.IAdd(sp, 4))); },
                    m => { m.Assign(r1, m.ISub(r1, 1)); },
                    m => { m.Assign(m.Mem32(m.IAdd(sp, 4)), r1); },
                    m => { m.Goto(Address.Ptr32(0x1200)); }
                },
                new RtlTrace(0x1120)
                {
                    m => { m.Assign(r1, Constant.Word32(0)); },
                    m => { m.Return(4, 4); }
                },

                new RtlTrace(0x1200)    // event
                {
                    m => { m.Assign(r1, m.Mem32(m.IAdd(sp, 4))); },
                    m => { m.Branch(m.Eq0(r1), Address.Ptr32(0x1220), InstrClass.ConditionalTransfer); },
                    m => { m.Assign(r1, m.Mem32(m.IAdd(sp, 4))); },
                    m => { m.Assign(r1, m.ISub(r1, 1)); },
                    m => { m.Assign(m.Mem32(m.IAdd(sp, 4)), r1); },
                    m => { m.Goto(Address.Ptr32(0x1100)); }
                },
                new RtlTrace(0x1220)
                {
                    m => { m.Assign(r1, Constant.Word32(1)); },
                    m => { m.Return(4, 4); }
                },
            });
        }
Exemplo n.º 2
0
        public void ExtpBind()
        {
            var sig = FunctionType.Func(
                new Identifier(Registers.ax.Name, PrimitiveType.Word16, Registers.ax),
                new Identifier [] {
                new Identifier(Registers.bx.Name, PrimitiveType.Word16, Registers.bx),
                new Identifier(Registers.cl.Name, PrimitiveType.Byte, Registers.cl)
            });
            var ep = new ExternalProcedure("foo", sig);

            Assert.AreEqual("Register word16 foo(Register word16 bx, Register byte cl)", ep.ToString());
            var fn    = new ProcedureConstant(PrimitiveType.Ptr32, ep);
            var arch  = new FakeArchitecture();
            var frame = arch.CreateFrame();
            var ab    = arch.CreateFrameApplicationBuilder(frame, new CallSite(0, 0), fn);
            var instr = ab.CreateInstruction(ep.Signature, ep.Characteristics);

            Assert.AreEqual("ax = foo(bx, cl)", instr.ToString());
        }
Exemplo n.º 3
0
        private void RunHllTest(string testName, string sExp, Action <Procedure, AbsynCodeEmitter> builder)
        {
            var arch  = new FakeArchitecture(new ServiceContainer());
            var frame = arch.CreateFrame();
            var proc  = Procedure.Create(arch, Address.Ptr32(0x00123400), frame);

            proc.Body = new List <Core.Absyn.AbsynStatement>();
            var m = new AbsynCodeEmitter(proc.Body);

            builder(proc, m);
            var program = CreateProgram(proc);
            var sActual = ProcedureRenderer.RenderProcedureHll(program, proc.EntryAddress.ToString());

            if (sExp != sActual)
            {
                Console.WriteLine(sActual);
                Assert.AreEqual(sExp, sActual);
            }
        }