Ejemplo n.º 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)
		{
			// 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);
		}
Ejemplo n.º 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)
        {
            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)
            {
                ;
            }

            SigType sigType = new RefSigType(ctx.RuntimeField.SignatureType);

            ctx.Result = LoadInstruction.CreateResultOperand(decoder, Operand.StackTypeFromSigType(sigType), sigType);
        }
Ejemplo n.º 3
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);
            }

            // Push the loaded value
            ctx.Result = LoadInstruction.CreateResultOperand(decoder, Operand.StackTypeFromSigType(this.typeRef), this.typeRef);
        }
Ejemplo n.º 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);

            // Opcode specific handling
            ushort locIdx;

            switch (opcode)
            {
            case OpCode.Ldloc:
                locIdx = decoder.DecodeUShort();
                break;

            case OpCode.Ldloc_s:
                locIdx = decoder.DecodeByte();
                break;

            case OpCode.Ldloc_0:
                locIdx = 0;
                break;

            case OpCode.Ldloc_1:
                locIdx = 1;
                break;

            case OpCode.Ldloc_2:
                locIdx = 2;
                break;

            case OpCode.Ldloc_3:
                locIdx = 3;
                break;

            default:
                throw new System.NotImplementedException();
            }

            // Push the loaded value onto the evaluation stack
            Operand localVariableOperand = decoder.Compiler.GetLocalOperand(locIdx);
            Operand result = LoadInstruction.CreateResultOperand(decoder, localVariableOperand.StackType, localVariableOperand.Type);

            ctx.Operand1 = localVariableOperand;
            ctx.Result   = result;
        }
Ejemplo n.º 5
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(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            ushort argIdx;

            // Opcode specific handling
            switch (opcode)
            {
            case OpCode.Ldarg:
                argIdx = decoder.DecodeUShort();
                break;

            case OpCode.Ldarg_s:
                argIdx = decoder.DecodeByte();
                break;

            case OpCode.Ldarg_0:
                argIdx = 0;
                break;

            case OpCode.Ldarg_1:
                argIdx = 1;
                break;

            case OpCode.Ldarg_2:
                argIdx = 2;
                break;

            case OpCode.Ldarg_3:
                argIdx = 3;
                break;

            default:
                throw new System.NotImplementedException();
            }

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

            ctx.Operand1 = parameterOperand;
            ctx.Result   = result;
        }
Ejemplo n.º 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);

            // Do we have a type?
            if (this.elementType == null)
            {
                // No, retrieve a type reference from the immediate argument
                Token token = decoder.DecodeTokenType();
                this.elementType = new ClassSigType(token);
            }

            StackTypeCode stackType = Operand.StackTypeFromSigType(this.elementType);
            Operand       result    = LoadInstruction.CreateResultOperand(decoder, stackType, this.elementType);

            ctx.Result = result;
        }
Ejemplo n.º 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);

            Token token = decoder.DecodeTokenType();

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

            if (ctx.RuntimeField.ContainsGenericParameter)
            {
                ;
            }

            SigType sigType = ctx.RuntimeField.SignatureType;

            Debug.Assert((ctx.RuntimeField.Attributes & FieldAttributes.Static) == FieldAttributes.Static, @"Static field access on non-static field.");
            ctx.Result = LoadInstruction.CreateResultOperand(decoder, Operand.StackTypeFromSigType(sigType), sigType);
        }