예제 #1
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            base.Decode(ctx, decoder);

            Token token = decoder.DecodeTokenType();
            ctx.RuntimeField = decoder.Method.Module.GetField(token);

            // FIXME: Can this be put into a re-used method?
            if (ctx.RuntimeField.ContainsGenericParameter || ctx.RuntimeField.DeclaringType.ContainsOpenGenericParameters)
            {
                foreach (var field in decoder.Method.DeclaringType.Fields)
                {
                    if (field.Name == ctx.RuntimeField.Name)
                    {
                        ctx.RuntimeField = field;
                        break;
                    }
                }

                if (ctx.RuntimeField.ContainsGenericParameter)
                {
                    ctx.RuntimeField = decoder.GenericTypePatcher.PatchField(decoder.TypeModule, decoder.Method.DeclaringType as CilGenericType, ctx.RuntimeField);
                }
                decoder.Compiler.Scheduler.TrackFieldReferenced(ctx.RuntimeField);
                Debug.Assert(!ctx.RuntimeField.ContainsGenericParameter);
            }

            SigType sigType = new RefSigType(ctx.RuntimeField.SignatureType);
            ctx.Result = LoadInstruction.CreateResultOperand(decoder, Operand.StackTypeFromSigType(sigType), sigType);
        }
예제 #2
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Read the branch target
            // Is this a short branch target?
            // FIXME: Remove unary branch instructions from this list.
            if (_opcode == OpCode.Beq_s || _opcode == OpCode.Bge_s || _opcode == OpCode.Bge_un_s || _opcode == OpCode.Bgt_s ||
                _opcode == OpCode.Bgt_un_s || _opcode == OpCode.Ble_s || _opcode == OpCode.Ble_un_s || _opcode == OpCode.Blt_s ||
                _opcode == OpCode.Blt_un_s || _opcode == OpCode.Bne_un_s) {
                sbyte target;
                decoder.Decode(out target);
                ctx.SetBranch(target);
            }
            else if (_opcode == OpCode.Beq || _opcode == OpCode.Bge || _opcode == OpCode.Bge_un || _opcode == OpCode.Bgt ||
                _opcode == OpCode.Bgt_un || _opcode == OpCode.Ble || _opcode == OpCode.Ble_un || _opcode == OpCode.Blt ||
                _opcode == OpCode.Blt_un || _opcode == OpCode.Bne_un) {
                int target;
                decoder.Decode(out target);
                ctx.SetBranch(target);
            }
            else {
                throw new NotSupportedException(@"Invalid branch opcode specified for BinaryBranchInstruction");
            }
        }
예제 #3
0
        /// <summary>
        /// Decodes the specified CIL instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        /// <remarks>
        /// This method is used by instructions to retrieve immediate operands
        /// From the instruction stream.
        /// </remarks>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            int index;

            // Opcode specific handling
            switch (opcode)
            {
                case OpCode.Ldarg:
                case OpCode.Ldarg_s: index = (int)decoder.Instruction.Operand; break;
                case OpCode.Ldarg_0: index = 0; break;
                case OpCode.Ldarg_1: index = 1; break;
                case OpCode.Ldarg_2: index = 2; break;
                case OpCode.Ldarg_3: index = 3; break;
                default: throw new System.NotImplementedException();
            }

            // Push the loaded value onto the evaluation stack
            var parameterOperand = decoder.Compiler.GetParameterOperand(index);
            var result = LoadInstruction.CreateResultOperand(decoder, parameterOperand.Type);

            ctx.Operand1 = parameterOperand;
            ctx.Result = result;
        }
