Ejemplo n.º 1
0
        internal BitcodeModule(LLVMModuleRef handle)
        {
            handle.ValidateNotDefault(nameof(handle));

            ModuleHandle  = handle;
            LazyDiBuilder = new Lazy <DebugInfoBuilder>(() => new DebugInfoBuilder(this));
            Context.AddModule(this);
            Comdats = new ComdatCollection(this);
        }
Ejemplo n.º 2
0
        /// <summary>Initializes a new instance of the <see cref="BitcodeModule"/> class in a given context</summary>
        /// <param name="moduleId">Module's ID</param>
        /// <param name="context">Context for the module</param>
        public BitcodeModule([NotNull] Context context, string moduleId)
        {
            moduleId.ValidateNotNull(nameof(moduleId));
            ModuleHandle = LLVMModuleCreateWithNameInContext(moduleId, context.ContextHandle);
            if (ModuleHandle == default)
            {
                throw new InternalCodeGeneratorException("Could not create module in context");
            }

            LazyDiBuilder = new Lazy <DebugInfoBuilder>(() => new DebugInfoBuilder(this));
            Context.AddModule(this);
            Comdats = new ComdatCollection(this);
        }
Ejemplo n.º 3
0
        /// <summary>Creates an named module in a given context</summary>
        /// <param name="moduleId">Module's ID</param>
        /// <param name="context">Context for the module</param>
        public NativeModule(string moduleId, Context context)
        {
            if (moduleId == null)
            {
                moduleId = string.Empty;
            }

            if (context == null)
            {
                context     = new Context( );
                OwnsContext = true;
            }

            Func <bool> onException = () =>
            {
                if (OwnsContext && context != null)
                {
                    context.Dispose( );
                }

                return(false);
            };

            try
            {
                ModuleHandle = NativeMethods.ModuleCreateWithNameInContext(moduleId, context.ContextHandle);
                if (ModuleHandle.Pointer == IntPtr.Zero)
                {
                    throw new InternalCodeGeneratorException("Could not create module in context");
                }

                LazyDiBuilder = new Lazy <DebugInfoBuilder>(() => new DebugInfoBuilder(this));
                Context.AddModule(this);
                Comdats = new ComdatCollection(this);
            }
            catch when(onException())
            {
                // NOP
            }
        }