Skip to content

Commit 7da559f

Browse files
author
George Rimar
committedSep 13, 2019
[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
1 parent 1572b68 commit 7da559f

File tree

7 files changed

+34
-36
lines changed

7 files changed

+34
-36
lines changed
 

‎llvm/include/llvm/ObjectYAML/yaml2obj.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ namespace yaml {
4444
class Input;
4545
struct YamlObjectFile;
4646

47-
int yaml2coff(COFFYAML::Object &Doc, raw_ostream &Out);
48-
int yaml2elf(ELFYAML::Object &Doc, raw_ostream &Out);
49-
int yaml2macho(YamlObjectFile &Doc, raw_ostream &Out);
50-
int yaml2minidump(MinidumpYAML::Object &Doc, raw_ostream &Out);
51-
int yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out);
47+
bool yaml2coff(COFFYAML::Object &Doc, raw_ostream &Out);
48+
bool yaml2elf(ELFYAML::Object &Doc, raw_ostream &Out);
49+
bool yaml2macho(YamlObjectFile &Doc, raw_ostream &Out);
50+
bool yaml2minidump(MinidumpYAML::Object &Doc, raw_ostream &Out);
51+
bool yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out);
5252

5353
Error convertYAML(Input &YIn, raw_ostream &Out, unsigned DocNum = 1);
5454