예제 #4
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Load the _stackFrameIndex token from the immediate
            Token token = decoder.DecodeTokenType();

            //Console.WriteLine("Stfld used in {0}.{1}", decoder.Method.DeclaringType.FullName, decoder.Method.Name);

            Debug.Assert(token.Table == TableType.Field || token.Table == TableType.MemberRef, @"Invalid token type.");

            ITypeModule module = null;
            Mosa.Runtime.TypeSystem.Generic.CilGenericType genericType = decoder.Method.DeclaringType as Mosa.Runtime.TypeSystem.Generic.CilGenericType;
            if (genericType != null)
                module = (decoder.Method.DeclaringType as Mosa.Runtime.TypeSystem.Generic.CilGenericType).BaseGenericType.Module;
            else
                module = decoder.Method.Module;

            ctx.RuntimeField = module.GetField(token);

            if (ctx.RuntimeField.ContainsGenericParameter)
            {
                foreach (RuntimeField field in decoder.Method.DeclaringType.Fields)
                    if (field.Name == ctx.RuntimeField.Name)
                    {
                        ctx.RuntimeField = field;
                        break;
                    }

                Debug.Assert(!ctx.RuntimeField.ContainsGenericParameter);
            }
        }
예제 #5
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Opcode specific handling
            int index;
            switch (opcode)
            {
                case OpCode.Ldloc:
                case OpCode.Ldloc_s: index = (int)decoder.Instruction.Operand; break;
                case OpCode.Ldloc_0: index = 0; break;
                case OpCode.Ldloc_1: index = 1; break;
                case OpCode.Ldloc_2: index = 2; break;
                case OpCode.Ldloc_3: index = 3; break;
                default: throw new InvalidMetadataException();
            }

            // Push the loaded value onto the evaluation stack
            var local = decoder.Compiler.GetLocalOperand(index);
            var result = LoadInstruction.CreateResultOperand(decoder, local.Type);

            ctx.Operand1 = local;
            ctx.Result = result;
        }
예제 #6
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            throw new NotImplementedException();
        }
예제 #7
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Read the branch target
            // Is this a short branch target?
            if (opcode == OpCode.Brfalse_s || opcode == OpCode.Brtrue_s)
            {
                sbyte target = decoder.DecodeSByte();
                ctx.SetBranch(target);
            }
            else if (opcode == OpCode.Brfalse || opcode == OpCode.Brtrue)
            {
                int target = decoder.DecodeInt();
                ctx.SetBranch(target);
            }
            else if (opcode == OpCode.Switch)
            {
                // Don't do anything, the derived class will do everything
            }
            else
            {
                throw new NotSupportedException(@"Invalid opcode " + opcode.ToString() + " specified for UnaryBranchInstruction.");
            }
        }
예제 #8
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode the base first
            base.Decode(ctx, decoder);

            ushort argIdx;

            // Opcode specific handling
            if (opcode == OpCode.Starg_s)
            {
                byte arg = decoder.DecodeByte();
                argIdx = arg;
            }
            else
            {
                argIdx = decoder.DecodeUShort();
            }

            // The argument is the result
            ctx.Result = decoder.Compiler.GetParameterOperand(argIdx);

            // FIXME: Do some type compatibility checks
            // See verification for this instruction and
            // verification types.
        }
예제 #9
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Load the _stackFrameIndex token from the immediate
            TokenTypes token = decoder.DecodeTokenType();

            //Console.WriteLine("Stfld used in {0}.{1}", decoder.Method.DeclaringType.FullName, decoder.Method.Name);

            Debug.Assert(TokenTypes.Field == (TokenTypes.TableMask & token) || TokenTypes.MemberRef == (TokenTypes.TableMask & token), @"Invalid token type.");

            ctx.RuntimeField = decoder.ModuleTypeSystem.GetField(token);

            if (ctx.RuntimeField.ContainsGenericParameter)
            {
                foreach (RuntimeField field in decoder.Method.DeclaringType.Fields)
                    if (field.Name == ctx.RuntimeField.Name)
                    {
                        ctx.RuntimeField = field;
                        break;
                    }

                Debug.Assert(!ctx.RuntimeField.ContainsGenericParameter);
            }
        }
