Exemple #1
0
        /// <summary>
        /// Matches the specified other.
        /// </summary>
        /// <param name="other">The other signature type.</param>
        /// <returns>True, if the signature type matches.</returns>
        public override bool Matches(SigType other)
        {
            RefSigType refOther = other as RefSigType;

            // FIXME: Do we need to consider custom mods here?
            return (refOther != null && refOther.elementType.Matches(this.ElementType) == true);
        }
        private IInstruction GetMoveInstruction(SigType sigType)
        {
            IInstruction moveInstruction;
            if (this.RequiresSseOperation(sigType) == false)
            {
                if (MustSignExtendOnLoad(sigType.Type) == true)
                {
                    moveInstruction = Instruction.MovsxInstruction;
                }
                else if (MustZeroExtendOnLoad(sigType.Type) == true)
                {
                    moveInstruction = Instruction.MovzxInstruction;
                }
                else
                {
                    moveInstruction = Instruction.MovInstruction;
                }
            }
            else if (sigType.Type == CilElementType.R8)
            {
                moveInstruction = Instruction.MovsdInstruction;
            }
            else
            {
                moveInstruction = Instruction.MovssInstruction;
            }

            return moveInstruction;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericInstSigType"/> class.
 /// </summary>
 /// <param name="baseType">Type of the base.</param>
 /// <param name="genericArguments">The generic args.</param>
 public GenericInstSigType(TypeSigType baseType, SigType[] genericArguments)
     : base(CilElementType.GenericInst)
 {
     this.baseType = baseType;
     this.genericArguments = genericArguments;
     this.containsGenericParameters = CheckContainsOpenGenericParameters();
 }
        /// <summary>
        /// Retrieves a constant operand to represent the null-value.
        /// </summary>
        /// <returns>A new instance of <see cref="ConstantOperand"/>, that represents the null value.</returns>
        public static ConstantOperand GetNull()
        {
            if (_sObject == null)
                _sObject = BuiltInSigType.Object;

            return new ConstantOperand(_sObject, null);
        }
Exemple #5
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        public override bool Equals(SigType other)
        {
            RefSigType rst = other as RefSigType;
            if (null == rst)
                return false;

            return (base.Equals(other) && this.elementType.Matches(rst.elementType) == true);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LocalVariableSignature"/> class.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="token">The token.</param>
        /// <param name="genericArguments">The generic arguments.</param>
        public LocalVariableSignature(LocalVariableSignature signature, SigType[] genericArguments)
            : base(signature.Token)
        {
            locals = new VariableSignature[signature.locals.Length];

            for (int i = 0; i < signature.locals.Length; i++)
                locals[i] = new VariableSignature(signature.locals[i], genericArguments);
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemberOperand"/> class.
        /// </summary>
        /// <param name="member">The member to reference.</param>
        /// <param name="type">The type of data held in the operand.</param>
        /// <param name="offset">The offset from the base register or absolute address to retrieve.</param>
        public MemberOperand(RuntimeMember member, SigType type, IntPtr offset)
            : base(null, type, offset)
        {
            if (member == null)
                throw new ArgumentNullException(@"member");

            this.member = member;
        }
        /// <summary>
        /// Initializes a new <see cref="RegisterOperand"/>.
        /// </summary>
        /// <param name="type">The signature type of the value the register holds.</param>
        /// <param name="register">The machine specific register used.</param>
        public RegisterOperand(SigType type, Register register)
            : base(type)
        {
            if (register == null)
                throw new ArgumentNullException(@"register");

            this.register = register;
        }
        /// <summary>
        /// Allocates the virtual register.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public Operand AllocateVirtualRegister(SigType type)
        {
            Operand virtualRegister = Operand.CreateVirtualRegister(type, virtualRegisters.Count + 1);

            virtualRegisters.Add(virtualRegister);

            return virtualRegister;
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RefSigType"/> class.
        /// </summary>
        /// <param name="type">The referenced type.</param>
        public RefSigType(SigType type)
            : base(CilElementType.ByRef)
        {
            if (null == type)
                throw new ArgumentNullException(@"type");

            ElementType = type;
        }
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        public override bool Equals(SigType other)
        {
            SZArraySigType szast = other as SZArraySigType;
            if (szast == null)
                return false;

            return (base.Equals(other) == true && _elementType.Equals(szast._elementType) && CustomMod.Equals(_customMods, szast._customMods));
        }
Exemple #12
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        public override bool Equals(SigType other)
        {
            ClassSigType cst = other as ClassSigType;
            if (null == cst)
                return false;

            return (base.Equals(other) == true && this.Token == cst.Token);
        }
Exemple #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PtrSigType"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="customMods">The custom mods.</param>
        public PtrSigType(SigType type, CustomMod[] customMods)
            : base(CilElementType.Ptr)
        {
            if (type == null)
                throw new ArgumentNullException(@"type");

            this.customMods = customMods;
            this.elementType = type;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LdobjInstruction"/> class.
        /// </summary>
        /// <param name="opcode">The opcode.</param>
        public LdobjInstruction(OpCode opcode)
            : base(opcode, 1)
        {
            switch (opcode)
            {
                case OpCode.Ldind_i1:
                    typeRef = BuiltInSigType.SByte;
                    break;

                case OpCode.Ldind_i2:
                    typeRef = BuiltInSigType.Int16;
                    break;

                case OpCode.Ldind_i4:
                    typeRef = BuiltInSigType.Int32;
                    break;

                case OpCode.Ldind_i8:
                    typeRef = BuiltInSigType.Int64;
                    break;

                case OpCode.Ldind_u1:
                    typeRef = BuiltInSigType.Byte;
                    break;

                case OpCode.Ldind_u2:
                    typeRef = BuiltInSigType.UInt16;
                    break;

                case OpCode.Ldind_u4:
                    typeRef = BuiltInSigType.UInt32;
                    break;

                case OpCode.Ldind_i:
                    typeRef = BuiltInSigType.IntPtr;
                    break;

                case OpCode.Ldind_r4:
                    typeRef = BuiltInSigType.Single;
                    break;

                case OpCode.Ldind_r8:
                    typeRef = BuiltInSigType.Double;
                    break;

                case OpCode.Ldind_ref: // FIXME: Really object?
                    typeRef = BuiltInSigType.Object;
                    break;

                case OpCode.Ldobj: // FIXME
                    typeRef = null; // BuiltInSigType.Object;
                    break;

                default:
                    throw new NotImplementedException();
            }
        }
Exemple #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PtrSigType"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        public PtrSigType(SigType type)
            : base(CilElementType.Ptr)
        {
            if (null == type)
                throw new ArgumentNullException(@"type");

            this.customMods = null;
            this.elementType = type;
        }
        /// <summary>
        /// Allocates the virtual register.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public VirtualRegisterOperand AllocateVirtualRegister(SigType type)
        {
            int index = virtualRegisters.Count + 1;

            VirtualRegisterOperand virtualRegister = new VirtualRegisterOperand(type, index);

            virtualRegisters.Add(virtualRegister);

            return virtualRegister;
        }
        private Operand InsertLoadBeforeInstruction(Context context, string symbolName, SigType type)
        {
            Context before = context.InsertBefore();
            Operand result = this.methodCompiler.CreateTemporary(type);
            Operand op = new SymbolOperand(type, symbolName);

            before.SetInstruction(Instruction.Get(OpCode.Ldc_i4), result, op);

            return result;
        }
        private Operand InsertLoadBeforeInstruction(Context context, string symbolName, SigType type)
        {
            Context before = context.InsertBefore();
            Operand result = methodCompiler.CreateVirtualRegister(type);
            Operand op = Operand.CreateSymbol(type, symbolName);

            before.SetInstruction(CILInstruction.Get(OpCode.Ldc_i4), result, op);

            return result;
        }
 private Operand AllocateRegister(SigType sigType)
 {
     if (RequiresSseOperation(sigType))
     {
         return Operand.CreateCPURegister(sigType, SSE2Register.XMM6);
     }
     else
     {
         return Operand.CreateCPURegister(sigType, GeneralPurposeRegister.EAX);
     }
 }
		public static SigType[] Resolve(SigType[] sigTypes, SigType[] genericArguments)
		{
			SigType[] newSigTypes = new SigType[sigTypes.Length];

			for (int i = 0; i < sigTypes.Length; i++)
			{
				newSigTypes[i] = Resolve(sigTypes[i], genericArguments);
			}

			return newSigTypes;
		}
Exemple #21
0
        /// <summary>
        /// Initializes a new instance of LiteralInstruction.
        /// </summary>
        /// <param name="label">The label used to identify the literal in code.</param>
        /// <param name="type">The signature type of the literal data.</param>
        /// <param name="data">The data to embed along with the code stream.</param>
        public LiteralData(int label, SigType type, object data)
        {
            if (null == type)
                throw new ArgumentNullException(@"type");
            if (null == data)
                throw new ArgumentNullException(@"data");

            _label = label;
            _type = type;
            _data = data;
        }
 public static Operand CreateResultOperand(IInstructionDecoder decoder, StackTypeCode operandType, SigType operandSigType)
 {
     if (operandType == StackTypeCode.O || operandType == StackTypeCode.Ptr || operandType == StackTypeCode.F)
     {
         return decoder.Compiler.CreateVirtualRegister(operandSigType);
     }
     else
     {
         return decoder.Compiler.CreateVirtualRegister(Operand.SigTypeFromStackType(operandType));
     }
 }
Exemple #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArraySigType"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="rank">The rank.</param>
        /// <param name="sizes">The sizes.</param>
        /// <param name="lowBounds">The low bounds.</param>
        public ArraySigType(SigType type, int rank, int[] sizes, int[] lowBounds)
            : base(CilElementType.Array)
        {
            if (type == null)
                throw new ArgumentNullException(@"type");

            ElementType = type;
            Rank = rank;
            Sizes = sizes;
            LowBounds = lowBounds;
        }
Exemple #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArraySigType"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="rank">The rank.</param>
        /// <param name="sizes">The sizes.</param>
        /// <param name="lowBounds">The low bounds.</param>
        public ArraySigType(SigType type, int rank, int[] sizes, int[] lowBounds)
            : base(CilElementType.Array)
        {
            if (null == type)
                throw new ArgumentNullException(@"type");

            _type = type;
            _rank = rank;
            _sizes = sizes;
            _lowbounds = lowBounds;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LdelemInstruction"/> class.
        /// </summary>
        /// <param name="opcode">The opcode.</param>
        public LdelemInstruction(OpCode opcode)
            : base(opcode, 1)
        {
            switch (opcode)
            {
                case OpCode.Ldelem_i1:
                    elementType = BuiltInSigType.SByte;
                    break;

                case OpCode.Ldelem_i2:
                    elementType = BuiltInSigType.Int16;
                    break;

                case OpCode.Ldelem_i4:
                    elementType = BuiltInSigType.Int32;
                    break;

                case OpCode.Ldelem_i8:
                    elementType = BuiltInSigType.Int64;
                    break;

                case OpCode.Ldelem_u1:
                    elementType = BuiltInSigType.Byte;
                    break;

                case OpCode.Ldelem_u2:
                    elementType = BuiltInSigType.UInt16;
                    break;

                case OpCode.Ldelem_u4:
                    elementType = BuiltInSigType.UInt32;
                    break;

                case OpCode.Ldelem_i:
                    elementType = BuiltInSigType.IntPtr;
                    break;

                case OpCode.Ldelem_r4:
                    elementType = BuiltInSigType.Single;
                    break;

                case OpCode.Ldelem_r8:
                    elementType = BuiltInSigType.Double;
                    break;

                case OpCode.Ldelem_ref: // FIXME: Really object?
                    elementType = BuiltInSigType.Object;
                    break;

                default:
                    throw new NotImplementedException();
            }
        }
        private RegisterOperand AllocateRegister(SigType sigType)
        {
            RegisterOperand result;
            if (RequiresSseOperation(sigType))
            {
                result = new RegisterOperand(sigType, SSE2Register.XMM6);
            }
            else
            {
                result = new RegisterOperand(sigType, GeneralPurposeRegister.EAX);
            }

            return result;
        }
Exemple #27
0
        public static Operand CreateResultOperand(IInstructionDecoder decoder, StackTypeCode operandType, SigType operandSigType)
        {
            Operand result;

            if (operandType == StackTypeCode.O || operandType == StackTypeCode.Ptr || operandType == StackTypeCode.F)
            {
                result = decoder.Compiler.CreateTemporary(operandSigType);
            }
            else
            {
                result = decoder.Compiler.CreateTemporary(Operand.SigTypeFromStackType(operandType));
            }

            return result;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StelemInstruction"/> class.
        /// </summary>
        /// <param name="opcode">The opcode.</param>
        public StelemInstruction(OpCode opcode)
            : base(opcode, 3)
        {
            switch (opcode)
            {
                case OpCode.Stelem_i1:
                    typeRef = BuiltInSigType.SByte;
                    break;

                case OpCode.Stelem_i2:
                    typeRef = BuiltInSigType.Int16;
                    break;

                case OpCode.Stelem_i4:
                    typeRef = BuiltInSigType.Int32;
                    break;

                case OpCode.Stelem_i8:
                    typeRef = BuiltInSigType.Int64;
                    break;

                case OpCode.Stelem_i:
                    typeRef = BuiltInSigType.IntPtr;
                    break;

                case OpCode.Stelem_r4:
                    typeRef = BuiltInSigType.Single;
                    break;

                case OpCode.Stelem_r8:
                    typeRef = BuiltInSigType.Double;
                    break;

                case OpCode.Stelem_ref: // FIXME: Really object?
                    typeRef = BuiltInSigType.Object;
                    break;

                case OpCode.Stelem:
                    typeRef = null;
                    break;

                default:
                    throw new NotImplementedException("Not implemented: " + opcode);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StobjInstruction"/> class.
        /// </summary>
        /// <param name="opcode">The opcode.</param>
        public StobjInstruction(OpCode opcode)
            : base(opcode)
        {
            switch (opcode)
            {
                case OpCode.Stind_i1:
                    valueType = BuiltInSigType.SByte;
                    break;

                case OpCode.Stind_i2:
                    valueType = BuiltInSigType.Int16;
                    break;

                case OpCode.Stind_i4:
                    valueType = BuiltInSigType.Int32;
                    break;

                case OpCode.Stind_i8:
                    valueType = BuiltInSigType.Int64;
                    break;

                case OpCode.Stind_r4:
                    valueType = BuiltInSigType.Single;
                    break;

                case OpCode.Stind_r8:
                    valueType = BuiltInSigType.Double;
                    break;

                case OpCode.Stind_i:
                    valueType = BuiltInSigType.IntPtr;
                    break;

                case OpCode.Stind_ref: // FIXME: Really object?
                    valueType = BuiltInSigType.Object;
                    break;

                case OpCode.Stobj:  // FIXME
                    valueType = null;
                    break;

                default:
                    throw new NotImplementedException();
            }
        }
		public static SigType Resolve(SigType sigType, SigType[] genericArguments)
		{
			if (genericArguments == null)
				return sigType;

			if (sigType is VarSigType)
			{
				if ((sigType as VarSigType).Index < genericArguments.Length)
					return genericArguments[(sigType as VarSigType).Index];
			}
			else if (sigType is GenericInstSigType)
			{
				var genericInstSigType = sigType as GenericInstSigType;
				for (var i = 0; i < genericInstSigType.GenericArguments.Length; ++i)
				{
					if (genericInstSigType.GenericArguments[i] is VarSigType)
						return genericArguments[(genericInstSigType.GenericArguments[i] as VarSigType).Index];
				}
			}

			return sigType;
		}
Exemple #31
0
        /// <summary>
        /// Parses the array signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static SigType ParseArraySignature(SignatureReader reader)
        {
            SigType elementType = ParseTypeSignature(reader);
            int     rank, count;

            int[] sizes, lowerBounds;

            rank  = reader.ReadCompressedInt32();
            count = reader.ReadCompressedInt32();
            sizes = new int[count];
            for (int i = 0; i < count; i++)
            {
                sizes[i] = reader.ReadCompressedInt32();
            }

            count       = reader.ReadCompressedInt32();
            lowerBounds = new int[count];
            for (int i = 0; i < count; i++)
            {
                lowerBounds[i] = reader.ReadCompressedInt32();
            }

            return(new ArraySigType(elementType, rank, sizes, lowerBounds));
        }
Exemple #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SZArraySigType"/> class.
 /// </summary>
 /// <param name="customMods">The custom mods.</param>
 /// <param name="type">The type.</param>
 public SZArraySigType(CustomMod[] customMods, SigType type) :
     base(CilElementType.SZArray)
 {
     CustomMods  = customMods;
     ElementType = type;
 }
Exemple #33
0
        /// <summary>
        /// Parses the reference.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static SigType ParseReference(SignatureReader reader)
        {
            SigType type = ParseTypeSignature(reader);

            return(new RefSigType(type));
        }
Exemple #34
0
 protected override void ParseSignature(SignatureReader reader)
 {
     ParseModifier(reader);
     CustomMods = CustomMod.ParseCustomMods(reader);
     Type       = SigType.ParseTypeSignature(reader);
 }