llvm.org GIT mirror llvm / 7b4608d
Removed the non-target independent AsmToken::Register enum constant from MCAsmLexer.h in preparation of supporting other targets. Changed the X86AsmParser code to reflect this by removing AsmLexer::LexPercent and looking for AsmToken::Percent when parsing in places that used AsmToken::Register. Then changed X86ATTAsmParser::ParseRegister to parse out registers as an AsmToken::Percent followed by an AsmToken::Identifier. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80929 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 11 years ago
5 changed file(s) with 13 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
2626
2727 // String values.
2828 Identifier,
29 Register,
3029 String,
3130
3231 // Integer values.
229229
230230
231231 bool X86ATTAsmParser::ParseRegister(X86Operand &Op) {
232 const AsmToken &TokPercent = getLexer().getTok();
233 assert(TokPercent.is(AsmToken::Percent) && "Invalid token kind!");
234 getLexer().Lex(); // Eat percent token.
235
232236 const AsmToken &Tok = getLexer().getTok();
233 assert(Tok.is(AsmToken::Register) && "Invalid token kind!");
237 assert(TokPercent.is(AsmToken::Identifier) && "Invalid token kind!");
234238
235239 // FIXME: Validate register for the current architecture; we have to do
236240 // validation later, so maybe there is no need for this here.
237241 unsigned RegNo;
238 assert(Tok.getString().startswith("%") && "Invalid register name!");
239
240 RegNo = MatchRegisterName(Tok.getString().substr(1));
242
243 RegNo = MatchRegisterName(Tok.getString());
241244 if (RegNo == 0)
242245 return Error(Tok.getLoc(), "invalid register name");
243246
244247 Op = X86Operand::CreateReg(RegNo);
245 getLexer().Lex(); // Eat register token.
248 getLexer().Lex(); // Eat identifier token.
246249
247250 return false;
248251 }
251254 switch (getLexer().getKind()) {
252255 default:
253256 return ParseMemOperand(Op);
254 case AsmToken::Register:
257 case AsmToken::Percent:
255258 // FIXME: if a segment register, this could either be just the seg reg, or
256259 // the start of a memory operand.
257260 return ParseRegister(Op);
298301 // so we have to eat the ( to see beyond it.
299302 getLexer().Lex(); // Eat the '('.
300303
301 if (getLexer().is(AsmToken::Register) || getLexer().is(AsmToken::Comma)) {
304 if (getLexer().is(AsmToken::Percent) || getLexer().is(AsmToken::Comma)) {
302305 // Nothing to do here, fall into the code below with the '(' part of the
303306 // memory operand consumed.
304307 } else {
326329 // the rest of the memory operand.
327330 unsigned BaseReg = 0, IndexReg = 0, Scale = 1;
328331
329 if (getLexer().is(AsmToken::Register)) {
332 if (getLexer().is(AsmToken::Percent)) {
330333 if (ParseRegister(Op))
331334 return true;
332335 BaseReg = Op.getReg();
341344 //
342345 // Not that even though it would be completely consistent to support syntax
343346 // like "1(%eax,,1)", the assembler doesn't.
344 if (getLexer().is(AsmToken::Register)) {
347 if (getLexer().is(AsmToken::Percent)) {
345348 if (ParseRegister(Op))
346349 return true;
347350 IndexReg = Op.getReg();
9898 *CurPtr == '.' || *CurPtr == '@')
9999 ++CurPtr;
100100 return AsmToken(AsmToken::Identifier, StringRef(TokStart, CurPtr - TokStart));
101 }
102
103 /// LexPercent: Register: %[a-zA-Z0-9]+
104 AsmToken AsmLexer::LexPercent() {
105 if (!isalnum(*CurPtr))
106 return AsmToken(AsmToken::Percent, StringRef(CurPtr, 1)); // Single %.
107
108 while (isalnum(*CurPtr))
109 ++CurPtr;
110
111 return AsmToken(AsmToken::Register, StringRef(TokStart, CurPtr - TokStart));
112101 }
113102
114103 /// LexSlash: Slash: /
297286 if (*CurPtr == '=')
298287 return ++CurPtr, AsmToken(AsmToken::ExclaimEqual, StringRef(TokStart, 2));
299288 return AsmToken(AsmToken::Exclaim, StringRef(TokStart, 1));
300 case '%': return LexPercent();
289 case '%': return AsmToken(AsmToken::Percent, StringRef(TokStart, 1));
301290 case '/': return LexSlash();
302291 case '#': return LexLineComment();
303292 case '"': return LexQuote();
6363 AsmToken ReturnError(const char *Loc, const std::string &Msg);
6464
6565 AsmToken LexIdentifier();
66 AsmToken LexPercent();
6766 AsmToken LexSlash();
6867 AsmToken LexLineComment();
6968 AsmToken LexDigit();
118118 break;
119119 case AsmToken::Identifier:
120120 outs() << "identifier: " << Lexer.getTok().getString() << '\n';
121 break;
122 case AsmToken::Register:
123 outs() << "register: " << Lexer.getTok().getString() << '\n';
124121 break;
125122 case AsmToken::String:
126123 outs() << "string: " << Lexer.getTok().getString() << '\n';