Beispiel #1
0
 public void Initiate()
 {
     ClassSkeletons = new Dictionary<string, LLVMTypeRef>();
     Context = LLVM.ContextCreate();
     Module = LLVM.ModuleCreateWithNameInContext("ADefaultModuleId", Context);
     Builder = LLVM.CreateBuilderInContext(Context);
 }
 public static LLVMTypeRef ToLLVMTy(TyRef ty, LLVMContextRef context)
 {
     if (ty is TyInt)
         return IntTypeInContext(context, (ty as TyInt).BitWidth);
     else if (ty is TyUint)
         return IntTypeInContext(context, (ty as TyUint).BitWidth);
     else if (ty is TyFloat)
     {
         switch ((ty as TyFloat).BitWidth)
         {
             case 16: return HalfTypeInContext(context);
             case 32: return FloatTypeInContext(context);
             case 64: return DoubleTypeInContext(context);
             // EW
             default: throw new ArgumentException("ty");
         }
     }
     else if (ty is TyBool)
         return Int1TypeInContext(context);
     else if (ty is TyVoid)
         return VoidTypeInContext(context);
     else if (ty is PointerTyRef)
         return PointerType(ToLLVMTy((ty as PointerTyRef).ty.Raw, context), 0);
     else if (ty is FnTyRef)
     {
         var fnTy = ty as FnTyRef;
         var llvmTyParams = fnTy.parameterTys.Select(param => ToLLVMTy(param.Raw, context)).ToArray();
         var llvmTyReturn = ToLLVMTy(fnTy.returnTy.Raw, context);
         return FunctionType(llvmTyReturn, llvmTyParams, false);
     }
     // TODO(kai): structs and things go here pls
     else throw new ArgumentException("ty");
 }
Beispiel #3
0
        public static LLVMBool ParseIRInContext(LLVMContextRef ContextRef, LLVMMemoryBufferRef MemBuf, out LLVMModuleRef OutM, out string OutMessage)
        {
            var retVal = ParseIRInContext(ContextRef, MemBuf, out OutM, out IntPtr message);

            OutMessage = message != IntPtr.Zero && retVal.Value != 0 ? Marshal.PtrToStringAnsi(message) : null;
            DisposeMessage(message);
            return(retVal);
        }
Beispiel #4
0
 public ModCompiler(DetailLogger log, SymbolTableWalker walker,
     LLVMContextRef context, LLVMModuleRef module, LLVMBuilderRef builder)
 {
     this.log = log;
     this.walker = walker;
     this.context = context;
     this.module = module;
     this.builder = builder;
 }
Beispiel #5
0
        public static LLVMValueRef ConstStructInContext(LLVMContextRef C, LLVMValueRef[] ConstantVals, bool Packed)
        {
            if (ConstantVals.Length == 0)
            {
                LLVMValueRef dummy;
                return(ConstStructInContext(C, out dummy, 0, Packed));
            }

            return(ConstStructInContext(C, out ConstantVals[0], (uint)ConstantVals.Length, Packed));
        }
Beispiel #6
0
        public static LLVMTypeRef StructTypeInContext(LLVMContextRef C, LLVMTypeRef[] ElementTypes, bool Packed)
        {
            if (ElementTypes.Length == 0)
            {
                LLVMTypeRef dummy;
                return(StructTypeInContext(C, out dummy, 0, Packed));
            }

            return(StructTypeInContext(C, out ElementTypes[0], (uint)ElementTypes.Length, Packed));
        }
Beispiel #7
0
        public static LLVMValueRef MDNodeInContext(LLVMContextRef C, LLVMValueRef[] Vals)
        {
            if (Vals.Length == 0)
            {
                LLVMValueRef dummy;
                return(MDNodeInContext(C, out dummy, 0));
            }

            return(MDNodeInContext(C, out Vals[0], (uint)Vals.Length));
        }
 public static extern LLVMMetadataRef MDNode2(LLVMContextRef @C, out LLVMMetadataRef @MDs, uint @Count);
Beispiel #9
0
 public static extern LLVMTypeRef X86MMXTypeInContext(LLVMContextRef @C);
Beispiel #10
0
 public static extern LLVMTypeRef StructTypeInContext(LLVMContextRef @C, out LLVMTypeRef @ElementTypes, uint @ElementCount, LLVMBool @Packed);
Beispiel #11
0
 public static extern LLVMTypeRef PPCFP128TypeInContext(LLVMContextRef @C);
Beispiel #12
0
 public static extern LLVMModuleRef ModuleCreateWithNameInContext([MarshalAs(UnmanagedType.LPStr)] string @ModuleID, LLVMContextRef @C);
Beispiel #13
0
 public static extern LLVMValueRef MDNodeInContext(LLVMContextRef @C, out LLVMValueRef @Vals, uint @Count);
Beispiel #14
0
 public static extern LLVMTypeRef FloatTypeInContext(LLVMContextRef @C);
Beispiel #15
0
 public static extern LLVMTypeRef DoubleTypeInContext(LLVMContextRef @C);
