This only needs a StringRef.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212401 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-07-06 14:17:29 +00:00
parent bb7ad610ef
commit 26a84a6e7c
4 changed files with 17 additions and 19 deletions

View File

@ -28,7 +28,7 @@ class AsmLexer : public MCAsmLexer {
const MCAsmInfo &MAI; const MCAsmInfo &MAI;
const char *CurPtr; const char *CurPtr;
const MemoryBuffer *CurBuf; StringRef CurBuf;
bool isAtStartOfLine; bool isAtStartOfLine;
void operator=(const AsmLexer&) LLVM_DELETED_FUNCTION; void operator=(const AsmLexer&) LLVM_DELETED_FUNCTION;
@ -42,7 +42,7 @@ public:
AsmLexer(const MCAsmInfo &MAI); AsmLexer(const MCAsmInfo &MAI);
~AsmLexer(); ~AsmLexer();
void setBuffer(const MemoryBuffer *buf, const char *ptr = nullptr); void setBuffer(StringRef Buf, const char *ptr = nullptr);
StringRef LexUntilEndOfStatement() override; StringRef LexUntilEndOfStatement() override;
StringRef LexUntilEndOfLine(); StringRef LexUntilEndOfLine();

View File

@ -22,7 +22,6 @@
using namespace llvm; using namespace llvm;
AsmLexer::AsmLexer(const MCAsmInfo &_MAI) : MAI(_MAI) { AsmLexer::AsmLexer(const MCAsmInfo &_MAI) : MAI(_MAI) {
CurBuf = nullptr;
CurPtr = nullptr; CurPtr = nullptr;
isAtStartOfLine = true; isAtStartOfLine = true;
AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@"); AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@");
@ -31,13 +30,13 @@ AsmLexer::AsmLexer(const MCAsmInfo &_MAI) : MAI(_MAI) {
AsmLexer::~AsmLexer() { AsmLexer::~AsmLexer() {
} }
void AsmLexer::setBuffer(const MemoryBuffer *buf, const char *ptr) { void AsmLexer::setBuffer(StringRef Buf, const char *ptr) {
CurBuf = buf; CurBuf = Buf;
if (ptr) if (ptr)
CurPtr = ptr; CurPtr = ptr;
else else
CurPtr = CurBuf->getBufferStart(); CurPtr = CurBuf.begin();
TokStart = nullptr; TokStart = nullptr;
} }
@ -58,7 +57,7 @@ int AsmLexer::getNextChar() {
case 0: case 0:
// A nul character in the stream is either the end of the current buffer or // A nul character in the stream is either the end of the current buffer or
// a random nul in the file. Disambiguate that here. // a random nul in the file. Disambiguate that here.
if (CurPtr-1 != CurBuf->getBufferEnd()) if (CurPtr - 1 != CurBuf.end())
return 0; // Just whitespace. return 0; // Just whitespace.
// Otherwise, return end of file. // Otherwise, return end of file.
@ -420,9 +419,8 @@ StringRef AsmLexer::LexUntilEndOfStatement() {
while (!isAtStartOfComment(*CurPtr) && // Start of line comment. while (!isAtStartOfComment(*CurPtr) && // Start of line comment.
!isAtStatementSeparator(CurPtr) && // End of statement marker. !isAtStatementSeparator(CurPtr) && // End of statement marker.
*CurPtr != '\n' && *CurPtr != '\n' && *CurPtr != '\r' &&
*CurPtr != '\r' && (*CurPtr != 0 || CurPtr != CurBuf.end())) {
(*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) {
++CurPtr; ++CurPtr;
} }
return StringRef(TokStart, CurPtr-TokStart); return StringRef(TokStart, CurPtr-TokStart);
@ -431,9 +429,8 @@ StringRef AsmLexer::LexUntilEndOfStatement() {
StringRef AsmLexer::LexUntilEndOfLine() { StringRef AsmLexer::LexUntilEndOfLine() {
TokStart = CurPtr; TokStart = CurPtr;
while (*CurPtr != '\n' && while (*CurPtr != '\n' && *CurPtr != '\r' &&
*CurPtr != '\r' && (*CurPtr != 0 || CurPtr != CurBuf.end())) {
(*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) {
++CurPtr; ++CurPtr;
} }
return StringRef(TokStart, CurPtr-TokStart); return StringRef(TokStart, CurPtr-TokStart);

View File

@ -499,7 +499,7 @@ AsmParser::AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out,
SavedDiagContext = SrcMgr.getDiagContext(); SavedDiagContext = SrcMgr.getDiagContext();
// Set our own handler which calls the saved handler. // Set our own handler which calls the saved handler.
SrcMgr.setDiagHandler(DiagHandler, this); SrcMgr.setDiagHandler(DiagHandler, this);
Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)); Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
// Initialize the platform / file format parser. // Initialize the platform / file format parser.
switch (_Ctx.getObjectFileInfo()->getObjectFileType()) { switch (_Ctx.getObjectFileInfo()->getObjectFileType()) {
@ -572,7 +572,7 @@ bool AsmParser::enterIncludeFile(const std::string &Filename) {
return true; return true;
CurBuffer = NewBuf; CurBuffer = NewBuf;
Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)); Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
return false; return false;
} }
@ -593,7 +593,8 @@ bool AsmParser::processIncbinFile(const std::string &Filename) {
void AsmParser::jumpToLoc(SMLoc Loc, unsigned InBuffer) { void AsmParser::jumpToLoc(SMLoc Loc, unsigned InBuffer) {
CurBuffer = InBuffer ? InBuffer : SrcMgr.FindBufferContainingLoc(Loc); CurBuffer = InBuffer ? InBuffer : SrcMgr.FindBufferContainingLoc(Loc);
Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer), Loc.getPointer()); Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer(),
Loc.getPointer());
} }
const AsmToken &AsmParser::Lex() { const AsmToken &AsmParser::Lex() {
@ -2127,7 +2128,7 @@ bool AsmParser::handleMacroEntry(const MCAsmMacro *M, SMLoc NameLoc) {
// Jump to the macro instantiation and prime the lexer. // Jump to the macro instantiation and prime the lexer.
CurBuffer = SrcMgr.AddNewSourceBuffer(MI->Instantiation, SMLoc()); CurBuffer = SrcMgr.AddNewSourceBuffer(MI->Instantiation, SMLoc());
Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)); Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
Lex(); Lex();
return false; return false;
@ -4264,7 +4265,7 @@ void AsmParser::instantiateMacroLikeBody(MCAsmMacro *M, SMLoc DirectiveLoc,
// Jump to the macro instantiation and prime the lexer. // Jump to the macro instantiation and prime the lexer.
CurBuffer = SrcMgr.AddNewSourceBuffer(MI->Instantiation, SMLoc()); CurBuffer = SrcMgr.AddNewSourceBuffer(MI->Instantiation, SMLoc());
Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)); Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
Lex(); Lex();
} }

View File

@ -242,7 +242,7 @@ static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI,
tool_output_file *Out) { tool_output_file *Out) {
AsmLexer Lexer(MAI); AsmLexer Lexer(MAI);
Lexer.setBuffer(SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID())); Lexer.setBuffer(SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID())->getBuffer());
bool Error = false; bool Error = false;
while (Lexer.Lex().isNot(AsmToken::Eof)) { while (Lexer.Lex().isNot(AsmToken::Eof)) {