[Lldb-commits] [lldb] r125788 - in /lldb/trunk/source/Plugins/Instruction/ARM: EmulateInstructionARM.cpp EmulateInstructionARM.h

Johnny Chen johnny.chen at apple.com
Thu Feb 17 14:37:12 PST 2011


Author: johnny
Date: Thu Feb 17 16:37:12 2011
New Revision: 125788

URL: http://llvm.org/viewvc/llvm-project?rev=125788&view=rev
Log:
Refactoring.  Abstracted the set flags operation into its own helper method
WriteFlags() and renamed WriteCoreRegisterWithFlags() to WriteCoreRegOptionalFlags().
Modified the call sites to use the helper methods.

Modified:
    lldb/trunk/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
    lldb/trunk/source/Plugins/Instruction/ARM/EmulateInstructionARM.h

Modified: lldb/trunk/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp?rev=125788&r1=125787&r2=125788&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp (original)
+++ lldb/trunk/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp Thu Feb 17 16:37:12 2011
@@ -622,7 +622,7 @@
         dwarf_reg.SetRegister (eRegisterKindDWARF, dwarf_r0 + Rm);
         context.SetRegisterPlusOffset (dwarf_reg, 0);
 
-        if (!WriteCoreRegisterWithFlags(context, result, Rd, setflags))
+        if (!WriteCoreRegOptionalFlags(context, result, Rd, setflags))
             return false;
     }
     return true;
@@ -688,7 +688,7 @@
         context.type = EmulateInstruction::eContextImmediate;
         context.SetNoArgs ();
 
-        if (!WriteCoreRegisterWithFlags(context, result, Rd, setflags, carry))
+        if (!WriteCoreRegOptionalFlags(context, result, Rd, setflags, carry))
             return false;
     }
     return true;
@@ -753,7 +753,7 @@
         context.type = EmulateInstruction::eContextImmediate;
         context.SetNoArgs ();
 
-        if (!WriteCoreRegisterWithFlags(context, result, Rd, setflags, carry))
+        if (!WriteCoreRegOptionalFlags(context, result, Rd, setflags, carry))
             return false;
     }
     return true;
@@ -2006,7 +2006,7 @@
         context.type = EmulateInstruction::eContextImmediate;
         context.SetNoArgs ();
 
-        if (!WriteCoreRegisterWithFlags(context, res.result, Rd, setflags, res.carry_out, res.overflow))
+        if (!WriteCoreRegOptionalFlags(context, res.result, Rd, setflags, res.carry_out, res.overflow))
             return false;
     }
     return true;
@@ -2047,24 +2047,14 @@
     if (!success)
         return false;
                   
+    AddWithCarryResult res = AddWithCarry(reg_val, ~imm32, 1);
+
     EmulateInstruction::Context context;
     context.type = EmulateInstruction::eContextImmediate;
     context.SetNoArgs ();
-                  
-    AddWithCarryResult res = AddWithCarry(reg_val, ~imm32, 1);
-    m_new_inst_cpsr = m_inst_cpsr;
-    SetBit32(m_new_inst_cpsr, CPSR_N, Bit32(res.result, CPSR_N));
-    SetBit32(m_new_inst_cpsr, CPSR_Z, res.result == 0 ? 1 : 0);
-    SetBit32(m_new_inst_cpsr, CPSR_C, res.carry_out);
-    SetBit32(m_new_inst_cpsr, CPSR_V, res.overflow);
-    if (m_new_inst_cpsr != m_inst_cpsr)
-    {
-        EmulateInstruction::Context context;
-        context.type = EmulateInstruction::eContextImmediate;
-        context.SetNoArgs ();
-        if (!WriteRegisterUnsigned (context, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS, m_new_inst_cpsr))
-            return false;
-    }
+    if (!WriteFlags(context, res.result, res.carry_out, res.overflow))
+        return false;
+
     return true;
 }
 
@@ -2117,24 +2107,14 @@
     if (!success)
         return false;
                   
+    AddWithCarryResult res = AddWithCarry(reg_val1, ~reg_val2, 1);
+
     EmulateInstruction::Context context;
     context.type = EmulateInstruction::eContextImmediate;
     context.SetNoArgs();
-                  
-    AddWithCarryResult res = AddWithCarry(reg_val1, reg_val2, 1);
-    m_new_inst_cpsr = m_inst_cpsr;
-    SetBit32(m_new_inst_cpsr, CPSR_N, Bit32(res.result, CPSR_N));
-    SetBit32(m_new_inst_cpsr, CPSR_Z, res.result == 0 ? 1 : 0);
-    SetBit32(m_new_inst_cpsr, CPSR_C, res.carry_out);
-    SetBit32(m_new_inst_cpsr, CPSR_V, res.overflow);
-    if (m_new_inst_cpsr != m_inst_cpsr)
-    {
-        EmulateInstruction::Context context;
-        context.type = EmulateInstruction::eContextImmediate;
-        context.SetNoArgs ();
-        if (!WriteRegisterUnsigned (context, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS, m_new_inst_cpsr))
-            return false;
-    }
+    if (!WriteFlags(context, res.result, res.carry_out, res.overflow))
+        return false;
+
     return true;
 }
 
