Chromium Code Reviews

Side by Side Diff: tools/pnacl-abicheck/pnacl-abicheck.cpp

Issue 770853002: Fix error reporting in the PNaCl bitcode reader. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix typo. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « tools/llvm-nm/llvm-nm.cpp ('k') | tools/pnacl-benchmark/pnacl-benchmark.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===-- pnacl-abicheck.cpp - Check PNaCl bitcode ABI ----------------===// 1 //===-- pnacl-abicheck.cpp - Check PNaCl bitcode ABI ----------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This tool checks files for compliance with the PNaCl bitcode ABI 10 // This tool checks files for compliance with the PNaCl bitcode ABI
(...skipping 11 matching lines...)
22 #include "llvm/Support/FormattedStream.h" 22 #include "llvm/Support/FormattedStream.h"
23 #include "llvm/Support/SourceMgr.h" 23 #include "llvm/Support/SourceMgr.h"
24 #include <string> 24 #include <string>
25 25
26 using namespace llvm; 26 using namespace llvm;
27 27
28 static cl::opt<std::string> 28 static cl::opt<std::string>
29 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); 29 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
30 30
31 static cl::opt<bool> 31 static cl::opt<bool>
32 VerboseErrors(
33 "verbose-parse-errors",
34 cl::desc("Print out more descriptive PNaCl bitcode parse errors"),
35 cl::init(false));
36
37 static cl::opt<bool>
32 Quiet("q", cl::desc("Do not print error messages")); 38 Quiet("q", cl::desc("Do not print error messages"));
33 39
34 static cl::opt<NaClFileFormat> 40 static cl::opt<NaClFileFormat>
35 InputFileFormat( 41 InputFileFormat(
36 "bitcode-format", 42 "bitcode-format",
37 cl::desc("Define format of input file:"), 43 cl::desc("Define format of input file:"),
38 cl::values( 44 cl::values(
39 clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"), 45 clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
40 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"), 46 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"),
41 clEnumValEnd), 47 clEnumValEnd),
(...skipping 12 matching lines...)
54 } 60 }
55 Reporter.reset(); 61 Reporter.reset();
56 return HasErrors; 62 return HasErrors;
57 } 63 }
58 64
59 int main(int argc, char **argv) { 65 int main(int argc, char **argv) {
60 LLVMContext &Context = getGlobalContext(); 66 LLVMContext &Context = getGlobalContext();
61 SMDiagnostic Err; 67 SMDiagnostic Err;
62 cl::ParseCommandLineOptions(argc, argv, "PNaCl Bitcode ABI checker\n"); 68 cl::ParseCommandLineOptions(argc, argv, "PNaCl Bitcode ABI checker\n");
63 69
70 if (Quiet)
71 VerboseErrors = false;
72
73 raw_ostream *Verbose = VerboseErrors ? &errs() : nullptr;
64 std::unique_ptr<Module> Mod( 74 std::unique_ptr<Module> Mod(
65 NaClParseIRFile(InputFilename, InputFileFormat, Err, Context)); 75 NaClParseIRFile(InputFilename, InputFileFormat, Err, Verbose, Context));
66 if (Mod.get() == 0) { 76 if (Mod.get() == 0) {
67 Err.print(argv[0], errs()); 77 Err.print(argv[0], errs());
68 return 1; 78 return 1;
69 } 79 }
70 PNaClABIErrorReporter ABIErrorReporter; 80 PNaClABIErrorReporter ABIErrorReporter;
71 ABIErrorReporter.setNonFatal(); 81 ABIErrorReporter.setNonFatal();
72 bool ErrorsFound = false; 82 bool ErrorsFound = false;
73 83
74 std::unique_ptr<ModulePass> ModuleChecker( 84 std::unique_ptr<ModulePass> ModuleChecker(
75 createPNaClABIVerifyModulePass(&ABIErrorReporter)); 85 createPNaClABIVerifyModulePass(&ABIErrorReporter));
76 ModuleChecker->doInitialization(*Mod); 86 ModuleChecker->doInitialization(*Mod);
77 ModuleChecker->runOnModule(*Mod); 87 ModuleChecker->runOnModule(*Mod);
78 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, "Module"); 88 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, "Module");
79 89
80 std::unique_ptr<FunctionPassManager> PM(new FunctionPassManager(&*Mod)); 90 std::unique_ptr<FunctionPassManager> PM(new FunctionPassManager(&*Mod));
81 PM->add(new DataLayoutPass(&*Mod)); 91 PM->add(new DataLayoutPass(&*Mod));
82 PM->add(createPNaClABIVerifyFunctionsPass(&ABIErrorReporter)); 92 PM->add(createPNaClABIVerifyFunctionsPass(&ABIErrorReporter));
83 93
84 PM->doInitialization(); 94 PM->doInitialization();
85 for (Module::iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { 95 for (Module::iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
86 PM->run(*I); 96 PM->run(*I);
87 ErrorsFound |= 97 ErrorsFound |=
88 CheckABIVerifyErrors(ABIErrorReporter, "Function " + I->getName()); 98 CheckABIVerifyErrors(ABIErrorReporter, "Function " + I->getName());
89 } 99 }
90 PM->doFinalization(); 100 PM->doFinalization();
91 101
92 return ErrorsFound ? 1 : 0; 102 return ErrorsFound ? 1 : 0;
93 } 103 }
OLDNEW
« no previous file with comments | « tools/llvm-nm/llvm-nm.cpp ('k') | tools/pnacl-benchmark/pnacl-benchmark.cpp » ('j') | no next file with comments »

Powered by Google App Engine