Skip to content

Commit 6ebb062

Browse files
committed
Add non-consuming module linking function
1 parent f14a9a2 commit 6ebb062

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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)