diff options
author | Derek Schuff <dschuff@chromium.org> | 2013-03-27 16:59:55 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2013-03-27 16:59:55 -0700 |
commit | aa101e39d60f96e435fbc619558d541c93431ef6 (patch) | |
tree | 1917af4a9a82dec293a65e8fbcec01d0ca591a42 | |
parent | 66afec2f1d3ebc1909f4acfea836cc4e0332dbce (diff) |
Make pnacl-abicheck return nonzero status if errors are found.
Also add -q flag for quiet operation; i.e. don't print the
errors, only use the exit status to indicate failure.
R=mseaborn@chromium.org,jvoung@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=2309
Review URL: https://codereview.chromium.org/13117004
-rw-r--r-- | tools/pnacl-abicheck/pnacl-abicheck.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/tools/pnacl-abicheck/pnacl-abicheck.cpp b/tools/pnacl-abicheck/pnacl-abicheck.cpp index 496a73c2fd..2fefd46c8b 100644 --- a/tools/pnacl-abicheck/pnacl-abicheck.cpp +++ b/tools/pnacl-abicheck/pnacl-abicheck.cpp @@ -26,13 +26,22 @@ using namespace llvm; static cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); -static void CheckABIVerifyErrors(PNaClABIErrorReporter &Reporter, +static cl::opt<bool, false> +Quiet("q", cl::desc("Do not print error messages")); + +// Print any errors collected by the error reporter. Return true if +// there were any. +static bool CheckABIVerifyErrors(PNaClABIErrorReporter &Reporter, const Twine &Name) { - if (Reporter.getErrorCount() > 0) { - outs() << "ERROR: " << Name << " is not valid PNaCl bitcode:\n"; - Reporter.printErrors(outs()); + bool HasErrors = Reporter.getErrorCount() > 0; + if (HasErrors) { + if (!Quiet) { + outs() << "ERROR: " << Name << " is not valid PNaCl bitcode:\n"; + Reporter.printErrors(outs()); + } } Reporter.reset(); + return HasErrors; } int main(int argc, char **argv) { @@ -46,17 +55,19 @@ int main(int argc, char **argv) { return 1; } PNaClABIErrorReporter ABIErrorReporter; + bool ErrorsFound = false; // Manually run the passes so we can tell the user which function had the // error. No need for a pass manager since it's just one pass. OwningPtr<ModulePass> ModuleChecker(createPNaClABIVerifyModulePass(&ABIErrorReporter)); ModuleChecker->runOnModule(*Mod); - CheckABIVerifyErrors(ABIErrorReporter, "Module"); + ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, "Module"); OwningPtr<FunctionPass> FunctionChecker( createPNaClABIVerifyFunctionsPass(&ABIErrorReporter)); for (Module::iterator MI = Mod->begin(), ME = Mod->end(); MI != ME; ++MI) { FunctionChecker->runOnFunction(*MI); - CheckABIVerifyErrors(ABIErrorReporter, "Function " + MI->getName()); + ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, + "Function " + MI->getName()); } - return 0; + return ErrorsFound; } |