LLVM  4.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 "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  bool IsParsingMSInlineAsm;
35  bool IsPeeking;
36  void operator=(const AsmLexer&) = delete;
37  AsmLexer(const AsmLexer&) = delete;
38 
39 protected:
40  /// LexToken - Read the next token and return its code.
41  AsmToken LexToken() override;
42 
43 public:
44  AsmLexer(const MCAsmInfo &MAI);
45  ~AsmLexer() override;
46 
47  void setBuffer(StringRef Buf, const char *ptr = nullptr);
48  void setParsingMSInlineAsm(bool V) { IsParsingMSInlineAsm = V; }
49 
51 
53  bool ShouldSkipSpace = true) override;
54 
55  const MCAsmInfo &getMAI() const { return MAI; }
56 
57 private:
58  bool isAtStartOfComment(const char *Ptr);
59  bool isAtStatementSeparator(const char *Ptr);
60  int getNextChar();
61  AsmToken ReturnError(const char *Loc, const std::string &Msg);
62 
63  AsmToken LexIdentifier();
64  AsmToken LexSlash();
65  AsmToken LexLineComment();
66  AsmToken LexDigit();
67  AsmToken LexSingleQuote();
68  AsmToken LexQuote();
69  AsmToken LexFloatLiteral();
70  AsmToken LexHexFloatLiteral(bool NoIntDigits);
71 
72  StringRef LexUntilEndOfLine();
73 };
74 
75 } // end namespace llvm
76 
77 #endif
void setParsingMSInlineAsm(bool V)
Definition: AsmLexer.h:48
AsmLexer - Lexer class for assembly files.
Definition: AsmLexer.h:27
void setBuffer(StringRef Buf, const char *ptr=nullptr)
Definition: AsmLexer.cpp:43
Generic assembler lexer interface, for use by target specific assembly lexers.
Definition: MCAsmLexer.h:147
Target independent representation for an assembler token.
Definition: MCAsmLexer.h:25
size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true) override
Look ahead an arbitrary number of tokens.
Definition: AsmLexer.cpp:503
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:57
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:283
StringRef LexUntilEndOfStatement() override
Definition: AsmLexer.cpp:483
~AsmLexer() override
Definition: AsmLexer.cpp:40
AsmToken LexToken() override
LexToken - Read the next token and return its code.
Definition: AsmLexer.cpp:546
const MCAsmInfo & getMAI() const
Definition: AsmLexer.h:55
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
int * Ptr