Ejemplo n.º 1
0
        public Comdat Add(string key, ComdatKind kind)
        {
            LLVMComdatRef comdatRef = NativeMethods.ModuleInsertOrUpdateComdat(Module.ModuleHandle, key, ( LLVMComdatSelectionKind )kind);

            if (!InternalComdatMap.TryGetValue(key, out Comdat retVal))
            {
                retVal = new Comdat(Module, comdatRef);
                InternalComdatMap.Add(retVal.Name, retVal);
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        /// <summary>Inserts or updates a <see cref="Comdat"/> entry</summary>
        /// <param name="key">Name of the <see cref="Comdat"/></param>
        /// <param name="kind"><see cref="ComdatKind"/> for the entry</param>
        /// <returns>New or updated <see cref="Comdat"/></returns>
        public Comdat InsertOrUpdate(string key, ComdatKind kind)
        {
            key.ValidateNotNullOrWhiteSpace(nameof(key));
            kind.ValidateDefined(nameof(kind));

            LLVMComdatRef comdatRef = LibLLVMModuleInsertOrUpdateComdat(Module.ModuleHandle, key, ( LLVMComdatSelectionKind )kind);

            if (!InternalComdatMap.TryGetValue(key, out Comdat retVal))
            {
                retVal = new Comdat(Module, comdatRef);
                InternalComdatMap.Add(retVal.Name, retVal);
            }

            return(retVal);
        }
Ejemplo n.º 3
0
        /// <summary>Sets a named <see cref="Llvm.NET.Comdat"/> for a <see cref="GlobalObject"/></summary>
        /// <param name="self">Global to get the Comdat for</param>
        /// <param name="name">name of the Comdat</param>
        /// <param name="kind">Kind of Comdat to create if it doesn't exist already</param>
        /// <returns><paramref name="self"/> for fluent use</returns>
        /// <remarks>
        /// This finds a <see cref="Llvm.NET.Comdat"/> in the <see cref="GlobalValue.ParentModule"/>
        /// of the object if it exists or creates a new one if it doesn't and assigns the <see cref="GlobalObject.Comdat"/>
        /// property with the <see cref="Llvm.NET.Comdat"/>.
        /// </remarks>
        /// <seealso cref="GlobalObject.Comdat"/>
        public static GlobalObject Comdat(this GlobalObject self, string name, ComdatKind kind)
        {
            if (self == null)
            {
                throw new ArgumentNullException(nameof(self));
            }

            if (!self.ParentModule.Comdats.TryGetValue(name, out Comdat comdat))
            {
                comdat = self.ParentModule.Comdats.InsertOrUpdate(name, kind);
            }
            else
            {
                comdat.Kind = kind;
            }

            self.Comdat = comdat;
            return(self);
        }