[PATCH 6/6] S/390: Various minor simplifications in disassembler

Andreas Arnez arnez@linux.vnet.ibm.com
Fri Jul 25 17:02:00 GMT 2014


opcodes/
	* s390-dis.c (s390_insn_length): Simplify formula for return
	value.
	(s390_print_insn_with_opcode): Avoid special handling for the
	separator before the first operand.  Use new local variable
	'flags' in place of 'operand->flags'.
---
 opcodes/s390-dis.c | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c
index 891970f..5cfc72b 100644
--- a/opcodes/s390-dis.c
+++ b/opcodes/s390-dis.c
@@ -71,7 +71,7 @@ static inline int
 s390_insn_length (const bfd_byte *buffer)
 {
   /* 00xxxxxx -> 2, 01xxxxxx/10xxxxxx -> 4, 11xxxxxx -> 6.  */
-  return ((((buffer[0] >> 6) + 1) >> 1) + 1) << 1;
+  return ((buffer[0] >> 6) + 3) & ~1U;
 }
 
 /* Match the instruction in BUFFER against the given OPCODE, excluding
@@ -158,50 +158,46 @@ s390_print_insn_with_opcode (bfd_vma memaddr,
   const unsigned char *opindex;
   char separator;
 
-  if (opcode->operands[0] != 0)
-    info->fprintf_func (info->stream, "%s\t", opcode->name);
-  else
-    info->fprintf_func (info->stream, "%s", opcode->name);
+  /* Mnemonic.  */
+  info->fprintf_func (info->stream, "%s", opcode->name);
 
-  /* Extract the operands.  */
-  separator = 0;
+  /* Operands.  */
+  separator = '\t';
   for (opindex = opcode->operands; *opindex != 0; opindex++)
     {
       const struct s390_operand *operand = s390_operands + *opindex;
       union operand_value val = s390_extract_operand (buffer, operand);
+      unsigned long flags = operand->flags;
 
-      if ((operand->flags & S390_OPERAND_INDEX) && val.u == 0)
+      if ((flags & S390_OPERAND_INDEX) && val.u == 0)
 	continue;
-      if ((operand->flags & S390_OPERAND_BASE) &&
+      if ((flags & S390_OPERAND_BASE) &&
 	  val.u == 0 && separator == '(')
 	{
 	  separator = ',';
 	  continue;
 	}
 
-      if (separator)
-	info->fprintf_func (info->stream, "%c", separator);
+      info->fprintf_func (info->stream, "%c", separator);
 
-      if (operand->flags & S390_OPERAND_GPR)
+      if (flags & S390_OPERAND_GPR)
 	info->fprintf_func (info->stream, "%%r%u", val.u);
-      else if (operand->flags & S390_OPERAND_FPR)
+      else if (flags & S390_OPERAND_FPR)
 	info->fprintf_func (info->stream, "%%f%u", val.u);
-      else if (operand->flags & S390_OPERAND_AR)
+      else if (flags & S390_OPERAND_AR)
 	info->fprintf_func (info->stream, "%%a%u", val.u);
-      else if (operand->flags & S390_OPERAND_CR)
+      else if (flags & S390_OPERAND_CR)
 	info->fprintf_func (info->stream, "%%c%u", val.u);
-      else if (operand->flags & S390_OPERAND_PCREL)
+      else if (flags & S390_OPERAND_PCREL)
 	info->print_address_func (memaddr + val.i + val.i, info);
-      else if (operand->flags & S390_OPERAND_SIGNED)
+      else if (flags & S390_OPERAND_SIGNED)
 	info->fprintf_func (info->stream, "%i", val.i);
       else
 	info->fprintf_func (info->stream, "%u", val.u);
 
-      if (operand->flags & S390_OPERAND_DISP)
-	{
-	  separator = '(';
-	}
-      else if (operand->flags & S390_OPERAND_BASE)
+      if (flags & S390_OPERAND_DISP)
+	separator = '(';
+      else if (flags & S390_OPERAND_BASE)
 	{
 	  info->fprintf_func (info->stream, ")");
 	  separator = ',';
-- 
1.8.4.2



More information about the Binutils mailing list