Skip to content

Commit 30eb3bf

Browse files
authored
Merge pull request #28 from CodaFi/assumed-alias
Add Alias emission to the builder
2 parents 35dc61a + cb66e61 commit 30eb3bf

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Sources/LLVM/Alias.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import cllvm
2+
3+
/// An `Alias` represents a global alias in an LLVM module - a new symbol and
4+
/// corresponding metadata for an existing position
5+
public struct Alias: IRValue {
6+
internal let llvm: LLVMValueRef
7+
8+
/// Retrieves the underlying LLVM value object.
9+
public func asLLVM() -> LLVMValueRef {
10+
return llvm
11+
}
12+
}

Sources/LLVM/IRBuilder.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,20 @@ public class IRBuilder {
13351335
public func buildGlobalStringPtr(_ string: String, name: String = "") -> IRValue {
13361336
return LLVMBuildGlobalStringPtr(llvm, string, name)
13371337
}
1338+
1339+
/// Builds a named alias to a global value or a constant expression.
1340+
///
1341+
/// Aliases, unlike function or variables, don’t create any new data. They are
1342+
/// just a new symbol and metadata for an existing position.
1343+
///
1344+
/// - parameter name: The name of the newly inserted alias.
1345+
/// - parameter aliasee: The value or constant to alias.
1346+
/// - parameter type: The type of the aliased value or expression.
1347+
///
1348+
/// - returns: A value representing the newly created alias.
1349+
public func addAlias(name: String, to aliasee: IRValue, type: IRType) -> Alias {
1350+
return Alias(llvm: LLVMAddAlias(module.llvm, type.asLLVM(), aliasee.asLLVM(), name))
1351+
}
13381352

13391353
deinit {
13401354
LLVMDisposeBuilder(llvm)

0 commit comments

Comments
 (0)