From 7da559f2f60ef69a0098487ea25e0d81fdccc2f2 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Fri, 13 Sep 2019 09:12:38 +0000 Subject: [PATCH] [lib/ObjectYAML] - Change interface to return `bool` instead of `int`. NFCI It was suggested in comments for D67445 to split this part. Differential revision: https://reviews.llvm.org/D67488 llvm-svn: 371828 --- llvm/include/llvm/ObjectYAML/yaml2obj.h | 10 +++++----- llvm/lib/ObjectYAML/COFFEmitter.cpp | 12 ++++++------ llvm/lib/ObjectYAML/ELFEmitter.cpp | 10 +++++----- llvm/lib/ObjectYAML/MachOEmitter.cpp | 6 +++--- llvm/lib/ObjectYAML/MinidumpEmitter.cpp | 4 ++-- llvm/lib/ObjectYAML/WasmEmitter.cpp | 13 ++++++------- llvm/lib/ObjectYAML/yaml2obj.cpp | 15 +++++++-------- 7 files changed, 34 insertions(+), 36 deletions(-) diff --git a/llvm/include/llvm/ObjectYAML/yaml2obj.h b/llvm/include/llvm/ObjectYAML/yaml2obj.h index d8d8dad..54c39ef 100644 --- a/llvm/include/llvm/ObjectYAML/yaml2obj.h +++ b/llvm/include/llvm/ObjectYAML/yaml2obj.h @@ -44,11 +44,11 @@ namespace yaml { class Input; struct YamlObjectFile; -int yaml2coff(COFFYAML::Object &Doc, raw_ostream &Out); -int yaml2elf(ELFYAML::Object &Doc, raw_ostream &Out); -int yaml2macho(YamlObjectFile &Doc, raw_ostream &Out); -int yaml2minidump(MinidumpYAML::Object &Doc, raw_ostream &Out); -int yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out); +bool yaml2coff(COFFYAML::Object &Doc, raw_ostream &Out); +bool yaml2elf(ELFYAML::Object &Doc, raw_ostream &Out); +bool yaml2macho(YamlObjectFile &Doc, raw_ostream &Out); +bool yaml2minidump(MinidumpYAML::Object &Doc, raw_ostream &Out); +bool yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out); Error convertYAML(Input &YIn, raw_ostream &Out, unsigned DocNum = 1); diff --git a/llvm/lib/ObjectYAML/COFFEmitter.cpp b/llvm/lib/ObjectYAML/COFFEmitter.cpp index d94cdbf..daa4f6d 100644 --- a/llvm/lib/ObjectYAML/COFFEmitter.cpp +++ b/llvm/lib/ObjectYAML/COFFEmitter.cpp @@ -592,27 +592,27 @@ static bool writeCOFF(COFFParser &CP, raw_ostream &OS) { namespace llvm { namespace yaml { -int yaml2coff(llvm::COFFYAML::Object &Doc, raw_ostream &Out) { +bool yaml2coff(llvm::COFFYAML::Object &Doc, raw_ostream &Out) { COFFParser CP(Doc); if (!CP.parse()) { errs() << "yaml2obj: Failed to parse YAML file!\n"; - return 1; + return false; } if (!layoutOptionalHeader(CP)) { errs() << "yaml2obj: Failed to layout optional header for COFF file!\n"; - return 1; + return false; } if (!layoutCOFF(CP)) { errs() << "yaml2obj: Failed to layout COFF file!\n"; - return 1; + return false; } if (!writeCOFF(CP, Out)) { errs() << "yaml2obj: Failed to write COFF file!\n"; - return 1; + return false; } - return 0; + return true; } } // namespace yaml diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp index 72063a5..6c64754 100644 --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -168,7 +168,7 @@ template class ELFState { ContiguousBlobAccumulator &CBA); ELFState(ELFYAML::Object &D); public: - static int writeELF(raw_ostream &OS, ELFYAML::Object &Doc); + static bool writeELF(raw_ostream &OS, ELFYAML::Object &Doc); }; } // end anonymous namespace @@ -983,7 +983,7 @@ template void ELFState::finalizeStrings() { } template -int ELFState::writeELF(raw_ostream &OS, ELFYAML::Object &Doc) { +bool ELFState::writeELF(raw_ostream &OS, ELFYAML::Object &Doc) { ELFState State(Doc); // Finalize .strtab and .dynstr sections. We do that early because want to @@ -1010,19 +1010,19 @@ int ELFState::writeELF(raw_ostream &OS, ELFYAML::Object &Doc) { State.setProgramHeaderLayout(PHeaders, SHeaders); if (State.HasError) - return 1; + return false; State.writeELFHeader(CBA, OS); writeArrayData(OS, makeArrayRef(PHeaders)); CBA.writeBlobToStream(OS); writeArrayData(OS, makeArrayRef(SHeaders)); - return 0; + return true; } namespace llvm { namespace yaml { -int yaml2elf(llvm::ELFYAML::Object &Doc, raw_ostream &Out) { +bool yaml2elf(llvm::ELFYAML::Object &Doc, raw_ostream &Out) { bool IsLE = Doc.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB); bool Is64Bit = Doc.Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64); if (Is64Bit) { diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp index 47d7667..621b9b2 100644 --- a/llvm/lib/ObjectYAML/MachOEmitter.cpp +++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp @@ -596,13 +596,13 @@ void UniversalWriter::ZeroToOffset(raw_ostream &OS, size_t Offset) { namespace llvm { namespace yaml { -int yaml2macho(YamlObjectFile &Doc, raw_ostream &Out) { +bool yaml2macho(YamlObjectFile &Doc, raw_ostream &Out) { UniversalWriter Writer(Doc); if (auto Err = Writer.writeMachO(Out)) { errs() << toString(std::move(Err)); - return 1; + return false; } - return 0; + return true; } } // namespace yaml diff --git a/llvm/lib/ObjectYAML/MinidumpEmitter.cpp b/llvm/lib/ObjectYAML/MinidumpEmitter.cpp index e02a01f..cc28f96 100644 --- a/llvm/lib/ObjectYAML/MinidumpEmitter.cpp +++ b/llvm/lib/ObjectYAML/MinidumpEmitter.cpp @@ -198,7 +198,7 @@ static Directory layout(BlobAllocator &File, Stream &S) { namespace llvm { namespace yaml { -int yaml2minidump(MinidumpYAML::Object &Obj, raw_ostream &Out) { +bool yaml2minidump(MinidumpYAML::Object &Obj, raw_ostream &Out) { BlobAllocator File; File.allocateObject(Obj.Header); @@ -211,7 +211,7 @@ int yaml2minidump(MinidumpYAML::Object &Obj, raw_ostream &Out) { StreamDirectory[Stream.index()] = layout(File, *Stream.value()); File.writeTo(Out); - return 0; + return true; } } // namespace yaml diff --git a/llvm/lib/ObjectYAML/WasmEmitter.cpp b/llvm/lib/ObjectYAML/WasmEmitter.cpp index 5769d7b..28d469c 100644 --- a/llvm/lib/ObjectYAML/WasmEmitter.cpp +++ b/llvm/lib/ObjectYAML/WasmEmitter.cpp @@ -26,7 +26,7 @@ namespace { class WasmWriter { public: WasmWriter(WasmYAML::Object &Obj) : Obj(Obj) {} - int writeWasm(raw_ostream &OS); + bool writeWasm(raw_ostream &OS); private: int writeRelocSection(raw_ostream &OS, WasmYAML::Section &Sec, @@ -563,7 +563,7 @@ int WasmWriter::writeRelocSection(raw_ostream &OS, WasmYAML::Section &Sec, return 0; } -int WasmWriter::writeWasm(raw_ostream &OS) { +bool WasmWriter::writeWasm(raw_ostream &OS) { // Write headers OS.write(wasm::WasmMagic, sizeof(wasm::WasmMagic)); writeUint32(OS, Obj.Header.Version); @@ -576,7 +576,7 @@ int WasmWriter::writeWasm(raw_ostream &OS) { SecName = S->Name; if (!Checker.isValidSectionOrder(Sec->Type, SecName)) { errs() << "Out of order section type: " << Sec->Type << "\n"; - return 1; + return false; } encodeULEB128(Sec->Type, OS); std::string OutString; @@ -625,7 +625,7 @@ int WasmWriter::writeWasm(raw_ostream &OS) { return Err; } else { errs() << "Unknown section type: " << Sec->Type << "\n"; - return 1; + return false; } StringStream.flush(); @@ -652,15 +652,14 @@ int WasmWriter::writeWasm(raw_ostream &OS) { OS << OutString; } - return 0; + return true; } namespace llvm { namespace yaml { -int yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out) { +bool yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out) { WasmWriter Writer(Doc); - return Writer.writeWasm(Out); } diff --git a/llvm/lib/ObjectYAML/yaml2obj.cpp b/llvm/lib/ObjectYAML/yaml2obj.cpp index f9bcba6..8ca490b 100644 --- a/llvm/lib/ObjectYAML/yaml2obj.cpp +++ b/llvm/lib/ObjectYAML/yaml2obj.cpp @@ -17,9 +17,8 @@ namespace llvm { namespace yaml { Error convertYAML(yaml::Input &YIn, raw_ostream &Out, unsigned DocNum) { - // TODO: make yaml2* functions return Error instead of int. - auto IntToErr = [](int Ret) -> Error { - if (Ret) + auto BoolToErr = [](bool Ret) -> Error { + if (!Ret) return createStringError(errc::invalid_argument, "yaml2obj failed"); return Error::success(); }; @@ -32,15 +31,15 @@ Error convertYAML(yaml::Input &YIn, raw_ostream &Out, unsigned DocNum) { if (std::error_code EC = YIn.error()) return createStringError(EC, "Failed to parse YAML input!"); if (Doc.Elf) - return IntToErr(yaml2elf(*Doc.Elf, Out)); + return BoolToErr(yaml2elf(*Doc.Elf, Out)); if (Doc.Coff) - return IntToErr(yaml2coff(*Doc.Coff, Out)); + return BoolToErr(yaml2coff(*Doc.Coff, Out)); if (Doc.MachO || Doc.FatMachO) - return IntToErr(yaml2macho(Doc, Out)); + return BoolToErr(yaml2macho(Doc, Out)); if (Doc.Minidump) - return IntToErr(yaml2minidump(*Doc.Minidump, Out)); + return BoolToErr(yaml2minidump(*Doc.Minidump, Out)); if (Doc.Wasm) - return IntToErr(yaml2wasm(*Doc.Wasm, Out)); + return BoolToErr(yaml2wasm(*Doc.Wasm, Out)); return createStringError(errc::invalid_argument, "Unknown document type!"); } -- 2.7.4