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); }
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; } }