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
        public ExprAST VariableExprVisit(VariableExprAST node)
        {
            LLVMValueRef initValue;

            this.Visit(node.Value);
            initValue = valueStack.Pop();
            LLVMValueRef alloca = default(LLVMValueRef);

            switch (LLVM.GetTypeKind(LLVM.TypeOf(initValue)))
            {
            case LLVMTypeKind.LLVMIntegerTypeKind:
                alloca = CreateEntryBlockAlloca(mainFunction, LLVMTypeRef.Int64Type(), node.Name);
                break;

            case LLVMTypeKind.LLVMDoubleTypeKind:
                alloca = CreateEntryBlockAlloca(mainFunction, LLVMTypeRef.DoubleType(), node.Name);
                break;
            }
            LLVM.BuildStore(builder, initValue, alloca);
            return(node);
        }
Esempio n. 3
0
 public static LlvmValue Double(double value)
 {
     return(LLVM.ConstReal(LLVMTypeRef.DoubleType(), value).Wrap());
 }