Пример #1
0
        private void GetOpCodeArg(ReadOnlySpan <byte> program, out string value)
        {
            if (_pointer >= program.Length)
            {
                Throw.MissingInstructionArgument(_pointer);
            }

            value = BinaryConvert.GetString(ref _pointer, program);
        }
Пример #2
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);
            }
            }
        }