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..2bee788872778a35a1a7dda08a69b69c54ee5575 |
--- /dev/null |
+++ b/tools/pnacl-abicheck/pnacl-abicheck.cpp |
@@ -0,0 +1,60 @@ |
+//===-- 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/Pass.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(); |
+ 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; |
+} |