Esempio n. 1
0
        public static void DisassembleBlock(ushort[] image, int pc, int depth)
        {
            while (pc < image.Length)
            {
                PatternCompiler.DecodeOp(image[pc], out OpCode op, out OpFlags _);
                Console.Write(FormatAddress(pc) + ": ");
                Console.Write(new string(' ', depth * 2));
                Console.Write(DisassembleOp(image, pc));
                Console.WriteLine();
                int num;
                switch (op)
                {
                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.Range:
                case OpCode.Balance:
                case OpCode.IfDefined:
                case OpCode.Test:
                case OpCode.Anchor:
                    num = 3;
                    break;

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

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

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

                default:
                    num = 1;
                    break;
                }
                pc += num;
            }
        }
Esempio n. 2
0
        public static string DisassembleOp(ushort[] image, int pc)
        {
            PatternCompiler.DecodeOp(image[pc], out OpCode op, out OpFlags flags);
            string text = op.ToString();

            if (flags != 0)
            {
                text = text + "[" + flags.ToString("f") + "]";
            }
            switch (op)
            {
            case OpCode.Info:
            {
                text = text + " " + image[pc + 1];
                string text2 = text;
                text = text2 + " (" + image[pc + 2] + ", " + image[pc + 3] + ")";
                break;
            }

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

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

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

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

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

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

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

            case OpCode.Balance:
            {
                string text2 = text;
                text = text2 + " " + image[pc + 1] + " " + image[pc + 2];
                break;
            }

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

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

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

            case OpCode.Repeat:
            case OpCode.FastRepeat:
            {
                text = text + " :" + FormatAddress(pc + image[pc + 1]);
                string text2 = text;
                text  = text2 + " (" + image[pc + 2] + ", ";
                text  = ((image[pc + 3] != ushort.MaxValue) ? (text + image[pc + 3]) : (text + "Inf"));
                text += ")";
                break;
            }
            }
            return(text);
        }