Exemplo n.º 1
0
        public DefaultABI(ContextRef context, TargetDataRef targetData)
        {
            this.context = context;
            this.targetData = targetData;

            var intPtrLLVM = LLVM.PointerType(LLVM.Int8TypeInContext(context), 0);
            intPtrSize = (int)LLVM.ABISizeOfType(targetData, intPtrLLVM);
        }
Exemplo n.º 2
0
        public DefaultABI(ContextRef context, TargetDataRef targetData)
        {
            this.context    = context;
            this.targetData = targetData;

            var intPtrLLVM = LLVM.PointerType(LLVM.Int8TypeInContext(context), 0);

            intPtrSize = (int)LLVM.ABISizeOfType(targetData, intPtrLLVM);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes common types.
        /// </summary>
        /// <param name="targetData">Target data.</param>
        /// <param name="compiler">The compiler.</param>
        public static void Init(TargetDataRef targetData, Compiler compiler)
        {
            Int64   = LLVM.Int64Type();
            Int32   = LLVM.Int32Type();
            Int16   = LLVM.Int16Type();
            Int8    = LLVM.Int8Type();
            Boolean = LLVM.Int1Type();
            String  = LLVM.PointerType(LLVM.Int8Type(), 0);
            Void    = LLVM.VoidType();
            Float   = LLVM.FloatType();
            Double  = LLVM.DoubleType();

            VoidPtr       = LLVM.PointerType(LLVM.VoidType(), 0);
            IntPtrSize    = (uint)LLVM.ABISizeOfType(targetData, VoidPtr);
            NativeIntType = LLVM.IntType(IntPtrSize * 8);

            mCompiler = compiler;
            mLookup   = compiler.Lookup;
        }
Exemplo n.º 4
0
 public unsafe static uint PreferredAlignmentOfGlobal(TargetDataRef TD, ValueRef GlobalVar) {
   uint ret = LLVMPINVOKE.PreferredAlignmentOfGlobal(TD.Value, GlobalVar.Value);
   return ret;
 }
Exemplo n.º 5
0
 public unsafe static uint PreferredAlignmentOfType(TargetDataRef TD, TypeRef Ty) {
   uint ret = LLVMPINVOKE.PreferredAlignmentOfType(TD.Value, Ty.Value);
   return ret;
 }
Exemplo n.º 6
0
 public unsafe static uint CallFrameAlignmentOfType(TargetDataRef TD, TypeRef Ty) {
   uint ret = LLVMPINVOKE.CallFrameAlignmentOfType(TD.Value, Ty.Value);
   return ret;
 }
Exemplo n.º 7
0
 public unsafe static ulong ABISizeOfType(TargetDataRef TD, TypeRef Ty) {
   ulong ret = LLVMPINVOKE.ABISizeOfType(TD.Value, Ty.Value);
   return ret;
 }
Exemplo n.º 8
0
 public unsafe static void DisposeTargetData(TargetDataRef TD) {
   LLVMPINVOKE.DisposeTargetData(TD.Value);
 }
Exemplo n.º 9
0
 public unsafe static uint PointerSizeForAS(TargetDataRef TD, uint AS) {
   uint ret = LLVMPINVOKE.PointerSizeForAS(TD.Value, AS);
   return ret;
 }
Exemplo n.º 10
0
 public unsafe static uint PointerSize(TargetDataRef TD) {
   uint ret = LLVMPINVOKE.PointerSize(TD.Value);
   return ret;
 }
Exemplo n.º 11
0
 public unsafe static ByteOrdering ByteOrder(TargetDataRef TD) {
   ByteOrdering ret = (ByteOrdering)LLVMPINVOKE.ByteOrder(TD.Value);
   return ret;
 }
Exemplo n.º 12
0
 public unsafe static string CopyStringRepOfTargetData(TargetDataRef TD) {
   string ret = LLVMPINVOKE.CopyStringRepOfTargetData(TD.Value);
   return ret;
 }
Exemplo n.º 13
0
 public unsafe static void AddTargetData(TargetDataRef TD, PassManagerRef PM) {
   LLVMPINVOKE.AddTargetData(TD.Value, PM.Value);
 }
Exemplo n.º 14
0
 public unsafe static TargetDataRef CreateTargetData(string StringRep) {
   TargetDataRef ret = new TargetDataRef(LLVMPINVOKE.CreateTargetData(StringRep));
   return ret;
 }
Exemplo n.º 15
0
 public unsafe static uint ElementAtOffset(TargetDataRef TD, TypeRef StructTy, ulong Offset) {
   uint ret = LLVMPINVOKE.ElementAtOffset(TD.Value, StructTy.Value, Offset);
   return ret;
 }
Exemplo n.º 16
0
 public unsafe static ulong OffsetOfElement(TargetDataRef TD, TypeRef StructTy, uint Element) {
   ulong ret = LLVMPINVOKE.OffsetOfElement(TD.Value, StructTy.Value, Element);
   return ret;
 }
Exemplo n.º 17
0
 public unsafe static TypeRef IntPtrType(TargetDataRef TD) {
   TypeRef ret = new TypeRef(LLVMPINVOKE.IntPtrType(TD.Value));
   return ret;
 }
Exemplo n.º 18
0
 public unsafe static TargetDataRef GetTargetMachineData(TargetMachineRef T) {
   TargetDataRef ret = new TargetDataRef(LLVMPINVOKE.GetTargetMachineData(T.Value));
   return ret;
 }
Exemplo n.º 19
0
 public unsafe static TypeRef IntPtrTypeForAS(TargetDataRef TD, uint AS) {
   TypeRef ret = new TypeRef(LLVMPINVOKE.IntPtrTypeForAS(TD.Value, AS));
   return ret;
 }
Exemplo n.º 20
0
        public void RegisterMainAssembly(AssemblyDefinition assembly)
        {
            this.assembly = assembly;
            corlib        = assembly.MainModule.Import(typeof(void)).Resolve().Module.Assembly;

            context = LLVM.GetGlobalContext();
            module  = LLVM.ModuleCreateWithName(assembly.Name.Name);

            MemoryBufferRef memoryBuffer;
            string          message;

            if (LLVM.CreateMemoryBufferWithContentsOfFile(@"..\..\..\..\src\SharpLang.Runtime\Runtime.bc", out memoryBuffer, out message))
            {
                throw new InvalidOperationException(message);
            }

            if (LLVM.GetBitcodeModuleInContext(context, memoryBuffer, out runtimeModule, out message))
            {
                throw new InvalidOperationException(message);
            }

            LLVM.DisposeMemoryBuffer(memoryBuffer);

            // TODO: Choose appropriate triple depending on target
            LLVM.SetTarget(module, "i686-pc-mingw32");

            var dataLayout = LLVM.GetDataLayout(runtimeModule);

            targetData = LLVM.CreateTargetData(dataLayout);

            allocObjectFunction           = ImportRuntimeFunction(module, "allocObject");
            resolveInterfaceCallFunction  = ImportRuntimeFunction(module, "resolveInterfaceCall");
            isInstInterfaceFunction       = ImportRuntimeFunction(module, "isInstInterface");
            throwExceptionFunction        = ImportRuntimeFunction(module, "throwException");
            sharpPersonalityFunction      = ImportRuntimeFunction(module, "sharpPersonality");
            pinvokeLoadLibraryFunction    = ImportRuntimeFunction(module, "PInvokeOpenLibrary");
            pinvokeGetProcAddressFunction = ImportRuntimeFunction(module, "PInvokeGetProcAddress");

            builder       = LLVM.CreateBuilderInContext(context);
            intPtrType    = LLVM.PointerType(LLVM.Int8TypeInContext(context), 0);
            int32Type     = LLVM.Int32TypeInContext(context);
            int64Type     = LLVM.Int64TypeInContext(context);
            intPtrSize    = 4;         // Or 8?
            nativeIntType = int32Type; // Or int64Type?
            builder2      = LLVM.CreateBuilderInContext(context);

            debugBuilder = LLVM.DIBuilderCreate(module);

            intPtr  = GetType(corlib.MainModule.GetType(typeof(IntPtr).FullName));
            int8    = GetType(corlib.MainModule.GetType(typeof(sbyte).FullName));
            int16   = GetType(corlib.MainModule.GetType(typeof(short).FullName));
            int32   = GetType(corlib.MainModule.GetType(typeof(int).FullName));
            int64   = GetType(corlib.MainModule.GetType(typeof(long).FullName));
            uint8   = GetType(corlib.MainModule.GetType(typeof(byte).FullName));
            uint16  = GetType(corlib.MainModule.GetType(typeof(ushort).FullName));
            uint32  = GetType(corlib.MainModule.GetType(typeof(uint).FullName));
            uint64  = GetType(corlib.MainModule.GetType(typeof(ulong).FullName));
            @bool   = GetType(corlib.MainModule.GetType(typeof(bool).FullName));
            @float  = GetType(corlib.MainModule.GetType(typeof(float).FullName));
            @double = GetType(corlib.MainModule.GetType(typeof(double).FullName));

            @object = GetType(corlib.MainModule.GetType(typeof(object).FullName));

            // struct IMTEntry { i32 functionId, i8* functionPtr }
            imtEntryType = LLVM.StructCreateNamed(context, "IMTEntry");
            LLVM.StructSetBody(imtEntryType, new[] { int32Type, intPtrType }, false);

            caughtResultType = LLVM.StructCreateNamed(context, "CaughtResultType");
            LLVM.StructSetBody(caughtResultType, new[] { intPtrType, int32Type }, false);

            RegisterAssembly(assembly);
        }
Exemplo n.º 21
0
 public unsafe static TypeRef IntPtrTypeForASInContext(ContextRef C, TargetDataRef TD, uint AS) {
   TypeRef ret = new TypeRef(LLVMPINVOKE.IntPtrTypeForASInContext(C.Value, TD.Value, AS));
   return ret;
 }