Example #1
0
        /// <summary>
        /// Helper function to compute field refence for the specified field of a type.
        /// </summary>
        /// <param name="type">The type node.</param>
        /// <param name="field">The field.</param>
        /// <returns>The target field span.</returns>
        private FieldSpan ComputeFieldSpan(TypeNode type, FieldInfo field)
        {
            var typeInfo   = TypeContext.GetTypeInfo(field.FieldType);
            var parentInfo = TypeContext.GetTypeInfo(field.DeclaringType);
            var fieldIndex = parentInfo.GetAbsoluteIndex(field);

            if (type.IsStructureType)
            {
                var structureType = type.As <StructureType>(Location);
                fieldIndex = structureType.RemapFieldIndex(fieldIndex);
            }
            return(new FieldSpan(fieldIndex, typeInfo.NumFlattendedFields));
        }
Example #2
0
        /// <summary>
        /// Helper function to compute field refence for the specified field of a type.
        /// </summary>
        /// <param name="type">The type node.</param>
        /// <param name="field">The field.</param>
        /// <returns>The target field span.</returns>
        private FieldSpan ComputeFieldSpan(TypeNode type, FieldInfo field)
        {
            var typeInfo   = TypeContext.GetTypeInfo(field.FieldType);
            var parentInfo = TypeContext.GetTypeInfo(field.DeclaringType);
            var fieldIndex = parentInfo.GetAbsoluteIndex(field);

            if (type.IsStructureType)
            {
                var structureType = type.As <StructureType>(Location);
                fieldIndex = structureType.RemapFieldIndex(fieldIndex);
            }

            // Compute the actual span based on the intrinsic mapping of .Net arrays
            // to ILGPU structure values
            int span = typeInfo.NumFlattendedFields;

            if (typeInfo.ManagedType.IsArray)
            {
                span += typeInfo.ManagedType.GetArrayRank();
            }
            return(new FieldSpan(fieldIndex, span));
        }