public void AddTarget(string name, IlAddress target) { if (_targets.ContainsKey(name)) { throw new InvalidOperationException($"Target '{name}' already exsists."); } _targets[name] = target; }
public void AddReference(IlAddress reference, string name) { if (_references.ContainsKey(reference)) { throw new InvalidOperationException("Call site already exsists."); } _references[reference] = name; }
private IlObject?ReadArguments(InstructionCode instruction, ReadOnlySpan <byte> program, ref int pointer) { var address = new IlAddress(pointer); switch (instruction) { case InstructionCode.Ldstr: { var arg = BinaryConvert.GetString(ref pointer, program); return(new IlObject(address, 0, arg)); } case InstructionCode.Ldloc: case InstructionCode.Stloc: case InstructionCode.Ldc_i4: case InstructionCode.Ldarg: case InstructionCode.Call: { var arg = BinaryConvert.GetInt32(ref pointer, program); return(new IlObject(address, 0, arg)); } case InstructionCode.Br: case InstructionCode.Brfalse: case InstructionCode.Brtrue: { var arg = BinaryConvert.GetInt32(ref pointer, program); _labelTargets.Add(new IlAddress(arg)); return(new IlObject(address, 0, arg)); } case InstructionCode.Ret: case InstructionCode.Add: case InstructionCode.Ceq: case InstructionCode.Pop: case InstructionCode.Nop: { return(null); } default: { Throw.NotSupportedInstruction(pointer, program[pointer - 1]); return(null); } } }
public bool TryGetReference(IlAddress reference, out string method) => _references.TryGetValue(reference, out method);
public static void InvalidStackSize(IlAddress ilAddress, int size) => throw new VmExecutionException($"Return failed because of invalid stack size '{size}'. Address: {ilAddress.ToString()}");
public static void ArgumentNotFound(IlAddress ilAddress) => throw new VmExecutionException($"Argument not found. Address: {ilAddress.ToString()}");
public static void LocalVariableNotSet(IlAddress ilAddress) => throw new VmExecutionException($"Local variable not set. Address: {ilAddress.ToString()}");
public static void StackUnderflowException(IlAddress ilAddress) => throw new VmExecutionException($"Stack underflow exception. Address: {ilAddress.ToString()}");
public static void NotSupportedInstruction(IlAddress ilAddress, byte code) => throw new VmExecutionException($"Not supported instruction. Address: {ilAddress.ToString()} Code: {InstructionFacts.Format(code)}");
public static void MissingInstructionArgument(IlAddress ilAddress) => throw new VmExecutionException($"Required instruction argument missing. Address: {ilAddress.ToString()}");
public static void InvalidInstructionArgument(IlAddress ilAddress) => throw new VmExecutionException($"Invalid instruction argument. Address: {ilAddress.ToString()}");