@@ -2438,7 +2418,7 @@
         context.type = EmulateInstruction::eContextImmediate;
         context.SetNoArgs ();
      
-        if (!WriteCoreRegisterWithFlags(context, result, Rd, setflags, carry))
+        if (!WriteCoreRegOptionalFlags(context, result, Rd, setflags, carry))
             return false;
     }
     return true;
@@ -2507,7 +2487,7 @@
         context.type = EmulateInstruction::eContextImmediate;
         context.SetNoArgs ();
      
-        if (!WriteCoreRegisterWithFlags(context, result, Rd, setflags, carry))
+        if (!WriteCoreRegOptionalFlags(context, result, Rd, setflags, carry))
             return false;
     }
     return true;
@@ -4802,12 +4782,12 @@
 // In the above case, the API client does not pass in the overflow arg, which
 // defaults to ~0u.
 bool
-EmulateInstructionARM::WriteCoreRegisterWithFlags (Context &context,
-                                                   const uint32_t result,
-                                                   const uint32_t Rd,
-                                                   bool setflags,
-                                                   const uint32_t carry,
-                                                   const uint32_t overflow)
+EmulateInstructionARM::WriteCoreRegOptionalFlags (Context &context,
+                                                  const uint32_t result,
+                                                  const uint32_t Rd,
+                                                  bool setflags,
+                                                  const uint32_t carry,
+                                                  const uint32_t overflow)
 {
     if (Rd == 15)
     {
@@ -4819,20 +4799,38 @@
         if (!WriteRegisterUnsigned (context, eRegisterKindDWARF, dwarf_r0 + Rd, result))
             return false;
         if (setflags)
-        {
-            m_new_inst_cpsr = m_inst_cpsr;
-            SetBit32(m_new_inst_cpsr, CPSR_N, Bit32(result, CPSR_N));
-            SetBit32(m_new_inst_cpsr, CPSR_Z, result == 0 ? 1 : 0);
-            if (carry != ~0u)
-                SetBit32(m_new_inst_cpsr, CPSR_C, carry);
-            if (overflow != ~0u)
-                SetBit32(m_new_inst_cpsr, CPSR_V, overflow);
-            if (m_new_inst_cpsr != m_inst_cpsr)
-            {
-                if (!WriteRegisterUnsigned (context, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS, m_new_inst_cpsr))
-                    return false;
-            }
-        }
+            return WriteFlags (context, result, carry, overflow);
+    }
+    return true;
+}
+
+// This helper method tries to encapsulate the following pseudocode from the
+// ARM Architecture Reference Manual:
+//
+// APSR.N = result<31>;
+// APSR.Z = IsZeroBit(result);
+// APSR.C = carry;
+// APSR.V = overflow
+//
+// Default arguments can be specified for carry and overflow parameters, which means
+// not to update the respective flags.
+bool
+EmulateInstructionARM::WriteFlags (Context &context,
+                                   const uint32_t result,
+                                   const uint32_t carry,
+                                   const uint32_t overflow)
+{
+    m_new_inst_cpsr = m_inst_cpsr;
+    SetBit32(m_new_inst_cpsr, CPSR_N, Bit32(result, CPSR_N));
+    SetBit32(m_new_inst_cpsr, CPSR_Z, result == 0 ? 1 : 0);
+    if (carry != ~0u)
+        SetBit32(m_new_inst_cpsr, CPSR_C, carry);
+    if (overflow != ~0u)
+        SetBit32(m_new_inst_cpsr, CPSR_V, overflow);
+    if (m_new_inst_cpsr != m_inst_cpsr)
+    {
+        if (!WriteRegisterUnsigned (context, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS, m_new_inst_cpsr))
+            return false;
     }
     return true;
 }

Modified: lldb/trunk/source/Plugins/Instruction/ARM/EmulateInstructionARM.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Instruction/ARM/EmulateInstructionARM.h?rev=125788&r1=125787&r2=125788&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Instruction/ARM/EmulateInstructionARM.h (original)
+++ lldb/trunk/source/Plugins/Instruction/ARM/EmulateInstructionARM.h Thu Feb 17 16:37:12 2011
@@ -194,14 +194,23 @@
 
     // See A8.6.96 MOV (immediate) Operation.
     // Default arguments are specified for carry and overflow parameters, which means
-    // not to update the respective flags if setflags is true.
+    // not to update the respective flags even if setflags is true.
     bool
-    WriteCoreRegisterWithFlags (Context &context,
-                                const uint32_t result,
-                                const uint32_t Rd,
-                                bool setflags,
-                                const uint32_t carry = ~0u,
-                                const uint32_t overflow = ~0u);
+    WriteCoreRegOptionalFlags (Context &context,
+                               const uint32_t result,
+                               const uint32_t Rd,
+                               bool setflags,
+                               const uint32_t carry = ~0u,
+                               const uint32_t overflow = ~0u);
+
+    // See A8.6.35 CMP (immediate) Operation.
+    // Default arguments are specified for carry and overflow parameters, which means
+    // not to update the respective flags.
+    bool
+    WriteFlags (Context &context,
+                const uint32_t result,
+                const uint32_t carry = ~0u,
+                const uint32_t overflow = ~0u);
 
     inline uint64_t
     MemARead (EmulateInstruction::Context &context, 





More information about the lldb-commits mailing list