Ejemplo n.º 1
0
        private static Type ConvertType(Module module, System.Type type)
        {
            if (type == typeof(void))
                return Type.GetVoid(module.Context);
            if (type == typeof(bool))
                return IntegerType.Get(module.Context, 1);
            if (type == typeof(byte))
                return IntegerType.Get(module.Context, 8);
            if (type == typeof(short))
                return IntegerType.Get(module.Context, 16);
            if (type == typeof(int))
                return IntegerType.GetInt32(module.Context);
            if (type == typeof(long))
                return IntegerType.Get(module.Context, 64);
            if (type == typeof(float))
                return FloatType.Get(module.Context, 32);
            if (type == typeof(double))
                return FloatType.Get(module.Context, 64);
            if (type.IsArray)
                return PointerType.Get(ConvertType(module, type.GetElementType()), 1);
            if (type.IsByRef)
                return PointerType.Get(ConvertType(module, type.GetElementType()));
            if (type.IsValueType)
            {
                var name = type.Name.StripNameToValidPtx();
                var preExisting = module.GetTypeByName(name);
                if (preExisting != null)
                    return preExisting;
                return new StructType(module.Context, name, AllFields(type).Select(t => ConvertType(module, t.FieldType)));
            }

            throw new CudaSharpException("Type cannot be translated to CUDA: " + type.FullName);
        }