private void OpToString(MachineOperand op, MachineInstructionWriter writer) { if (op is ImmediateOperand) { writer.Write("#" + op.ToString()); } else { writer.Write(op.ToString()); } }
private int Ea(MachineOperand op) { var rop = op as RegisterOperand; if (rop != null) { var dReg = rop.Register as DataRegister; if (dReg != null) return (dReg.Number & 7); var aReg = rop.Register as AddressRegister; if (aReg != null) return (aReg.Number & 7) | 8; throw new NotImplementedException(op.ToString()); } var mop = op as MemoryOperand; if (mop != null) { var aReg = mop.Base; if (mop.Offset == null || mop.Offset.ToInt32() == 0) return (aReg.Number & 7 | 0x10); constants.Add((ushort) mop.Offset.ToInt32()); return (aReg.Number & 7 | 0x28); } var postOp = op as PostIncrementMemoryOperand; if (postOp != null) { return (postOp.Register.Number & 7 | 0x18); } var preOp = op as PredecrementMemoryOperand; if (preOp != null) { return (preOp.Register.Number & 7 | 0x20); } var addrOp = op as M68kAddressOperand; if (addrOp != null) { Imm(addrOp.Width.Size, addrOp.Address.ToUInt32()); return 0x39; } var immOp = op as M68kImmediateOperand; if (immOp != null) { Imm(immOp.Width.Size, immOp.Constant.ToUInt32()); return 0x3C; } throw new NotImplementedException(op.ToString()); }
private void Write(MachineOperand op, MachineInstructionWriter writer) { var reg = op as RegisterOperand; if (reg != null) { writer.Write("%{0}", reg.Register.Name); return; } var imm = op as ImmediateOperand; if (imm != null) { writer.Write(imm.Value.ToString()); return; } var mem = op as MemoryOperand; if (mem != null) { mem.Write(false, writer); return; } var idx = op as IndexedMemoryOperand; if (idx != null) { idx.Write(false, writer); return; } writer.Write(op.ToString()); }
public Expression RewriteDst(MachineOperand operand, Address addrInstr, PrimitiveType dataWidth, Expression src, Func<Expression ,Expression, Expression> opGen) { var reg = operand as RegisterOperand; if (reg != null) { Expression r = frame.EnsureRegister(reg.Register); Expression tmp = r; if (dataWidth != null && reg.Width.BitSize > dataWidth.BitSize) { Expression rSub = m.Cast(dataWidth, r); var srcExp = opGen(src, rSub); if (srcExp is Identifier || srcExp is Constant || srcExp is DepositBits) { tmp = srcExp; } else { tmp = frame.CreateTemporary(dataWidth); m.Assign(tmp, srcExp); } src = m.Dpb(r, tmp, 0, dataWidth.BitSize); } else { src = opGen(src, r); } m.Assign(r, src); return tmp; } var dbl = operand as DoubleRegisterOperand; if (dbl != null) { Identifier h = frame.EnsureRegister(dbl.Register1); Identifier l = frame.EnsureRegister( dbl.Register2); var d = frame.EnsureSequence(h, l, PrimitiveType.Word64); var result = opGen(src, l); m.Assign(d, result); return d; } var addr = operand as M68kAddressOperand; if (addr != null) { var load = m.Load(dataWidth, addr.Address); var tmp = frame.CreateTemporary(dataWidth); m.Assign(tmp, opGen(src, load)); m.Assign(load, tmp); return tmp; } var mem = operand as MemoryOperand; if (mem != null) { var load = RewriteMemoryAccess(mem, dataWidth, addrInstr); var tmp = frame.CreateTemporary(dataWidth); m.Assign(tmp, opGen(src, load)); m.Assign(load, tmp); return tmp; } var post = operand as PostIncrementMemoryOperand; if (post != null) { var r = frame.EnsureRegister(post.Register); var tmp = frame.CreateTemporary(dataWidth); m.Assign(tmp, opGen(src, m.Load(post.Width, r))); m.Assign(m.Load(dataWidth, r), tmp); m.Assign(r, m.IAdd(r, dataWidth.Size)); return tmp; } var pre = operand as PredecrementMemoryOperand; if (pre != null) { var r = frame.EnsureRegister(pre.Register); src = Spill(src, r); m.Assign(r, m.ISub(r, dataWidth.Size)); var load = m.Load(dataWidth, r); var tmp = frame.CreateTemporary(dataWidth); m.Assign(tmp, opGen(src, load)); m.Assign(m.Load(dataWidth, r), tmp); return tmp; } var indidx = operand as IndirectIndexedOperand; if (indidx != null) { Expression ea = frame.EnsureRegister(indidx.ARegister); if (indidx.Imm8 != 0) ea = m.IAdd(ea, Constant.Int32(indidx.Imm8)); Expression ix = frame.EnsureRegister(indidx.XRegister); if (indidx.Scale > 1) ix = m.IMul(ix, Constant.Int32(indidx.Scale)); var load = m.Load(dataWidth, m.IAdd(ea, ix)); var tmp = frame.CreateTemporary(dataWidth); m.Assign(tmp, opGen(src, load)); m.Assign(load, tmp); return tmp; } throw new NotImplementedException("Unimplemented RewriteDst for operand type " + operand.ToString()); }
public Expression RewriteUnary( MachineOperand operand, Address addrInstr, PrimitiveType dataWidth, Func<Expression, Expression> opGen) { var reg = operand as RegisterOperand; if (reg != null) { Expression r = frame.EnsureRegister(reg.Register); if (r.DataType.Size > dataWidth.Size) { var tmp = frame.CreateTemporary(dataWidth); m.Assign(tmp, opGen(m.Cast(dataWidth, r))); m.Assign(r, m.Dpb(r, tmp, 0, dataWidth.BitSize)); return tmp; } else { m.Assign(r, opGen(r)); return r; } } var addr = operand as M68kAddressOperand; if (addr != null) { var load = m.Load(dataWidth, addr.Address); var tmp = frame.CreateTemporary(dataWidth); m.Assign(tmp, opGen(load)); m.Assign(load, tmp); return tmp; } var mem = operand as MemoryOperand; if (mem != null) { var load = RewriteMemoryAccess(mem, dataWidth, addrInstr); var tmp = frame.CreateTemporary(dataWidth); m.Assign(tmp, opGen(load)); m.Assign(RewriteMemoryAccess(mem,dataWidth, addrInstr), tmp); return tmp; } var post = operand as PostIncrementMemoryOperand; if (post != null) { var r = frame.EnsureRegister(post.Register); var tmp = frame.CreateTemporary(dataWidth); m.Assign(tmp, opGen(m.Load(dataWidth, r))); m.Assign(m.Load(dataWidth, r), tmp); m.Assign(r, m.IAdd(r, dataWidth.Size)); return tmp; } var pre = operand as PredecrementMemoryOperand; if (pre != null) { var r = frame.EnsureRegister(pre.Register); m.Assign(r, m.ISub(r, dataWidth.Size)); var tmp = frame.CreateTemporary(dataWidth); m.Assign(tmp, opGen(m.Load(dataWidth, r))); m.Assign(m.Load(dataWidth, r), tmp); return tmp; } throw new NotImplementedException("Unimplemented RewriteUnary for operand type " + operand.ToString()); }