ARM Asm parser range checking for [0,31] immediates.
authorJim Grosbach <grosbach@apple.com>
Thu, 21 Jul 2011 23:26:25 +0000 (23:26 +0000)
committerJim Grosbach <grosbach@apple.com>
Thu, 21 Jul 2011 23:26:25 +0000 (23:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135719 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 41808c533280df04b281e2676d99904e3942df03..2c26ae010458c99e0679c4dc9064ef586ea2ccdf 100644 (file)
@@ -497,6 +497,7 @@ def imm0_15 : Operand<i32>, ImmLeaf<i32, [{
 }
 
 /// imm0_31 predicate - True if the 32-bit immediate is in the range [0,31].
+def Imm0_31AsmOperand: AsmOperandClass { let Name = "Imm0_31"; }
 def imm0_31 : Operand<i32>, ImmLeaf<i32, [{
   return Imm >= 0 && Imm < 32;
 }]>;
index 5fc78499610920f789023134a575cdecd472b297..827ad0fb9f9ae49be87d2f57601eab37bba7978c 100644 (file)
@@ -418,6 +418,14 @@ public:
     int64_t Value = CE->getValue();
     return Value >= 0 && Value < 16;
   }
+  bool isImm0_31() const {
+    if (Kind != Immediate)
+      return false;
+    const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
+    if (!CE) return false;
+    int64_t Value = CE->getValue();
+    return Value >= 0 && Value < 32;
+  }
   bool isImm0_65535() const {
     if (Kind != Immediate)
       return false;
@@ -672,6 +680,11 @@ public:
     addExpr(Inst, getImm());
   }
 
+  void addImm0_31Operands(MCInst &Inst, unsigned N) const {
+    assert(N == 1 && "Invalid number of operands!");
+    addExpr(Inst, getImm());
+  }
+
   void addImm0_65535Operands(MCInst &Inst, unsigned N) const {
     assert(N == 1 && "Invalid number of operands!");
     addExpr(Inst, getImm());