mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-26 13:10:34 +00:00
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
This commit is contained in:
parent
aa551ae10e
commit
faf32c102d
@ -12,6 +12,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "AsmLexer.h"
|
#include "AsmLexer.h"
|
||||||
|
#include "llvm/ADT/StringSet.h"
|
||||||
#include "llvm/Support/SourceMgr.h"
|
#include "llvm/Support/SourceMgr.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Config/config.h" // for strtoull.
|
#include "llvm/Config/config.h" // for strtoull.
|
||||||
@ -20,11 +21,21 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
static StringSet<> &getSS(void *TheSS) {
|
||||||
|
return *(StringSet<>*)TheSS;
|
||||||
|
}
|
||||||
|
|
||||||
AsmLexer::AsmLexer(SourceMgr &SM) : SrcMgr(SM) {
|
AsmLexer::AsmLexer(SourceMgr &SM) : SrcMgr(SM) {
|
||||||
CurBuffer = 0;
|
CurBuffer = 0;
|
||||||
CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
|
CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
|
||||||
CurPtr = CurBuf->getBufferStart();
|
CurPtr = CurBuf->getBufferStart();
|
||||||
TokStart = 0;
|
TokStart = 0;
|
||||||
|
|
||||||
|
TheStringSet = new StringSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
AsmLexer::~AsmLexer() {
|
||||||
|
delete &getSS(TheStringSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
SMLoc AsmLexer::getLoc() const {
|
SMLoc AsmLexer::getLoc() const {
|
||||||
@ -75,7 +86,9 @@ asmtok::TokKind AsmLexer::LexIdentifier() {
|
|||||||
while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' ||
|
while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' ||
|
||||||
*CurPtr == '.' || *CurPtr == '@')
|
*CurPtr == '.' || *CurPtr == '@')
|
||||||
++CurPtr;
|
++CurPtr;
|
||||||
CurStrVal.assign(TokStart, CurPtr);
|
// Unique string.
|
||||||
|
CurStrVal =
|
||||||
|
getSS(TheStringSet).GetOrCreateValue(TokStart, CurPtr, 0).getKeyData();
|
||||||
return asmtok::Identifier;
|
return asmtok::Identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +99,10 @@ asmtok::TokKind AsmLexer::LexPercent() {
|
|||||||
|
|
||||||
while (isalnum(*CurPtr))
|
while (isalnum(*CurPtr))
|
||||||
++CurPtr;
|
++CurPtr;
|
||||||
CurStrVal.assign(TokStart, CurPtr); // Include %
|
|
||||||
|
// Unique string.
|
||||||
|
CurStrVal =
|
||||||
|
getSS(TheStringSet).GetOrCreateValue(TokStart, CurPtr, 0).getKeyData();
|
||||||
return asmtok::Register;
|
return asmtok::Register;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +224,9 @@ asmtok::TokKind AsmLexer::LexQuote() {
|
|||||||
CurChar = getNextChar();
|
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;
|
return asmtok::String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,20 +55,24 @@ class AsmLexer {
|
|||||||
|
|
||||||
const char *CurPtr;
|
const char *CurPtr;
|
||||||
const MemoryBuffer *CurBuf;
|
const MemoryBuffer *CurBuf;
|
||||||
|
// A llvm::StringSet<>, which provides uniqued and null-terminated strings.
|
||||||
|
void *TheStringSet;
|
||||||
|
|
||||||
// Information about the current token.
|
// Information about the current token.
|
||||||
const char *TokStart;
|
const char *TokStart;
|
||||||
asmtok::TokKind CurKind;
|
asmtok::TokKind CurKind;
|
||||||
std::string CurStrVal; // This is valid for Identifier.
|
const char *CurStrVal; // This is valid for Identifier.
|
||||||
int64_t CurIntVal;
|
int64_t CurIntVal;
|
||||||
|
|
||||||
/// CurBuffer - This is the current buffer index we're lexing from as managed
|
/// CurBuffer - This is the current buffer index we're lexing from as managed
|
||||||
/// by the SourceMgr object.
|
/// by the SourceMgr object.
|
||||||
int CurBuffer;
|
int CurBuffer;
|
||||||
|
|
||||||
|
void operator=(const AsmLexer&); // DO NOT IMPLEMENT
|
||||||
|
AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT
|
||||||
public:
|
public:
|
||||||
AsmLexer(SourceMgr &SrcMgr);
|
AsmLexer(SourceMgr &SrcMgr);
|
||||||
~AsmLexer() {}
|
~AsmLexer();
|
||||||
|
|
||||||
asmtok::TokKind Lex() {
|
asmtok::TokKind Lex() {
|
||||||
return CurKind = LexToken();
|
return CurKind = LexToken();
|
||||||
@ -78,7 +82,7 @@ public:
|
|||||||
bool is(asmtok::TokKind K) const { return CurKind == K; }
|
bool is(asmtok::TokKind K) const { return CurKind == K; }
|
||||||
bool isNot(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 ||
|
assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register ||
|
||||||
CurKind == asmtok::String) &&
|
CurKind == asmtok::String) &&
|
||||||
"This token doesn't have a string value");
|
"This token doesn't have a string value");
|
||||||
|
@ -179,7 +179,7 @@ bool AsmParser::ParseStatement() {
|
|||||||
|
|
||||||
// If we have an identifier, handle it as the key symbol.
|
// If we have an identifier, handle it as the key symbol.
|
||||||
SMLoc IDLoc = Lexer.getLoc();
|
SMLoc IDLoc = Lexer.getLoc();
|
||||||
std::string IDVal = Lexer.getCurStrVal();
|
const char *IDVal = Lexer.getCurStrVal();
|
||||||
|
|
||||||
// Consume the identifier, see what is after it.
|
// Consume the identifier, see what is after it.
|
||||||
if (Lexer.Lex() == asmtok::Colon) {
|
if (Lexer.Lex() == asmtok::Colon) {
|
||||||
|
Loading…
Reference in New Issue
Block a user