public static string OpcodeName(OpcodeCompiler handler) { if (handler == null) { return("<unknown>"); } MethodInfo mi = handler.Method; string name = mi.Name; if (name.StartsWith("op_")) { return(name.Remove(0, 3)); } else { return(name); } }
public Opcode(ZMachine zm, OpcodeCompiler compiler, OpcodeAttribute attribute, int pc, int zCodeLength, int argc, OperandType[] operandTypes, short[] operandValues, string operandText, int resultStorage, bool branchIfTrue, int branchOffset) { this.zm = zm; this.compiler = compiler; this.attribute = attribute; this.PC = pc; this.ZCodeLength = zCodeLength; this.argc = argc; this.operandTypes = new OperandType[argc]; Array.Copy(operandTypes, this.operandTypes, argc); this.operandValues = new short[argc]; Array.Copy(operandValues, this.operandValues, argc); this.operandText = operandText; this.resultStorage = resultStorage; this.branchIfTrue = branchIfTrue; this.branchOffset = branchOffset; }
private static void InitOpcodeTable() { MethodInfo[] mis = typeof(Opcode).GetMethods( BindingFlags.NonPublic | BindingFlags.Instance); foreach (MethodInfo mi in mis) { OpcodeAttribute[] attrs = (OpcodeAttribute[])mi.GetCustomAttributes(typeof(OpcodeAttribute), false); if (attrs.Length > 0) { OpcodeCompiler del = (OpcodeCompiler)Delegate.CreateDelegate( typeof(OpcodeCompiler), null, mi); OpcodeAttribute a = attrs[0]; OpcodeInfo info = new OpcodeInfo(a, del); switch (a.OpCount) { case OpCount.Zero: zeroOpInfos.Add((byte)(a.Number - 176), info); break; case OpCount.One: oneOpInfos.Add((byte)(a.Number - 128), info); break; case OpCount.Two: twoOpInfos.Add(a.Number, info); break; case OpCount.Var: varOpInfos.Add((byte)(a.Number - 224), info); break; case OpCount.Ext: extOpInfos.Add(a.Number, info); break; } } } }
internal static string GetOpcodeName(OpcodeAttribute attribute, OpcodeCompiler handler) { if (attribute != null && attribute.Alias != null) { return(attribute.Alias); } if (handler == null) { return("<unknown>"); } MethodInfo mi = handler.Method; string name = mi.Name; if (name.StartsWith("op_")) { return(name.Remove(0, 3)); } else { return(name); } }
public OpcodeInfo(OpcodeAttribute attr, OpcodeCompiler compiler) { this.Attr = attr; this.Compiler = compiler; }
public static string OpcodeName(OpcodeCompiler handler) { if (handler == null) return "<unknown>"; MethodInfo mi = handler.Method; string name = mi.Name; if (name.StartsWith("op_")) return name.Remove(0, 3); else return name; }
private static void InitOpcodeTable() { MethodInfo[] mis = typeof(Opcode).GetMethods( BindingFlags.NonPublic | BindingFlags.Instance); foreach (MethodInfo mi in mis) { OpcodeAttribute[] attrs = (OpcodeAttribute[])mi.GetCustomAttributes(typeof(OpcodeAttribute), false); if (attrs.Length > 0) { OpcodeCompiler del = (OpcodeCompiler)Delegate.CreateDelegate( typeof(OpcodeCompiler), null, mi); foreach (OpcodeAttribute a in attrs) { OpcodeInfo info = new OpcodeInfo(a, del); byte num; Dictionary <byte, OpcodeInfo[]> dict; switch (a.OpCount) { case OpCount.Zero: dict = zeroOpInfos; num = (byte)(a.Number - 176); break; case OpCount.One: dict = oneOpInfos; num = (byte)(a.Number - 128); break; case OpCount.Two: dict = twoOpInfos; num = a.Number; break; case OpCount.Var: dict = varOpInfos; num = (byte)(a.Number - 224); break; case OpCount.Ext: dict = extOpInfos; num = a.Number; break; default: throw new Exception("BUG:BADOPCOUNT"); } OpcodeInfo[] array; if (dict.TryGetValue(num, out array) == false) { array = new OpcodeInfo[] { info }; dict.Add(num, array); } else { OpcodeInfo[] newArray = new OpcodeInfo[array.Length + 1]; Array.Copy(array, newArray, array.Length); newArray[newArray.Length - 1] = info; dict[num] = newArray; } } } } }