예제 #10
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            Token token = decoder.DecodeTokenType();
            ITypeModule module = null;
            Mosa.Runtime.TypeSystem.Generic.CilGenericType genericType = decoder.Method.DeclaringType as Mosa.Runtime.TypeSystem.Generic.CilGenericType;
            if (genericType != null)
                module = (decoder.Method.DeclaringType as Mosa.Runtime.TypeSystem.Generic.CilGenericType).BaseGenericType.Module;
            else
                module = decoder.Method.Module;
            ctx.RuntimeField = module.GetField(token);

            if (ctx.RuntimeField.ContainsGenericParameter)
            {
                foreach (RuntimeField field in decoder.Method.DeclaringType.Fields)
                    if (field.Name == ctx.RuntimeField.Name)
                    {
                        ctx.RuntimeField = field;
                        break;
                    }

                Debug.Assert(!ctx.RuntimeField.ContainsGenericParameter);
            }

            SigType sigType = ctx.RuntimeField.SignatureType;
            ctx.Result = LoadInstruction.CreateResultOperand(decoder, Operand.StackTypeFromSigType(sigType), sigType);
        }
예제 #11
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Opcode specific handling
            int index;
            switch (opcode)
            {
                case OpCode.Ldloc:
                case OpCode.Ldloc_s: index = (int)decoder.Instruction.Operand; break;
                case OpCode.Ldloc_0: index = 0; break;
                case OpCode.Ldloc_1: index = 1; break;
                case OpCode.Ldloc_2: index = 2; break;
                case OpCode.Ldloc_3: index = 3; break;
                default: throw new InvalidMetadataException();
            }

            // Push the loaded value onto the evaluation stack
            var local = decoder.Compiler.LocalVariables[index];
            var result = AllocateVirtualRegisterOrStackSlot(decoder.Compiler, local.Type);

            ctx.Operand1 = local;
            ctx.Result = result;
        }
예제 #12
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Read the type specification
            TokenTypes arrayEType;
            decoder.Decode(out arrayEType);
            ctx.Token = arrayEType;

            Mosa.Runtime.Vm.RuntimeType type = RuntimeBase.Instance.TypeLoader.GetType(decoder.Compiler.Assembly, arrayEType);
            //ctx.Result =
            /*
                TypeReference eType = MetadataTypeReference.FromToken(decoder.Metadata, arrayEType);

                // FIXME: If _operands[0] is an integral constant, we can infer the maximum size of the array
                // and instantiate an ArrayTypeSpecification with max. sizes. This way we could eliminate bounds
                // checks in an optimization stage later on, if we find that a value never exceeds the array
                // bounds.

                // Build a type specification
                ArrayTypeSpecification typeRef = new ArrayTypeSpecification(eType);
                _results[0] = CreateResultOperand(typeRef);
             */
        }
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Push the address on the stack
            ctx.Result = decoder.Compiler.CreateVirtualRegister(decoder.TypeSystem.BuiltIn.U);
        }
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            byte alignment = decoder.DecodeByte();
            ctx.Other = alignment;
        }
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // FIXME: Validate operands & verify instruction
            ctx.Result = decoder.Compiler.CreateTemporary(new SigType(CilElementType.I4));
        }
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // FIXME: Validate operands & verify instruction
            ctx.Result = decoder.Compiler.CreateVirtualRegister(decoder.TypeSystem.BuiltIn.I4);
        }
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Set the result
            ctx.Result = decoder.Compiler.CreateTemporary(new SigType(CilElementType.I4));
        }
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            byte alignment = (byte)decoder.Instruction.Operand;
            ctx.Other = alignment;
        }
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Set the result
            ctx.Result = decoder.Compiler.CreateVirtualRegister(decoder.TypeSystem.BuiltIn.I4);
        }
예제 #20
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // FIXME: Validate operands & verify instruction
            ctx.Result = decoder.Compiler.CreateVirtualRegister(BuiltInSigType.Int32);
        }
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Set the result
            ctx.Result = decoder.Compiler.CreateTemporary(BuiltInSigType.Int32);
        }
예제 #22
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Push the address on the stack
            ctx.Result = decoder.Compiler.CreateTemporary(BuiltInSigType.IntPtr);
        }
