/// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            // Simple result is the same type as the unary argument
            ctx.Result = compiler.CreateTemporary(ctx.Operand1.Type);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            // Simple result is the same type as the unary argument
            ctx.Result = compiler.CreateTemporary(ctx.Operand1.Type);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            StackTypeCode result = StackTypeCode.Unknown;

            switch (_opcode)
            {
            case OpCode.Add_ovf_un:
                result = _addovfunTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                break;

            case OpCode.Sub_ovf_un:
                result = _subovfunTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                break;

            default:

                result = _operandTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                break;
            }

            if (StackTypeCode.Unknown == result)
            {
                throw new InvalidOperationException("Invalid operand types passed to " + _opcode);
            }

            ctx.Result = compiler.CreateTemporary(Operand.SigTypeFromStackType(result));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            Mosa.Runtime.Metadata.Signatures.ArraySigType a = ctx.Operand1.Type as Mosa.Runtime.Metadata.Signatures.ArraySigType;
            if (null == a || 1 != a.Rank)
                throw new InvalidProgramException(@"Operand to ldlen is not a vector.");
            ctx.Result = compiler.CreateTemporary(new SigType(CilElementType.I));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            StackTypeCode result = StackTypeCode.Unknown;

            switch (_opcode)
            {
            case OpCode.Add:
                result = _addTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                break;

            case OpCode.Sub:
                result = _subTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                break;

            default:

                result = _operandTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                break;
            }

            if (StackTypeCode.Unknown == result)
            {
                throw new InvalidOperationException("Invalid operand types passed to " + _opcode);
            }

            SigType resultType;

            if (result != StackTypeCode.Ptr)
            {
                resultType = Operand.SigTypeFromStackType(result);
            }

            else
            {
                // Copy the pointer element type
                PtrSigType op0 = ctx.Operand1.Type as PtrSigType;
                PtrSigType op1 = ctx.Operand2.Type as PtrSigType;
                if (op0 != null)
                {
                    resultType = new PtrSigType(op0.CustomMods, op0.ElementType);
                }
                else if (op1 != null)
                {
                    resultType = new PtrSigType(op1.CustomMods, op1.ElementType);
                }

                else
                {
                    throw new InvalidOperationException();
                }
            }

            ctx.Result = compiler.CreateTemporary(resultType);
        }
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            StackTypeCode result = _opTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
            if (result == StackTypeCode.Unknown)
                throw new InvalidOperationException(@"Invalid stack result of instruction.");

            ctx.Result = compiler.CreateTemporary(Operand.SigTypeFromStackType(result));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            SZArraySigType arrayType = ctx.Operand1.Type as SZArraySigType;
            if (arrayType == null)
                throw new InvalidProgramException(@"Operand to ldlen is not a vector.");

            ctx.Result = compiler.CreateTemporary(BuiltInSigType.IntPtr);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            Mosa.Runtime.Metadata.Signatures.ArraySigType a = ctx.Operand1.Type as Mosa.Runtime.Metadata.Signatures.ArraySigType;
            if (null == a || 1 != a.Rank)
            {
                throw new InvalidProgramException(@"Operand to ldlen is not a vector.");
            }
            ctx.Result = compiler.CreateTemporary(new SigType(CilElementType.I));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            // Validate the operand
            StackTypeCode result = _opTable[(int)ctx.Operand1.StackType];
            if (StackTypeCode.Unknown == result)
                throw new InvalidOperationException(@"Invalid operand to Not instruction.");

            ctx.Result = compiler.CreateTemporary(ctx.Operand1.Type);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            StackTypeCode result = _operandTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
            Debug.Assert(StackTypeCode.Unknown != result, @"Can't shift with the given stack operands.");
            if (StackTypeCode.Unknown == result)
                throw new InvalidOperationException(@"Invalid stack state for pairing (" + ctx.Operand1.StackType + ", " + ctx.Operand2.StackType + ")");

            ctx.Result = compiler.CreateTemporary(Operand.SigTypeFromStackType(result));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            StackTypeCode result = _opTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];

            if (result == StackTypeCode.Unknown)
            {
                throw new ExecutionEngineException("Invalid stack result of instruction.");
            }

            ctx.Result = compiler.CreateTemporary(Operand.SigTypeFromStackType(result));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            // Validate the operand
            StackTypeCode result = _typeCodes[(int)ctx.Operand1.StackType];

            if (StackTypeCode.Unknown == result)
            {
                throw new InvalidOperationException(@"Invalid operand to Neg instruction.");
            }

            ctx.Result = compiler.CreateTemporary(ctx.Operand1.Type);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            StackTypeCode result = _operandTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];

            Debug.Assert(StackTypeCode.Unknown != result, @"Can't shift with the given stack operands.");
            if (StackTypeCode.Unknown == result)
            {
                throw new ExecutionEngineException(@"Invalid stack state.");
            }

            ctx.Result = compiler.CreateTemporary(Operand.SigTypeFromStackType(result));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            // If we're ldind.i8, fix an IL deficiency that the result may be U8
            if (opcode == OpCode.Ldind_i8 && this.typeRef.Type == CilElementType.I8)
            {
                SigType    opType = ctx.Operand1.Type;
                RefSigType rst    = opType as RefSigType;
                PtrSigType ptr    = opType as PtrSigType;

                if (rst != null && rst.ElementType.Type == CilElementType.U8 ||
                    ptr != null && ptr.ElementType.Type == CilElementType.U8)
                {
                    ctx.Result = compiler.CreateTemporary(BuiltInSigType.UInt64);
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Sets the invoke target.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        /// <param name="method">The method.</param>
        private static void SetInvokeTarget(Context ctx, IMethodCompiler compiler, RuntimeMethod method)
        {
            if (method == null)
            {
                throw new ArgumentNullException(@"method");
            }

            // Signature of the call target
            // Number of parameters required for the call

            ctx.InvokeTarget = method;

            // Retrieve the target signature
            MethodSignature signature = ctx.InvokeTarget.Signature;

            // Fix the parameter list
            byte paramCount = (byte)signature.Parameters.Length;

            if (signature.HasThis && !signature.HasExplicitThis)
            {
                paramCount++;
            }

            // Setup operands for parameters and the return value
            if (signature.ReturnType.Type != CilElementType.Void)
            {
                ctx.ResultCount = 1;
                ctx.Result      = compiler.CreateTemporary(signature.ReturnType);
            }
            else
            {
                ctx.ResultCount = 0;
            }

            ctx.OperandCount = paramCount;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            // If we're ldind.i8, fix an IL deficiency that the result may be U8
            if (_opcode == OpCode.Ldind_i8 && this.typeRef.Type == CilElementType.I8)
            {
                SigType opType = ctx.Operand1.Type;
                RefSigType rst = opType as RefSigType;
                PtrSigType ptr = opType as PtrSigType;

                if (rst != null && rst.ElementType.Type == CilElementType.U8
                    || ptr != null && ptr.ElementType.Type == CilElementType.U8)
                {
                    ctx.Result = compiler.CreateTemporary(BuiltInSigType.UInt64);
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            // Validate the typecode & determine the resulting stack type
            SigType resultType;

            switch (_opcode)
            {
            case OpCode.Conv_u: goto case OpCode.Conv_i;

            case OpCode.Conv_i:
                resultType = compiler.Architecture.NativeType;
                break;

            case OpCode.Conv_i1:
                resultType = new SigType(CilElementType.I1);
                break;

            case OpCode.Conv_i2:
                resultType = new SigType(CilElementType.I2);
                break;

            case OpCode.Conv_i4:
                resultType = new SigType(CilElementType.I4);
                break;

            case OpCode.Conv_i8:
                resultType = new SigType(CilElementType.I8);
                break;

            case OpCode.Conv_r4:
                resultType = new SigType(CilElementType.R4);
                break;

            case OpCode.Conv_r8:
                resultType = new SigType(CilElementType.R8);
                break;

            case OpCode.Conv_u1:
                resultType = new SigType(CilElementType.U1);
                break;

            case OpCode.Conv_u2:
                resultType = new SigType(CilElementType.U2);
                break;

            case OpCode.Conv_u4:
                resultType = new SigType(CilElementType.U4);
                break;

            case OpCode.Conv_u8:
                resultType = new SigType(CilElementType.U8);
                break;

            default:
                throw new NotSupportedException(@"Overflow checking conversions not supported.");
            }

            ctx.Result = compiler.CreateTemporary(resultType);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            // Validate the typecode & determine the resulting stack type
            SigType resultType;

            switch (_opcode) {
                case OpCode.Conv_u: goto case OpCode.Conv_i;
                case OpCode.Conv_i:
                    resultType = compiler.Architecture.NativeType;
                    break;

                case OpCode.Conv_i1:
                    resultType = new SigType(CilElementType.I1);
                    break;

                case OpCode.Conv_i2:
                    resultType = new SigType(CilElementType.I2);
                    break;

                case OpCode.Conv_i4:
                    resultType = new SigType(CilElementType.I4);
                    break;

                case OpCode.Conv_i8:
                    resultType = new SigType(CilElementType.I8);
                    break;

                case OpCode.Conv_r4:
                    resultType = new SigType(CilElementType.R4);
                    break;

                case OpCode.Conv_r8:
                    resultType = new SigType(CilElementType.R8);
                    break;

                case OpCode.Conv_u1:
                    resultType = new SigType(CilElementType.U1);
                    break;

                case OpCode.Conv_u2:
                    resultType = new SigType(CilElementType.U2);
                    break;

                case OpCode.Conv_u4:
                    resultType = new SigType(CilElementType.U4);
                    break;

                case OpCode.Conv_u8:
                    resultType = new SigType(CilElementType.U8);
                    break;

                default:
                    throw new NotSupportedException(@"Overflow checking conversions not supported.");
            }

            ctx.Result = compiler.CreateTemporary(resultType);
        }
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            StackTypeCode result = StackTypeCode.Unknown;
            switch (_opcode) {
                case OpCode.Add_ovf_un:
                    result = _addovfunTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                    break;

                case OpCode.Sub_ovf_un:
                    result = _subovfunTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                    break;

                default:
                    result = _operandTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                    break;
            }

            if (StackTypeCode.Unknown == result)
                throw new InvalidOperationException(@"Invalid operand types passed to " + _opcode);

            ctx.Result = compiler.CreateTemporary(Operand.SigTypeFromStackType(result));
        }
Exemplo n.º 20
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            var stackTypeForOperand1 = ctx.Operand1.StackType;
            var stackTypeForOperand2 = ctx.Operand2.StackType;

            if (ctx.Operand1.Type is ValueTypeSigType)
            {
                var op1Type = compiler.Method.Module.GetType ((ctx.Operand1.Type as ValueTypeSigType).Token);
                if (op1Type.BaseType.FullName == "System.Enum")
                    stackTypeForOperand1 = this.FromSigType (op1Type.Fields[0].SignatureType.Type);
            }

            if (ctx.Operand2.Type is ValueTypeSigType)
            {
                var op2Type = compiler.Method.Module.GetType ((ctx.Operand2.Type as ValueTypeSigType).Token);
                if (op2Type.BaseType.FullName == "System.Enum")
                    stackTypeForOperand2 = this.FromSigType (op2Type.Fields[0].SignatureType.Type);
            }

            var result = _opTable[(int)stackTypeForOperand1][(int)stackTypeForOperand2];

            if (result == StackTypeCode.Unknown)
                throw new InvalidOperationException (@"Invalid stack result of instruction: " + result.ToString () + " (" + ctx.Operand1.ToString () + ")");

            ctx.Result = compiler.CreateTemporary(Operand.SigTypeFromStackType(result));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate(ctx, compiler);

            // Validate the typecode & determine the resulting stack type
            SigType resultType;

            switch (opcode)
            {
                case OpCode.Conv_u: goto case OpCode.Conv_i;
                case OpCode.Conv_i:
                    resultType = compiler.Architecture.NativeType;
                    break;

                case OpCode.Conv_i1:
                    resultType = BuiltInSigType.SByte;
                    break;

                case OpCode.Conv_i2:
                    resultType = BuiltInSigType.Int16;
                    break;

                case OpCode.Conv_i4:
                    resultType = BuiltInSigType.Int32;
                    break;

                case OpCode.Conv_i8:
                    resultType = BuiltInSigType.Int64;
                    break;

                case OpCode.Conv_r4:
                    resultType = BuiltInSigType.Single;
                    break;

                case OpCode.Conv_r8:
                    resultType = BuiltInSigType.Double;
                    break;

                case OpCode.Conv_u1:
                    resultType = BuiltInSigType.Byte;
                    break;

                case OpCode.Conv_u2:
                    resultType = BuiltInSigType.UInt16;
                    break;

                case OpCode.Conv_u4:
                    resultType = BuiltInSigType.UInt32;
                    break;

                case OpCode.Conv_u8:
                    resultType = BuiltInSigType.UInt64;
                    break;

                case OpCode.Conv_ovf_i: goto case OpCode.Conv_i;
                case OpCode.Conv_ovf_u: goto case OpCode.Conv_i;

                case OpCode.Conv_ovf_i_un: goto case OpCode.Conv_i;
                case OpCode.Conv_ovf_u_un: goto case OpCode.Conv_i;

                default:
                    throw new NotSupportedException(@"Overflow checking conversions not supported.");
            }

            ctx.Result = compiler.CreateTemporary(resultType);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Sets the invoke target.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        /// <param name="method">The method.</param>
        private static void SetInvokeTarget(Context ctx, IMethodCompiler compiler, RuntimeMethod method)
        {
            if (method == null)
                throw new ArgumentNullException(@"method");

            // Signature of the call target
            // Number of parameters required for the call

            ctx.InvokeTarget = method;

            // Retrieve the target signature
            MethodSignature signature = ctx.InvokeTarget.Signature;

            // Fix the parameter list
            byte paramCount = (byte)signature.Parameters.Length;
            if (signature.HasThis && !signature.HasExplicitThis)
                paramCount++;

            // Setup operands for parameters and the return value
            if (signature.ReturnType.Type != CilElementType.Void)
            {
                ctx.ResultCount = 1;
                ctx.Result = compiler.CreateTemporary(signature.ReturnType);
            }
            else
                ctx.ResultCount = 0;

            ctx.OperandCount = paramCount;
        }
Exemplo n.º 23
0
        /// <summary>
        /// Validates the instruction operands and creates a matching variable for the result.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="compiler">The compiler.</param>
        public override void Validate(Context ctx, IMethodCompiler compiler)
        {
            base.Validate (ctx, compiler);

            StackTypeCode result = StackTypeCode.Unknown;
            switch (_opcode) {
                case OpCode.Add:
                    result = _addTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                    break;

                case OpCode.Sub:
                    result = _subTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                    break;
                default:

                    result = _operandTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
                    break;
            }

            if (StackTypeCode.Unknown == result)
                throw new InvalidOperationException ("Invalid operand types passed to " + _opcode);

            SigType resultType;
            if (result != StackTypeCode.Ptr)
            {
                resultType = Operand.SigTypeFromStackType (result);
            }

            else
            {
                // Copy the pointer element type
                PtrSigType op0 = ctx.Operand1.Type as PtrSigType;
                PtrSigType op1 = ctx.Operand2.Type as PtrSigType;
                if (op0 != null)
                    resultType = new PtrSigType (op0.CustomMods, op0.ElementType);
                else if (op1 != null)
                {
                    resultType = new PtrSigType (op1.CustomMods, op1.ElementType);
                }

                else
                    throw new InvalidOperationException ();
            }

            ctx.Result = compiler.CreateTemporary (resultType);
        }