Example #1
0
 /// <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);
     }
 }
Example #2
0
 public static int GetByteCount(this OpcodeValue value)
 {
     return(HasTwoBytes(value) ? 2 : 1);
 }
Example #3
0
 public static bool HasTwoBytes(this OpcodeValue value)
 {
     return((int)value >= 0x100);
 }
Example #4
0
 public static byte GetSecondByte(this OpcodeValue value)
 {
     Contract.Requires(HasTwoBytes(value));
     return(unchecked ((byte)value));
 }
Example #5
0
 public static byte GetFirstByte(this OpcodeValue value)
 {
     return(unchecked (HasTwoBytes(value) ? (byte)((ushort)value >> 8) : (byte)value));
 }
Example #6
0
 internal Opcode(OpcodeValue code, params IByteCode[] parameters) : base((byte)code, parameters)
 {
     this.code = code;
 }
Example #7
0
        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;
                }
            };
        }
Example #8
0
 public OpcodeInfo(OpcodeValue code, string comment, string arguments, string stackBefore,
                   string?stackAfter = null)
     : this(code, comment, arguments, null, stackBefore, stackAfter)
 {
 }