MC/ARM/AsmParser: Split out SplitMnemonicAndCC().
authorDaniel Dunbar <daniel@zuster.org>
Mon, 10 Jan 2011 12:24:52 +0000 (12:24 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 10 Jan 2011 12:24:52 +0000 (12:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123169 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/AsmParser/ARMAsmParser.cpp

index 8322d70cedbc29db70b60d4320bb8b33e08745d5..ed664e9554752f1cdb403d9d47d42a8a8b64a9e0 100644 (file)
@@ -866,19 +866,20 @@ bool ARMAsmParser::ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands){
   }
 }
 
-/// 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.
+// FIXME: Would be nice to autogen this.
+static unsigned SplitMnemonicAndCC(StringRef &Mnemonic) {
+  // Ignore some mnemonics we know aren't predicated forms.
+  if (Mnemonic == "movs" ||
+      Mnemonic == "vmls" ||
+      Mnemonic == "vnmls")
+    return ARMCC::AL;
+
+  // Otherwise, determine the predicate.
   //
   // 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
   // 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("ne", ARMCC::NE)
     .Case("hs", ARMCC::HS)
@@ -895,20 +896,31 @@ bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
     .Case("le", ARMCC::LE)
     .Case("al", ARMCC::AL)
     .Default(~0U);
-
-  if (CC == ~0U ||
-      (CC == ARMCC::LS && (Head == "vmls" || Head == "vnmls"))) {
-    CC = ARMCC::AL;
-  } else {
-    Head = Head.slice(0, Head.size() - 2);
+  if (CC != ~0U) {
+    Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
+    return CC;
   }
 
+  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));
 
-  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),
                                                   NameLoc));
+  }
 
   // Add the remaining tokens in the mnemonic.
   while (Next != StringRef::npos) {