[llvm-commits] CVS: llvm/lib/Bytecode/Writer/Writer.cpp WriterInternals.h

Reid Spencer reid at x10sys.com
Tue Aug 17 00:45:24 PDT 2004



Changes in directory llvm/lib/Bytecode/Writer:

Writer.cpp updated: 1.74 -> 1.75
WriterInternals.h updated: 1.22 -> 1.23
---
Log message:

Bytecode File Format Changes:
- File format version number bumped to 4
- Writer will now align nothing
- Reader now only expects alignment for version 3 or earlier


---
Diffs of the changes:  (+17 -30)

Index: llvm/lib/Bytecode/Writer/Writer.cpp
diff -u llvm/lib/Bytecode/Writer/Writer.cpp:1.74 llvm/lib/Bytecode/Writer/Writer.cpp:1.75
--- llvm/lib/Bytecode/Writer/Writer.cpp:1.74	Mon Aug 16 21:59:02 2004
+++ llvm/lib/Bytecode/Writer/Writer.cpp	Tue Aug 17 02:45:14 2004
@@ -31,6 +31,12 @@
 #include <algorithm>
 using namespace llvm;
 
+/// This value needs to be incremented every time the bytecode format changes
+/// so that the reader can distinguish which format of the bytecode file has
+/// been written.
+/// @brief The bytecode version number
+const unsigned BCVersionNum = 4;
+
 static RegisterPass<WriteBytecodePass> X("emitbytecode", "Bytecode Writer");
 
 static Statistic<> 
@@ -65,8 +71,7 @@
 /// possible.  This is useful because many of our "infinite" values are really
 /// very small most of the time; but can be large a few times.
 /// Data format used:  If you read a byte with the high bit set, use the low 
-/// seven bits as data and then read another byte. Note that using this may 
-/// cause the output buffer to become unaligned.
+/// seven bits as data and then read another byte. 
 inline void BytecodeWriter::output_vbr(uint64_t i) {
   while (1) {
     if (i < 0x80) { // done?
@@ -119,21 +124,10 @@
     output_vbr((unsigned)i << 1);          // Low order bit is clear.
 }
 
-// align32 - emit the minimal number of bytes that will bring us to 32 bit 
-// alignment...
-//
-inline void BytecodeWriter::align32() {
-  int NumPads = (4-(Out.size() & 3)) & 3; // Bytes to get padding to 32 bits
-  while (NumPads--) Out.push_back((unsigned char)0xAB);
-}
-
-inline void BytecodeWriter::output(const std::string &s, bool Aligned ) {
+inline void BytecodeWriter::output(const std::string &s) {
   unsigned Len = s.length();
   output_vbr(Len );             // Strings may have an arbitrary length...
   Out.insert(Out.end(), s.begin(), s.end());
-
-  if (Aligned)
-    align32();                   // Make sure we are now aligned...
 }
 
 inline void BytecodeWriter::output_data(const void *Ptr, const void *End) {
@@ -200,7 +194,6 @@
     Writer.output(unsigned(Writer.size()-Loc), int(Loc-4));
   else
     Writer.output(unsigned(Writer.size()-Loc) << 5 | (Id & 0x1F), int(Loc-4));
-  Writer.align32();  // Blocks must ALWAYS be aligned
 }
 
 //===----------------------------------------------------------------------===//
@@ -470,8 +463,6 @@
       output_vbr(unsigned(Slot));
     }
   }
-
-  align32();    // We must maintain correct alignment!
 }
 
 
@@ -529,7 +520,6 @@
     assert(Slot >= 0 && "No slot number for value!?!?");      
     output_vbr((unsigned)Slot);
   }
-  align32();    // We must maintain correct alignment!
 }
 
 
@@ -757,10 +747,11 @@
 
   // Output the version identifier... we are currently on bytecode version #2,
   // which corresponds to LLVM v1.3.
-  unsigned Version = (3 << 4) | (unsigned)isBigEndian | (hasLongPointers << 1) |
-                     (hasNoEndianness << 2) | (hasNoPointerSize << 3);
+  unsigned Version = (BCVersionNum << 4) | 
+                     (unsigned)isBigEndian | (hasLongPointers << 1) |
+                     (hasNoEndianness << 2) | 
+                     (hasNoPointerSize << 3);
   output_vbr(Version);
-  align32();
 
   // The Global type plane comes first
   {
@@ -926,11 +917,11 @@
   Module::lib_iterator LE = M->lib_end();
   output_vbr( unsigned(LE - LI) ); // Put out the number of dependent libraries
   for ( ; LI != LE; ++LI ) {
-    output(*LI, /*aligned=*/false);
+    output(*LI);
   }
 
   // Output the target triple from the module
-  output(M->getTargetTriple(), /*aligned=*/ true);
+  output(M->getTargetTriple());
 }
 
 void BytecodeWriter::outputInstructions(const Function *F) {
@@ -1049,7 +1040,7 @@
        TE = MST.type_end(); TI != TE; ++TI ) {
     // Symtab entry:[def slot #][name]
     output_typeid((unsigned)Table.getSlot(TI->second));
-    output(TI->first, /*align=*/false); 
+    output(TI->first); 
   }
 
   // Now do each of the type planes in order.
@@ -1075,7 +1066,7 @@
       Slot = Table.getSlot(I->second);
       assert(Slot != -1 && "Value in symtab but has no slot number!!");
       output_vbr((unsigned)Slot);
-      output(I->first, false); // Don't force alignment...
+      output(I->first);
     }
   }
 }


Index: llvm/lib/Bytecode/Writer/WriterInternals.h
diff -u llvm/lib/Bytecode/Writer/WriterInternals.h:1.22 llvm/lib/Bytecode/Writer/WriterInternals.h:1.23
--- llvm/lib/Bytecode/Writer/WriterInternals.h:1.22	Sun Jul 25 13:07:36 2004
+++ llvm/lib/Bytecode/Writer/WriterInternals.h	Tue Aug 17 02:45:14 2004
@@ -92,11 +92,7 @@
   /// @brief Signed 32-bit variable bit rate output primitive.
   inline void output_vbr(int i);
 
-  /// Emit the minimal number of bytes that will bring us to 32 bit alignment.
-  /// @brief 32-bit alignment output primitive
-  inline void align32();
-
-  inline void output(const std::string &s, bool Aligned = true);
+  inline void output(const std::string &s );
 
   inline void output_data(const void *Ptr, const void *End);
 






More information about the llvm-commits mailing list