Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Unified Diff: tools/pnacl-abicheck/pnacl-abicheck.cpp

Issue 12449014: ABI verifier: Add standalone tool pnacl-abicheck (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: add pnacl-abicheck standalone tool Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+}
« lib/Analysis/NaCl/PNaClABIVerifyModule.cpp ('K') | « tools/pnacl-abicheck/Makefile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698