Thumb assembly parsing and encoding for LDRH.
authorJim Grosbach <grosbach@apple.com>
Fri, 19 Aug 2011 18:55:51 +0000 (18:55 +0000)
committerJim Grosbach <grosbach@apple.com>
Fri, 19 Aug 2011 18:55:51 +0000 (18:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138060 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMInstrThumb.td
lib/Target/ARM/AsmParser/ARMAsmParser.cpp
test/MC/ARM/basic-thumb-instructions.s

index 35a745aa78a23c01da9d0cd9c6d639f9f56d4078..edc4660034f615cb45bed94ae685c8a61b902b60 100644 (file)
@@ -169,11 +169,13 @@ def t_addrmode_is4 : Operand<i32>,
 
 // t_addrmode_is2 := reg + imm5 * 2
 //
+def t_addrmode_is2_asm_operand : AsmOperandClass { let Name = "MemThumbRIs2"; }
 def t_addrmode_is2 : Operand<i32>,
                      ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
   let EncoderMethod = "getAddrModeISOpValue";
   let DecoderMethod = "DecodeThumbAddrModeIS";
   let PrintMethod = "printThumbAddrModeImm5S2Operand";
+  let ParserMatchClass = t_addrmode_is2_asm_operand;
   let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
 }
 
index d04b9b73cc4dae299f02cf02f0e67ec79d9f6688..60f16f836258f310b32e2808f160ae4aedc3e981 100644 (file)
@@ -628,6 +628,15 @@ public:
     int64_t Val = Mem.OffsetImm->getValue();
     return Val >= 0 && Val <= 124 && (Val % 4) == 0;
   }
+  bool isMemThumbRIs2() const {
+    if (Kind != Memory || Mem.OffsetRegNum != 0 ||
+        !isARMLowRegister(Mem.BaseRegNum))
+      return false;
+    // Immediate offset, multiple of 4 in range [0, 62].
+    if (!Mem.OffsetImm) return true;
+    int64_t Val = Mem.OffsetImm->getValue();
+    return Val >= 0 && Val <= 62 && (Val % 2) == 0;
+  }
   bool isMemThumbRIs1() const {
     if (Kind != Memory || Mem.OffsetRegNum != 0 ||
         !isARMLowRegister(Mem.BaseRegNum))
@@ -1009,6 +1018,13 @@ public:
     Inst.addOperand(MCOperand::CreateImm(Val));
   }
 
+  void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
+    assert(N == 2 && "Invalid number of operands!");
+    int64_t Val = Mem.OffsetImm ? (Mem.OffsetImm->getValue() / 2) : 0;
+    Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
+    Inst.addOperand(MCOperand::CreateImm(Val));
+  }
+
   void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
     assert(N == 2 && "Invalid number of operands!");
     int64_t Val = Mem.OffsetImm ? (Mem.OffsetImm->getValue()) : 0;
index 4a45820b88a1a52a1d72db4d4d9ca2a81d7fbf5e..591c6c6dd0bef6303ca5525bef38663a5370c597 100644 (file)
@@ -230,3 +230,23 @@ _func:
         ldrb r6, [r4, r5]
 
 @ CHECK: ldrb  r6, [r4, r5]            @ encoding: [0x66,0x5d]
+
+
+@------------------------------------------------------------------------------
+@ LDRH (immediate)
+@------------------------------------------------------------------------------
+        ldrh r3, [r3]
+        ldrh r4, [r6, #2]
+        ldrh r5, [r7, #62]
+
+@ CHECK: ldrh  r3, [r3]                @ encoding: [0x1b,0x88]
+@ CHECK: ldrh  r4, [r6, #2]            @ encoding: [0x74,0x88]
+@ CHECK: ldrh  r5, [r7, #62]           @ encoding: [0xfd,0x8f]
+
+
+@------------------------------------------------------------------------------
+@ LDRH (register)
+@------------------------------------------------------------------------------
+        ldrh r6, [r2, r6]
+
+@ CHECK: ldrh  r6, [r2, r6]            @ encoding: [0x96,0x5b]