Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- AsmLexer.h - Lexer for Assembly Files --------------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This class declares the lexer for assembly files. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_MC_MCPARSER_ASMLEXER_H |
| 14 | #define LLVM_MC_MCPARSER_ASMLEXER_H |
| 15 | |
| 16 | #include "llvm/ADT/StringRef.h" |
| 17 | #include "llvm/MC/MCParser/MCAsmLexer.h" |
| 18 | #include <string> |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | class MCAsmInfo; |
| 23 | |
| 24 | /// AsmLexer - Lexer class for assembly files. |
| 25 | class AsmLexer : public MCAsmLexer { |
| 26 | const MCAsmInfo &MAI; |
| 27 | |
| 28 | const char *CurPtr = nullptr; |
| 29 | StringRef CurBuf; |
| 30 | bool IsAtStartOfLine = true; |
| 31 | bool IsAtStartOfStatement = true; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 32 | bool IsPeeking = false; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 33 | bool EndStatementAtEOF = true; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 34 | |
| 35 | protected: |
| 36 | /// LexToken - Read the next token and return its code. |
| 37 | AsmToken LexToken() override; |
| 38 | |
| 39 | public: |
| 40 | AsmLexer(const MCAsmInfo &MAI); |
| 41 | AsmLexer(const AsmLexer &) = delete; |
| 42 | AsmLexer &operator=(const AsmLexer &) = delete; |
| 43 | ~AsmLexer() override; |
| 44 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 45 | void setBuffer(StringRef Buf, const char *ptr = nullptr, |
| 46 | bool EndStatementAtEOF = true); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 47 | |
| 48 | StringRef LexUntilEndOfStatement() override; |
| 49 | |
| 50 | size_t peekTokens(MutableArrayRef<AsmToken> Buf, |
| 51 | bool ShouldSkipSpace = true) override; |
| 52 | |
| 53 | const MCAsmInfo &getMAI() const { return MAI; } |
| 54 | |
| 55 | private: |
| 56 | bool isAtStartOfComment(const char *Ptr); |
| 57 | bool isAtStatementSeparator(const char *Ptr); |
| 58 | int getNextChar(); |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 59 | int peekNextChar(); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 60 | AsmToken ReturnError(const char *Loc, const std::string &Msg); |
| 61 | |
| 62 | AsmToken LexIdentifier(); |
| 63 | AsmToken LexSlash(); |
| 64 | AsmToken LexLineComment(); |
| 65 | AsmToken LexDigit(); |
| 66 | AsmToken LexSingleQuote(); |
| 67 | AsmToken LexQuote(); |
| 68 | AsmToken LexFloatLiteral(); |
| 69 | AsmToken LexHexFloatLiteral(bool NoIntDigits); |
| 70 | |
| 71 | StringRef LexUntilEndOfLine(); |
| 72 | }; |
| 73 | |
| 74 | } // end namespace llvm |
| 75 | |
| 76 | #endif // LLVM_MC_MCPARSER_ASMLEXER_H |