Ejemplo n.º 1
0
        public void AddTarget(string name, IlAddress target)
        {
            if (_targets.ContainsKey(name))
            {
                throw new InvalidOperationException($"Target '{name}' already exsists.");
            }

            _targets[name] = target;
        }
Ejemplo n.º 2
0
        public void AddReference(IlAddress reference, string name)
        {
            if (_references.ContainsKey(reference))
            {
                throw new InvalidOperationException("Call site already exsists.");
            }

            _references[reference] = name;
        }
Ejemplo n.º 3
0
        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);
            }
            }
        }
Ejemplo n.º 4
0
 public bool TryGetReference(IlAddress reference, out string method)
 => _references.TryGetValue(reference, out method);
Ejemplo n.º 5
0
 public static void InvalidStackSize(IlAddress ilAddress, int size)
 => throw new VmExecutionException($"Return failed because of invalid stack size '{size}'. Address: {ilAddress.ToString()}");
Ejemplo n.º 6
0
 public static void ArgumentNotFound(IlAddress ilAddress)
 => throw new VmExecutionException($"Argument not found. Address: {ilAddress.ToString()}");
Ejemplo n.º 7
0
 public static void LocalVariableNotSet(IlAddress ilAddress)
 => throw new VmExecutionException($"Local variable not set. Address: {ilAddress.ToString()}");
Ejemplo n.º 8
0
 public static void StackUnderflowException(IlAddress ilAddress)
 => throw new VmExecutionException($"Stack underflow exception. Address: {ilAddress.ToString()}");
Ejemplo n.º 9
0
 public static void NotSupportedInstruction(IlAddress ilAddress, byte code)
 => throw new VmExecutionException($"Not supported instruction. Address: {ilAddress.ToString()} Code: {InstructionFacts.Format(code)}");
Ejemplo n.º 10
0
 public static void MissingInstructionArgument(IlAddress ilAddress)
 => throw new VmExecutionException($"Required instruction argument missing. Address: {ilAddress.ToString()}");
Ejemplo n.º 11
0
 public static void InvalidInstructionArgument(IlAddress ilAddress)
 => throw new VmExecutionException($"Invalid instruction argument. Address: {ilAddress.ToString()}");