LLVM  8.0.1
AsmLexer.h
Go to the documentation of this file.
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"
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 IsPeeking = false;
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 
45  void setBuffer(StringRef Buf, const char *ptr = nullptr);
46 
48 
50  bool ShouldSkipSpace = true) override;
51 
52  const MCAsmInfo &getMAI() const { return MAI; }
53 
54 private:
55  bool isAtStartOfComment(const char *Ptr);
56  bool isAtStatementSeparator(const char *Ptr);
57  int getNextChar();
58  AsmToken ReturnError(const char *Loc, const std::string &Msg);
59 
60  AsmToken LexIdentifier();
61  AsmToken LexSlash();
62  AsmToken LexLineComment();
63  AsmToken LexDigit();
64  AsmToken LexSingleQuote();
65  AsmToken LexQuote();
66  AsmToken LexFloatLiteral();
67  AsmToken LexHexFloatLiteral(bool NoIntDigits);
68 
69  StringRef LexUntilEndOfLine();
70 };
71 
72 } // end namespace llvm
73 
74 #endif // LLVM_MC_MCPARSER_ASMLEXER_H
const MCAsmInfo & getMAI() const
Definition: AsmLexer.h:52
This class represents lattice values for constants.
Definition: AllocatorList.h:24
AsmLexer & operator=(const AsmLexer &)=delete
AsmLexer - Lexer class for assembly files.
Definition: AsmLexer.h:26
void setBuffer(StringRef Buf, const char *ptr=nullptr)
Definition: AsmLexer.cpp:40
Generic assembler lexer interface, for use by target specific assembly lexers.
Definition: MCAsmLexer.h:40
Target independent representation for an assembler token.
Definition: MCAsmMacro.h:22
size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true) override
Look ahead an arbitrary number of tokens.
Definition: AsmLexer.cpp:506
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:291
StringRef LexUntilEndOfStatement() override
Definition: AsmLexer.cpp:486
~AsmLexer() override
AsmToken LexToken() override
LexToken - Read the next token and return its code.
Definition: AsmLexer.cpp:549
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
AsmLexer(const MCAsmInfo &MAI)
Definition: AsmLexer.cpp:34