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   bool IsAtStartOfStatement;
34 
35   void operator=(const AsmLexer&) = delete;
36   AsmLexer(const AsmLexer&) = delete;
37 
38 protected:
39   /// LexToken - Read the next token and return its code.
40   AsmToken LexToken() override;
41 
42 public:
43   AsmLexer(const MCAsmInfo &MAI);
44   ~AsmLexer() override;
45 
46   void setBuffer(StringRef Buf, const char *ptr = nullptr);
47 
48   StringRef LexUntilEndOfStatement() override;
49 
50   size_t peekTokens(MutableArrayRef<AsmToken> Buf,
51                     bool ShouldSkipSpace = true) override;
52 
getMAI()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();
59   AsmToken ReturnError(const char *Loc, const std::string &Msg);
60 
61   AsmToken LexIdentifier();
62   AsmToken LexSlash();
63   AsmToken LexLineComment();
64   AsmToken LexDigit();
65   AsmToken LexSingleQuote();
66   AsmToken LexQuote();
67   AsmToken LexFloatLiteral();
68   AsmToken LexHexFloatLiteral(bool NoIntDigits);
69 
70   StringRef LexUntilEndOfLine();
71 };
72 
73 } // end namespace llvm
74 
75 #endif
76