[llvm] r371828 - [lib/ObjectYAML] - Change interface to return `bool` instead of `int`. NFCI

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 02:12:38 PDT 2019


Author: grimar
Date: Fri Sep 13 02:12:38 2019
New Revision: 371828

URL: http://llvm.org/viewvc/llvm-project?rev=371828&view=rev
Log:
[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

Modified:
    llvm/trunk/include/llvm/ObjectYAML/yaml2obj.h
    llvm/trunk/lib/ObjectYAML/COFFEmitter.cpp
    llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
    llvm/trunk/lib/ObjectYAML/MachOEmitter.cpp
    llvm/trunk/lib/ObjectYAML/MinidumpEmitter.cpp
    llvm/trunk/lib/ObjectYAML/WasmEmitter.cpp
    llvm/trunk/lib/ObjectYAML/yaml2obj.cpp

Modified: llvm/trunk/include/llvm/ObjectYAML/yaml2obj.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/yaml2obj.h?rev=371828&r1=371827&r2=371828&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/yaml2obj.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/yaml2obj.h Fri Sep 13 02:12:38 2019
@@ -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);
 

Modified: llvm/trunk/lib/ObjectYAML/COFFEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/COFFEmitter.cpp?rev=371828&r1=371827&r2=371828&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/COFFEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/COFFEmitter.cpp Fri Sep 13 02:12:38 2019
@@ -592,27 +592,27 @@ static bool writeCOFF(COFFParser &CP, ra
 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

Modified: llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp?rev=371828&r1=371827&r2=371828&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp Fri Sep 13 02:12:38 2019
@@ -168,7 +168,7 @@ template <class ELFT> 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 <class ELFT> void ELFState<ELFT
 }
 
 template <class ELFT>
-int ELFState<ELFT>::writeELF(raw_ostream &OS, ELFYAML::Object &Doc) {
+bool ELFState<ELFT>::writeELF(raw_ostream &OS, ELFYAML::Object &Doc) {
   ELFState<ELFT> State(Doc);
 
   // Finalize .strtab and .dynstr sections. We do that early because want to
@@ -1010,19 +1010,19 @@ int ELFState<ELFT>::writeELF(raw_ostream
   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) {

Modified: llvm/trunk/lib/ObjectYAML/MachOEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/MachOEmitter.cpp?rev=371828&r1=371827&r2=371828&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/MachOEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/MachOEmitter.cpp Fri Sep 13 02:12:38 2019
@@ -596,13 +596,13 @@ void UniversalWriter::ZeroToOffset(raw_o
 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

Modified: llvm/trunk/lib/ObjectYAML/MinidumpEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/MinidumpEmitter.cpp?rev=371828&r1=371827&r2=371828&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/MinidumpEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/MinidumpEmitter.cpp Fri Sep 13 02:12:38 2019
@@ -198,7 +198,7 @@ static Directory layout(BlobAllocator &F
 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 &
     StreamDirectory[Stream.index()] = layout(File, *Stream.value());
 
   File.writeTo(Out);
-  return 0;
+  return true;
 }
 
 } // namespace yaml

Modified: llvm/trunk/lib/ObjectYAML/WasmEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/WasmEmitter.cpp?rev=371828&r1=371827&r2=371828&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/WasmEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/WasmEmitter.cpp Fri Sep 13 02:12:38 2019
@@ -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_os
   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 &O
       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 &O
         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 &O
     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);
 }
 

Modified: llvm/trunk/lib/ObjectYAML/yaml2obj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/yaml2obj.cpp?rev=371828&r1=371827&r2=371828&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/yaml2obj.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/yaml2obj.cpp Fri Sep 13 02:12:38 2019
@@ -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_
       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!");
     }




More information about the llvm-commits mailing list