MC/ARM/AsmParser: Split out SplitMnemonicAndCC().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123169 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar
2011-01-10 12:24:52 +00:00
parent f4db877cff
commit badbd2fde9

View File

@ -866,19 +866,20 @@ bool ARMAsmParser::ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands){
} }
} }
/// Parse an arm instruction mnemonic followed by its operands. // FIXME: Would be nice to autogen this.
bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc, static unsigned SplitMnemonicAndCC(StringRef &Mnemonic) {
SmallVectorImpl<MCParsedAsmOperand*> &Operands) { // Ignore some mnemonics we know aren't predicated forms.
// Create the leading tokens for the mnemonic, split by '.' characters. if (Mnemonic == "movs" ||
size_t Start = 0, Next = Name.find('.'); Mnemonic == "vmls" ||
StringRef Head = Name.slice(Start, Next); Mnemonic == "vnmls")
return ARMCC::AL;
// Determine the predicate, if any. // Otherwise, determine the predicate.
// //
// FIXME: We need a way to check whether a prefix supports predication, // FIXME: We need a way to check whether a prefix supports predication,
// otherwise we will end up with an ambiguity for instructions that happen to // otherwise we will end up with an ambiguity for instructions that happen to
// end with a predicate name. // end with a predicate name.
unsigned CC = StringSwitch<unsigned>(Head.substr(Head.size()-2)) unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
.Case("eq", ARMCC::EQ) .Case("eq", ARMCC::EQ)
.Case("ne", ARMCC::NE) .Case("ne", ARMCC::NE)
.Case("hs", ARMCC::HS) .Case("hs", ARMCC::HS)
@ -895,20 +896,31 @@ bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
.Case("le", ARMCC::LE) .Case("le", ARMCC::LE)
.Case("al", ARMCC::AL) .Case("al", ARMCC::AL)
.Default(~0U); .Default(~0U);
if (CC != ~0U) {
if (CC == ~0U || Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
(CC == ARMCC::LS && (Head == "vmls" || Head == "vnmls"))) { return CC;
CC = ARMCC::AL;
} else {
Head = Head.slice(0, Head.size() - 2);
} }
return ARMCC::AL;
}
/// Parse an arm instruction mnemonic followed by its operands.
bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
// Create the leading tokens for the mnemonic, split by '.' characters.
size_t Start = 0, Next = Name.find('.');
StringRef Head = Name.slice(Start, Next);
// Determine the predicate, if any.
unsigned CC = SplitMnemonicAndCC(Head);
Operands.push_back(ARMOperand::CreateToken(Head, NameLoc)); Operands.push_back(ARMOperand::CreateToken(Head, NameLoc));
if (Head != "trap")
// FIXME: Should only add this operand for predicated instructions // FIXME: Should only add this operand for predicated instructions
if (Head != "trap") {
Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC),
NameLoc)); NameLoc));
}
// Add the remaining tokens in the mnemonic. // Add the remaining tokens in the mnemonic.
while (Next != StringRef::npos) { while (Next != StringRef::npos) {