Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

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

Issue 1310883003: Install notion of diagnostic handler into PNaCl bitcode readers. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix issues in patch set 2. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/llvm-dis/llvm-dis.cpp ('k') | tools/pnacl-llc/pnacl-llc.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
11 // 11 //
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 #include "llvm/Analysis/NaCl.h" 14 #include "llvm/Analysis/NaCl.h"
15 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
15 #include "llvm/IR/DataLayout.h" 16 #include "llvm/IR/DataLayout.h"
16 #include "llvm/IR/LLVMContext.h" 17 #include "llvm/IR/LLVMContext.h"
17 #include "llvm/IR/Module.h" 18 #include "llvm/IR/Module.h"
18 #include "llvm/IRReader/IRReader.h" 19 #include "llvm/IRReader/IRReader.h"
19 #include "llvm/Pass.h" 20 #include "llvm/Pass.h"
20 #include "llvm/IR/LegacyPassManager.h" 21 #include "llvm/IR/LegacyPassManager.h"
21 #include "llvm/Support/CommandLine.h" 22 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/FormattedStream.h" 23 #include "llvm/Support/FormattedStream.h"
23 #include "llvm/Support/SourceMgr.h" 24 #include "llvm/Support/SourceMgr.h"
24 #include <string> 25 #include <string>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 64 }
64 65
65 int main(int argc, char **argv) { 66 int main(int argc, char **argv) {
66 LLVMContext &Context = getGlobalContext(); 67 LLVMContext &Context = getGlobalContext();
67 SMDiagnostic Err; 68 SMDiagnostic Err;
68 cl::ParseCommandLineOptions(argc, argv, "PNaCl Bitcode ABI checker\n"); 69 cl::ParseCommandLineOptions(argc, argv, "PNaCl Bitcode ABI checker\n");
69 70
70 if (Quiet) 71 if (Quiet)
71 VerboseErrors = false; 72 VerboseErrors = false;
72 73
73 raw_ostream *Verbose = VerboseErrors ? &errs() : nullptr; 74 DiagnosticHandlerFunction DiagnosticHandler =
74 std::unique_ptr<Module> Mod( 75 VerboseErrors ? redirectNaClDiagnosticToStream(errs()) : nullptr;
75 NaClParseIRFile(InputFilename, InputFileFormat, Err, Verbose, Context)); 76 std::unique_ptr<Module> Mod(NaClParseIRFile(InputFilename, InputFileFormat,
77 Err, Context, DiagnosticHandler));
76 if (Mod.get() == 0) { 78 if (Mod.get() == 0) {
77 Err.print(argv[0], errs()); 79 Err.print(argv[0], errs());
78 return 1; 80 return 1;
79 } 81 }
80 PNaClABIErrorReporter ABIErrorReporter; 82 PNaClABIErrorReporter ABIErrorReporter;
81 ABIErrorReporter.setNonFatal(); 83 ABIErrorReporter.setNonFatal();
82 bool ErrorsFound = false; 84 bool ErrorsFound = false;
83 85
84 std::unique_ptr<ModulePass> ModuleChecker( 86 std::unique_ptr<ModulePass> ModuleChecker(
85 createPNaClABIVerifyModulePass(&ABIErrorReporter)); 87 createPNaClABIVerifyModulePass(&ABIErrorReporter));
86 ModuleChecker->doInitialization(*Mod); 88 ModuleChecker->doInitialization(*Mod);
87 ModuleChecker->runOnModule(*Mod); 89 ModuleChecker->runOnModule(*Mod);
88 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, "Module"); 90 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, "Module");
89 91
90 std::unique_ptr<legacy::FunctionPassManager> PM( 92 std::unique_ptr<legacy::FunctionPassManager> PM(
91 new legacy::FunctionPassManager(&*Mod)); 93 new legacy::FunctionPassManager(&*Mod));
92 PM->add(createPNaClABIVerifyFunctionsPass(&ABIErrorReporter)); 94 PM->add(createPNaClABIVerifyFunctionsPass(&ABIErrorReporter));
93 95
94 PM->doInitialization(); 96 PM->doInitialization();
95 for (Module::iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { 97 for (Module::iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
96 PM->run(*I); 98 PM->run(*I);
97 ErrorsFound |= 99 ErrorsFound |=
98 CheckABIVerifyErrors(ABIErrorReporter, "Function " + I->getName()); 100 CheckABIVerifyErrors(ABIErrorReporter, "Function " + I->getName());
99 } 101 }
100 PM->doFinalization(); 102 PM->doFinalization();
101 103
102 return ErrorsFound ? 1 : 0; 104 return ErrorsFound ? 1 : 0;
103 } 105 }
OLDNEW
« no previous file with comments | « tools/llvm-dis/llvm-dis.cpp ('k') | tools/pnacl-llc/pnacl-llc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698