예제 #23
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            var type = (MosaType)decoder.Instruction.Operand;
            ctx.Result = decoder.Compiler.CreateVirtualRegister(decoder.TypeSystem.BuiltIn.Object);
            ctx.MosaType = type;
        }
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            var block = decoder.GetBlock((int)decoder.Instruction.Operand);

            ctx.AddBranchTarget(block);
        }
예제 #25
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            var type = (MosaType)decoder.Instruction.Operand;

            ctx.Result = decoder.Compiler.CreateVirtualRegister(type.ToManagedPointer());
        }
예제 #26
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            byte nocheck = (byte)decoder.Instruction.Operand;
            //FUTURE:
            //ctx.Other = nocheck;
        }
예제 #27
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            byte nocheck= decoder.DecodeByte();

            ctx.Other = nocheck;
        }
예제 #28
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            var type = (MosaType)decoder.Instruction.Operand;

            throw new NotImplementCompilerException();
        }
예제 #29
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Set the result
            ctx.TokenType = ((HeapIndexToken)decoder.DecodeInt()) | HeapIndexToken.UserString;

            ctx.Result = decoder.Compiler.CreateTemporary(BuiltInSigType.String);
        }
예제 #30
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Retrieve the provider token to check against
            TokenTypes token = decoder.DecodeTokenType();

            ctx.Result = decoder.Compiler.CreateTemporary(new ClassSigType(token));
        }
예제 #31
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            MosaType type = (elementType == null)
                                ? type = (MosaType)decoder.Instruction.Operand
                                : type = decoder.TypeSystem.GetTypeFromTypeCode(elementType.Value);

            ctx.MosaType = type;
        }
예제 #32
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            var field = (MosaField)decoder.Instruction.Operand;

            decoder.Compiler.Scheduler.TrackFieldReferenced(field);

            ctx.MosaField = field;
        }
예제 #33
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            base.Decode(ctx, decoder);

            var field = (MosaField)decoder.Instruction.Operand;

            decoder.Compiler.Scheduler.TrackFieldReferenced(field);

            ctx.MosaField = field;
            ctx.Result    = LoadInstruction.CreateResultOperand(decoder, field.FieldType.ToManagedPointer());
        }
예제 #34
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Retrieve a type reference from the immediate argument
            // FIXME: Limit the token types
            Token token = decoder.DecodeTokenType();

            throw new NotImplementedException();
        }
예제 #35
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            MosaType type = (MosaType)decoder.Instruction.Operand;

            ctx.MosaType = type;

            ctx.Result = decoder.Compiler.CreateVirtualRegister(decoder.TypeSystem.BuiltIn.I4);
        }
예제 #36
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            MosaType type = (elementType == null)
                                ? type = (MosaType)decoder.Instruction.Operand
                                : type = decoder.TypeSystem.GetTypeFromTypeCode(elementType.Value);

            ctx.Result = AllocateVirtualRegisterOrStackSlot(decoder.Compiler, type);
        }
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="node">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode node, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(node, decoder);

            // Retrieve a type reference from the immediate argument
            // FIXME: Limit the token types
            var token = (MosaType)decoder.Instruction.Operand;

            throw new CompilerException();
        }
예제 #38
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="node">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode node, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(node, decoder);

            node.MosaType = (elementType == null)
                                ? (MosaType)decoder.Instruction.Operand
                                : decoder.MethodCompiler.Compiler.GetTypeFromTypeCode(elementType.Value);

            // FIXME: Check the value/destinations
        }
예제 #39
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            byte nocheck;

            decoder.Decode(out nocheck);

            ctx.Other = nocheck;
        }
예제 #40
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            base.Decode(ctx, decoder);

            var field = (MosaField)decoder.Instruction.Operand;

            decoder.Compiler.Scheduler.TrackFieldReferenced(field);

            ctx.MosaField = field;
            ctx.Result    = AllocateVirtualRegisterOrStackSlot(decoder.Compiler, field.FieldType.ToManagedPointer());
        }
