forked from OSchip/llvm-project
add parseObjectTextFileOrSTDIN() utility
llvm-svn: 146931
This commit is contained in:
parent
1cbbdac108
commit
070e1a7643
|
@ -21,7 +21,16 @@ namespace llvm { class MemoryBuffer; }
|
||||||
namespace lld {
|
namespace lld {
|
||||||
namespace yaml {
|
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 *>&);
|
, std::vector<File *>&);
|
||||||
|
|
||||||
} // namespace yaml
|
} // namespace yaml
|
||||||
|
|
|
@ -555,5 +555,20 @@ llvm::error_code parseObjectText( llvm::MemoryBuffer *mb
|
||||||
result.push_back(file);
|
result.push_back(file);
|
||||||
return success;
|
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 yaml
|
||||||
} // namespace lld
|
} // namespace lld
|
||||||
|
|
|
@ -171,19 +171,18 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char *argv[]) {
|
||||||
llvm::OwningPtr<llvm::MemoryBuffer> mb;
|
// read input YAML doc into object file(s)
|
||||||
if (error(llvm::MemoryBuffer::getFileOrSTDIN(llvm::StringRef(argv[1]), mb)))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
std::vector<File *> files;
|
std::vector<File *> files;
|
||||||
if (error(yaml::parseObjectText(mb.get(), files)))
|
if (error(yaml::parseObjectTextFileOrSTDIN(llvm::StringRef(argv[1]), files)))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
// merge all atom graphs
|
||||||
LdCore core(files);
|
LdCore core(files);
|
||||||
Resolver resolver(core, core);
|
Resolver resolver(core, core);
|
||||||
std::vector<const Atom *> &mergedAtoms = resolver.resolve();
|
std::vector<const Atom *> &mergedAtoms = resolver.resolve();
|
||||||
MergedFile outFile(mergedAtoms);
|
MergedFile outFile(mergedAtoms);
|
||||||
|
|
||||||
|
// write new atom graph out as YAML doc
|
||||||
std::string errorInfo;
|
std::string errorInfo;
|
||||||
llvm::raw_fd_ostream out("-", errorInfo);
|
llvm::raw_fd_ostream out("-", errorInfo);
|
||||||
yaml::writeObjectText(&outFile, out);
|
yaml::writeObjectText(&outFile, out);
|
||||||
|
|
Loading…
Reference in New Issue