From cb66e61dd01b0c6094e1874cdcc9328600c8251b Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 13 Jan 2017 22:16:18 -0700 Subject: [PATCH] Add Alias emission to the builder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Aliases are completely useless at the moment as there aren’t wrappers for its accessors. --- Sources/LLVM/Alias.swift | 12 ++++++++++++ Sources/LLVM/IRBuilder.swift | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Sources/LLVM/Alias.swift diff --git a/Sources/LLVM/Alias.swift b/Sources/LLVM/Alias.swift new file mode 100644 index 00000000..9bd23d14 --- /dev/null +++ b/Sources/LLVM/Alias.swift @@ -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 { + internal let llvm: LLVMValueRef + + /// Retrieves the underlying LLVM value object. + public func asLLVM() -> LLVMValueRef { + return llvm + } +} diff --git a/Sources/LLVM/IRBuilder.swift b/Sources/LLVM/IRBuilder.swift index f475befc..da556597 100644 --- a/Sources/LLVM/IRBuilder.swift +++ b/Sources/LLVM/IRBuilder.swift @@ -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)