예제 #41
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode the base first
            base.Decode(ctx, decoder);

            // The argument is the result
            ctx.Result = decoder.Compiler.GetParameterOperand((int)decoder.Instruction.Operand);

            // FIXME: Do some type compatibility checks
            // See verification for this instruction and
            // verification types.
        }
예제 #42
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Opcode specific handling

            Operand local = decoder.Compiler.GetLocalOperand((int)decoder.Instruction.Operand);

            ctx.Operand1 = local;
            ctx.Result   = decoder.Compiler.CreateVirtualRegister(local.Type.ToManagedPointer());
        }
예제 #43
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="node">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode node, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(node, decoder);

            var field = (MosaField)decoder.Instruction.Operand;

            Debug.Assert(field.IsStatic, "Static field access on non-static field.");

            node.MosaField = field;
            node.Result    = decoder.MethodCompiler.AllocateVirtualRegisterOrStackSlot(field.FieldType);
        }
예제 #44
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="node">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode node, IInstructionDecoder decoder)
        {
            // Decode the base first
            base.Decode(node, decoder);

            // The argument is the result
            node.Result = decoder.MethodCompiler.Parameters[(int)decoder.Instruction.Operand];

            // FIXME: Do some type compatibility checks
            // See verification for this instruction and
            // verification types.
        }
예제 #45
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="node">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode node, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(node, decoder);

            var field = (MosaField)decoder.Instruction.Operand;

            decoder.MethodCompiler.Scheduler.TrackFieldReferenced(field);

            node.Result    = AllocateVirtualRegisterOrStackSlot(decoder.MethodCompiler, field.FieldType);
            node.MosaField = field;
        }
예제 #46
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            Token token = decoder.DecodeTokenType();

            RuntimeType type = decoder.TypeModule.GetType(token);

            ctx.Result = decoder.Compiler.CreateTemporary(new ClassSigType(token));
            //throw new NotImplementedException();
        }
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            var type = (MosaType)decoder.Instruction.Operand;

            //Operand result = decoder.Compiler.CreateVirtualRegister(type);
            //ctx.Result = result;
            ctx.Result   = LoadInstruction.CreateResultOperand(decoder, type);
            ctx.MosaType = type;
        }
예제 #48
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            var field = (MosaField)decoder.Instruction.Operand;

            decoder.Compiler.Scheduler.TrackFieldReferenced(field);

            ctx.MosaField = field;
            ctx.Result    = LoadInstruction.CreateResultOperand(decoder, field.FieldType);
        }
예제 #49
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="node">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode node, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(node, decoder);

            var method = (MosaMethod)decoder.Instruction.Operand;

            decoder.MethodCompiler.Scheduler.TrackMethodInvoked(method);

            node.Result       = decoder.MethodCompiler.CreateVirtualRegister(decoder.TypeSystem.ToFnPtr(method.Signature));
            node.InvokeMethod = method;
        }
예제 #50
0
        public override void Decode(InstructionNode node, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(node, decoder);

            var type = (MosaType)decoder.Instruction.Operand;

            //Operand result = decoder.Compiler.CreateVirtualRegister(type);
            //ctx.Result = result;
            node.Result   = decoder.MethodCompiler.AllocateVirtualRegisterOrStackSlot(type);
            node.MosaType = type;
        }
예제 #51
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            var field = (MosaField)decoder.Instruction.Operand;

            decoder.Compiler.Scheduler.TrackFieldReferenced(field);

            ctx.MosaField = field;
            ctx.Result    = decoder.Compiler.CreateVirtualRegister(field.FieldType.ToManagedPointer());
        }
예제 #52
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Retrieve the type reference
            Token token = decoder.DecodeTokenType();

            ctx.Token = token;

            decoder.TypeModule.GetType(token);
        }
