LLVM: include/llvm/MC/MCParser/AsmLexer.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_MC_MCPARSER_ASMLEXER_H
14#define LLVM_MC_MCPARSER_ASMLEXER_H
15
21#include
22#include
23#include
24
25namespace llvm {
26
28
29
30
32public:
34
35
36
37
38
40};
41
43
45
46 const char *CurPtr = nullptr;
47
49
50
52 std::string Err;
53
55
56 bool IsAtStartOfLine = true;
57 bool JustConsumedEOL = true;
58 bool IsPeeking = false;
59 bool EndStatementAtEOF = true;
60
61 const char *TokStart = nullptr;
62 bool SkipSpace = true;
63 bool AllowAtInIdentifier = false;
64 bool AllowHashInIdentifier = false;
65 bool IsAtStartOfStatement = true;
66 bool LexMasmHexFloats = false;
67 bool LexMasmIntegers = false;
68 bool LexMasmStrings = false;
69 bool LexMotorolaIntegers = false;
70 bool UseMasmDefaultRadix = false;
71 unsigned DefaultRadix = 10;
72 bool LexHLASMIntegers = false;
73 bool LexHLASMStrings = false;
75
77
78 void SetError(SMLoc errLoc, const std::string &err) {
79 ErrLoc = errLoc;
80 Err = err;
81 }
82
83public:
87
88
89
90
91
93 assert(!CurTok.empty());
94
96 CurTok.erase(CurTok.begin());
97
98
99 if (CurTok.empty()) {
101 CurTok.insert(CurTok.begin(), T);
102 }
103 return CurTok.front();
104 }
105
107 CurTok.insert(CurTok.begin(), Token);
108 }
109
111
113
114
116
117
119
120
123
125 size_t ReadCount = peekTokens(Buf, ShouldSkipSpace);
126
127 assert(ReadCount == 1);
128 (void)ReadCount;
129
130 return Tok;
131 }
132
133
135 bool ShouldSkipSpace = true);
136
137
139
140
141 const std::string &getErr() { return Err; }
142
143
145
146
148
149
151
152
154
157
159
161 this->CommentConsumer = CommentConsumer;
162 }
163
164
165
167
168
169
171
174
175
177
178
179
181
182
183
185
186
188
189
190
191
193
194
195
196
197
198
199
201 bool EndStatementAtEOF = true);
202
204
205private:
206 bool isAtStartOfComment(const char *Ptr);
207 bool isAtStatementSeparator(const char *Ptr);
208 [[nodiscard]] int getNextChar();
209 int peekNextChar();
210 AsmToken ReturnError(const char *Loc, const std::string &Msg);
211
219 AsmToken LexHexFloatLiteral(bool NoIntDigits);
220
222};
223
224}
225
226#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the SmallVector class.
void setLexHLASMStrings(bool V)
Set whether to "lex" HLASM-flavour character and string literals.
Definition AsmLexer.h:192
void setLexMasmIntegers(bool V)
Set whether to lex masm-style binary (e.g., 0b1101) and radix-specified literals (e....
Definition AsmLexer.h:166
SMLoc getLoc() const
Get the current source location.
Definition AsmLexer.h:115
void setLexMasmStrings(bool V)
Set whether to lex masm-style string literals, such as 'Can''t find file' and "This ""value"" not fou...
Definition AsmLexer.h:180
LLVM_ABI AsmLexer(const MCAsmInfo &MAI)
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
Definition AsmLexer.h:121
bool getAllowAtInIdentifier()
Definition AsmLexer.h:155
void UnLex(AsmToken const &Token)
Definition AsmLexer.h:106
void setMasmDefaultRadix(unsigned Radix)
Definition AsmLexer.h:173
AsmToken::TokenKind getKind() const
Get the kind of current token.
Definition AsmLexer.h:144
void setLexMasmHexFloats(bool V)
Set whether to lex masm-style hex float literals, such as 3f800000r.
Definition AsmLexer.h:176
const MCAsmInfo & getMAI() const
Definition AsmLexer.h:203
const AsmToken & getTok() const
Get the current (last) lexed token.
Definition AsmLexer.h:118
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
Definition AsmLexer.h:147
void setLexMotorolaIntegers(bool V)
Set whether to lex Motorola-style integer literals, such as $deadbeef or %01010110.
Definition AsmLexer.h:184
SMLoc getErrLoc()
Get the current error location.
Definition AsmLexer.h:138
bool justConsumedEOL()
Definition AsmLexer.h:110
AsmLexer(const AsmLexer &)=delete
const std::string & getErr()
Get the current error string.
Definition AsmLexer.h:141
const AsmToken & Lex()
Consume the next token from the input stream and return it.
Definition AsmLexer.h:92
void setSkipSpace(bool val)
Set whether spaces should be ignored by the lexer.
Definition AsmLexer.h:153
void setAllowAtInIdentifier(bool v)
Definition AsmLexer.h:156
LLVM_ABI StringRef LexUntilEndOfStatement()
AsmLexer & operator=(const AsmLexer &)=delete
LLVM_ABI void setBuffer(StringRef Buf, const char *ptr=nullptr, bool EndStatementAtEOF=true)
Set buffer to be lexed.
unsigned getMasmDefaultRadix() const
Definition AsmLexer.h:172
void useMasmDefaultRadix(bool V)
Set whether to use masm-style default-radix integer literals.
Definition AsmLexer.h:170
void setLexHLASMIntegers(bool V)
Set whether to lex HLASM-flavour integers. For now this is only [0-9]*.
Definition AsmLexer.h:187
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
Definition AsmLexer.h:150
LLVM_ABI size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true)
Look ahead an arbitrary number of tokens.
void setCommentConsumer(AsmCommentConsumer *CommentConsumer)
Definition AsmLexer.h:160
void setAllowHashInIdentifier(bool V)
Definition AsmLexer.h:158
Target independent representation for an assembler token.
bool isNot(TokenKind K) const
bool is(TokenKind K) const
TokenKind getKind() const
This class is intended to be used as a base class for asm properties and features specific to the tar...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
This is an optimization pass for GlobalISel generic memory operations.