Skip to content

Commit d734db6

Browse files
authored
Merge pull request #119 from CodaFi/link-in-berry-jam
Wrap Some Linking-Related Functions
2 parents c66da21 + 36c1d22 commit d734db6

File tree

5 files changed

+265
-166
lines changed

5 files changed

+265
-166
lines changed

Sources/LLVM/IRGlobal.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,18 @@ extension IRGlobal {
3131
get { return StorageClass(llvm: LLVMGetDLLStorageClass(asLLVM())) }
3232
set { LLVMSetDLLStorageClass(asLLVM(), newValue.llvm) }
3333
}
34+
35+
/// Retrieves the section associated with the symbol that will eventually be
36+
/// emitted for this global value.
37+
///
38+
/// - Note: Global `Alias` values may or may not be resolvable to any
39+
/// particular section given the state of the IR in an arbitrary module. A
40+
/// return value of the empty string indicates a failed section lookup.
41+
public var section: String {
42+
get {
43+
guard let sname = LLVMGetSection(asLLVM()) else { return "" }
44+
return String(cString: sname)
45+
}
46+
set { LLVMSetSection(asLLVM(), newValue) }
47+
}
3448
}

Sources/LLVM/Module.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ public final class Module: CustomStringConvertible {
148148
}
149149
}
150150

151+
/// Links the given module with this module. If the link succeeds, this
152+
/// module will the composite of the two input modules.
153+
///
154+
/// The result of this function is `true` if the link succeeds, or `false`
155+
/// otherwise - unlike `llvm::Linker::linkModules`.
156+
///
157+
/// - parameter other: The module to link with this module.
158+
public func link(_ other: Module) -> Bool {
159+
// First clone the other module; `LLVMLinkModules2` consumes the source
160+
// module via a move and that module still owns its ModuleRef.
161+
let otherClone = LLVMCloneModule(other.llvm)
162+
// N.B. Returns `true` on error.
163+
return LLVMLinkModules2(self.llvm, otherClone) == 0
164+
}
165+
151166
/// Retrieves the sequence of functions that make up this module.
152167
public var functions: AnySequence<Function> {
153168
var current = firstFunction

0 commit comments

Comments
 (0)