[cleanup] remove readFile and replace with getBuffer.
no functionality change. llvm-svn: 194360
This commit is contained in:
parent
ba470fa875
commit
29ffee7af9
|
@ -42,10 +42,19 @@ public:
|
|||
|
||||
/// \brief Parse the input file to lld::File.
|
||||
error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) {
|
||||
// Read the file to _buffer.
|
||||
bool isYaml = false;
|
||||
if (error_code ec = readFile(ctx, diagnostics, isYaml))
|
||||
ErrorOr<StringRef> filePath = getPath(ctx);
|
||||
if (!filePath)
|
||||
return error_code(filePath);
|
||||
|
||||
if (error_code ec = getBuffer(*filePath))
|
||||
return ec;
|
||||
|
||||
if (ctx.logInputFiles())
|
||||
diagnostics << *filePath << "\n";
|
||||
|
||||
if (filePath->endswith(".objtxt"))
|
||||
return ctx.getYAMLReader().parseFile(_buffer, _files);
|
||||
|
||||
(void) (_isWholeArchive);
|
||||
return error_code::success();
|
||||
}
|
||||
|
|
|
@ -72,12 +72,18 @@ public:
|
|||
|
||||
/// \brief Parse the input file to lld::File.
|
||||
error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) {
|
||||
// Read the file to _buffer.
|
||||
bool isYaml = false;
|
||||
if (error_code ec = readFile(ctx, diagnostics, isYaml))
|
||||
ErrorOr<StringRef> filePath = getPath(ctx);
|
||||
if (!filePath)
|
||||
return error_code(filePath);
|
||||
|
||||
if (error_code ec = getBuffer(*filePath))
|
||||
return ec;
|
||||
if (isYaml)
|
||||
return error_code::success();
|
||||
|
||||
if (ctx.logInputFiles())
|
||||
diagnostics << *filePath << "\n";
|
||||
|
||||
if (filePath->endswith(".objtxt"))
|
||||
return ctx.getYAMLReader().parseFile(_buffer, _files);
|
||||
|
||||
// Identify File type
|
||||
llvm::sys::fs::file_magic FileType =
|
||||
|
|
|
@ -297,8 +297,7 @@ public:
|
|||
|
||||
protected:
|
||||
/// \brief Read the file into _buffer.
|
||||
error_code readFile(const LinkingContext &ctx, raw_ostream &diagnostics,
|
||||
bool &isYaml);
|
||||
error_code getBuffer(StringRef filePath);
|
||||
|
||||
StringRef _path; // The path of the Input file
|
||||
InputGraph::FileVectorT _files; // A vector of lld File objects
|
||||
|
|
|
@ -39,12 +39,18 @@ public:
|
|||
|
||||
/// \brief Parse the input file to lld::File.
|
||||
error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) {
|
||||
// Read the file to _buffer.
|
||||
bool isYaml = false;
|
||||
if (error_code ec = readFile(ctx, diagnostics, isYaml))
|
||||
ErrorOr<StringRef> filePath = getPath(ctx);
|
||||
if (!filePath)
|
||||
return error_code(filePath);
|
||||
|
||||
if (error_code ec = getBuffer(*filePath))
|
||||
return ec;
|
||||
if (isYaml)
|
||||
return error_code::success();
|
||||
|
||||
if (ctx.logInputFiles())
|
||||
diagnostics << *filePath << "\n";
|
||||
|
||||
if (filePath->endswith(".objtxt"))
|
||||
return ctx.getYAMLReader().parseFile(_buffer, _files);
|
||||
|
||||
llvm::sys::fs::file_magic FileType =
|
||||
llvm::sys::fs::identify_magic(_buffer->getBuffer());
|
||||
|
|
|
@ -98,33 +98,16 @@ FileNode::FileNode(StringRef path, int64_t ordinal)
|
|||
_resolveState(Resolver::StateNoChange), _nextFileIndex(0) {}
|
||||
|
||||
/// \brief Read the file into _buffer.
|
||||
error_code
|
||||
FileNode::readFile(const LinkingContext &ctx, raw_ostream &diagnostics,
|
||||
bool &isYaml) {
|
||||
ErrorOr<StringRef> filePath = getPath(ctx);
|
||||
if (!filePath &&
|
||||
error_code(filePath) == llvm::errc::no_such_file_or_directory)
|
||||
return make_error_code(llvm::errc::no_such_file_or_directory);
|
||||
|
||||
error_code FileNode::getBuffer(StringRef filePath) {
|
||||
// Create a memory buffer
|
||||
OwningPtr<MemoryBuffer> opmb;
|
||||
|
||||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(*filePath, opmb))
|
||||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(filePath, opmb))
|
||||
return ec;
|
||||
|
||||
std::unique_ptr<MemoryBuffer> mb(opmb.take());
|
||||
_buffer = std::move(mb);
|
||||
|
||||
if (ctx.logInputFiles())
|
||||
diagnostics << _buffer->getBufferIdentifier() << "\n";
|
||||
|
||||
// YAML file is identified by a .objtxt extension
|
||||
// FIXME : Identify YAML files by using a magic
|
||||
if (filePath->endswith(".objtxt")) {
|
||||
if (error_code ec = ctx.getYAMLReader().parseFile(_buffer, _files))
|
||||
return ec;
|
||||
isYaml = true;
|
||||
}
|
||||
return error_code::success();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue