aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2011-12-12 22:57:31 +0000
committerChad Rosier <mcrosier@apple.com>2011-12-12 22:57:31 +0000
commitb3025864e5765ad4e9d0958e96c4812aeda263f4 (patch)
tree842c40ffbd213848e71fb33fe2e3ff62526544b5
parent86d34100cf164f6ba5c0c2344b7dff86cc0a0980 (diff)
downloadexternal_llvm-b3025864e5765ad4e9d0958e96c4812aeda263f4.zip
external_llvm-b3025864e5765ad4e9d0958e96c4812aeda263f4.tar.gz
external_llvm-b3025864e5765ad4e9d0958e96c4812aeda263f4.tar.bz2
Begin sketching out a bitcode verifier pass. Idea is to emit a .bc file and
then read the file back in to verify use-list serialization/deserialization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146439 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Bitcode/ReaderWriter.h8
-rw-r--r--lib/Bitcode/Writer/BitcodeVerifier.cpp54
2 files changed, 60 insertions, 2 deletions
diff --git a/include/llvm/Bitcode/ReaderWriter.h b/include/llvm/Bitcode/ReaderWriter.h
index fa754c0..4f86303 100644
--- a/include/llvm/Bitcode/ReaderWriter.h
+++ b/include/llvm/Bitcode/ReaderWriter.h
@@ -60,8 +60,12 @@ namespace llvm {
/// createBitcodeWriterPass - Create and return a pass that writes the module
/// to the specified ostream.
ModulePass *createBitcodeWriterPass(raw_ostream &Str);
-
-
+
+ /// createBitcodeVerifierPass - Create a pass that writes a module to disk and
+ /// then reads the module back in to verify bitcode serialization and
+ /// deserialization.
+ ModulePass *createBitcodeVerifierPass(raw_ostream &Str);
+
/// isBitcodeWrapper - Return true if the given bytes are the magic bytes
/// for an LLVM IR bitcode wrapper.
///
diff --git a/lib/Bitcode/Writer/BitcodeVerifier.cpp b/lib/Bitcode/Writer/BitcodeVerifier.cpp
new file mode 100644
index 0000000..9296e29
--- /dev/null
+++ b/lib/Bitcode/Writer/BitcodeVerifier.cpp
@@ -0,0 +1,54 @@
+//===--- Bitcode/Writer/BitcodeVerifier.cpp - Bitcode Writer ----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// BitcodeVerifier implementation.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Pass.h"
+#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+namespace {
+ struct VerifyBitcode : public ModulePass {
+ raw_ostream &OS; // raw_ostream to read from
+ public:
+ static char ID; // Pass identification, replacement for typeid
+ explicit VerifyBitcode(raw_ostream &o)
+ : ModulePass(ID), OS(o) {}
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ }
+
+ const char *getPassName() const { return "Bitcode Verifier"; }
+
+ bool runOnModule(Module &M) {
+ Verify(M);
+ return false;
+ }
+
+ void Verify(Module &M);
+ };
+}
+
+char VerifyBitcode::ID = 0;
+
+/// createBitcodeVerifierPass - Create a pass that writes a module to disk and
+/// then reads the module back in to verify bitcode serialization and
+/// deserialization.
+ModulePass *llvm::createBitcodeVerifierPass(raw_ostream &Str) {
+ return new VerifyBitcode(Str);
+}
+
+void VerifyBitcode::Verify(Module &M) {
+ dbgs() << "BitcodeVerifier!\n";
+}