‎llvm/lib/ObjectYAML/COFFEmitter.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -592,27 +592,27 @@ static bool writeCOFF(COFFParser &CP, raw_ostream &OS) {
592592
namespace llvm {
593593
namespace yaml {
594594

595-
int yaml2coff(llvm::COFFYAML::Object &Doc, raw_ostream &Out) {
595+
bool yaml2coff(llvm::COFFYAML::Object &Doc, raw_ostream &Out) {
596596
COFFParser CP(Doc);
597597
if (!CP.parse()) {
598598
errs() << "yaml2obj: Failed to parse YAML file!\n";
599-
return 1;
599+
return false;
600600
}
601601

602602
if (!layoutOptionalHeader(CP)) {
603603
errs() << "yaml2obj: Failed to layout optional header for COFF file!\n";
604-
return 1;
604+
return false;
605605
}
606606

607607
if (!layoutCOFF(CP)) {
608608
errs() << "yaml2obj: Failed to layout COFF file!\n";
609-
return 1;
609+
return false;
610610
}
611611
if (!writeCOFF(CP, Out)) {
612612
errs() << "yaml2obj: Failed to write COFF file!\n";
613-
return 1;
613+
return false;
614614
}
615-
return 0;
615+
return true;
616616
}
617617

618618
} // namespace yaml

‎llvm/lib/ObjectYAML/ELFEmitter.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ template <class ELFT> class ELFState {
168168
ContiguousBlobAccumulator &CBA);
169169
ELFState(ELFYAML::Object &D);
170170
public:
171-
static int writeELF(raw_ostream &OS, ELFYAML::Object &Doc);
171+
static bool writeELF(raw_ostream &OS, ELFYAML::Object &Doc);
172172
};
173173
} // end anonymous namespace
174174

@@ -983,7 +983,7 @@ template <class ELFT> void ELFState<ELFT>::finalizeStrings() {
983983
}
984984

985985
template <class ELFT>
986-
int ELFState<ELFT>::writeELF(raw_ostream &OS, ELFYAML::Object &Doc) {
986+
bool ELFState<ELFT>::writeELF(raw_ostream &OS, ELFYAML::Object &Doc) {
987987
ELFState<ELFT> State(Doc);
988988

989989
// Finalize .strtab and .dynstr sections. We do that early because want to
@@ -1010,19 +1010,19 @@ int ELFState<ELFT>::writeELF(raw_ostream &OS, ELFYAML::Object &Doc) {
10101010
State.setProgramHeaderLayout(PHeaders, SHeaders);
10111011

10121012
if (State.HasError)
1013-
return 1;
1013+
return false;
10141014

10151015
State.writeELFHeader(CBA, OS);
10161016
writeArrayData(OS, makeArrayRef(PHeaders));
10171017
CBA.writeBlobToStream(OS);
10181018
writeArrayData(OS, makeArrayRef(SHeaders));
1019-
return 0;
1019+
return true;
10201020
}
10211021

10221022
namespace llvm {
10231023
namespace yaml {
10241024

1025-
int yaml2elf(llvm::ELFYAML::Object &Doc, raw_ostream &Out) {
1025+
bool yaml2elf(llvm::ELFYAML::Object &Doc, raw_ostream &Out) {
10261026
bool IsLE = Doc.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB);
10271027
bool Is64Bit = Doc.Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64);
10281028
if (Is64Bit) {

‎llvm/lib/ObjectYAML/MachOEmitter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -596,13 +596,13 @@ void UniversalWriter::ZeroToOffset(raw_ostream &OS, size_t Offset) {
596596
namespace llvm {
597597
namespace yaml {
598598

599-
int yaml2macho(YamlObjectFile &Doc, raw_ostream &Out) {
599+
bool yaml2macho(YamlObjectFile &Doc, raw_ostream &Out) {
600600
UniversalWriter Writer(Doc);
601601
if (auto Err = Writer.writeMachO(Out)) {
602602
errs() << toString(std::move(Err));
603-
return 1;
603+
return false;
604604
}
605-
return 0;
605+
return true;
606606
}
607607

608608
} // namespace yaml

‎llvm/lib/ObjectYAML/MinidumpEmitter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static Directory layout(BlobAllocator &File, Stream &S) {
198198
namespace llvm {
199199
namespace yaml {
200200

201-
int yaml2minidump(MinidumpYAML::Object &Obj, raw_ostream &Out) {
201+
bool yaml2minidump(MinidumpYAML::Object &Obj, raw_ostream &Out) {
202202
BlobAllocator File;
203203
File.allocateObject(Obj.Header);
204204

@@ -211,7 +211,7 @@ int yaml2minidump(MinidumpYAML::Object &Obj, raw_ostream &Out) {
211211
StreamDirectory[Stream.index()] = layout(File, *Stream.value());
212212

213213
File.writeTo(Out);
214-
return 0;
214+
return true;
215215
}
216216

217217
} // namespace yaml

‎llvm/lib/ObjectYAML/WasmEmitter.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace {
2626
class WasmWriter {
2727
public:
2828
WasmWriter(WasmYAML::Object &Obj) : Obj(Obj) {}
29-
int writeWasm(raw_ostream &OS);
29+
bool writeWasm(raw_ostream &OS);
3030

3131
private:
3232
int writeRelocSection(raw_ostream &OS, WasmYAML::Section &Sec,
@@ -563,7 +563,7 @@ int WasmWriter::writeRelocSection(raw_ostream &OS, WasmYAML::Section &Sec,
563563
return 0;
564564
}
565565

566-
int WasmWriter::writeWasm(raw_ostream &OS) {
566+
bool WasmWriter::writeWasm(raw_ostream &OS) {
567567
// Write headers
568568
OS.write(wasm::WasmMagic, sizeof(wasm::WasmMagic));
569569
writeUint32(OS, Obj.Header.Version);
@@ -576,7 +576,7 @@ int WasmWriter::writeWasm(raw_ostream &OS) {
576576
SecName = S->Name;
577577
if (!Checker.isValidSectionOrder(Sec->Type, SecName)) {
578578
errs() << "Out of order section type: " << Sec->Type << "\n";
579-
return 1;
579+
return false;
580580
}
581581
encodeULEB128(Sec->Type, OS);
582582
std::string OutString;
@@ -625,7 +625,7 @@ int WasmWriter::writeWasm(raw_ostream &OS) {
625625
return Err;
626626
} else {
627627
errs() << "Unknown section type: " << Sec->Type << "\n";
628-
return 1;
628+
return false;
629629
}
630630
StringStream.flush();
631631

@@ -652,15 +652,14 @@ int WasmWriter::writeWasm(raw_ostream &OS) {
652652
OS << OutString;
653653
}
654654

655-
return 0;
655+
return true;
656656
}
657657

658658
namespace llvm {
659659
namespace yaml {
660660

661-
int yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out) {
661+
bool yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out) {
662662
WasmWriter Writer(Doc);
663-
664663
return Writer.writeWasm(Out);
665664
}
666665

‎llvm/lib/ObjectYAML/yaml2obj.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ namespace llvm {
1717
namespace yaml {
1818

1919
Error convertYAML(yaml::Input &YIn, raw_ostream &Out, unsigned DocNum) {
20-
// TODO: make yaml2* functions return Error instead of int.
21-
auto IntToErr = [](int Ret) -> Error {
22-
if (Ret)
20+
auto BoolToErr = [](bool Ret) -> Error {
21+
if (!Ret)
2322
return createStringError(errc::invalid_argument, "yaml2obj failed");
2423
return Error::success();
2524
};
@@ -32,15 +31,15 @@ Error convertYAML(yaml::Input &YIn, raw_ostream &Out, unsigned DocNum) {
3231
if (std::error_code EC = YIn.error())
3332
return createStringError(EC, "Failed to parse YAML input!");
3433
if (Doc.Elf)
35-
return IntToErr(yaml2elf(*Doc.Elf, Out));
34+
return BoolToErr(yaml2elf(*Doc.Elf, Out));
3635
if (Doc.Coff)
37-
return IntToErr(yaml2coff(*Doc.Coff, Out));
36+
return BoolToErr(yaml2coff(*Doc.Coff, Out));
3837
if (Doc.MachO || Doc.FatMachO)
39-
return IntToErr(yaml2macho(Doc, Out));
38+
return BoolToErr(yaml2macho(Doc, Out));
4039
if (Doc.Minidump)
41-
return IntToErr(yaml2minidump(*Doc.Minidump, Out));
40+
return BoolToErr(yaml2minidump(*Doc.Minidump, Out));
4241
if (Doc.Wasm)
43-
return IntToErr(yaml2wasm(*Doc.Wasm, Out));
42+
return BoolToErr(yaml2wasm(*Doc.Wasm, Out));
4443
return createStringError(errc::invalid_argument,
4544
"Unknown document type!");
4645
}

0 commit comments

Comments
 (0)
Please sign in to comment.