DecodeOp() public static method

public static DecodeOp ( ushort word, System.Text.RegularExpressions.OpCode &op, OpFlags &flags ) : void
word ushort
op System.Text.RegularExpressions.OpCode
flags OpFlags
return void
Beispiel #1
0
        public static string DisassembleOp(ushort[] image, int pc)
        {
            OpCode  opCode;
            OpFlags opFlags;

            PatternCompiler.DecodeOp(image[pc], out opCode, out opFlags);
            string text = opCode.ToString();

            if (opFlags != OpFlags.None)
            {
                text = text + "[" + opFlags.ToString("f") + "]";
            }
            switch (opCode)
            {
            case OpCode.Position:
                text = text + " /" + (Position)image[pc + 1];
                break;

            case OpCode.String:
                text = text + " '" + Disassembler.ReadString(image, pc + 1) + "'";
                break;

            case OpCode.Reference:
            case OpCode.Open:
            case OpCode.Close:
                text = text + " " + image[pc + 1];
                break;

            case OpCode.Character:
                text = text + " '" + Disassembler.FormatChar((char)image[pc + 1]) + "'";
                break;

            case OpCode.Category:
            case OpCode.NotCategory:
                text = text + " /" + (Category)image[pc + 1];
                break;

            case OpCode.Range:
                text = text + " '" + Disassembler.FormatChar((char)image[pc + 1]) + "', ";
                text = text + " '" + Disassembler.FormatChar((char)image[pc + 2]) + "'";
                break;

            case OpCode.Set:
                text = text + " " + Disassembler.FormatSet(image, pc + 1);
                break;

            case OpCode.In:
            case OpCode.Sub:
            case OpCode.Branch:
            case OpCode.Jump:
                text = text + " :" + Disassembler.FormatAddress(pc + (int)image[pc + 1]);
                break;

            case OpCode.Balance:
            {
                string text2 = text;
                text = string.Concat(new object[]
                    {
                        text2,
                        " ",
                        image[pc + 1],
                        " ",
                        image[pc + 2]
                    });
                break;
            }

            case OpCode.IfDefined:
            case OpCode.Anchor:
                text = text + " :" + Disassembler.FormatAddress(pc + (int)image[pc + 1]);
                text = text + " " + image[pc + 2];
                break;

            case OpCode.Test:
                text = text + " :" + Disassembler.FormatAddress(pc + (int)image[pc + 1]);
                text = text + ", :" + Disassembler.FormatAddress(pc + (int)image[pc + 2]);
                break;

            case OpCode.Repeat:
            case OpCode.FastRepeat:
            {
                text = text + " :" + Disassembler.FormatAddress(pc + (int)image[pc + 1]);
                string text2 = text;
                text = string.Concat(new object[]
                    {
                        text2,
                        " (",
                        image[pc + 2],
                        ", "
                    });
                if (image[pc + 3] == 65535)
                {
                    text += "Inf";
                }
                else
                {
                    text += image[pc + 3];
                }
                text += ")";
                break;
            }

            case OpCode.Info:
            {
                text = text + " " + image[pc + 1];
                string text2 = text;
                text = string.Concat(new object[]
                    {
                        text2,
                        " (",
                        image[pc + 2],
                        ", ",
                        image[pc + 3],
                        ")"
                    });
                break;
            }
            }
            return(text);
        }
Beispiel #2
0
        public static void DisassembleBlock(ushort[] image, int pc, int depth)
        {
            OpCode  op;
            OpFlags flags;

            for (;;)
            {
                if (pc >= image.Length)
                {
                    return;
                }

                PatternCompiler.DecodeOp(image[pc], out op, out flags);
                Console.Write(FormatAddress(pc) + ": ");                                // address
                Console.Write(new string (' ', depth * 2));                             // indent
                Console.Write(DisassembleOp(image, pc));                                // instruction
                Console.WriteLine();

                int skip;
                switch (op)
                {
                case OpCode.False:
                case OpCode.True:
                case OpCode.Until:
                    skip = 1;
                    break;

                case OpCode.Character:
                case OpCode.Category:
                case OpCode.Position:
                case OpCode.Open:
                case OpCode.Close:
                case OpCode.Reference:
                case OpCode.Sub:
                case OpCode.Branch:
                case OpCode.Jump:
                case OpCode.In:
                    skip = 2;
                    break;

                case OpCode.Balance:
                case OpCode.IfDefined:
                case OpCode.Range:
                case OpCode.Test:
                case OpCode.Anchor:
                    skip = 3;
                    break;

                case OpCode.Repeat:
                case OpCode.FastRepeat:
                case OpCode.Info:
                    skip = 4;
                    break;

                case OpCode.String: skip = image[pc + 1] + 2; break;

                case OpCode.Set: skip = image[pc + 2] + 3; break;

                default:
                    skip = 1;
                    break;
                }

                pc += skip;
            }
        }