예제 #53
0
        /// <summary>
        /// Decodes the invocation target.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The IL decoder, which provides decoding functionality.</param>
        /// <param name="flags">Flags, which control the</param>
        /// <returns></returns>
        protected static Token DecodeInvocationTarget(Context ctx, IInstructionDecoder decoder, InvokeSupportFlags flags)
        {
            // Retrieve the immediate argument - it contains the token
            // of the methoddef, methodref, methodspec or callsite to call.
            Token callTarget = decoder.DecodeTokenType();

            if (!IsCallTargetSupported(callTarget.Table, flags))
            {
                throw new InvalidOperationException(@"Invalid IL call target specification.");
            }

            RuntimeMethod method = null;
            ITypeModule   module = null;

            Mosa.Runtime.TypeSystem.Generic.CilGenericType genericType = decoder.Method.DeclaringType as Mosa.Runtime.TypeSystem.Generic.CilGenericType;
            if (genericType != null)
            {
                module = (decoder.Method.DeclaringType as Mosa.Runtime.TypeSystem.Generic.CilGenericType).BaseGenericType.Module;
            }
            else
            {
                module = decoder.Method.Module;
            }

            switch (callTarget.Table)
            {
            case TableType.MethodDef:
                method = module.GetMethod(callTarget);
                break;

            case TableType.MemberRef:
                method = module.GetMethod(callTarget, decoder.Method.DeclaringType);
                if (method.DeclaringType.IsGeneric)
                {
                    decoder.Compiler.Scheduler.ScheduleTypeForCompilation(method.DeclaringType);
                }
                break;

            case TableType.MethodSpec:
                method = module.GetMethod(callTarget);
                decoder.Compiler.Scheduler.ScheduleTypeForCompilation(method.DeclaringType);
                break;

            default:
                Debug.Assert(false, @"Should never reach this!");
                break;
            }

            SetInvokeTarget(ctx, decoder.Compiler, method);

            return(callTarget);
        }
예제 #54
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="node">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode node, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(node, decoder);

            MosaType type = (elementType == null)
                                ? type = (MosaType)decoder.Instruction.Operand
                                : type = decoder.TypeSystem.GetTypeFromTypeCode(elementType.Value);

            node.MosaType = type;

            // FIXME: Check the value/destinations
        }
예제 #55
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Opcode specific handling
            int index = (int)decoder.Instruction.Operand;

            var parameterOperand = decoder.Compiler.Parameters[index];

            ctx.Operand1 = parameterOperand;
            ctx.Result   = decoder.Compiler.CreateVirtualRegister(parameterOperand.Type.ToManagedPointer());
        }
예제 #56
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Retrieve a type reference From the immediate argument
            // FIXME: Limit the token types
            TokenTypes token;

            decoder.Decode(out token);
            throw new NotImplementedException();
            //_typeRef = MetadataTypeReference.FromToken(decoder.Metadata, token);
        }
예제 #57
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Do we have a type?
            if (this._typeRef == null)
            {
                // No, retrieve a type reference from the immediate argument
                Token token = decoder.DecodeTokenType();
                this._typeRef = new ClassSigType(token);
            }
        }
예제 #58
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            MosaType type = (elementType == null)
                                ? type = (MosaType)decoder.Instruction.Operand
                                : type = decoder.TypeSystem.GetTypeFromTypeCode(elementType.Value);

            // Push the loaded value
            ctx.Result   = LoadInstruction.CreateResultOperand(decoder, type);
            ctx.MosaType = type;
        }
예제 #59
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="node">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(InstructionNode node, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(node, decoder);

            // Opcode specific handling
            var local = decoder.MethodCompiler.LocalVariables[(int)decoder.Instruction.Operand];

            local = decoder.ConvertVirtualRegisterToStackLocal(local);

            node.Operand1 = local;
            node.Result   = decoder.MethodCompiler.CreateVirtualRegister(local.Type.ToManagedPointer());
        }
예제 #60
0
        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Read the field From the code
            TokenTypes token;

            decoder.Decode(out token);

            ctx.RuntimeField = RuntimeBase.Instance.TypeLoader.GetField(decoder.Compiler.Assembly, token);
            Debug.Assert((ctx.RuntimeField.Attributes & FieldAttributes.Static) == FieldAttributes.Static, @"Static field access on non-static field.");
        }