[llvm-commits] [llvm] r146439 - in /llvm/trunk: include/llvm/Bitcode/ReaderWriter.h lib/Bitcode/Writer/BitcodeVerifier.cpp

Chad Rosier mcrosier at apple.com
Mon Dec 12 14:57:31 PST 2011


Author: mcrosier
Date: Mon Dec 12 16:57:31 2011
New Revision: 146439

URL: http://llvm.org/viewvc/llvm-project?rev=146439&view=rev
Log:
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.

Added:
    llvm/trunk/lib/Bitcode/Writer/BitcodeVerifier.cpp
Modified:
    llvm/trunk/include/llvm/Bitcode/ReaderWriter.h

Modified: llvm/trunk/include/llvm/Bitcode/ReaderWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/ReaderWriter.h?rev=146439&r1=146438&r2=146439&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/ReaderWriter.h (original)
+++ llvm/trunk/include/llvm/Bitcode/ReaderWriter.h Mon Dec 12 16:57:31 2011
@@ -60,8 +60,12 @@
   /// 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.
   ///

Added: llvm/trunk/lib/Bitcode/Writer/BitcodeVerifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeVerifier.cpp?rev=146439&view=auto
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeVerifier.cpp (added)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeVerifier.cpp Mon Dec 12 16:57:31 2011
@@ -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";
+}





More information about the llvm-commits mailing list