Esempio n. 1
0
        public static LLVMTypeRef ToLLVMType(this Type type)
        {
            if (type.IsConstructedGenericType && type.GetGenericTypeDefinition() == typeof(Vector128 <>))
            {
                var et = type.GetGenericArguments()[0];
                return(LLVMTypeRef.VectorType(et.ToLLVMType(), 16U / (uint)Marshal.SizeOf(et)));
            }
            if (typeof(MulticastDelegate).IsAssignableFrom(type))
            {
                var mi = type.GetMethod("Invoke");
                return(LLVMTypeRef.FunctionType(mi.ReturnType.ToLLVMType(),
                                                mi.GetParameters().Select(x => x.ParameterType.ToLLVMType()).ToArray(), false));
            }
            if (type == typeof(void))
            {
                return(LLVMTypeRef.VoidType());
            }
            if (type.IsPointer)
            {
                return(LLVMTypeRef.Int64Type());
            }
            switch (Activator.CreateInstance(type))
            {
            case sbyte _:
            case byte _: return(LLVMTypeRef.Int8Type());

            case short _:
            case ushort _: return(LLVMTypeRef.Int16Type());

            case int _:
            case uint _: return(LLVMTypeRef.Int32Type());

            case long _:
            case ulong _: return(LLVMTypeRef.Int64Type());

            case Int128 _:
            case UInt128 _: return(LLVMTypeRef.IntType(128));

            case float _: return(LLVMTypeRef.FloatType());

            case double _: return(LLVMTypeRef.DoubleType());

            case bool _: return(LLVMTypeRef.IntType(1));

            default: throw new NotSupportedException(type.Name);
            }
        }
Esempio n. 2
0
        private static LLVMTypeRef GetLlvmType([NotNull] Type lambdaTypeParam)
        {
            switch (lambdaTypeParam)
            {
            case PrimaryType primaryType:
                if (string.Equals(primaryType.Name, "f64", Ordinal))
                {
                    return(LLVMSharp.LLVM.DoubleType());
                }
                if (string.Equals(primaryType.Name, "f32", Ordinal))
                {
                    return(LLVMTypeRef.FloatType());
                }
                if (string.Equals(primaryType.Name, "i8", Ordinal))
                {
                    return(LLVMTypeRef.Int8Type());
                }
                if (string.Equals(primaryType.Name, "i16", Ordinal))
                {
                    return(LLVMTypeRef.Int16Type());
                }
                if (string.Equals(primaryType.Name, "i32", Ordinal))
                {
                    return(LLVMTypeRef.Int32Type());
                }
                if (string.Equals(primaryType.Name, "i64", Ordinal))
                {
                    return(LLVMTypeRef.Int64Type());
                }
                break;

            case LambdaType lambdaType:
                return(LLVMTypeRef.FunctionType(GetLlvmType(lambdaType.RetType),
                                                (from type in lambdaType.ParamsList select GetLlvmType(type)).ToArray(), false));

            case SecondaryType secondaryType:
                break;
            }
            throw new NotImplementedException();
        }