OLD | NEW |
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/IR/LLVMContext.h" | 16 #include "llvm/IR/LLVMContext.h" |
17 #include "llvm/IR/Module.h" | 17 #include "llvm/IR/Module.h" |
18 #include "llvm/Pass.h" | 18 #include "llvm/Pass.h" |
19 #include "llvm/Support/CommandLine.h" | 19 #include "llvm/Support/CommandLine.h" |
20 #include "llvm/Support/FormattedStream.h" | 20 #include "llvm/Support/FormattedStream.h" |
21 #include "llvm/Support/IRReader.h" | 21 #include "llvm/Support/IRReader.h" |
22 #include <string> | 22 #include <string> |
23 | 23 |
24 using namespace llvm; | 24 using namespace llvm; |
25 | 25 |
26 static cl::opt<std::string> | 26 static cl::opt<std::string> |
27 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); | 27 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); |
28 | 28 |
29 static cl::opt<bool, false> | 29 static cl::opt<bool> |
30 Quiet("q", cl::desc("Do not print error messages")); | 30 Quiet("q", cl::desc("Do not print error messages")); |
31 | 31 |
32 // Print any errors collected by the error reporter. Return true if | 32 // Print any errors collected by the error reporter. Return true if |
33 // there were any. | 33 // there were any. |
34 static bool CheckABIVerifyErrors(PNaClABIErrorReporter &Reporter, | 34 static bool CheckABIVerifyErrors(PNaClABIErrorReporter &Reporter, |
35 const Twine &Name) { | 35 const Twine &Name) { |
36 bool HasErrors = Reporter.getErrorCount() > 0; | 36 bool HasErrors = Reporter.getErrorCount() > 0; |
37 if (HasErrors) { | 37 if (HasErrors) { |
38 if (!Quiet) { | 38 if (!Quiet) { |
39 outs() << "ERROR: " << Name << " is not valid PNaCl bitcode:\n"; | 39 outs() << "ERROR: " << Name << " is not valid PNaCl bitcode:\n"; |
(...skipping 12 matching lines...) Expand all Loading... |
52 OwningPtr<Module> Mod(ParseIRFile(InputFilename, Err, Context)); | 52 OwningPtr<Module> Mod(ParseIRFile(InputFilename, Err, Context)); |
53 if (Mod.get() == 0) { | 53 if (Mod.get() == 0) { |
54 Err.print(argv[0], errs()); | 54 Err.print(argv[0], errs()); |
55 return 1; | 55 return 1; |
56 } | 56 } |
57 PNaClABIErrorReporter ABIErrorReporter; | 57 PNaClABIErrorReporter ABIErrorReporter; |
58 ABIErrorReporter.setNonFatal(); | 58 ABIErrorReporter.setNonFatal(); |
59 bool ErrorsFound = false; | 59 bool ErrorsFound = false; |
60 // Manually run the passes so we can tell the user which function had the | 60 // 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. | 61 // error. No need for a pass manager since it's just one pass. |
62 OwningPtr<ModulePass> ModuleChecker(createPNaClABIVerifyModulePass(&ABIErrorRe
porter)); | 62 OwningPtr<ModulePass> ModuleChecker( |
| 63 createPNaClABIVerifyModulePass(&ABIErrorReporter)); |
63 ModuleChecker->runOnModule(*Mod); | 64 ModuleChecker->runOnModule(*Mod); |
64 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, "Module"); | 65 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, "Module"); |
65 OwningPtr<FunctionPass> FunctionChecker( | 66 OwningPtr<FunctionPass> FunctionChecker( |
66 createPNaClABIVerifyFunctionsPass(&ABIErrorReporter)); | 67 createPNaClABIVerifyFunctionsPass(&ABIErrorReporter)); |
67 for (Module::iterator MI = Mod->begin(), ME = Mod->end(); MI != ME; ++MI) { | 68 for (Module::iterator MI = Mod->begin(), ME = Mod->end(); MI != ME; ++MI) { |
68 FunctionChecker->runOnFunction(*MI); | 69 FunctionChecker->runOnFunction(*MI); |
69 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, | 70 ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, |
70 "Function " + MI->getName()); | 71 "Function " + MI->getName()); |
71 } | 72 } |
72 | 73 |
73 return ErrorsFound ? 1 : 0; | 74 return ErrorsFound ? 1 : 0; |
74 } | 75 } |
OLD | NEW |