[llvm-commits] CVS: llvm/lib/Bitcode/Reader/BitcodeReader.cpp BitcodeReader.h

Chris Lattner sabre at nondot.org
Thu May 3 20:30:34 PDT 2007



Changes in directory llvm/lib/Bitcode/Reader:

BitcodeReader.cpp updated: 1.32 -> 1.33
BitcodeReader.h updated: 1.16 -> 1.17
---
Log message:

add support for reading the param attrs block


---
Diffs of the changes:  (+82 -0)

 BitcodeReader.cpp |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 BitcodeReader.h   |   13 ++++++++++
 2 files changed, 82 insertions(+)


Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.32 llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.33
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp:1.32	Thu May  3 22:02:54 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp	Thu May  3 22:30:17 2007
@@ -17,6 +17,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
+#include "llvm/ParameterAttributes.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -26,6 +27,9 @@
   delete Buffer;
 }
 
+//===----------------------------------------------------------------------===//
+//  Helper functions to implement forward reference resolution, etc.
+//===----------------------------------------------------------------------===//
 
 /// ConvertToString - Convert a string from a record into an std::string, return
 /// true on failure.
@@ -173,6 +177,67 @@
   return TypeList.back().get();
 }
 
+//===----------------------------------------------------------------------===//
+//  Functions for parsing blocks from the bitcode file
+//===----------------------------------------------------------------------===//
+
+bool BitcodeReader::ParseParamAttrBlock() {
+  if (Stream.EnterSubBlock())
+    return Error("Malformed block record");
+  
+  if (!ParamAttrs.empty())
+    return Error("Multiple PARAMATTR blocks found!");
+  
+  SmallVector<uint64_t, 64> Record;
+  
+  ParamAttrsVector Attrs;
+  
+  // Read all the records.
+  while (1) {
+    unsigned Code = Stream.ReadCode();
+    if (Code == bitc::END_BLOCK) {
+      if (Stream.ReadBlockEnd())
+        return Error("Error at end of PARAMATTR block");
+      return false;
+    }
+    
+    if (Code == bitc::ENTER_SUBBLOCK) {
+      // No known subblocks, always skip them.
+      Stream.ReadSubBlockID();
+      if (Stream.SkipBlock())
+        return Error("Malformed block record");
+      continue;
+    }
+    
+    if (Code == bitc::DEFINE_ABBREV) {
+      Stream.ReadAbbrevRecord();
+      continue;
+    }
+    
+    // Read a record.
+    Record.clear();
+    switch (Stream.ReadRecord(Code, Record)) {
+    default:  // Default behavior: ignore.
+      break;
+    case bitc::PARAMATTR_CODE_ENTRY: { // ENTRY: [paramidx0, attr0, ...]
+      if (Record.size() & 1)
+        return Error("Invalid ENTRY record");
+
+      ParamAttrsWithIndex PAWI;
+      for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
+        PAWI.index = Record[i];
+        PAWI.attrs = Record[i+1];
+        Attrs.push_back(PAWI);
+      }
+      ParamAttrs.push_back(ParamAttrsList::get(Attrs));
+      Attrs.clear();
+      break;
+    }
+    }    
+  }
+}
+
+
 bool BitcodeReader::ParseTypeTable() {
   if (Stream.EnterSubBlock())
     return Error("Malformed block record");
@@ -742,6 +807,10 @@
         if (Stream.SkipBlock())
           return Error("Malformed block record");
         break;
+      case bitc::PARAMATTR_BLOCK_ID:
+        if (ParseParamAttrBlock())
+          return true;
+        break;
       case bitc::TYPE_BLOCK_ID:
         if (ParseTypeTable())
           return true;


Index: llvm/lib/Bitcode/Reader/BitcodeReader.h
diff -u llvm/lib/Bitcode/Reader/BitcodeReader.h:1.16 llvm/lib/Bitcode/Reader/BitcodeReader.h:1.17
--- llvm/lib/Bitcode/Reader/BitcodeReader.h:1.16	Wed May  2 00:46:45 2007
+++ llvm/lib/Bitcode/Reader/BitcodeReader.h	Thu May  3 22:30:17 2007
@@ -24,6 +24,7 @@
 
 namespace llvm {
   class MemoryBuffer;
+  class ParamAttrsList;
   
 class BitcodeReaderValueList : public User {
   std::vector<Use> Uses;
@@ -85,6 +86,11 @@
   std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits;
   std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits;
   
+  /// ParamAttrs - The set of parameter attributes by index.  Index zero in the
+  /// file is for null, and is thus not represented here.  As such all indices
+  /// are off by one.
+  std::vector<const ParamAttrsList*> ParamAttrs;
+  
   /// FunctionBBs - While parsing a function body, this is a list of the basic
   /// blocks for the function.
   std::vector<BasicBlock*> FunctionBBs;
@@ -136,8 +142,15 @@
     if (ID >= FunctionBBs.size()) return 0; // Invalid ID
     return FunctionBBs[ID];
   }
+  const ParamAttrsList *getParamAttrs(unsigned i) const {
+    if (i-1 < ParamAttrs.size())
+      return ParamAttrs[i-1];
+    return 0;
+  }
+
   
   bool ParseModule(const std::string &ModuleID);
+  bool ParseParamAttrBlock();
   bool ParseTypeTable();
   bool ParseTypeSymbolTable();
   bool ParseValueSymbolTable();






More information about the llvm-commits mailing list