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.LoadDw(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.LoadDw(sp), r1); }, m => { m.Call(Address.Ptr32(0x1100), 4); }, m => { m.Return(4, 4); } }, new RtlTrace(0x1100) // odd { m => { m.Assign(r1, m.LoadDw(m.IAdd(sp, 4))); }, m => { m.Branch(m.Eq0(r1), Address.Ptr32(0x1120), RtlClass.ConditionalTransfer); }, m => { m.Assign(r1, m.LoadDw(m.IAdd(sp, 4))); }, m => { m.Assign(r1, m.ISub(r1, 1)); }, m => { m.Assign(m.LoadDw(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.LoadDw(m.IAdd(sp, 4))); }, m => { m.Branch(m.Eq0(r1), Address.Ptr32(0x1220), RtlClass.ConditionalTransfer); }, m => { m.Assign(r1, m.LoadDw(m.IAdd(sp, 4))); }, m => { m.Assign(r1, m.ISub(r1, 1)); }, m => { m.Assign(m.LoadDw(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); } }, }; }
public void ExtpBind() { var sig = new ProcedureSignature( 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.Pointer32, ep); var arch = new FakeArchitecture(); var frame = arch.CreateFrame(); var ab = new ApplicationBuilder(new FakeArchitecture(), frame, new CallSite(0, 0), fn, ep.Signature, false); var instr = ab.CreateInstruction(); Assert.AreEqual("ax = foo(bx, cl)", instr.ToString()); }