private static Expression <Action <Cpu, byte, uint[]> > BuildExpression(OpCodeMetaInformation metaInformation) { var pCpu = Expression.Parameter(typeof(Cpu), "cpu"); var pControlFlag = Expression.Parameter(typeof(byte), "controlFlag"); var pValues = Expression.Parameter(typeof(uint[]), "values"); var actionParams = new[] { pCpu, pControlFlag, pValues }; var pParams = new List <Expression> { pCpu, pControlFlag }; pParams.AddRange( metaInformation .Parameters .Select((x, i) => Expression.ArrayIndex(pValues, Expression.Constant(i))) ); Expression body = Expression.Call(metaInformation.Method, pParams); return(Expression.Lambda <Action <Cpu, byte, uint[]> >(body, actionParams)); }
public static string ToString(OpCodeMetaInformation meta, Instruction instruction) { var format = "{0}{1};{2}"; return(string.Format(format, instruction.OpCode.ToString().PadRight(10), string.Join(string.Empty, instruction.Parameters.Select((x, i) => FormatValue(meta.Parameters, i, instruction.OpCodeMask, x))).PadRight(24), instruction.Comment ?? meta.Comment)); }
public static string ToString(OpCodeMetaInformation meta, Instruction instruction) { var format = "{0}{1};{2}"; return string.Format(format, instruction.OpCode.ToString().PadRight(10), string.Join(string.Empty, instruction.Parameters.Select((x, i) => FormatValue(meta.Parameters, i, instruction.OpCodeMask, x))).PadRight(24), instruction.Comment ?? meta.Comment); }
public static bool GetMetaData(Instruction instruction, out OpCodeMetaInformation result) { if (OpCodeMetaInformation.Lookup.TryGetValue(instruction.OpCode, out result)) { return true; } result = new OpCodeMetaInformation { OpCode = instruction.OpCode, Comment = "Unknown instruction", Parameters = instruction.Parameters.Select(x => new ParameterInfo {Name = "Unknown", Type = ParamType.None}).ToArray() }; return false; }
public static bool GetMetaData(Instruction instruction, out OpCodeMetaInformation result) { if (OpCodeMetaInformation.Lookup.TryGetValue(instruction.OpCode, out result)) { return(true); } result = new OpCodeMetaInformation { OpCode = instruction.OpCode, Comment = "Unknown instruction", Parameters = instruction.Parameters.Select(x => new ParameterInfo { Name = "Unknown", Type = ParamType.None }).ToArray() }; return(false); }
public static void ValidateMetaParameters(Instruction instruction, OpCodeMetaInformation meta) { if (meta.Parameters.Length != instruction.Parameters.Length) { throw new InvalidOperationException($"Parameter mismatch: {meta.OpCode} ({meta.Parameters.Length}, {instruction.Parameters.Length})"); } for (var i = 0; i < meta.Parameters.Length; i++) { var metaParameter = meta.Parameters[i]; if (metaParameter.Type != ParamType.Register) { continue; } var parameterValue = instruction.Parameters[i]; if (parameterValue >= Cpu.RegisterCount) throw new ArgumentOutOfRangeException("Unknown register: r" + parameterValue + 1); } }
private static Expression<Action<Cpu, byte, uint[]>> BuildExpression(OpCodeMetaInformation metaInformation) { var pCpu = Expression.Parameter(typeof (Cpu), "cpu"); var pControlFlag = Expression.Parameter(typeof (byte), "controlFlag"); var pValues = Expression.Parameter(typeof (uint[]), "values"); var actionParams = new[] { pCpu, pControlFlag, pValues }; var pParams = new List<Expression> {pCpu, pControlFlag}; pParams.AddRange( metaInformation .Parameters .Select((x, i) => Expression.ArrayIndex(pValues, Expression.Constant(i))) ); Expression body = Expression.Call(metaInformation.Method, pParams); return Expression.Lambda<Action<Cpu, byte, uint[]>>(body, actionParams); }
public static void ValidateMetaParameters(Instruction instruction, OpCodeMetaInformation meta) { if (meta.Parameters.Length != instruction.Parameters.Length) { throw new InvalidOperationException($"Parameter mismatch: {meta.OpCode} ({meta.Parameters.Length}, {instruction.Parameters.Length})"); } for (var i = 0; i < meta.Parameters.Length; i++) { var metaParameter = meta.Parameters[i]; if (metaParameter.Type != ParamType.Register) { continue; } var parameterValue = instruction.Parameters[i]; if (parameterValue >= Cpu.RegisterCount) { throw new ArgumentOutOfRangeException("Unknown register: r" + parameterValue + 1); } } }
public static Action <Cpu, byte, uint[]> BuildOperation(OpCodeMetaInformation metaInformation) { var expression = BuildExpression(metaInformation); return(expression.Compile()); }
public static Action<Cpu, byte, uint[]> BuildOperation(OpCodeMetaInformation metaInformation) { var expression = BuildExpression(metaInformation); return expression.Compile(); }