Esempio n. 1
0
        /// <summary>
        /// Gets whether reading/writing an element of accessType from the pointer
        /// is equivalent to reading/writing an element of the pointer's element type.
        /// </summary>
        /// <remarks>
        /// The access semantics may sligthly differ on read accesses of small integer types,
        /// due to zero extension vs. sign extension when the signs differ.
        /// </remarks>
        public static bool IsCompatibleTypeForMemoryAccess(IType pointerType, IType accessType)
        {
            IType memoryType;

            if (pointerType is PointerType || pointerType is ByReferenceType)
            {
                memoryType = ((TypeWithElementType)pointerType).ElementType;
            }
            else
            {
                return(false);
            }
            memoryType = memoryType.AcceptVisitor(NormalizeTypeVisitor.TypeErasure);
            accessType = accessType.AcceptVisitor(NormalizeTypeVisitor.TypeErasure);
            if (memoryType.Equals(accessType))
            {
                return(true);
            }
            // If the types are not equal, the access still might produce equal results in some cases:
            // 1) Both types are reference types
            if (memoryType.IsReferenceType == true && accessType.IsReferenceType == true)
            {
                return(true);
            }
            // 2) Both types are integer types of equal size
            StackType memoryStackType = memoryType.GetStackType();
            StackType accessStackType = accessType.GetStackType();

            if (memoryStackType == accessStackType && memoryStackType.IsIntegerType() && GetSize(memoryType) == GetSize(accessType))
            {
                return(true);
            }
            // 3) Any of the types is unknown: we assume they are compatible.
            return(memoryType.Kind == TypeKind.Unknown || accessType.Kind == TypeKind.Unknown);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets whether reading/writing an element of accessType from the pointer
        /// is equivalent to reading/writing an element of the pointer's element type.
        /// </summary>
        /// <remarks>
        /// The access semantics may sligthly differ on read accesses of small integer types,
        /// due to zero extension vs. sign extension when the signs differ.
        /// </remarks>
        public static bool IsCompatibleTypeForMemoryAccess(IType pointerType, IType accessType)
        {
            IType memoryType;

            if (pointerType is PointerType || pointerType is ByReferenceType)
            {
                memoryType = ((TypeWithElementType)pointerType).ElementType;
            }
            else
            {
                return(false);
            }
            if (memoryType.Equals(accessType))
            {
                return(true);
            }
            // If the types are not equal, the access still might produce equal results in some cases:
            // 1) Both types are reference types
            if (memoryType.IsReferenceType == true && accessType.IsReferenceType == true)
            {
                return(true);
            }
            // 2) Both types are integer types of equal size
            StackType memoryStackType = memoryType.GetStackType();
            StackType accessStackType = accessType.GetStackType();

            return(memoryStackType == accessStackType && memoryStackType.IsIntegerType() && GetSize(memoryType) == GetSize(accessType));
        }