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

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

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 9 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/pnacl-abicheck/Makefile ('k') | tools/pnacl-bcanalyzer/CMakeLists.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===-- pnacl-abicheck.cpp - Check PNaCl bitcode ABI ----------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This tool checks files for compliance with the PNaCl bitcode ABI
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Analysis/NaCl.h"
15 #include "llvm/IR/DataLayout.h"
16 #include "llvm/IR/LLVMContext.h"
17 #include "llvm/IR/Module.h"
18 #include "llvm/IRReader/IRReader.h"
19 #include "llvm/Pass.h"
20 #include "llvm/PassManager.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/FormattedStream.h"
23 #include "llvm/Support/SourceMgr.h"
24 #include <string>
25
26 using namespace llvm;
27
28 static cl::opt<std::string>
29 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
30
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>
38 Quiet("q", cl::desc("Do not print error messages"));
39
40 static cl::opt<NaClFileFormat>
41 InputFileFormat(
42 "bitcode-format",
43 cl::desc("Define format of input file:"),
44 cl::values(
45 clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
46 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"),
47 clEnumValEnd),
48 cl::init(AutodetectFileFormat));
49
50 // Print any errors collected by the error reporter. Return true if
51 // there were any.
52 static bool CheckABIVerifyErrors(PNaClABIErrorReporter &Reporter,
53 const Twine &Name) {
54 bool HasErrors = Reporter.getErrorCount() > 0;
55 if (HasErrors) {
56 if (!Quiet) {
57 outs() << "ERROR: " << Name << " is not valid PNaCl bitcode:\n";
58 Reporter.printErrors(outs());
59 }
60 }
61 Reporter.reset();
62 return HasErrors;
63 }
64
65 int main(int argc, char **argv) {
66 LLVMContext &Context = getGlobalContext();
67 SMDiagnostic Err;
68 cl::ParseCommandLineOptions(argc, argv, "PNaCl Bitcode ABI checker\n");
69
70 if (Quiet)
71 VerboseErrors = false;
72
73 raw_ostream *Verbose = VerboseErrors ? &errs() : nullptr;
74 std::unique_ptr<Module> Mod(
75 NaClParseIRFile(InputFilename, InputFileFormat, Err, Verbose, Context));
76 if (Mod.get() == 0) {
77 Err.print(argv[0], errs());
78 return 1;
79 }
80 PNaClABIErrorReporter ABIErrorReporter;
81 ABIErrorReporter.setNonFatal();
82 bool ErrorsFound = false;
83
84 std::unique_ptr<ModulePass> ModuleChecker(
85 createPNaClABIVerifyModulePass(&ABIErrorReporter));
86 ModuleChecker->doInitialization(*Mod);
87 ModuleChecker->runOnModule(*Mod);
88 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, "Module");
89
90 std::unique_ptr<FunctionPassManager> PM(new FunctionPassManager(&*Mod));
91 PM->add(new DataLayoutPass());
92 PM->add(createPNaClABIVerifyFunctionsPass(&ABIErrorReporter));
93
94 PM->doInitialization();
95 for (Module::iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
96 PM->run(*I);
97 ErrorsFound |=
98 CheckABIVerifyErrors(ABIErrorReporter, "Function " + I->getName());
99 }
100 PM->doFinalization();
101
102 return ErrorsFound ? 1 : 0;
103 }
OLDNEW
« no previous file with comments | « tools/pnacl-abicheck/Makefile ('k') | tools/pnacl-bcanalyzer/CMakeLists.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698