Add AsmToken::getEndLoc and use it to add ranges to x86 asm register parsing.

<stdin>:1:12: error: register %rax is only available in 64-bit mode
   incl    %rax
           ^~~~

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142137 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2011-10-16 12:10:27 +00:00
parent 3a35a3813d
commit 5efabcf01d
3 changed files with 19 additions and 9 deletions

View File

@ -71,6 +71,7 @@ public:
bool isNot(TokenKind K) const { return Kind != K; } bool isNot(TokenKind K) const { return Kind != K; }
SMLoc getLoc() const; SMLoc getLoc() const;
SMLoc getEndLoc() const;
/// getStringContents - Get the contents of a string token (without quotes). /// getStringContents - Get the contents of a string token (without quotes).
StringRef getStringContents() const { StringRef getStringContents() const {

View File

@ -25,3 +25,7 @@ SMLoc MCAsmLexer::getLoc() const {
SMLoc AsmToken::getLoc() const { SMLoc AsmToken::getLoc() const {
return SMLoc::getFromPointer(Str.data()); return SMLoc::getFromPointer(Str.data());
} }
SMLoc AsmToken::getEndLoc() const {
return SMLoc::getFromPointer(Str.data() + Str.size() - 1);
}

View File

@ -405,7 +405,8 @@ bool X86ATTAsmParser::ParseRegister(unsigned &RegNo,
const AsmToken &Tok = Parser.getTok(); const AsmToken &Tok = Parser.getTok();
if (Tok.isNot(AsmToken::Identifier)) if (Tok.isNot(AsmToken::Identifier))
return Error(Tok.getLoc(), "invalid register name"); return Error(StartLoc, "invalid register name",
SMRange(StartLoc, Tok.getEndLoc()));
RegNo = MatchRegisterName(Tok.getString()); RegNo = MatchRegisterName(Tok.getString());
@ -423,8 +424,9 @@ bool X86ATTAsmParser::ParseRegister(unsigned &RegNo,
X86MCRegisterClasses[X86::GR64RegClassID].contains(RegNo) || X86MCRegisterClasses[X86::GR64RegClassID].contains(RegNo) ||
X86II::isX86_64NonExtLowByteReg(RegNo) || X86II::isX86_64NonExtLowByteReg(RegNo) ||
X86II::isX86_64ExtendedReg(RegNo)) X86II::isX86_64ExtendedReg(RegNo))
return Error(Tok.getLoc(), "register %" return Error(StartLoc, "register %"
+ Tok.getString() + " is only available in 64-bit mode"); + Tok.getString() + " is only available in 64-bit mode",
SMRange(StartLoc, Tok.getEndLoc()));
} }
// Parse "%st" as "%st(0)" and "%st(1)", which is multiple tokens. // Parse "%st" as "%st(0)" and "%st(1)", which is multiple tokens.
@ -485,9 +487,10 @@ bool X86ATTAsmParser::ParseRegister(unsigned &RegNo,
} }
if (RegNo == 0) if (RegNo == 0)
return Error(Tok.getLoc(), "invalid register name"); return Error(StartLoc, "invalid register name",
SMRange(StartLoc, Tok.getEndLoc()));
EndLoc = Tok.getLoc(); EndLoc = Tok.getEndLoc();
Parser.Lex(); // Eat identifier token. Parser.Lex(); // Eat identifier token.
return false; return false;
} }
@ -503,7 +506,8 @@ X86Operand *X86ATTAsmParser::ParseOperand() {
SMLoc Start, End; SMLoc Start, End;
if (ParseRegister(RegNo, Start, End)) return 0; if (ParseRegister(RegNo, Start, End)) return 0;
if (RegNo == X86::EIZ || RegNo == X86::RIZ) { if (RegNo == X86::EIZ || RegNo == X86::RIZ) {
Error(Start, "%eiz and %riz can only be used as index registers"); Error(Start, "%eiz and %riz can only be used as index registers",
SMRange(Start, End));
return 0; return 0;
} }
@ -587,10 +591,11 @@ X86Operand *X86ATTAsmParser::ParseMemOperand(unsigned SegReg, SMLoc MemStart) {
unsigned BaseReg = 0, IndexReg = 0, Scale = 1; unsigned BaseReg = 0, IndexReg = 0, Scale = 1;
if (getLexer().is(AsmToken::Percent)) { if (getLexer().is(AsmToken::Percent)) {
SMLoc L; SMLoc StartLoc, EndLoc;
if (ParseRegister(BaseReg, L, L)) return 0; if (ParseRegister(BaseReg, StartLoc, EndLoc)) return 0;
if (BaseReg == X86::EIZ || BaseReg == X86::RIZ) { if (BaseReg == X86::EIZ || BaseReg == X86::RIZ) {
Error(L, "eiz and riz can only be used as index registers"); Error(StartLoc, "eiz and riz can only be used as index registers",
SMRange(StartLoc, EndLoc));
return 0; return 0;
} }
} }