Skip to content

Miscellaneous Tweaks #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Sources/LLVM/IRBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1288,10 +1288,18 @@ public class IRBuilder {
///
/// - parameter name: The name of the newly inserted global value.
/// - parameter type: The type of the newly inserted global value.
/// - parameter addressSpace: The optional address space where the global
/// variable resides.
///
/// - returns: A value representing the newly inserted global variable.
public func addGlobal(_ name: String, type: IRType) -> Global {
return Global(llvm: LLVMAddGlobal(module.llvm, type.asLLVM(), name))
public func addGlobal(_ name: String, type: IRType, addressSpace: Int? = nil) -> Global {
let llvm: LLVMValueRef
if let addressSpace = addressSpace {
llvm = LLVMAddGlobalInAddressSpace(module.llvm, type.asLLVM(), name, UInt32(addressSpace))
} else {
llvm = LLVMAddGlobal(module.llvm, type.asLLVM(), name)
}
return Global(llvm: llvm)
}

/// Build a named global string consisting of an array of `i8` type filled in
Expand Down
2 changes: 1 addition & 1 deletion Sources/LLVM/IntType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public struct IntType: IRType {
/// type's bit width. Defaults to `false`.
public func constant<IntTy: Integer>(_ value: IntTy, signExtend: Bool = false) -> IRValue {
return LLVMConstInt(asLLVM(),
unsafeBitCast(value.toIntMax(), to: UInt64.self),
UInt64(bitPattern: value.toIntMax()),
signExtend.llvm)
}

Expand Down