Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame^] | 1 | //===- AsmLexer.h - Lexer for Assembly Files --------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This class declares the lexer for assembly files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_MC_MCPARSER_ASMLEXER_H |
| 15 | #define LLVM_MC_MCPARSER_ASMLEXER_H |
| 16 | |
| 17 | #include "llvm/ADT/StringRef.h" |
| 18 | #include "llvm/MC/MCParser/MCAsmLexer.h" |
| 19 | #include <string> |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | class MCAsmInfo; |
| 24 | |
| 25 | /// AsmLexer - Lexer class for assembly files. |
| 26 | class AsmLexer : public MCAsmLexer { |
| 27 | const MCAsmInfo &MAI; |
| 28 | |
| 29 | const char *CurPtr = nullptr; |
| 30 | StringRef CurBuf; |
| 31 | bool IsAtStartOfLine = true; |
| 32 | bool IsAtStartOfStatement = true; |
| 33 | bool IsParsingMSInlineAsm = false; |
| 34 | bool IsPeeking = false; |
| 35 | |
| 36 | protected: |
| 37 | /// LexToken - Read the next token and return its code. |
| 38 | AsmToken LexToken() override; |
| 39 | |
| 40 | public: |
| 41 | AsmLexer(const MCAsmInfo &MAI); |
| 42 | AsmLexer(const AsmLexer &) = delete; |
| 43 | AsmLexer &operator=(const AsmLexer &) = delete; |
| 44 | ~AsmLexer() override; |
| 45 | |
| 46 | void setBuffer(StringRef Buf, const char *ptr = nullptr); |
| 47 | void setParsingMSInlineAsm(bool V) { IsParsingMSInlineAsm = V; } |
| 48 | |
| 49 | StringRef LexUntilEndOfStatement() override; |
| 50 | |
| 51 | size_t peekTokens(MutableArrayRef<AsmToken> Buf, |
| 52 | bool ShouldSkipSpace = true) override; |
| 53 | |
| 54 | const MCAsmInfo &getMAI() const { return MAI; } |
| 55 | |
| 56 | private: |
| 57 | bool isAtStartOfComment(const char *Ptr); |
| 58 | bool isAtStatementSeparator(const char *Ptr); |
| 59 | int getNextChar(); |
| 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 |