Skip to content

Commit 45da8cc

Browse files
authored
Merge pull request #52 from CodaFi/zen
Miscellaneous Tweaks
2 parents fabfcc7 + 168e779 commit 45da8cc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Sources/LLVM/IRBuilder.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,10 +1288,18 @@ public class IRBuilder {
12881288
///
12891289
/// - parameter name: The name of the newly inserted global value.
12901290
/// - parameter type: The type of the newly inserted global value.
1291+
/// - parameter addressSpace: The optional address space where the global
1292+
/// variable resides.
12911293
///
12921294
/// - returns: A value representing the newly inserted global variable.
1293-
public func addGlobal(_ name: String, type: IRType) -> Global {
1294-
return Global(llvm: LLVMAddGlobal(module.llvm, type.asLLVM(), name))
1295+
public func addGlobal(_ name: String, type: IRType, addressSpace: Int? = nil) -> Global {
1296+
let llvm: LLVMValueRef
1297+
if let addressSpace = addressSpace {
1298+
llvm = LLVMAddGlobalInAddressSpace(module.llvm, type.asLLVM(), name, UInt32(addressSpace))
1299+
} else {
1300+
llvm = LLVMAddGlobal(module.llvm, type.asLLVM(), name)
1301+
}
1302+
return Global(llvm: llvm)
12951303
}
12961304

12971305
/// Build a named global string consisting of an array of `i8` type filled in

Sources/LLVM/IntType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public struct IntType: IRType {
4242
/// type's bit width. Defaults to `false`.
4343
public func constant<IntTy: Integer>(_ value: IntTy, signExtend: Bool = false) -> IRValue {
4444
return LLVMConstInt(asLLVM(),
45-
unsafeBitCast(value.toIntMax(), to: UInt64.self),
45+
UInt64(bitPattern: value.toIntMax()),
4646
signExtend.llvm)
4747
}
4848

0 commit comments

Comments
 (0)