@@ -39,17 +39,24 @@ class AsmCommentConsumer {
39
39
virtual void HandleComment (SMLoc Loc, StringRef CommentText) = 0;
40
40
};
41
41
42
- // / Generic assembler lexer interface, for use by target specific assembly
43
- // / lexers.
44
- class MCAsmLexer {
42
+ class AsmLexer {
45
43
// / The current token, stored in the base class for faster access.
46
44
SmallVector<AsmToken, 1 > CurTok;
47
45
46
+ const char *CurPtr = nullptr ;
47
+ StringRef CurBuf;
48
+
48
49
// / The location and description of the current error
49
50
SMLoc ErrLoc;
50
51
std::string Err;
51
52
52
- protected: // Can only create subclasses.
53
+ const MCAsmInfo &MAI;
54
+
55
+ bool IsAtStartOfLine = true ;
56
+ bool AtStartOfStatement = true ;
57
+ bool IsPeeking = false ;
58
+ bool EndStatementAtEOF = true ;
59
+
53
60
const char *TokStart = nullptr ;
54
61
bool SkipSpace = true ;
55
62
bool AllowAtInIdentifier = false ;
@@ -65,19 +72,17 @@ class MCAsmLexer {
65
72
bool LexHLASMStrings = false ;
66
73
AsmCommentConsumer *CommentConsumer = nullptr ;
67
74
68
- MCAsmLexer ();
69
-
70
- virtual AsmToken LexToken () = 0;
75
+ AsmToken LexToken ();
71
76
72
77
void SetError (SMLoc errLoc, const std::string &err) {
73
78
ErrLoc = errLoc;
74
79
Err = err;
75
80
}
76
81
77
82
public:
78
- MCAsmLexer (const MCAsmLexer &) = delete ;
79
- MCAsmLexer & operator = (const MCAsmLexer &) = delete ;
80
- virtual ~MCAsmLexer () ;
83
+ AsmLexer (const MCAsmInfo &MAI) ;
84
+ AsmLexer (const AsmLexer &) = delete ;
85
+ AsmLexer & operator =( const AsmLexer &) = delete ;
81
86
82
87
// / Consume the next token from the input stream and return it.
83
88
// /
@@ -86,7 +91,7 @@ class MCAsmLexer {
86
91
const AsmToken &Lex () {
87
92
assert (!CurTok.empty ());
88
93
// Mark if we parsing out a EndOfStatement.
89
- IsAtStartOfStatement = CurTok.front ().getKind () == AsmToken::EndOfStatement;
94
+ AtStartOfStatement = CurTok.front ().getKind () == AsmToken::EndOfStatement;
90
95
CurTok.erase (CurTok.begin ());
91
96
// LexToken may generate multiple tokens via UnLex but will always return
92
97
// the first one. Place returned value at head of CurTok vector.
@@ -98,16 +103,16 @@ class MCAsmLexer {
98
103
}
99
104
100
105
void UnLex (AsmToken const &Token) {
101
- IsAtStartOfStatement = false ;
106
+ AtStartOfStatement = false ;
102
107
CurTok.insert (CurTok.begin (), Token);
103
108
}
104
109
105
- bool isAtStartOfStatement () { return IsAtStartOfStatement ; }
110
+ bool isAtStartOfStatement () { return AtStartOfStatement ; }
106
111
107
- virtual StringRef LexUntilEndOfStatement () = 0 ;
112
+ StringRef LexUntilEndOfStatement ();
108
113
109
114
// / Get the current source location.
110
- SMLoc getLoc () const ;
115
+ SMLoc getLoc () const { return SMLoc::getFromPointer (TokStart); }
111
116
112
117
// / Get the current (last) lexed token.
113
118
const AsmToken &getTok () const { return CurTok[0 ]; }
@@ -126,8 +131,7 @@ class MCAsmLexer {
126
131
}
127
132
128
133
// / Look ahead an arbitrary number of tokens.
129
- virtual size_t peekTokens (MutableArrayRef<AsmToken> Buf,
130
- bool ShouldSkipSpace = true ) = 0;
134
+ size_t peekTokens (MutableArrayRef<AsmToken> Buf, bool ShouldSkipSpace = true );
131
135
132
136
// / Get the current error location
133
137
SMLoc getErrLoc () { return ErrLoc; }
@@ -185,37 +189,10 @@ class MCAsmLexer {
185
189
// / setting this option to true, will disable lexing for character and string
186
190
// / literals.
187
191
void setLexHLASMStrings (bool V) { LexHLASMStrings = V; }
188
- };
189
-
190
- // / AsmLexer - Lexer class for assembly files.
191
- class AsmLexer final : public MCAsmLexer {
192
- const MCAsmInfo &MAI;
193
-
194
- const char *CurPtr = nullptr ;
195
- StringRef CurBuf;
196
- bool IsAtStartOfLine = true ;
197
- bool IsAtStartOfStatement = true ;
198
- bool IsPeeking = false ;
199
- bool EndStatementAtEOF = true ;
200
-
201
- protected:
202
- // / LexToken - Read the next token and return its code.
203
- AsmToken LexToken () override ;
204
-
205
- public:
206
- AsmLexer (const MCAsmInfo &MAI);
207
- AsmLexer (const AsmLexer &) = delete ;
208
- AsmLexer &operator =(const AsmLexer &) = delete ;
209
- ~AsmLexer () override ;
210
192
211
193
void setBuffer (StringRef Buf, const char *ptr = nullptr ,
212
194
bool EndStatementAtEOF = true );
213
195
214
- StringRef LexUntilEndOfStatement () override ;
215
-
216
- size_t peekTokens (MutableArrayRef<AsmToken> Buf,
217
- bool ShouldSkipSpace = true ) override ;
218
-
219
196
const MCAsmInfo &getMAI () const { return MAI; }
220
197
221
198
private:
@@ -237,6 +214,8 @@ class AsmLexer final : public MCAsmLexer {
237
214
StringRef LexUntilEndOfLine ();
238
215
};
239
216
217
+ using MCAsmLexer = AsmLexer;
218
+
240
219
} // end namespace llvm
241
220
242
221
#endif // LLVM_MC_MCPARSER_ASMLEXER_H
0 commit comments