PECOFFFileNode(PECOFFLinkingContext &ctx, StringRef path)
: FileNode(path), _ctx(ctx), _parsed(false) {}
- ErrorOr<StringRef> getPath(const LinkingContext &ctx) const override;
-
/// \brief Parse the input file to lld::File.
std::error_code parse(const LinkingContext &ctx,
raw_ostream &diagnostics) override;
public:
PECOFFLibraryNode(PECOFFLinkingContext &ctx, StringRef path)
: PECOFFFileNode(ctx, path) {}
-
- ErrorOr<StringRef> getPath(const LinkingContext &ctx) const override;
};
} // namespace lld
return true;
}
+StringRef getObjectPath(PECOFFLinkingContext &ctx, StringRef path) {
+ std::string result;
+ if (isCOFFLibraryFileExtension(path)) {
+ result =ctx.searchLibraryFile(path);
+ } else if (llvm::sys::path::extension(path).empty()) {
+ result = path.str() + ".obj";
+ } else {
+ result = path;
+ }
+ return ctx.allocate(result);
+}
+
+StringRef getLibraryPath(PECOFFLinkingContext &ctx, StringRef path) {
+ std::string result = isCOFFLibraryFileExtension(path)
+ ? ctx.searchLibraryFile(path)
+ : ctx.searchLibraryFile(path.str() + ".lib");
+ return ctx.allocate(result);
+}
+
// Returns true if the given file is a Windows resource file.
static bool isResoruceFile(StringRef path) {
llvm::sys::fs::file_magic fileType;
for (StringRef path : inputFiles) {
path = ctx.allocate(path);
if (isCOFFLibraryFileExtension(path)) {
- libraries.push_back(std::unique_ptr<FileNode>(new PECOFFLibraryNode(ctx, path)));
+ libraries.push_back(std::unique_ptr<FileNode>(
+ new PECOFFLibraryNode(ctx, getLibraryPath(ctx, path))));
} else {
- files.push_back(std::unique_ptr<FileNode>(new PECOFFFileNode(ctx, path)));
+ files.push_back(std::unique_ptr<FileNode>(
+ new PECOFFFileNode(ctx, getObjectPath(ctx, path))));
}
}
for (const StringRef path : defaultLibs)
if (!ctx.hasNoDefaultLib(path))
libraries.push_back(std::unique_ptr<FileNode>(
- new PECOFFLibraryNode(ctx, ctx.allocate(path.lower()))));
+ new PECOFFLibraryNode(ctx, getLibraryPath(ctx, path.lower()))));
if (files.empty() && !isReadingDirectiveSection) {
diag << "No input files\n";
return ctx.registry().parseFile(std::move(mb.get()), _files);
}
-ErrorOr<StringRef> PECOFFFileNode::getPath(const LinkingContext &) const {
- if (isCOFFLibraryFileExtension(_path))
- return _ctx.searchLibraryFile(_path);
- if (llvm::sys::path::extension(_path).empty())
- return _ctx.allocate(_path.str() + ".obj");
- return _path;
-}
-
-ErrorOr<StringRef> PECOFFLibraryNode::getPath(const LinkingContext &) const {
- if (isCOFFLibraryFileExtension(_path))
- return _ctx.searchLibraryFile(_path);
- return _ctx.searchLibraryFile(_ctx.allocate(_path.str() + ".lib"));
-}
-
} // end anonymous namespace