OLD | NEW |
(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/ADT/OwningPtr.h" |
| 15 #include "llvm/Analysis/NaCl.h" |
| 16 #include "llvm/IR/LLVMContext.h" |
| 17 #include "llvm/IR/Module.h" |
| 18 #include "llvm/Pass.h" |
| 19 #include "llvm/Support/CommandLine.h" |
| 20 #include "llvm/Support/FormattedStream.h" |
| 21 #include "llvm/Support/IRReader.h" |
| 22 #include <string> |
| 23 |
| 24 using namespace llvm; |
| 25 |
| 26 static cl::opt<std::string> |
| 27 InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); |
| 28 |
| 29 static void CheckABIVerifyErrors(PNaClABIErrorReporter &Reporter, |
| 30 const Twine &Name) { |
| 31 if (Reporter.getErrorCount() > 0) { |
| 32 errs() << "ERROR: " << Name << " is not valid PNaCl bitcode:\n"; |
| 33 Reporter.printErrors(errs()); |
| 34 } |
| 35 Reporter.reset(); |
| 36 } |
| 37 |
| 38 int main(int argc, char **argv) { |
| 39 LLVMContext &Context = getGlobalContext(); |
| 40 SMDiagnostic Err; |
| 41 OwningPtr<Module> Mod(ParseIRFile(InputFilename, Err, Context)); |
| 42 if (Mod.get() == 0) { |
| 43 Err.print(argv[0], errs()); |
| 44 return 1; |
| 45 } |
| 46 PNaClABIErrorReporter ABIErrorReporter; |
| 47 // Manually run the passes so we can tell the user which function had the |
| 48 // error. No need for a pass manager since it's just one pass. |
| 49 ModulePass *ModuleChecker = createPNaClABIVerifyModulePass(&ABIErrorReporter); |
| 50 ModuleChecker->runOnModule(*Mod); |
| 51 CheckABIVerifyErrors(ABIErrorReporter, "Module"); |
| 52 FunctionPass *FunctionChecker = |
| 53 createPNaClABIVerifyFunctionsPass(&ABIErrorReporter); |
| 54 for (Module::iterator MI = Mod->begin(), ME = Mod->end(); MI != ME; ++MI) { |
| 55 FunctionChecker->runOnFunction(*MI); |
| 56 CheckABIVerifyErrors(ABIErrorReporter, "Function " + MI->getName()); |
| 57 } |
| 58 |
| 59 return 0; |
| 60 } |
OLD | NEW |