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

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: cleanup, use << for error streams uniformly 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
« no previous file with comments | « tools/pnacl-abicheck/Makefile ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+}
« no previous file with comments | « tools/pnacl-abicheck/Makefile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698