Skip to content

Commit ce2daf2

Browse files
committed
Added convenience function for adding a global with an initializer (#69)
1 parent 70619ba commit ce2daf2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Sources/LLVM/IRBuilder.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,20 @@ public class IRBuilder {
14801480
return Global(llvm: llvm)
14811481
}
14821482

1483+
/// Build a named global of the given type.
1484+
///
1485+
/// - parameter name: The name of the newly inserted global value.
1486+
/// - parameter initializer: The initial value for the global variable.
1487+
/// - parameter addressSpace: The optional address space where the global
1488+
/// variable resides.
1489+
///
1490+
/// - returns: A value representing the newly inserted global variable.
1491+
public func addGlobal(_ name: String, initializer: IRValue, addressSpace: Int? = nil) -> Global {
1492+
var global = addGlobal(name, type: initializer.type)
1493+
global.initializer = initializer
1494+
return global
1495+
}
1496+
14831497
/// Build a named global string consisting of an array of `i8` type filled in
14841498
/// with the nul terminated string value.
14851499
///

0 commit comments

Comments
 (0)