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 "llvm/Support/DataTypes.h" 20 #include <string> 21 22 namespace llvm { 23 class MemoryBuffer; 24 class MCAsmInfo; 25 26 /// AsmLexer - Lexer class for assembly files. 27 class AsmLexer : public MCAsmLexer { 28 const MCAsmInfo &MAI; 29 30 const char *CurPtr; 31 StringRef CurBuf; 32 bool isAtStartOfLine; 33 34 void operator=(const AsmLexer&) = delete; 35 AsmLexer(const AsmLexer&) = delete; 36 37 protected: 38 /// LexToken - Read the next token and return its code. 39 AsmToken LexToken() override; 40 41 public: 42 AsmLexer(const MCAsmInfo &MAI); 43 ~AsmLexer() override; 44 45 void setBuffer(StringRef Buf, const char *ptr = nullptr); 46 47 StringRef LexUntilEndOfStatement() override; 48 StringRef LexUntilEndOfLine(); 49 50 size_t peekTokens(MutableArrayRef<AsmToken> Buf, 51 bool ShouldSkipSpace = true) override; 52 53 bool isAtStartOfComment(const char *Ptr); 54 bool isAtStatementSeparator(const char *Ptr); 55 getMAI()56 const MCAsmInfo &getMAI() const { return MAI; } 57 58 private: 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 72 } // end namespace llvm 73 74 #endif 75