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

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

Issue 18884003: Add option to pnacl-abicheck to handle pnacl bitcode (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Created 7 years, 5 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') | no next file » | 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/ADT/OwningPtr.h" 14 #include "llvm/ADT/OwningPtr.h"
15 #include "llvm/Analysis/NaCl.h" 15 #include "llvm/Analysis/NaCl.h"
16 #include "llvm/IRReader/IRReader.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/Pass.h" 19 #include "llvm/Pass.h"
19 #include "llvm/Support/CommandLine.h" 20 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/FormattedStream.h" 21 #include "llvm/Support/FormattedStream.h"
21 #include "llvm/Support/IRReader.h" 22 #include "llvm/Support/IRReader.h"
22 #include <string> 23 #include <string>
23 24
24 using namespace llvm; 25 using namespace llvm;
25 26
26 static cl::opt<std::string> 27 static cl::opt<std::string>
27 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); 28 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
28 29
29 static cl::opt<bool> 30 static cl::opt<bool>
30 Quiet("q", cl::desc("Do not print error messages")); 31 Quiet("q", cl::desc("Do not print error messages"));
31 32
33 static cl::opt<NaClFileFormat>
34 InputFileFormat(
35 "bitcode-format",
36 cl::desc("Define format of input file:"),
37 cl::values(
38 clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
39 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"),
40 clEnumValEnd),
41 cl::init(LLVMFormat));
42
32 // Print any errors collected by the error reporter. Return true if 43 // Print any errors collected by the error reporter. Return true if
33 // there were any. 44 // there were any.
34 static bool CheckABIVerifyErrors(PNaClABIErrorReporter &Reporter, 45 static bool CheckABIVerifyErrors(PNaClABIErrorReporter &Reporter,
35 const Twine &Name) { 46 const Twine &Name) {
36 bool HasErrors = Reporter.getErrorCount() > 0; 47 bool HasErrors = Reporter.getErrorCount() > 0;
37 if (HasErrors) { 48 if (HasErrors) {
38 if (!Quiet) { 49 if (!Quiet) {
39 outs() << "ERROR: " << Name << " is not valid PNaCl bitcode:\n"; 50 outs() << "ERROR: " << Name << " is not valid PNaCl bitcode:\n";
40 Reporter.printErrors(outs()); 51 Reporter.printErrors(outs());
41 } 52 }
42 } 53 }
43 Reporter.reset(); 54 Reporter.reset();
44 return HasErrors; 55 return HasErrors;
45 } 56 }
46 57
47 int main(int argc, char **argv) { 58 int main(int argc, char **argv) {
48 LLVMContext &Context = getGlobalContext(); 59 LLVMContext &Context = getGlobalContext();
49 SMDiagnostic Err; 60 SMDiagnostic Err;
50 cl::ParseCommandLineOptions(argc, argv, "PNaCl Bitcode ABI checker\n"); 61 cl::ParseCommandLineOptions(argc, argv, "PNaCl Bitcode ABI checker\n");
51 62
52 OwningPtr<Module> Mod(ParseIRFile(InputFilename, Err, Context)); 63 OwningPtr<Module> Mod(
64 NaClParseIRFile(InputFilename, InputFileFormat, Err, Context));
53 if (Mod.get() == 0) { 65 if (Mod.get() == 0) {
54 Err.print(argv[0], errs()); 66 Err.print(argv[0], errs());
55 return 1; 67 return 1;
56 } 68 }
57 PNaClABIErrorReporter ABIErrorReporter; 69 PNaClABIErrorReporter ABIErrorReporter;
58 ABIErrorReporter.setNonFatal(); 70 ABIErrorReporter.setNonFatal();
59 bool ErrorsFound = false; 71 bool ErrorsFound = false;
60 // Manually run the passes so we can tell the user which function had the 72 // Manually run the passes so we can tell the user which function had the
61 // error. No need for a pass manager since it's just one pass. 73 // error. No need for a pass manager since it's just one pass.
62 OwningPtr<ModulePass> ModuleChecker( 74 OwningPtr<ModulePass> ModuleChecker(
63 createPNaClABIVerifyModulePass(&ABIErrorReporter)); 75 createPNaClABIVerifyModulePass(&ABIErrorReporter));
64 ModuleChecker->runOnModule(*Mod); 76 ModuleChecker->runOnModule(*Mod);
65 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, "Module"); 77 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, "Module");
66 OwningPtr<FunctionPass> FunctionChecker( 78 OwningPtr<FunctionPass> FunctionChecker(
67 createPNaClABIVerifyFunctionsPass(&ABIErrorReporter)); 79 createPNaClABIVerifyFunctionsPass(&ABIErrorReporter));
68 for (Module::iterator MI = Mod->begin(), ME = Mod->end(); MI != ME; ++MI) { 80 for (Module::iterator MI = Mod->begin(), ME = Mod->end(); MI != ME; ++MI) {
69 FunctionChecker->runOnFunction(*MI); 81 FunctionChecker->runOnFunction(*MI);
70 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, 82 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter,
71 "Function " + MI->getName()); 83 "Function " + MI->getName());
72 } 84 }
73 85
74 return ErrorsFound ? 1 : 0; 86 return ErrorsFound ? 1 : 0;
75 } 87 }
OLDNEW
« no previous file with comments | « tools/pnacl-abicheck/Makefile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698