[llvm] r299551 - [yaml2obj] Factor out error handling code.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 5 08:18:16 PDT 2017
Author: davide
Date: Wed Apr 5 10:18:16 2017
New Revision: 299551
URL: http://llvm.org/viewvc/llvm-project?rev=299551&view=rev
Log:
[yaml2obj] Factor out error handling code.
Modified:
llvm/trunk/tools/yaml2obj/yaml2obj.cpp
Modified: llvm/trunk/tools/yaml2obj/yaml2obj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2obj.cpp?rev=299551&r1=299550&r2=299551&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2obj.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2obj.cpp Wed Apr 5 10:18:16 2017
@@ -40,17 +40,19 @@ DocNum("docnum", cl::init(1),
static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
cl::value_desc("filename"));
+LLVM_ATTRIBUTE_NORETURN static void error(Twine Message) {
+ errs() << Message << "\n";
+ exit(1);
+}
+
static int convertYAML(yaml::Input &YIn, raw_ostream &Out) {
unsigned CurDocNum = 0;
do {
if (++CurDocNum == DocNum) {
yaml::YamlObjectFile Doc;
YIn >> Doc;
- if (YIn.error()) {
- errs() << "yaml2obj: Failed to parse YAML file!\n";
- return 1;
- }
-
+ if (YIn.error())
+ error("yaml2obj: Failed to parse YAML file!");
if (Doc.Elf)
return yaml2elf(*Doc.Elf, Out);
if (Doc.Coff)
@@ -59,14 +61,12 @@ static int convertYAML(yaml::Input &YIn,
return yaml2macho(Doc, Out);
if (Doc.Wasm)
return yaml2wasm(*Doc.Wasm, Out);
- errs() << "yaml2obj: Unknown document type!\n";
- return 1;
+ error("yaml2obj: Unknown document type!");
}
} while (YIn.nextDocument());
- errs() << "yaml2obj: Cannot find the " << DocNum
- << llvm::getOrdinalSuffix(DocNum) << " document\n";
- return 1;
+ error("yaml2obj: Cannot find the " + utostr(DocNum) +
+ llvm::getOrdinalSuffix(DocNum) + " document");
}
int main(int argc, char **argv) {
@@ -81,11 +81,8 @@ int main(int argc, char **argv) {
std::error_code EC;
std::unique_ptr<tool_output_file> Out(
new tool_output_file(OutputFilename, EC, sys::fs::F_None));
- if (EC) {
- errs() << "yaml2obj: Error opening '" << OutputFilename
- << "': " + EC.message() << "\n";
- return 1;
- }
+ if (EC)
+ error("yaml2obj: Error opening '" + OutputFilename + "': " + EC.message());
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =
MemoryBuffer::getFileOrSTDIN(Input);
More information about the llvm-commits
mailing list