[cfe-commits] r62671 - /cfe/trunk/lib/Lex/PTHLexer.cpp

Chris Lattner sabre at nondot.org
Tue Jan 20 23:21:56 PST 2009


Author: lattner
Date: Wed Jan 21 01:21:56 2009
New Revision: 62671

URL: http://llvm.org/viewvc/llvm-project?rev=62671&view=rev
Log:
revert my previous patch, it assumed endianness.

Modified:
    cfe/trunk/lib/Lex/PTHLexer.cpp

Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=62671&r1=62670&r2=62671&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Wed Jan 21 01:21:56 2009
@@ -50,6 +50,38 @@
   return V;
 }
 
+static inline uint32_t Read24(const unsigned char *&Data) {
+// Targets that directly support unaligned little-endian 16-bit loads can just
+// use them.
+#if defined(__i386__) || defined(__x86_64__)
+  uint32_t V = ((uint16_t*)Data)[0] | 
+                 ((uint32_t)Data[2] << 16);
+#else
+  uint32_t V = ((uint32_t)Data[0] <<  0) |
+               ((uint32_t)Data[1] <<  8) |
+               ((uint32_t)Data[2] << 16);
+#endif
+  
+  Data += 3;
+  return V;
+}
+
+static inline uint32_t Read24(const unsigned char *&Data) {
+// Targets that directly support unaligned little-endian 16-bit loads can just
+// use them.
+#if defined(__i386__) || defined(__x86_64__)
+  uint32_t V = ((uint16_t*)Data)[0] | 
+                 ((uint32_t)Data[2] << 16);
+#else
+  uint32_t V = ((uint32_t)Data[0] <<  0) |
+               ((uint32_t)Data[1] <<  8) |
+               ((uint32_t)Data[2] << 16);
+#endif
+  
+  Data += 3;
+  return V;
+}
+
 static inline uint32_t Read32(const unsigned char *&Data) {
 // Targets that directly support unaligned little-endian 32-bit loads can just
 // use them.
@@ -88,18 +120,18 @@
   //===--------------------------------------==//
   
   // Shadow CurPtr into an automatic variable.
-  const unsigned *CurPtrShadow = (const unsigned *)CurPtr;  
+  const unsigned char *CurPtrShadow = CurPtr;  
 
   // Read in the data for the token.
-  unsigned Word0 = CurPtrShadow[0];
-  unsigned IdentifierID = CurPtrShadow[1];
-  unsigned FileOffset = CurPtrShadow[2];
+  unsigned Word0 = Read32(CurPtrShadow);
+  uint32_t IdentifierID = Read32(CurPtrShadow);
+  uint32_t FileOffset = Read32(CurPtrShadow);
   
   tok::TokenKind TKind = (tok::TokenKind) (Word0 & 0xFF);
   Token::TokenFlags TFlags = (Token::TokenFlags) ((Word0 >> 8) & 0xFF);
-  unsigned Len = Word0 >> 16;
+  uint32_t Len = Word0 >> 16;
 
-  CurPtr = (const unsigned char*)(CurPtrShadow+3);
+  CurPtr = CurPtrShadow;
   
   //===--------------------------------------==//
   // Construct the token itself.





More information about the cfe-commits mailing list