/// <summary> /// Creates a new physical register <see cref="Operand" />. /// </summary> /// <param name="type">The type.</param> /// <param name="register">The register.</param> /// <returns></returns> public static Operand CreateCPURegister(MosaType type, Register register) { var operand = new Operand(type); operand.IsCPURegister = true; operand.Register = register; return operand; }
/// <summary> /// Creates a new local variable <see cref="Operand" />. /// </summary> /// <param name="type">The type.</param> /// <param name="register">The register.</param> /// <param name="displacement">The displacement.</param> /// <param name="index">The index.</param> /// <returns></returns> public static Operand CreateParameter(MosaType type, Register register, int displacement, int index, string name) { var operand = new Operand(type); operand.IsMemoryAddress = true; operand.IsParameter = true; operand.Register = register; operand.Index = index; operand.Displacement = displacement; operand.Name = name; return operand; }
/// <summary> /// Creates a new stack address <see cref="Operand"/>. /// </summary> /// <param name="sigType">Type of the sig.</param> /// <param name="baseRegister">The base register.</param> /// <param name="index">The index.</param> /// <returns></returns> public static Operand CreateStackLocalTemp(SigType sigType, Register baseRegister, int index) { Operand operand = new Operand(sigType, OperandType.MemoryAddress | OperandType.StackLocal | OperandType.VirtualRegister); operand.register = baseRegister; operand.index = index; operand.offset = new IntPtr(-index * 4); return operand; }
/// <summary> /// Creates the stack local. /// </summary> /// <param name="type">The type.</param> /// <param name="register">The register.</param> /// <param name="index">The index.</param> /// <param name="pinned">if set to <c>true</c> [pinned].</param> /// <returns></returns> public static Operand CreateStackLocal(MosaType type, Register register, int index, bool pinned) { var operand = new Operand(type); operand.IsMemoryAddress = true; operand.Register = register; operand.Index = index; operand.IsStackLocal = true; operand.IsPinned = pinned; return operand; }
/// <summary> /// Creates a new memory address <see cref="Operand"/>. /// </summary> /// <param name="sigType">Type of the sig.</param> /// <param name="baseRegister">The base register.</param> /// <param name="offset">The offset.</param> /// <returns></returns> public static Operand CreateMemoryAddress(SigType sigType, Register baseRegister, IntPtr offset) { Operand operand = new Operand(sigType, OperandType.MemoryAddress); operand.register = baseRegister; operand.offset = offset; return operand; }
/// <summary> /// Creates a new local variable <see cref="Operand"/>. /// </summary> /// <param name="type">The type.</param> /// <param name="register">The register.</param> /// <param name="param">The param.</param> /// <returns></returns> public static Operand CreateParameter(SigType type, Register register, RuntimeParameter param, int index) { Operand operand = new Operand(type, OperandType.MemoryAddress | OperandType.Parameter); operand.register = register; operand.index = index; // param.Position; operand.offset = new IntPtr(param.Position * 4); return operand; }
/// <summary> /// Creates a new physical register <see cref="Operand"/>. /// </summary> /// <param name="sigType">Type of the sig.</param> /// <param name="register">The register.</param> /// <returns></returns> public static Operand CreateCPURegister(SigType sigType, Register register) { Operand operand = new Operand(sigType, OperandType.Register | OperandType.CPURegister); operand.register = register; return operand; }
/// <summary> /// Creates a new local variable <see cref="Operand"/>. /// </summary> /// <param name="type">The type.</param> /// <param name="register">The register.</param> /// <param name="index">The index.</param> /// <param name="name">The name.</param> /// <returns></returns> public static Operand CreateLocalVariable(SigType type, Register register, int index, string name) { Operand operand = new Operand(type, OperandType.MemoryAddress | OperandType.StackLocal | OperandType.LocalVariable); operand.name = name; operand.register = register; operand.index = index; operand.offset = new IntPtr(-index * 4); return operand; }
/// <summary> /// Initializes a new instance of the <see cref="LiveRange"/> class. /// </summary> /// <param name="block">The block.</param> /// <param name="op">The op.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> public LiveRange(BasicBlock block, Operand op, int start, int end) { this.Block = block; this.Op = op; this.Reg = null; this.Start = start; this.End = end; }
private SimRegister ConvertToRegister(Mosa.Compiler.Framework.Register register) { if (register == Mosa.Platform.x86.GeneralPurposeRegister.EAX) { return(CPU.EAX); } if (register == Mosa.Platform.x86.GeneralPurposeRegister.EBX) { return(CPU.EBX); } if (register == Mosa.Platform.x86.GeneralPurposeRegister.ECX) { return(CPU.ECX); } if (register == Mosa.Platform.x86.GeneralPurposeRegister.EDX) { return(CPU.EDX); } if (register == Mosa.Platform.x86.GeneralPurposeRegister.ESI) { return(CPU.ESI); } if (register == Mosa.Platform.x86.GeneralPurposeRegister.EDI) { return(CPU.EDI); } if (register == Mosa.Platform.x86.GeneralPurposeRegister.EBP) { return(CPU.EBP); } if (register == Mosa.Platform.x86.GeneralPurposeRegister.ESP) { return(CPU.ESP); } if (register == Mosa.Platform.x86.SSE2Register.XMM0) { return(CPU.XMM0); } if (register == Mosa.Platform.x86.SSE2Register.XMM1) { return(CPU.XMM1); } if (register == Mosa.Platform.x86.SSE2Register.XMM2) { return(CPU.XMM2); } if (register == Mosa.Platform.x86.SSE2Register.XMM3) { return(CPU.XMM3); } if (register == Mosa.Platform.x86.SSE2Register.XMM4) { return(CPU.XMM4); } if (register == Mosa.Platform.x86.SSE2Register.XMM5) { return(CPU.XMM5); } if (register == Mosa.Platform.x86.SSE2Register.XMM6) { return(CPU.XMM6); } if (register == Mosa.Platform.x86.SSE2Register.XMM7) { return(CPU.XMM7); } if (register == Mosa.Platform.x86.ControlRegister.CR0) { return(CPU.CR0); } if (register == Mosa.Platform.x86.ControlRegister.CR2) { return(CPU.CR2); } if (register == Mosa.Platform.x86.ControlRegister.CR3) { return(CPU.CR3); } if (register == Mosa.Platform.x86.ControlRegister.CR4) { return(CPU.CR4); } if (register == Mosa.Platform.x86.SegmentRegister.CS) { return(CPU.CS); } if (register == Mosa.Platform.x86.SegmentRegister.DS) { return(CPU.DS); } if (register == Mosa.Platform.x86.SegmentRegister.ES) { return(CPU.ES); } if (register == Mosa.Platform.x86.SegmentRegister.FS) { return(CPU.FS); } if (register == Mosa.Platform.x86.SegmentRegister.GS) { return(CPU.GS); } if (register == Mosa.Platform.x86.SegmentRegister.SS) { return(CPU.SS); } return(null); }
public static OpcodeEncoder AppendSIB(this OpcodeEncoder encoder, int scale, Register index, Register @base) { Debug.Assert(scale == 1 || scale == 2 || scale == 4 || scale == 8); int svalue = 0; if (scale == 1) svalue = 0; else if (scale == 2) svalue = 1; else if (scale == 4) svalue = 2; else if (scale == 8) svalue = 3; // scale encoder.AppendBits(svalue, 2); // index if (index == null) encoder.Append3Bits(Bits.b100); else encoder.AppendRegister(index); // base if (@base == null) encoder.Append3Bits(Bits.b101); else encoder.AppendRegister(@base); return encoder; }
public static OpcodeEncoder AppendRM(this OpcodeEncoder encoder, Register register) { return encoder.Append3Bits(register.RegisterCode); }
/// <summary> /// Returns a string representation of <see cref="Operand"/>. /// </summary> /// <returns>A string representation of the operand.</returns> public string ToString(bool full) { if (IsSSA) { string ssa = SSAParent.ToString(full); int pos = ssa.IndexOf(' '); if (pos < 0) { return(ssa + "<" + SSAVersion + ">"); } else { return(ssa.Substring(0, pos) + "<" + SSAVersion + ">" + ssa.Substring(pos)); } } var sb = new StringBuilder(); if (IsVirtualRegister) { sb.AppendFormat("V_{0}", Index); } else if (IsStackLocal && Name == null) { sb.AppendFormat("T_{0}", Index); } else if (IsParameter && Name == null) { sb.AppendFormat("P_{0}", Index); } if (Name != null) { sb.Append(Name); sb.Append(' '); } if (IsField) { sb.Append(' '); sb.Append(Field.FullName); } if (IsSplitChild) { sb.Append(' '); sb.Append("(" + SplitParent.ToString(full) + ")"); if (SplitParent.High == this) { sb.Append("/high"); } else { sb.Append("/low"); } } if (IsConstant) { sb.Append(" const {"); if (IsNull) { sb.Append("null"); } else if (IsUnsigned || IsBoolean || IsChar || IsPointer) { if (IsU8) { sb.AppendFormat("{0}", ConstantUnsignedLongInteger); } else { sb.AppendFormat("{0}", ConstantUnsignedInteger); } } else if (IsSigned) { if (IsI8) { sb.AppendFormat("{0}", ConstantSignedLongInteger); } else { sb.AppendFormat("{0}", ConstantSignedInteger); } } if (IsR8) { sb.AppendFormat("{0}", ConstantDoubleFloatingPoint); } else if (IsR4) { sb.AppendFormat("{0}", ConstantSingleFloatingPoint); } sb.Append('}'); } if (IsCPURegister) { sb.AppendFormat(" {0}", Register); } else if (IsMemoryAddress) { sb.Append(' '); if (OffsetBase != null) { if (Displacement > 0) { sb.AppendFormat("[{0}+{1:X}h]", OffsetBase.ToString(full), Displacement); } else { sb.AppendFormat("[{0}-{1:X}h]", OffsetBase.ToString(full), -Displacement); } } else if (Register != null) { if (Displacement > 0) { sb.AppendFormat("[{0}+{1:X}h]", Register.ToString(), Displacement); } else { sb.AppendFormat("[{0}-{1:X}h]", Register.ToString(), -Displacement); } } else if (IsField && IsSplitChild) { if (Displacement > 0) { sb.AppendFormat("+{0:X}h", Displacement); } else { sb.AppendFormat("-{0:X}h", -Displacement); } } } if (full) { sb.AppendFormat(" [{0}]", Type.FullName); } return(sb.ToString().Replace(" ", " ").Trim()); }