Пример #1
0
        /// <summary>
        /// Computes the address of a single element in the scope of a view or a pointer.
        /// </summary>
        /// <param name="location">The current location.</param>
        /// <param name="source">The source view.</param>
        /// <param name="elementIndex">The element index to load.</param>
        /// <returns>A node that represents the element address.</returns>
        public ValueReference CreateLoadElementAddress(
            Location location,
            Value source,
            Value elementIndex)
        {
            // Remove unnecessary pointer casts
            if (elementIndex is IntAsPointerCast cast)
            {
                elementIndex = cast.Value;
            }

            // Assert a valid indexing type from here on
            location.Assert(
                IRTypeContext.IsViewIndexType(elementIndex.BasicValueType));
            var addressSpaceType = source.Type as AddressSpaceType;

            location.AssertNotNull(addressSpaceType);

            // Fold primitive pointer arithmetic that does not change anything
            return(source.Type is PointerType && elementIndex.IsPrimitive(0)
                ? (ValueReference)source
                : Append(new LoadElementAddress(
                             GetInitializer(location),
                             source,
                             elementIndex)));
        }
Пример #2
0
        /// <summary>
        /// Constructs a new view from a pointer and a length.
        /// </summary>
        /// <param name="location">The current location.</param>
        /// <param name="pointer">The source pointer.</param>
        /// <param name="length">The length.</param>
        /// <returns>A node that represents the created view.</returns>
        public ValueReference CreateNewView(
            Location location,
            Value pointer,
            Value length)
        {
            location.Assert(
                IRTypeContext.IsViewIndexType(length.BasicValueType));

            return(Append(new NewView(
                              GetInitializer(location),
                              pointer,
                              length)));
        }
Пример #3
0
        /// <summary>
        /// Computes a new sub view from a given view.
        /// </summary>
        /// <param name="location">The current location.</param>
        /// <param name="source">The source.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <returns>A node that represents the new sub view.</returns>
        public ValueReference CreateSubViewValue(
            Location location,
            Value source,
            Value offset,
            Value length)
        {
            location.Assert(
                source.Type.IsViewType &&
                IRTypeContext.IsViewIndexType(offset.BasicValueType) &&
                IRTypeContext.IsViewIndexType(length.BasicValueType));

            return(Append(new SubViewValue(
                              GetInitializer(location),
                              source,
                              offset,
                              length)));
        }