aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-mc/AsmLexer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-06-24 00:33:19 +0000
committerChris Lattner <sabre@nondot.org>2009-06-24 00:33:19 +0000
commitfaf32c102db556e367af1e5bca7359160840d2d0 (patch)
tree531c390bfcb86473d300fb78717286591a1ff93c /tools/llvm-mc/AsmLexer.cpp
parentaa551ae10e0cac338a9fa1ff9e20571eae07aac2 (diff)
make the lexer unique strings it lexes instead of passing them back as
std::strings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74036 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-mc/AsmLexer.cpp')
-rw-r--r--tools/llvm-mc/AsmLexer.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/tools/llvm-mc/AsmLexer.cpp b/tools/llvm-mc/AsmLexer.cpp
index dbd3c06db7..186a058552 100644
--- a/tools/llvm-mc/AsmLexer.cpp
+++ b/tools/llvm-mc/AsmLexer.cpp
@@ -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 @@ asmtok::TokKind AsmLexer::LexIdentifier() {
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 @@ asmtok::TokKind AsmLexer::LexPercent() {
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 @@ asmtok::TokKind AsmLexer::LexQuote() {
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;
}