LLVM  7.0.0
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 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 
50 
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
const MCAsmInfo & getMAI() const
Definition: AsmLexer.h:54
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
AsmLexer & operator=(const AsmLexer &)=delete
void setParsingMSInlineAsm(bool V)
Definition: AsmLexer.h:47
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:502
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:482
~AsmLexer() override
AsmToken LexToken() override
LexToken - Read the next token and return its code.
Definition: AsmLexer.cpp:545
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
AsmLexer(const MCAsmInfo &MAI)
Definition: AsmLexer.cpp:34