| 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/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 Loading... |
| 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 } |
| OLD | NEW |