llvm.org GIT mirror llvm / 26a84a6
This only needs a StringRef. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212401 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
4 changed file(s) with 17 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
2727 const MCAsmInfo &MAI;
2828
2929 const char *CurPtr;
30 const MemoryBuffer *CurBuf;
30 StringRef CurBuf;
3131 bool isAtStartOfLine;
3232
3333 void operator=(const AsmLexer&) LLVM_DELETED_FUNCTION;
4141 AsmLexer(const MCAsmInfo &MAI);
4242 ~AsmLexer();
4343
44 void setBuffer(const MemoryBuffer *buf, const char *ptr = nullptr);
44 void setBuffer(StringRef Buf, const char *ptr = nullptr);
4545
4646 StringRef LexUntilEndOfStatement() override;
4747 StringRef LexUntilEndOfLine();
2121 using namespace llvm;
2222
2323 AsmLexer::AsmLexer(const MCAsmInfo &_MAI) : MAI(_MAI) {
24 CurBuf = nullptr;
2524 CurPtr = nullptr;
2625 isAtStartOfLine = true;
2726 AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@");
3029 AsmLexer::~AsmLexer() {
3130 }
3231
33 void AsmLexer::setBuffer(const MemoryBuffer *buf, const char *ptr) {
34 CurBuf = buf;
32 void AsmLexer::setBuffer(StringRef Buf, const char *ptr) {
33 CurBuf = Buf;
3534
3635 if (ptr)
3736 CurPtr = ptr;
3837 else
39 CurPtr = CurBuf->getBufferStart();
38 CurPtr = CurBuf.begin();
4039
4140 TokStart = nullptr;
4241 }
5756 case 0:
5857 // A nul character in the stream is either the end of the current buffer or
5958 // a random nul in the file. Disambiguate that here.
60 if (CurPtr-1 != CurBuf->getBufferEnd())
59 if (CurPtr - 1 != CurBuf.end())
6160 return 0; // Just whitespace.
6261
6362 // Otherwise, return end of file.
419418
420419 while (!isAtStartOfComment(*CurPtr) && // Start of line comment.
421420 !isAtStatementSeparator(CurPtr) && // End of statement marker.
422 *CurPtr != '\n' &&
423 *CurPtr != '\r' &&
424 (*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) {
421 *CurPtr != '\n' && *CurPtr != '\r' &&
422 (*CurPtr != 0 || CurPtr != CurBuf.end())) {
425423 ++CurPtr;
426424 }
427425 return StringRef(TokStart, CurPtr-TokStart);
430428 StringRef AsmLexer::LexUntilEndOfLine() {
431429 TokStart = CurPtr;
432430
433 while (*CurPtr != '\n' &&
434 *CurPtr != '\r' &&
435 (*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) {
431 while (*CurPtr != '\n' && *CurPtr != '\r' &&
432 (*CurPtr != 0 || CurPtr != CurBuf.end())) {
436433 ++CurPtr;
437434 }
438435 return StringRef(TokStart, CurPtr-TokStart);
498498 SavedDiagContext = SrcMgr.getDiagContext();
499499 // Set our own handler which calls the saved handler.
500500 SrcMgr.setDiagHandler(DiagHandler, this);
501 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
501 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
502502
503503 // Initialize the platform / file format parser.
504504 switch (_Ctx.getObjectFileInfo()->getObjectFileType()) {
571571 return true;
572572
573573 CurBuffer = NewBuf;
574 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
574 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
575575 return false;
576576 }
577577
592592
593593 void AsmParser::jumpToLoc(SMLoc Loc, unsigned InBuffer) {
594594 CurBuffer = InBuffer ? InBuffer : SrcMgr.FindBufferContainingLoc(Loc);
595 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer), Loc.getPointer());
595 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer(),
596 Loc.getPointer());
596597 }
597598
598599 const AsmToken &AsmParser::Lex() {
21262127
21272128 // Jump to the macro instantiation and prime the lexer.
21282129 CurBuffer = SrcMgr.AddNewSourceBuffer(MI->Instantiation, SMLoc());
2129 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
2130 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
21302131 Lex();
21312132
21322133 return false;
42634264
42644265 // Jump to the macro instantiation and prime the lexer.
42654266 CurBuffer = SrcMgr.AddNewSourceBuffer(MI->Instantiation, SMLoc());
4266 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
4267 Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
42674268 Lex();
42684269 }
42694270
241241 tool_output_file *Out) {
242242
243243 AsmLexer Lexer(MAI);
244 Lexer.setBuffer(SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID()));
244 Lexer.setBuffer(SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID())->getBuffer());
245245
246246 bool Error = false;
247247 while (Lexer.Lex().isNot(AsmToken::Eof)) {