diff --git a/include/llvm/MC/MCAsmLexer.h b/include/llvm/MC/MCAsmLexer.h index 43bbfd2b458..a1d67b1861a 100644 --- a/include/llvm/MC/MCAsmLexer.h +++ b/include/llvm/MC/MCAsmLexer.h @@ -27,7 +27,6 @@ struct AsmToken { // String values. Identifier, - Register, String, // Integer values. diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp index d06350b8058..d102b371d4a 100644 --- a/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -230,20 +230,23 @@ struct X86Operand { bool X86ATTAsmParser::ParseRegister(X86Operand &Op) { + const AsmToken &TokPercent = getLexer().getTok(); + assert(TokPercent.is(AsmToken::Percent) && "Invalid token kind!"); + getLexer().Lex(); // Eat percent token. + const AsmToken &Tok = getLexer().getTok(); - assert(Tok.is(AsmToken::Register) && "Invalid token kind!"); + assert(TokPercent.is(AsmToken::Identifier) && "Invalid token kind!"); // FIXME: Validate register for the current architecture; we have to do // validation later, so maybe there is no need for this here. unsigned RegNo; - assert(Tok.getString().startswith("%") && "Invalid register name!"); - RegNo = MatchRegisterName(Tok.getString().substr(1)); + RegNo = MatchRegisterName(Tok.getString()); if (RegNo == 0) return Error(Tok.getLoc(), "invalid register name"); Op = X86Operand::CreateReg(RegNo); - getLexer().Lex(); // Eat register token. + getLexer().Lex(); // Eat identifier token. return false; } @@ -252,7 +255,7 @@ bool X86ATTAsmParser::ParseOperand(X86Operand &Op) { switch (getLexer().getKind()) { default: return ParseMemOperand(Op); - case AsmToken::Register: + case AsmToken::Percent: // FIXME: if a segment register, this could either be just the seg reg, or // the start of a memory operand. return ParseRegister(Op); @@ -299,7 +302,7 @@ bool X86ATTAsmParser::ParseMemOperand(X86Operand &Op) { // so we have to eat the ( to see beyond it. getLexer().Lex(); // Eat the '('. - if (getLexer().is(AsmToken::Register) || getLexer().is(AsmToken::Comma)) { + if (getLexer().is(AsmToken::Percent) || getLexer().is(AsmToken::Comma)) { // Nothing to do here, fall into the code below with the '(' part of the // memory operand consumed. } else { @@ -327,7 +330,7 @@ bool X86ATTAsmParser::ParseMemOperand(X86Operand &Op) { // the rest of the memory operand. unsigned BaseReg = 0, IndexReg = 0, Scale = 1; - if (getLexer().is(AsmToken::Register)) { + if (getLexer().is(AsmToken::Percent)) { if (ParseRegister(Op)) return true; BaseReg = Op.getReg(); @@ -342,7 +345,7 @@ bool X86ATTAsmParser::ParseMemOperand(X86Operand &Op) { // // Not that even though it would be completely consistent to support syntax // like "1(%eax,,1)", the assembler doesn't. - if (getLexer().is(AsmToken::Register)) { + if (getLexer().is(AsmToken::Percent)) { if (ParseRegister(Op)) return true; IndexReg = Op.getReg(); diff --git a/tools/llvm-mc/AsmLexer.cpp b/tools/llvm-mc/AsmLexer.cpp index 27454ee922c..4dafa0eae94 100644 --- a/tools/llvm-mc/AsmLexer.cpp +++ b/tools/llvm-mc/AsmLexer.cpp @@ -101,17 +101,6 @@ AsmToken AsmLexer::LexIdentifier() { return AsmToken(AsmToken::Identifier, StringRef(TokStart, CurPtr - TokStart)); } -/// LexPercent: Register: %[a-zA-Z0-9]+ -AsmToken AsmLexer::LexPercent() { - if (!isalnum(*CurPtr)) - return AsmToken(AsmToken::Percent, StringRef(CurPtr, 1)); // Single %. - - while (isalnum(*CurPtr)) - ++CurPtr; - - return AsmToken(AsmToken::Register, StringRef(TokStart, CurPtr - TokStart)); -} - /// LexSlash: Slash: / /// C-Style Comment: /* ... */ AsmToken AsmLexer::LexSlash() { @@ -298,7 +287,7 @@ AsmToken AsmLexer::LexToken() { if (*CurPtr == '=') return ++CurPtr, AsmToken(AsmToken::ExclaimEqual, StringRef(TokStart, 2)); return AsmToken(AsmToken::Exclaim, StringRef(TokStart, 1)); - case '%': return LexPercent(); + case '%': return AsmToken(AsmToken::Percent, StringRef(TokStart, 1)); case '/': return LexSlash(); case '#': return LexLineComment(); case '"': return LexQuote(); diff --git a/tools/llvm-mc/AsmLexer.h b/tools/llvm-mc/AsmLexer.h index 905ff75ec9f..000df59c88d 100644 --- a/tools/llvm-mc/AsmLexer.h +++ b/tools/llvm-mc/AsmLexer.h @@ -64,7 +64,6 @@ private: AsmToken ReturnError(const char *Loc, const std::string &Msg); AsmToken LexIdentifier(); - AsmToken LexPercent(); AsmToken LexSlash(); AsmToken LexLineComment(); AsmToken LexDigit(); diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index fd0316460b6..84131c7ca66 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -120,9 +120,6 @@ static int AsLexInput(const char *ProgName) { case AsmToken::Identifier: outs() << "identifier: " << Lexer.getTok().getString() << '\n'; break; - case AsmToken::Register: - outs() << "register: " << Lexer.getTok().getString() << '\n'; - break; case AsmToken::String: outs() << "string: " << Lexer.getTok().getString() << '\n'; break;