Skip to content
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: 12 additions & 0 deletions Sources/LLVM/Alias.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc comment here. Can probably just copy&paste the one from addAlias

internal let llvm: LLVMValueRef

/// Retrieves the underlying LLVM value object.
public func asLLVM() -> LLVMValueRef {
return llvm
}
}
14 changes: 14 additions & 0 deletions Sources/LLVM/IRBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,20 @@ public class IRBuilder {
public func buildGlobalStringPtr(_ string: String, name: String = "") -> IRValue {
return LLVMBuildGlobalStringPtr(llvm, string, name)
}

/// Builds a named alias to a global value or a constant expression.
///
/// Aliases, unlike function or variables, don’t create any new data. They are
/// just a new symbol and metadata for an existing position.
///
/// - parameter name: The name of the newly inserted alias.
/// - parameter aliasee: The value or constant to alias.
/// - 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 {
return Alias(llvm: LLVMAddAlias(module.llvm, type.asLLVM(), aliasee.asLLVM(), name))
}

deinit {
LLVMDisposeBuilder(llvm)
Expand Down