Beispiel #3
0
        public static void DisassembleBlock(ushort[] image, int pc, int depth)
        {
            while (pc < image.Length)
            {
                OpCode  opCode;
                OpFlags opFlags;
                PatternCompiler.DecodeOp(image[pc], out opCode, out opFlags);
                Console.Write(Disassembler.FormatAddress(pc) + ": ");
                Console.Write(new string(' ', depth * 2));
                Console.Write(Disassembler.DisassembleOp(image, pc));
                Console.WriteLine();
                int num;
                switch (opCode)
                {
                case OpCode.False:
                case OpCode.True:
                case OpCode.Until:
                    num = 1;
                    break;

                case OpCode.Position:
                case OpCode.Reference:
                case OpCode.Character:
                case OpCode.Category:
                case OpCode.NotCategory:
                case OpCode.In:
                case OpCode.Open:
                case OpCode.Close:
                case OpCode.Sub:
                case OpCode.Branch:
                case OpCode.Jump:
                    num = 2;
                    break;

                case OpCode.String:
                    num = (int)(image[pc + 1] + 2);
                    break;

                case OpCode.Range:
                case OpCode.Balance:
                case OpCode.IfDefined:
                case OpCode.Test:
                case OpCode.Anchor:
                    num = 3;
                    break;

                case OpCode.Set:
                    num = (int)(image[pc + 2] + 3);
                    break;

                case OpCode.BalanceStart:
                    goto IL_F7;

                case OpCode.Repeat:
                case OpCode.FastRepeat:
                case OpCode.Info:
                    num = 4;
                    break;

                default:
                    goto IL_F7;
                }
IL_FE:
                pc += num;
                continue;
IL_F7:
                num = 1;
                goto IL_FE;
            }
        }
Beispiel #4
0
        public static string DisassembleOp(ushort[] image, int pc)
        {
            OpCode  op;
            OpFlags flags;

            PatternCompiler.DecodeOp(image[pc], out op, out flags);
            string str = op.ToString();

            if (flags != 0)
            {
                str += "[" + flags.ToString("f") + "]";
            }

            switch (op)
            {
            case OpCode.False:
            case OpCode.True:
            case OpCode.Until:
            default:
                break;

            case OpCode.Info:
                str += " " + image[pc + 1];
                str += " (" + image[pc + 2] + ", " + image[pc + 3] + ")";
                break;

            case OpCode.Character:
                str += " '" + FormatChar((char)image[pc + 1]) + "'";
                break;

            case OpCode.Category:
                str += " /" + (Category)image[pc + 1];
                break;

            case OpCode.Range:
                str += " '" + FormatChar((char)image[pc + 1]) + "', ";
                str += " '" + FormatChar((char)image[pc + 2]) + "'";
                break;

            case OpCode.Set:
                str += " " + FormatSet(image, pc + 1);
                break;

            case OpCode.String:
                str += " '" + ReadString(image, pc + 1) + "'";
                break;

            case OpCode.Position:
                str += " /" + (Position)image[pc + 1];
                break;

            case OpCode.Open:
            case OpCode.Close:
            case OpCode.Reference:
                str += " " + image[pc + 1];
                break;

            case OpCode.Balance:
                str += " " + image[pc + 1] + " " + image[pc + 2];
                break;

            case OpCode.IfDefined:
            case OpCode.Anchor:
                str += " :" + FormatAddress(pc + image[pc + 1]);
                str += " " + image[pc + 2];
                break;

            case OpCode.Sub:
            case OpCode.Branch:
            case OpCode.Jump:
            case OpCode.In:
                str += " :" + FormatAddress(pc + image[pc + 1]);
                break;

            case OpCode.Test:
                str += " :" + FormatAddress(pc + image[pc + 1]);
                str += ", :" + FormatAddress(pc + image[pc + 2]);
                break;

            case OpCode.Repeat:
            case OpCode.FastRepeat:
                str += " :" + FormatAddress(pc + image[pc + 1]);
                str += " (" + image[pc + 2] + ", ";
                if (image[pc + 3] == 0xffff)
                {
                    str += "Inf";
                }
                else
                {
                    str += image[pc + 3];
                }
                str += ")";
                break;
            }

            return(str);
        }