[TextAPI][elfabi] Make TBE handlers functions that return Errors

Since TBEHandler doesn't maintain state or otherwise have any need to be
a class right now, the read and write functions have been moved out and
turned into standalone functions. Additionally, the TBE read function
has been updated to return an Expected value for better error handling.
Tests have been updated to reflect these changes.

Differential Revision: https://reviews.llvm.org/D55450

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348735 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Armando Montanez
2018-12-10 02:36:33 +00:00
parent dcf592e012
commit 01342484a4
4 changed files with 28 additions and 34 deletions
+5 -4
View File
@@ -142,16 +142,17 @@ template <> struct MappingTraits<ELFStub> {
} // end namespace yaml
} // end namespace llvm
std::unique_ptr<ELFStub> TBEHandler::readFile(StringRef Buf) {
Expected<std::unique_ptr<ELFStub>> elfabi::readTBEFromBuffer(StringRef Buf) {
yaml::Input YamlIn(Buf);
std::unique_ptr<ELFStub> Stub(new ELFStub());
YamlIn >> *Stub;
if (YamlIn.error())
return nullptr;
if (std::error_code Err = YamlIn.error())
return createStringError(Err, "YAML failed reading as TBE");
return Stub;
}
Error TBEHandler::writeFile(raw_ostream &OS, const ELFStub &Stub) {
Error elfabi::writeTBEToOutputStream(raw_ostream &OS, const ELFStub &Stub) {
yaml::Output YamlOut(OS, NULL, /*WrapColumn =*/0);
YamlOut << const_cast<ELFStub &>(Stub);