예제 #1
0
        /// <summary>
        /// X86: Indicates whether an argument is to be put in a register using the
        /// default IL calling convention. This should be called on each parameter
        /// in the order it appears in the call signature. For a non-static meethod,
        /// this function should also be called once for the "this" argument, prior
        /// to calling it for the "real" arguments. Pass in a typ of ELEMENT_TYPE_CLASS.
        /// </summary>
        /// <param name="pNumRegistersUsed">
        /// keeps track of the number of argument registers assigned previously.
        /// The caller should initialize this variable to 0 - then each call will update it.
        /// </param>
        /// <param name="typ">parameter type</param>
        /// <param name="thArgType">Exact type info is used to check struct enregistration</param>
        public bool IsArgumentInRegister(ref int pNumRegistersUsed, CorElementType typ, TypeHandle thArgType)
        {
            Debug.Assert(IsX86);

            //        LIMITED_METHOD_CONTRACT;
            if (pNumRegistersUsed < NumArgumentRegisters)
            {
                switch (typ)
                {
                case CorElementType.ELEMENT_TYPE_BOOLEAN:
                case CorElementType.ELEMENT_TYPE_CHAR:
                case CorElementType.ELEMENT_TYPE_I1:
                case CorElementType.ELEMENT_TYPE_U1:
                case CorElementType.ELEMENT_TYPE_I2:
                case CorElementType.ELEMENT_TYPE_U2:
                case CorElementType.ELEMENT_TYPE_I4:
                case CorElementType.ELEMENT_TYPE_U4:
                case CorElementType.ELEMENT_TYPE_STRING:
                case CorElementType.ELEMENT_TYPE_PTR:
                case CorElementType.ELEMENT_TYPE_BYREF:
                case CorElementType.ELEMENT_TYPE_CLASS:
                case CorElementType.ELEMENT_TYPE_ARRAY:
                case CorElementType.ELEMENT_TYPE_I:
                case CorElementType.ELEMENT_TYPE_U:
                case CorElementType.ELEMENT_TYPE_FNPTR:
                case CorElementType.ELEMENT_TYPE_OBJECT:
                case CorElementType.ELEMENT_TYPE_SZARRAY:
                    pNumRegistersUsed++;
                    return(true);

#if PROJECTN
                case CorElementType.ELEMENT_TYPE_VALUETYPE:
                {
                    // On ProjectN valuetypes of integral size are passed enregistered
                    int structSize = TypeHandle.GetElemSize(typ, thArgType);
                    switch (structSize)
                    {
                    case 1:
                    case 2:
                    case 4:
                        pNumRegistersUsed++;
                        return(true);
                    }
                    break;
                }
#elif READYTORUN
                case CorElementType.ELEMENT_TYPE_VALUETYPE:
                    if (IsTrivialPointerSizedStruct(thArgType))
                    {
                        pNumRegistersUsed++;
                        return(true);
                    }
                    break;
#endif
                }
            }

            return(false);
        }