Beispiel #16
0
 public static extern LLVMBuilderRef CreateBuilderInContext(LLVMContextRef @C);
Beispiel #17
0
 public static extern void ContextSetYieldCallback(LLVMContextRef @C, LLVMYieldCallback @Callback, IntPtr @OpaqueHandle);
Beispiel #18
0
 public static extern void ContextSetDiagnosticHandler(LLVMContextRef @C, LLVMDiagnosticHandler @Handler, IntPtr @DiagnosticContext);
Beispiel #19
0
 public static extern void ContextDispose(LLVMContextRef @C);
Beispiel #20
0
 public static extern LLVMBool GetBitcodeModuleProviderInContext(LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleProviderRef @OutMP, out IntPtr @OutMessage);
Beispiel #21
0
 public bool Equals(LLVMContextRef other) => this.Pointer == other.Pointer;
Beispiel #22
0
 public static extern uint GetMDKindIDInContext(LLVMContextRef @C, [MarshalAs(UnmanagedType.LPStr)] string @Name, uint @SLen);
Beispiel #23
0
 public static extern LLVMValueRef MDStringInContext(LLVMContextRef @C, [MarshalAs(UnmanagedType.LPStr)] string @Str, uint @SLen);
Beispiel #24
0
 public static extern LLVMTypeRef HalfTypeInContext(LLVMContextRef @C);
Beispiel #25
0
 public static extern LLVMBool ParseIRInContext(LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage);
Beispiel #26
0
 public static extern LLVMBasicBlockRef InsertBasicBlockInContext(LLVMContextRef @C, LLVMBasicBlockRef @BB, [MarshalAs(UnmanagedType.LPStr)] string @Name);
Beispiel #27
0
 public static extern LLVMTypeRef StructCreateNamed(LLVMContextRef @C, [MarshalAs(UnmanagedType.LPStr)] string @Name);
Beispiel #28
0
        public static LLVMValueRef ConstStructInContext(LLVMContextRef C, LLVMValueRef[] ConstantVals, bool Packed)
        {
            if (ConstantVals.Length == 0)
            {
                LLVMValueRef dummy;
                return ConstStructInContext(C, out dummy, 0, Packed);
            }

            return ConstStructInContext(C, out ConstantVals[0], (uint)ConstantVals.Length, Packed);
        }
Beispiel #29
0
 public static extern LLVMTypeRef VoidTypeInContext(LLVMContextRef @C);
Beispiel #30
0
        public static LLVMTypeRef StructTypeInContext(LLVMContextRef C, LLVMTypeRef[] ElementTypes, bool Packed)
        {
            if (ElementTypes.Length == 0)
            {
                LLVMTypeRef dummy;
                return StructTypeInContext(C, out dummy, 0, Packed);
            }

            return StructTypeInContext(C, out ElementTypes[0], (uint)ElementTypes.Length, Packed);
        }
Beispiel #31
0
 public static extern LLVMTypeRef Int8TypeInContext(LLVMContextRef @C);
Beispiel #32
0
 public LLVMContext()
 {
     Handle = LLVMContextRef.Create();
 }
Beispiel #33
0
        public static LLVMValueRef MDNodeInContext(LLVMContextRef C, LLVMValueRef[] Vals)
        {
            if (Vals.Length == 0)
            {
                LLVMValueRef dummy;
                return MDNodeInContext(C, out dummy, 0);
            }

            return MDNodeInContext(C, out Vals[0], (uint)Vals.Length);
        }
Beispiel #34
0
 public static extern LLVMTypeRef IntPtrTypeForASInContext(LLVMContextRef @C, LLVMTargetDataRef @TD, uint @AS);
Beispiel #35
0
 public Module(string moduleId, LLVMContextRef context)
 {
     this.instance = LLVM.ModuleCreateWithNameInContext(moduleId, context);
 }
Beispiel #36
0
 public static extern LLVMTypeRef IntPtrTypeInContext(LLVMContextRef @C, LLVMTargetDataRef @TD);
Beispiel #37
0
 public static LLVMAttributeRef CreateStringAttribute(LLVMContextRef C, string Kind, string Value)
 {
     return(CreateStringAttribute(C,
                                  Kind, Kind == null ? 0 : (uint)Kind.Length,
                                  Value, Value == null ? 0 : (uint)Value.Length));
 }
 public static extern LLVMMetadataRef MDString2(LLVMContextRef @C, [MarshalAs(UnmanagedType.LPStr)] string @Str, uint @SLen);
Beispiel #39
0
 public static extern LLVMTypeRef IntTypeInContext(LLVMContextRef @C, uint @NumBits);
 public static extern LLVMMetadataRef TemporaryMDNode(LLVMContextRef @C, out LLVMMetadataRef @MDs, uint @Count);
Beispiel #41
0
 public static extern LLVMTypeRef LabelTypeInContext(LLVMContextRef @C);
Beispiel #42
0
 public IRBuilder(LLVMContextRef context)
 {
     this.instance = LLVM.CreateBuilderInContext(context);
 }