@@ -242,6 +242,18 @@ public final class Module: CustomStringConvertible {
242242 }
243243 }
244244
245+ /// Retrieves the first alias in this module, if there are any aliases.
246+ public var firstAlias : Alias ? {
247+ guard let fn = LLVMGetFirstGlobalAlias ( llvm) else { return nil }
248+ return Alias ( llvm: fn)
249+ }
250+
251+ /// Retrieves the last alias in this module, if there are any aliases.
252+ public var lastAlias : Alias ? {
253+ guard let fn = LLVMGetLastGlobalAlias ( llvm) else { return nil }
254+ return Alias ( llvm: fn)
255+ }
256+
245257 /// Retrieves the sequence of aliases that make up this module.
246258 public var aliases : AnySequence < Alias > {
247259 var current = firstAlias
@@ -254,15 +266,26 @@ public final class Module: CustomStringConvertible {
254266 }
255267
256268 /// Retrieves the first alias in this module, if there are any aliases.
257- public var firstAlias : Alias ? {
258- guard let fn = LLVMGetFirstGlobalAlias ( llvm) else { return nil }
259- return Alias ( llvm: fn)
269+ public var firstNamedMetadata : NamedMetadata ? {
270+ guard let fn = LLVMGetFirstNamedMetadata ( llvm) else { return nil }
271+ return NamedMetadata ( module : self , llvm: fn)
260272 }
261273
262274 /// Retrieves the last alias in this module, if there are any aliases.
263- public var lastAlias : Alias ? {
264- guard let fn = LLVMGetLastGlobalAlias ( llvm) else { return nil }
265- return Alias ( llvm: fn)
275+ public var lastNamedMetadata : NamedMetadata ? {
276+ guard let fn = LLVMGetLastNamedMetadata ( llvm) else { return nil }
277+ return NamedMetadata ( module: self , llvm: fn)
278+ }
279+
280+ /// Retrieves the sequence of aliases that make up this module.
281+ public var namedMetadata : AnySequence < NamedMetadata > {
282+ var current = firstNamedMetadata
283+ return AnySequence< NamedMetadata> {
284+ return AnyIterator< NamedMetadata> {
285+ defer { current = current? . next ( ) }
286+ return current
287+ }
288+ }
266289 }
267290
268291 /// The current debug metadata version number.
@@ -375,7 +398,7 @@ extension Module {
375398 /// - returns: A representation of the newly created metadata with the
376399 /// given name.
377400 public func metadata( named name: String ) -> NamedMetadata {
378- return NamedMetadata ( module: self , name : name)
401+ return NamedMetadata ( module: self , llvm : LLVMGetOrInsertNamedMetadata ( self . llvm , name, name . count ) )
379402 }
380403
381404 /// Build a named global of the given type.
0 commit comments