add parseObjectTextFileOrSTDIN() utility

llvm-svn: 146931
This commit is contained in:
Nick Kledzik 2011-12-20 00:07:11 +00:00
parent 1cbbdac108
commit 070e1a7643
3 changed files with 29 additions and 6 deletions

View File

@ -21,7 +21,16 @@ namespace llvm { class MemoryBuffer; }
namespace lld {
namespace yaml {
llvm::error_code parseObjectText( llvm::MemoryBuffer *mb
/// parseObjectTextFileOrSTDIN - Open the specified YAML file (use stdin if
/// the path is "-") and parse into lld::File object(s) and append each to
/// the specified vector<File*>.
llvm::error_code parseObjectTextFileOrSTDIN(llvm::StringRef path
, std::vector<File *>&);
/// parseObjectText - Parse the specified YAML formatted MemoryBuffer
/// into lld::File object(s) and append each to the specified vector<File*>.
llvm::error_code parseObjectText(llvm::MemoryBuffer *mb
, std::vector<File *>&);
} // namespace yaml

View File

@ -555,5 +555,20 @@ llvm::error_code parseObjectText( llvm::MemoryBuffer *mb
result.push_back(file);
return success;
}
//
// Fill in vector<File*> from path to input text file.
//
llvm::error_code parseObjectTextFileOrSTDIN(llvm::StringRef path
, std::vector<File*>& result) {
llvm::OwningPtr<llvm::MemoryBuffer> mb;
llvm::error_code ec = llvm::MemoryBuffer::getFileOrSTDIN(path, mb);
if ( ec )
return ec;
return parseObjectText(mb.get(), result);
}
} // namespace yaml
} // namespace lld

View File

@ -171,19 +171,18 @@ private:
}
int main(int argc, const char *argv[]) {
llvm::OwningPtr<llvm::MemoryBuffer> mb;
if (error(llvm::MemoryBuffer::getFileOrSTDIN(llvm::StringRef(argv[1]), mb)))
return 1;
// read input YAML doc into object file(s)
std::vector<File *> files;
if (error(yaml::parseObjectText(mb.get(), files)))
if (error(yaml::parseObjectTextFileOrSTDIN(llvm::StringRef(argv[1]), files)))
return 1;
// merge all atom graphs
LdCore core(files);
Resolver resolver(core, core);
std::vector<const Atom *> &mergedAtoms = resolver.resolve();
MergedFile outFile(mergedAtoms);
// write new atom graph out as YAML doc
std::string errorInfo;
llvm::raw_fd_ostream out("-", errorInfo);
yaml::writeObjectText(&outFile, out);