[llvm-commits] [llvm] r74036 - in /llvm/trunk/tools/llvm-mc: AsmLexer.cpp AsmLexer.h AsmParser.cpp

Chris Lattner sabre at nondot.org
Tue Jun 23 17:33:19 PDT 2009


Author: lattner
Date: Tue Jun 23 19:33:19 2009
New Revision: 74036

URL: http://llvm.org/viewvc/llvm-project?rev=74036&view=rev
Log:
make the lexer unique strings it lexes instead of passing them back as
std::strings.

Modified:
    llvm/trunk/tools/llvm-mc/AsmLexer.cpp
    llvm/trunk/tools/llvm-mc/AsmLexer.h
    llvm/trunk/tools/llvm-mc/AsmParser.cpp

Modified: llvm/trunk/tools/llvm-mc/AsmLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.cpp?rev=74036&r1=74035&r2=74036&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.cpp Tue Jun 23 19:33:19 2009
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "AsmLexer.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Config/config.h"  // for strtoull.
@@ -20,11 +21,21 @@
 #include <cstdlib>
 using namespace llvm;
 
+static StringSet<> &getSS(void *TheSS) {
+  return *(StringSet<>*)TheSS;
+}
+
 AsmLexer::AsmLexer(SourceMgr &SM) : SrcMgr(SM) {
   CurBuffer = 0;
   CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
   CurPtr = CurBuf->getBufferStart();
   TokStart = 0;
+  
+  TheStringSet = new StringSet<>();
+}
+
+AsmLexer::~AsmLexer() {
+  delete &getSS(TheStringSet);
 }
 
 SMLoc AsmLexer::getLoc() const {
@@ -75,7 +86,9 @@
   while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' ||
          *CurPtr == '.' || *CurPtr == '@')
     ++CurPtr;
-  CurStrVal.assign(TokStart, CurPtr);
+  // Unique string.
+  CurStrVal =
+    getSS(TheStringSet).GetOrCreateValue(TokStart, CurPtr, 0).getKeyData();
   return asmtok::Identifier;
 }
 
@@ -86,7 +99,10 @@
   
   while (isalnum(*CurPtr))
     ++CurPtr;
-  CurStrVal.assign(TokStart, CurPtr);   // Include %
+  
+  // Unique string.
+  CurStrVal =
+    getSS(TheStringSet).GetOrCreateValue(TokStart, CurPtr, 0).getKeyData();
   return asmtok::Register;
 }
 
@@ -208,7 +224,9 @@
     CurChar = getNextChar();
   }
   
-  CurStrVal.assign(TokStart, CurPtr);   // include quotes.
+  // Unique string, include quotes for now.
+  CurStrVal =
+    getSS(TheStringSet).GetOrCreateValue(TokStart, CurPtr, 0).getKeyData();
   return asmtok::String;
 }
 

Modified: llvm/trunk/tools/llvm-mc/AsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.h?rev=74036&r1=74035&r2=74036&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.h Tue Jun 23 19:33:19 2009
@@ -55,20 +55,24 @@
   
   const char *CurPtr;
   const MemoryBuffer *CurBuf;
+  // A llvm::StringSet<>, which provides uniqued and null-terminated strings.
+  void *TheStringSet;
   
   // Information about the current token.
   const char *TokStart;
   asmtok::TokKind CurKind;
-  std::string CurStrVal;  // This is valid for Identifier.
+  const char *CurStrVal;  // This is valid for Identifier.
   int64_t CurIntVal;
   
   /// CurBuffer - This is the current buffer index we're lexing from as managed
   /// by the SourceMgr object.
   int CurBuffer;
   
+  void operator=(const AsmLexer&); // DO NOT IMPLEMENT
+  AsmLexer(const AsmLexer&);       // DO NOT IMPLEMENT
 public:
   AsmLexer(SourceMgr &SrcMgr);
-  ~AsmLexer() {}
+  ~AsmLexer();
   
   asmtok::TokKind Lex() {
     return CurKind = LexToken();
@@ -78,7 +82,7 @@
   bool is(asmtok::TokKind K) const { return CurKind == K; }
   bool isNot(asmtok::TokKind K) const { return CurKind != K; }
   
-  const std::string &getCurStrVal() const {
+  const char *getCurStrVal() const {
     assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register ||
             CurKind == asmtok::String) &&
            "This token doesn't have a string value");

Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=74036&r1=74035&r2=74036&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Tue Jun 23 19:33:19 2009
@@ -179,7 +179,7 @@
   
   // If we have an identifier, handle it as the key symbol.
   SMLoc IDLoc = Lexer.getLoc();
-  std::string IDVal = Lexer.getCurStrVal();
+  const char *IDVal = Lexer.getCurStrVal();
   
   // Consume the identifier, see what is after it.
   if (Lexer.Lex() == asmtok::Colon) {





More information about the llvm-commits mailing list