Index: tools/pnacl-abicheck/pnacl-abicheck.cpp |
diff --git a/tools/pnacl-abicheck/pnacl-abicheck.cpp b/tools/pnacl-abicheck/pnacl-abicheck.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8a6ff02b276c2b5d4c7ea0ac2fa2c0b19a8d7c40 |
--- /dev/null |
+++ b/tools/pnacl-abicheck/pnacl-abicheck.cpp |
@@ -0,0 +1,61 @@ |
+//===-- pnacl-abicheck.cpp - Check PNaCl bitcode ABI ----------------===// |
+// |
+// The LLVM Compiler Infrastructure |
+// |
+// This file is distributed under the University of Illinois Open Source |
+// License. See LICENSE.TXT for details. |
+// |
+//===----------------------------------------------------------------------===// |
+// |
+// This tool checks files for compliance with the PNaCl bitcode ABI |
+// |
+//===----------------------------------------------------------------------===// |
+ |
+#include "llvm/ADT/OwningPtr.h" |
+#include "llvm/Analysis/NaCl.h" |
+#include "llvm/IR/LLVMContext.h" |
+#include "llvm/IR/Module.h" |
+#include "llvm/PassManager.h" |
+#include "llvm/Support/CommandLine.h" |
+#include "llvm/Support/FormattedStream.h" |
+#include "llvm/Support/IRReader.h" |
+#include <string> |
+ |
+using namespace llvm; |
+ |
+static cl::opt<std::string> |
+InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); |
+ |
+static void CheckABIVerifyErrors(PNaClABIErrorReporter &Reporter, |
+ const Twine &Name) { |
+ if (Reporter.getErrorCount() > 0) { |
+ errs() << "ERROR: " << Name << " is not valid PNaCl bitcode:\n"; |
+ Reporter.printErrors(errs()); |
+ } |
+ Reporter.reset(); |
+} |
+ |
+int main(int argc, char **argv) { |
+ LLVMContext &Context = getGlobalContext(); |
+ PassManager PM; |
+ SMDiagnostic Err; |
+ OwningPtr<Module> Mod(ParseIRFile(InputFilename, Err, Context)); |
+ if (Mod.get() == 0) { |
+ Err.print(argv[0], errs()); |
+ return 1; |
+ } |
+ PNaClABIErrorReporter ABIErrorReporter; |
+ // Manually run the passes so we can tell the user which function had the |
+ // error. No need for a pass manager since it's just one pass. |
+ ModulePass *ModuleChecker = createPNaClABIVerifyModulePass(&ABIErrorReporter); |
+ ModuleChecker->runOnModule(*Mod); |
+ CheckABIVerifyErrors(ABIErrorReporter, "Module"); |
+ FunctionPass *FunctionChecker = |
+ createPNaClABIVerifyFunctionsPass(&ABIErrorReporter); |
+ for (Module::iterator MI = Mod->begin(), ME = Mod->end(); MI != ME; ++MI) { |
+ FunctionChecker->runOnFunction(*MI); |
+ CheckABIVerifyErrors(ABIErrorReporter, "Function " + MI->getName()); |
+ } |
+ |
+ return 0; |
+} |