예제 #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);
        }
예제 #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);
        }
예제 #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;
        }
예제 #4
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static uint PreferredAlignmentOfGlobal(TargetDataRef TD, ValueRef GlobalVar) {
   uint ret = LLVMPINVOKE.PreferredAlignmentOfGlobal(TD.Value, GlobalVar.Value);
   return ret;
 }
예제 #5
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static uint PreferredAlignmentOfType(TargetDataRef TD, TypeRef Ty) {
   uint ret = LLVMPINVOKE.PreferredAlignmentOfType(TD.Value, Ty.Value);
   return ret;
 }
예제 #6
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static uint CallFrameAlignmentOfType(TargetDataRef TD, TypeRef Ty) {
   uint ret = LLVMPINVOKE.CallFrameAlignmentOfType(TD.Value, Ty.Value);
   return ret;
 }
예제 #7
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static ulong ABISizeOfType(TargetDataRef TD, TypeRef Ty) {
   ulong ret = LLVMPINVOKE.ABISizeOfType(TD.Value, Ty.Value);
   return ret;
 }
예제 #8
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static void DisposeTargetData(TargetDataRef TD) {
   LLVMPINVOKE.DisposeTargetData(TD.Value);
 }
예제 #9
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static uint PointerSizeForAS(TargetDataRef TD, uint AS) {
   uint ret = LLVMPINVOKE.PointerSizeForAS(TD.Value, AS);
   return ret;
 }
예제 #10
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static uint PointerSize(TargetDataRef TD) {
   uint ret = LLVMPINVOKE.PointerSize(TD.Value);
   return ret;
 }
예제 #11
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static ByteOrdering ByteOrder(TargetDataRef TD) {
   ByteOrdering ret = (ByteOrdering)LLVMPINVOKE.ByteOrder(TD.Value);
   return ret;
 }
예제 #12
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static string CopyStringRepOfTargetData(TargetDataRef TD) {
   string ret = LLVMPINVOKE.CopyStringRepOfTargetData(TD.Value);
   return ret;
 }
예제 #13
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static void AddTargetData(TargetDataRef TD, PassManagerRef PM) {
   LLVMPINVOKE.AddTargetData(TD.Value, PM.Value);
 }
예제 #14
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static TargetDataRef CreateTargetData(string StringRep) {
   TargetDataRef ret = new TargetDataRef(LLVMPINVOKE.CreateTargetData(StringRep));
   return ret;
 }
예제 #15
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static uint ElementAtOffset(TargetDataRef TD, TypeRef StructTy, ulong Offset) {
   uint ret = LLVMPINVOKE.ElementAtOffset(TD.Value, StructTy.Value, Offset);
   return ret;
 }
예제 #16
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static ulong OffsetOfElement(TargetDataRef TD, TypeRef StructTy, uint Element) {
   ulong ret = LLVMPINVOKE.OffsetOfElement(TD.Value, StructTy.Value, Element);
   return ret;
 }
예제 #17
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static TypeRef IntPtrType(TargetDataRef TD) {
   TypeRef ret = new TypeRef(LLVMPINVOKE.IntPtrType(TD.Value));
   return ret;
 }
예제 #18
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static TargetDataRef GetTargetMachineData(TargetMachineRef T) {
   TargetDataRef ret = new TargetDataRef(LLVMPINVOKE.GetTargetMachineData(T.Value));
   return ret;
 }
예제 #19
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static TypeRef IntPtrTypeForAS(TargetDataRef TD, uint AS) {
   TypeRef ret = new TypeRef(LLVMPINVOKE.IntPtrTypeForAS(TD.Value, AS));
   return ret;
 }
예제 #20
0
파일: Compiler.cs 프로젝트: frje/SharpLang
        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);
        }
예제 #21
0
파일: LLVM.cs 프로젝트: RainsSoft/SharpLang
 public unsafe static TypeRef IntPtrTypeForASInContext(ContextRef C, TargetDataRef TD, uint AS) {
   TypeRef ret = new TypeRef(LLVMPINVOKE.IntPtrTypeForASInContext(C.Value, TD.Value, AS));
   return ret;
 }