mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
[mips] Remove the last usage of parseRegister from MipsAsmParser.
Summary: Added negative test case so that we can be sure we handle erroneous situations while parsing the .cpsetup directive. Reviewers: dsanders Reviewed By: dsanders Differential Revision: http://reviews.llvm.org/D3681 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211160 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c32d52df24
commit
dd9e510da7
@ -183,8 +183,6 @@ class MipsAsmParser : public MCTargetAsmParser {
|
|||||||
return STI.getFeatureBits() & Mips::FeatureMips64r6;
|
return STI.getFeatureBits() & Mips::FeatureMips64r6;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parseRegister(unsigned &RegNum);
|
|
||||||
|
|
||||||
bool eatComma(StringRef ErrorStr);
|
bool eatComma(StringRef ErrorStr);
|
||||||
|
|
||||||
int matchCPURegisterName(StringRef Symbol);
|
int matchCPURegisterName(StringRef Symbol);
|
||||||
@ -2342,25 +2340,6 @@ bool MipsAsmParser::parseSetFeature(uint64_t Feature) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MipsAsmParser::parseRegister(unsigned &RegNum) {
|
|
||||||
if (!getLexer().is(AsmToken::Dollar))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Parser.Lex();
|
|
||||||
|
|
||||||
const AsmToken &Reg = Parser.getTok();
|
|
||||||
if (Reg.is(AsmToken::Identifier)) {
|
|
||||||
RegNum = matchCPURegisterName(Reg.getIdentifier());
|
|
||||||
} else if (Reg.is(AsmToken::Integer)) {
|
|
||||||
RegNum = Reg.getIntVal();
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Parser.Lex();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MipsAsmParser::eatComma(StringRef ErrorStr) {
|
bool MipsAsmParser::eatComma(StringRef ErrorStr) {
|
||||||
if (getLexer().isNot(AsmToken::Comma)) {
|
if (getLexer().isNot(AsmToken::Comma)) {
|
||||||
SMLoc Loc = getLexer().getLoc();
|
SMLoc Loc = getLexer().getLoc();
|
||||||
@ -2400,23 +2379,48 @@ bool MipsAsmParser::parseDirectiveCPSetup() {
|
|||||||
unsigned Save;
|
unsigned Save;
|
||||||
bool SaveIsReg = true;
|
bool SaveIsReg = true;
|
||||||
|
|
||||||
if (!parseRegister(FuncReg))
|
SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> TmpReg;
|
||||||
return reportParseError("expected register containing function address");
|
OperandMatchResultTy ResTy = ParseAnyRegister(TmpReg);
|
||||||
FuncReg = getGPR(FuncReg);
|
if (ResTy == MatchOperand_NoMatch) {
|
||||||
|
reportParseError("expected register containing function address");
|
||||||
|
Parser.eatToEndOfStatement();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
MipsOperand &FuncRegOpnd = static_cast<MipsOperand &>(*TmpReg[0]);
|
||||||
|
if (!FuncRegOpnd.isGPRAsmReg()) {
|
||||||
|
reportParseError(FuncRegOpnd.getStartLoc(), "invalid register");
|
||||||
|
Parser.eatToEndOfStatement();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
FuncReg = FuncRegOpnd.getGPR32Reg();
|
||||||
|
TmpReg.clear();
|
||||||
|
|
||||||
if (!eatComma("expected comma parsing directive"))
|
if (!eatComma("expected comma parsing directive"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!parseRegister(Save)) {
|
ResTy = ParseAnyRegister(TmpReg);
|
||||||
|
if (ResTy == MatchOperand_NoMatch) {
|
||||||
const AsmToken &Tok = Parser.getTok();
|
const AsmToken &Tok = Parser.getTok();
|
||||||
if (Tok.is(AsmToken::Integer)) {
|
if (Tok.is(AsmToken::Integer)) {
|
||||||
Save = Tok.getIntVal();
|
Save = Tok.getIntVal();
|
||||||
SaveIsReg = false;
|
SaveIsReg = false;
|
||||||
Parser.Lex();
|
Parser.Lex();
|
||||||
} else
|
} else {
|
||||||
return reportParseError("expected save register or stack offset");
|
reportParseError("expected save register or stack offset");
|
||||||
} else
|
Parser.eatToEndOfStatement();
|
||||||
Save = getGPR(Save);
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MipsOperand &SaveOpnd = static_cast<MipsOperand &>(*TmpReg[0]);
|
||||||
|
if (!SaveOpnd.isGPRAsmReg()) {
|
||||||
|
reportParseError(SaveOpnd.getStartLoc(), "invalid register");
|
||||||
|
Parser.eatToEndOfStatement();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Save = SaveOpnd.getGPR32Reg();
|
||||||
|
}
|
||||||
|
|
||||||
if (!eatComma("expected comma parsing directive"))
|
if (!eatComma("expected comma parsing directive"))
|
||||||
return true;
|
return true;
|
||||||
|
14
test/MC/Mips/cpsetup-bad.s
Normal file
14
test/MC/Mips/cpsetup-bad.s
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# RUN: not llvm-mc %s -triple mips64-unknown-unknown 2>%t1
|
||||||
|
# RUN: FileCheck %s < %t1 -check-prefix=ASM
|
||||||
|
|
||||||
|
.text
|
||||||
|
.option pic2
|
||||||
|
t1:
|
||||||
|
.cpsetup $bar, 8, __cerror
|
||||||
|
# ASM: :[[@LINE-1]]:18: error: expected register containing function address
|
||||||
|
.cpsetup $33, 8, __cerror
|
||||||
|
# ASM: :[[@LINE-1]]:18: error: invalid register
|
||||||
|
.cpsetup $31, foo, __cerror
|
||||||
|
# ASM: :[[@LINE-1]]:23: error: expected save register or stack offset
|
||||||
|
.cpsetup $31, $32, __cerror
|
||||||
|
# ASM: :[[@LINE-1]]:23: error: invalid register
|
Loading…
Reference in New Issue
Block a user