Skip to content

Make IRGlobal a Thing #30

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
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
2 changes: 1 addition & 1 deletion Sources/LLVM/Alias.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cllvm

/// An `Alias` represents a global alias in an LLVM module - a new symbol and
/// corresponding metadata for an existing position
public struct Alias: IRValue {
public struct Alias: IRGlobal {
internal let llvm: LLVMValueRef

/// Retrieves the underlying LLVM value object.
Expand Down
14 changes: 1 addition & 13 deletions Sources/LLVM/Function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cllvm
/// A `Function` represents a named function body in LLVM IR source. Functions
/// in LLVM IR encapsulate a list of parameters and a sequence of basic blocks
/// and provide a way to append to that sequence to build out its body.
public class Function: IRValue {
public class Function: IRGlobal {
internal let llvm: LLVMValueRef
internal init(llvm: LLVMValueRef) {
self.llvm = llvm
Expand Down Expand Up @@ -107,18 +107,6 @@ public class Function: IRValue {
LLVMDeleteFunction(llvm)
}

/// Retrieves the linkage information for this function.
public var linkage: Linkage {
get { return Linkage(llvm: LLVMGetLinkage(asLLVM())) }
set { LLVMSetLinkage(asLLVM(), newValue.llvm) }
}

/// Retrieves the visibility style for this function.
public var visibility: Visibility {
get { return Visibility(llvm: LLVMGetVisibility(asLLVM())) }
set { LLVMSetVisibility(asLLVM(), newValue.llvm) }
}

/// Retrieves the underlying LLVM value object.
public func asLLVM() -> LLVMValueRef {
return llvm
Expand Down
14 changes: 1 addition & 13 deletions Sources/LLVM/Global.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cllvm
/// A `Global` represents a region of memory allocated at compile time instead
/// of at runtime. A global variable must either have an initializer, or make
/// reference to an external definition that has an initializer.
public struct Global: IRValue {
public struct Global: IRGlobal {
internal let llvm: LLVMValueRef

/// Returns whether this global variable has no initializer because it makes
Expand Down Expand Up @@ -33,18 +33,6 @@ public struct Global: IRValue {
set { LLVMSetThreadLocal(asLLVM(), newValue.llvm) }
}

/// Retrieves the linkage information for this global value.
public var linkage: Linkage {
get { return Linkage(llvm: LLVMGetLinkage(asLLVM())) }
set { LLVMSetLinkage(asLLVM(), newValue.llvm) }
}

/// Retrieves the visibility style for this global value.
public var visibility: Visibility {
get { return Visibility(llvm: LLVMGetVisibility(asLLVM())) }
set { LLVMSetVisibility(asLLVM(), newValue.llvm) }
}

/// Deletes the global variable from its containing module.
/// - note: This does not remove references to this global from the
/// module. Ensure you have removed all insructions that reference
Expand Down
2 changes: 1 addition & 1 deletion Sources/LLVM/IRBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ public class IRBuilder {
/// - parameter type: The type of the aliased value or expression.
///
/// - returns: A value representing the newly created alias.
public func addAlias(name: String, to aliasee: IRValue, type: IRType) -> Alias {
public func addAlias(name: String, to aliasee: IRGlobal, type: IRType) -> Alias {
return Alias(llvm: LLVMAddAlias(module.llvm, type.asLLVM(), aliasee.asLLVM(), name))
}

Expand Down
19 changes: 19 additions & 0 deletions Sources/LLVM/IRGlobal.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import cllvm

/// An `IRGlobal` is a value, alias, or function that exists at the top level of
/// an LLVM module.
public protocol IRGlobal: IRValue {}

extension IRGlobal {
/// Retrieves the linkage information for this global.
public var linkage: Linkage {
get { return Linkage(llvm: LLVMGetLinkage(asLLVM())) }
set { LLVMSetLinkage(asLLVM(), newValue.llvm) }
}

/// Retrieves the visibility style for this global.
public var visibility: Visibility {
get { return Visibility(llvm: LLVMGetVisibility(asLLVM())) }
set { LLVMSetVisibility(asLLVM(), newValue.llvm) }
}
}