MC/ARM: Add an ARMOperand class for condition codes.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 11 Aug 2010 06:36:53 +0000 (06:36 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 11 Aug 2010 06:36:53 +0000 (06:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110788 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMInstrFormats.td
lib/Target/ARM/AsmParser/ARMAsmParser.cpp

index a0f887b41d2b4876cdf7ceaa171f2375d5fb927f..25c94331a4c3466d2381c4adfcdfdc91991c955c 100644 (file)
@@ -138,11 +138,17 @@ def VFPNeonDomain : Domain<3>; // Instructions in both VFP & Neon domains
 // ARM special operands.
 //
 
+def CondCodeOperand : AsmOperandClass {
+  let Name = "CondCode";
+  let SuperClasses = [];
+}
+
 // ARM Predicate operand. Default to 14 = always (AL). Second part is CC
 // register whose default is 0 (no register).
 def pred : PredicateOperand<OtherVT, (ops i32imm, CCR),
                                      (ops (i32 14), (i32 zero_reg))> {
   let PrintMethod = "printPredicateOperand";
+  let ParserMatchClass = CondCodeOperand;
 }
 
 // Conditional code result for instructions whose 's' bit is set, e.g. subs.
index b3d956e8cd3cdabe6a829573c454cbf9acb43ad8..19d7d9aa47984e1501883571d19a1d34c2dfb238 100644 (file)
@@ -106,15 +106,20 @@ private:
   ARMOperand() {}
 public:
   enum KindTy {
-    Token,
-    Register,
+    CondCode,
     Immediate,
-    Memory
+    Memory,
+    Register,
+    Token
   } Kind;
 
   SMLoc StartLoc, EndLoc;
 
   union {
+    struct {
+      ARMCC::CondCodes Val;
+    } CC;
+
     struct {
       const char *Data;
       unsigned Length;
@@ -155,8 +160,11 @@ public:
     StartLoc = o.StartLoc;
     EndLoc = o.EndLoc;
     switch (Kind) {
+    case CondCode:
+      CC = o.CC;
+      break;
     case Token:
-    Tok = o.Tok;
+      Tok = o.Tok;
       break;
     case Register:
       Reg = o.Reg;
@@ -175,6 +183,11 @@ public:
   /// getEndLoc - Get the location of the last token of this operand.
   SMLoc getEndLoc() const { return EndLoc; }
 
+  ARMCC::CondCodes getCondCode() const {
+    assert(Kind == CondCode && "Invalid access!");
+    return CC.Val;
+  }
+
   StringRef getToken() const {
     assert(Kind == Token && "Invalid access!");
     return StringRef(Tok.Data, Tok.Length);
@@ -190,6 +203,8 @@ public:
     return Imm.Val;
   }
 
+  bool isCondCode() const { return Kind == CondCode; }
+
   bool isImm() const { return Kind == Immediate; }
 
   bool isReg() const { return Kind == Register; }
@@ -204,6 +219,11 @@ public:
       Inst.addOperand(MCOperand::CreateExpr(Expr));
   }
 
+  void addCondCodeOperands(MCInst &Inst, unsigned N) const {
+    assert(N == 1 && "Invalid number of operands!");
+    Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
+  }
+
   void addRegOperands(MCInst &Inst, unsigned N) const {
     assert(N == 1 && "Invalid number of operands!");
     Inst.addOperand(MCOperand::CreateReg(getReg()));