Skip to content

[Module] sourceFileName #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2021
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
22 changes: 21 additions & 1 deletion Sources/LLVM/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,27 @@ public final class Module: CustomStringConvertible {
LLVMSetModuleIdentifier(llvm, newValue, newValue.utf8.count)
}
}


/// The source filename of this module.
///
/// The source filename appears at the top of an IR module:
///
/// source_filename = "/path/to/source.c"
///
/// Local functions used in profile data prepend the source file name to the local function name.
///
/// If not otherwise set, `name` is used.
public var sourceFileName: String {
get {
var count = 0
guard let fn = LLVMGetSourceFileName(llvm, &count) else { return "" }
return String(cString: fn)
}
set {
LLVMSetSourceFileName(llvm, newValue, newValue.utf8.count)
}
}

/// Retrieves the inline assembly for this module, if any.
public var inlineAssembly: String {
get {
Expand Down
8 changes: 6 additions & 2 deletions Tests/LLVMTests/ModuleLinkSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ class ModuleLinkSpec : XCTestCase {
// MODULE-LINK-NEXT: }
module1.dump()

// MODULE-LINK: ; ModuleID = '[[ModuleName2:ModuleLinkModuleTwo]]'
// MODULE-LINK-NEXT: source_filename = "[[ModuleName2]]"
// MODULE-LINK: ; ModuleID = 'ModuleLinkModuleTwo'
// MODULE-LINK-NEXT: source_filename = "/Users/user/Developer/Project/file.ext"
let module2 = Module(name: "ModuleLinkModuleTwo")
XCTAssertEqual(module2.name, "ModuleLinkModuleTwo")
XCTAssertEqual(module2.sourceFileName, "ModuleLinkModuleTwo")
module2.sourceFileName = "/Users/user/Developer/Project/file.ext"
XCTAssertEqual(module2.sourceFileName, "/Users/user/Developer/Project/file.ext")

let builder2 = IRBuilder(module: module2)
// MODULE-LINK: define void @moduleTwo() {
let mod2f = builder2.addFunction("moduleTwo",
Expand Down