Skip to content

Upgrade a bunch of Ints to Alignment #159

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
Oct 23, 2018
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
4 changes: 2 additions & 2 deletions Sources/LLVM/Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public struct Call: IRValue {
///
/// - parameter i: The index of the parameter to retrieve.
/// - parameter alignment: The alignment to apply to the parameter.
public func setParameterAlignment(at i : Int, to alignment: Int) {
LLVMSetInstrParamAlignment(self.llvm, UInt32(i), UInt32(alignment))
public func setParameterAlignment(at i : Int, to alignment: Alignment) {
LLVMSetInstrParamAlignment(self.llvm, UInt32(i), alignment.rawValue)
}
}

Expand Down
14 changes: 7 additions & 7 deletions Sources/LLVM/IRBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ extension Module {
var global = addGlobal(name, type:
ArrayType(elementType: IntType.int8, count: length + 1))

global.alignment = 1
global.alignment = Alignment(1)
global.initializer = value

return global
Expand Down Expand Up @@ -1247,14 +1247,14 @@ public class IRBuilder {
///
/// - returns: A value representing `void`.
public func buildAlloca(type: IRType, count: IRValue? = nil,
alignment: Int = 0, name: String = "") -> IRValue {
alignment: Alignment = .zero, name: String = "") -> IRValue {
let allocaInst: LLVMValueRef
if let count = count {
allocaInst = LLVMBuildArrayAlloca(llvm, type.asLLVM(), count.asLLVM(), name)
} else {
allocaInst = LLVMBuildAlloca(llvm, type.asLLVM(), name)!
}
LLVMSetAlignment(allocaInst, UInt32(alignment))
LLVMSetAlignment(allocaInst, alignment.rawValue)
return allocaInst
}

Expand All @@ -1270,11 +1270,11 @@ public class IRBuilder {
///
/// - returns: A value representing `void`.
@discardableResult
public func buildStore(_ val: IRValue, to ptr: IRValue, ordering: AtomicOrdering = .notAtomic, volatile: Bool = false, alignment: Int = 0) -> IRValue {
public func buildStore(_ val: IRValue, to ptr: IRValue, ordering: AtomicOrdering = .notAtomic, volatile: Bool = false, alignment: Alignment = .zero) -> IRValue {
let storeInst = LLVMBuildStore(llvm, val.asLLVM(), ptr.asLLVM())!
LLVMSetOrdering(storeInst, ordering.llvm)
LLVMSetVolatile(storeInst, volatile.llvm)
LLVMSetAlignment(storeInst, UInt32(alignment))
LLVMSetAlignment(storeInst, alignment.rawValue)
return storeInst
}

Expand All @@ -1290,11 +1290,11 @@ public class IRBuilder {
///
/// - returns: A value representing the result of a load from the given
/// pointer value.
public func buildLoad(_ ptr: IRValue, ordering: AtomicOrdering = .notAtomic, volatile: Bool = false, alignment: Int = 0, name: String = "") -> IRValue {
public func buildLoad(_ ptr: IRValue, ordering: AtomicOrdering = .notAtomic, volatile: Bool = false, alignment: Alignment = .zero, name: String = "") -> IRValue {
let loadInst = LLVMBuildLoad(llvm, ptr.asLLVM(), name)!
LLVMSetOrdering(loadInst, ordering.llvm)
LLVMSetVolatile(loadInst, volatile.llvm)
LLVMSetAlignment(loadInst, UInt32(alignment))
LLVMSetAlignment(loadInst, alignment.rawValue)
return loadInst
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/LLVM/IRGlobal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public protocol IRGlobal: IRConstant {}

extension IRGlobal {
/// Retrieves the alignment of this value.
public var alignment: Int {
get { return Int(LLVMGetAlignment(asLLVM())) }
set { LLVMSetAlignment(asLLVM(), UInt32(newValue)) }
public var alignment: Alignment {
get { return Alignment(LLVMGetAlignment(asLLVM())) }
set { LLVMSetAlignment(asLLVM(), newValue.rawValue) }
}

/// Retrieves the linkage information for this global.
Expand Down