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

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

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 10 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') | tools/pnacl-bcanalyzer/CMakeLists.txt » ('j') | 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..20c80637dbfd46d92d71a482b33ede568b3dff35
--- /dev/null
+++ b/tools/pnacl-abicheck/pnacl-abicheck.cpp
@@ -0,0 +1,103 @@
+//===-- 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/Analysis/NaCl.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IRReader/IRReader.h"
+#include "llvm/Pass.h"
+#include "llvm/PassManager.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/SourceMgr.h"
+#include <string>
+
+using namespace llvm;
+
+static cl::opt<std::string>
+InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
+
+static cl::opt<bool>
+VerboseErrors(
+ "verbose-parse-errors",
+ cl::desc("Print out more descriptive PNaCl bitcode parse errors"),
+ cl::init(false));
+
+static cl::opt<bool>
+Quiet("q", cl::desc("Do not print error messages"));
+
+static cl::opt<NaClFileFormat>
+InputFileFormat(
+ "bitcode-format",
+ cl::desc("Define format of input file:"),
+ cl::values(
+ clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
+ clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"),
+ clEnumValEnd),
+ cl::init(AutodetectFileFormat));
+
+// Print any errors collected by the error reporter. Return true if
+// there were any.
+static bool CheckABIVerifyErrors(PNaClABIErrorReporter &Reporter,
+ const Twine &Name) {
+ bool HasErrors = Reporter.getErrorCount() > 0;
+ if (HasErrors) {
+ if (!Quiet) {
+ outs() << "ERROR: " << Name << " is not valid PNaCl bitcode:\n";
+ Reporter.printErrors(outs());
+ }
+ }
+ Reporter.reset();
+ return HasErrors;
+}
+
+int main(int argc, char **argv) {
+ LLVMContext &Context = getGlobalContext();
+ SMDiagnostic Err;
+ cl::ParseCommandLineOptions(argc, argv, "PNaCl Bitcode ABI checker\n");
+
+ if (Quiet)
+ VerboseErrors = false;
+
+ raw_ostream *Verbose = VerboseErrors ? &errs() : nullptr;
+ std::unique_ptr<Module> Mod(
+ NaClParseIRFile(InputFilename, InputFileFormat, Err, Verbose, Context));
+ if (Mod.get() == 0) {
+ Err.print(argv[0], errs());
+ return 1;
+ }
+ PNaClABIErrorReporter ABIErrorReporter;
+ ABIErrorReporter.setNonFatal();
+ bool ErrorsFound = false;
+
+ std::unique_ptr<ModulePass> ModuleChecker(
+ createPNaClABIVerifyModulePass(&ABIErrorReporter));
+ ModuleChecker->doInitialization(*Mod);
+ ModuleChecker->runOnModule(*Mod);
+ ErrorsFound |= CheckABIVerifyErrors(ABIErrorReporter, "Module");
+
+ std::unique_ptr<FunctionPassManager> PM(new FunctionPassManager(&*Mod));
+ PM->add(new DataLayoutPass());
+ PM->add(createPNaClABIVerifyFunctionsPass(&ABIErrorReporter));
+
+ PM->doInitialization();
+ for (Module::iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
+ PM->run(*I);
+ ErrorsFound |=
+ CheckABIVerifyErrors(ABIErrorReporter, "Function " + I->getName());
+ }
+ PM->doFinalization();
+
+ return ErrorsFound ? 1 : 0;
+}
« no previous file with comments | « tools/pnacl-abicheck/Makefile ('k') | tools/pnacl-bcanalyzer/CMakeLists.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698