/// <summary> /// Obtains the <see cref="Opcode"/> instance for the given value. /// </summary> /// <param name="value">The value of the opcode.</param> /// <returns>The corresponding <see cref="Opcode"/> instance, or <c>null</c> if there is none.</returns> public static Opcode FromValue(OpcodeValue value) { if (value.GetByteCount() == 1) { return(Lookup.oneByte[(int)value]); } else { Opcode opcode; Lookup.twoByte.TryGetValue((ushort)value, out opcode); return(opcode); } }
public static int GetByteCount(this OpcodeValue value) { return(HasTwoBytes(value) ? 2 : 1); }
public static bool HasTwoBytes(this OpcodeValue value) { return((int)value >= 0x100); }
public static byte GetSecondByte(this OpcodeValue value) { Contract.Requires(HasTwoBytes(value)); return(unchecked ((byte)value)); }
public static byte GetFirstByte(this OpcodeValue value) { return(unchecked (HasTwoBytes(value) ? (byte)((ushort)value >> 8) : (byte)value)); }
internal Opcode(OpcodeValue code, params IByteCode[] parameters) : base((byte)code, parameters) { this.code = code; }
private OpcodeInfo(OpcodeValue code, string comment, string arguments, Action <OpcodeInfo, VirtualMachine.SegmentInfo, ushort, IndentedTextWriter>?writer = null, string?stackBefore = null, string?stackAfter = null) { this.Code = code; this.Comment = comment; this.arguments = arguments; this.stackBefore = stackBefore; this.stackAfter = stackAfter; if (writer != null) { this.Write = writer; return; } this.Write = (o, si, j, w) => { var lastArg = 0; var times = 1; foreach (var argument in o.arguments) { switch (argument) { case 'B': while (--times >= 0) { w.Write(" 0x{0:X2}", lastArg = VM.FetchByte()); } break; case 'N': case 'S': while (--times >= 0) { w.Write(" " + (lastArg = VM.FetchSignedByte())); } break; case 'W': while (--times >= 0) { w.Write(" 0x{0:X4}", lastArg = VM.FetchWord()); } break; case 'C': while (--times >= 0) { w.Write(" 0x{0:X4}", lastArg = VM.FetchBig()); } break; case 'A': var bytes = new byte[times]; for (var i = 0; i < times; i++) { lastArg = bytes[i] = VM.FetchByte(); } w.Write(" \"{0}\"", VM.Escape(Encoding.ASCII.GetString(bytes))); break; case '*': times = lastArg - 2; break; } times += 2; } }; }
public OpcodeInfo(OpcodeValue code, string comment, string arguments, string stackBefore, string?stackAfter = null) : this(code, comment, arguments, null, stackBefore, stackAfter) { }