* m10300-dis.c: Do not emit a comma before a PLUS (autoincrement)
[deliverable/binutils-gdb.git] / opcodes / m32r-asm.c
index 27f5ea98ae8d68fac11a3a7f9c8e0c1c63f73d4b..0531c64e1e94041f1553c3826d38e65ea69090ed 100644 (file)
@@ -1,7 +1,7 @@
 /* Assembler interface for targets using CGEN. -*- C -*-
    CGEN: Cpu tools GENerator
 
-This file is used to generate m32r-asm.c.
+THIS FILE IS USED TO GENERATE m32r-asm.c.
 
 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
 
@@ -18,8 +18,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+along with this program; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "sysdep.h"
 #include <ctype.h>
@@ -28,6 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "bfd.h"
 #include "symcat.h"
 #include "m32r-opc.h"
+#include "opintl.h"
 
 /* ??? The layout of this stuff is still work in progress.
    For speed in assembly/disassembly, we use inline functions.  That of course
@@ -36,127 +37,33 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    compiled with GCC), or switch to macros, or use something else.
 */
 
+static const char * insert_normal
+     PARAMS ((long, unsigned int, int, int, int, char *));
 static const char * parse_insn_normal
      PARAMS ((const CGEN_INSN *, const char **, CGEN_FIELDS *));
 static const char * insert_insn_normal
-     PARAMS ((const CGEN_INSN *, CGEN_FIELDS *, cgen_insn_t *));
+     PARAMS ((const CGEN_INSN *, CGEN_FIELDS *, cgen_insn_t *, bfd_vma));
 \f
-/* Default insertion routine.
-
-   ATTRS is a mask of the boolean attributes.
-   LENGTH is the length of VALUE in bits.
-   TOTAL_LENGTH is the total length of the insn (currently 8,16,32).
-
-   The result is an error message or NULL if success.  */
+/* -- assembler routines inserted here */
+/* -- asm.c */
 
-/* ??? This duplicates functionality with bfd's howto table and
-   bfd_install_relocation.  */
-/* ??? For architectures where insns can be representable as ints,
-   store insn in `field' struct and add registers, etc. while parsing?  */
+/* Handle '#' prefixes (i.e. skip over them).  */
 
 static const char *
-insert_normal (value, attrs, start, length, shift, total_length, buffer)
-     long value;
-     unsigned int attrs;
-     int start;
-     int length;
-     int shift;
-     int total_length;
-     char * buffer;
+parse_hash (strp, opindex, valuep)
+     const char **strp;
+     int opindex;
+     unsigned long *valuep;
 {
-  bfd_vma x;
-  static char buf[100];
-
-  if (shift < 0)
-    value <<= -shift;
-  else
-    value >>= shift;
-
-  /* Ensure VALUE will fit.  */
-  if ((attrs & (1 << CGEN_OPERAND_UNSIGNED)) != 0)
-    {
-      unsigned long max = (1 << length) - 1;
-      if ((unsigned long) value > max)
-       {
-         const char *err = "operand out of range (%lu not between 0 and %lu)";
-
-         sprintf (buf, err, value, max);
-         return buf;
-       }
-    }
-  else
-    {
-      long min = - (1 << (length - 1));
-      long max = (1 << (length - 1)) - 1;
-      if (value < min || value > max)
-       {
-         const char *err = "operand out of range (%ld not between %ld and %ld)";
-
-         sprintf (buf, err, value, min, max);
-         return buf;
-       }
-    }
-
-#if 0 /*def CGEN_INT_INSN*/
-  *buffer |= ((value & ((1 << length) - 1))
-             << (total_length - (start + length)));
-#else
-  switch (total_length)
-    {
-    case 8:
-      x = * (unsigned char *) buffer;
-      break;
-    case 16:
-      if (CGEN_CURRENT_ENDIAN == CGEN_ENDIAN_BIG)
-       x = bfd_getb16 (buffer);
-      else
-       x = bfd_getl16 (buffer);
-      break;
-    case 32:
-      if (CGEN_CURRENT_ENDIAN == CGEN_ENDIAN_BIG)
-       x = bfd_getb32 (buffer);
-      else
-       x = bfd_getl32 (buffer);
-      break;
-    default :
-      abort ();
-    }
-
-  x |= ((value & ((1 << length) - 1))
-       << (total_length - (start + length)));
-
-  switch (total_length)
-    {
-    case 8:
-      * buffer = value;
-      break;
-    case 16:
-      if (CGEN_CURRENT_ENDIAN == CGEN_ENDIAN_BIG)
-       bfd_putb16 (x, buffer);
-      else
-       bfd_putl16 (x, buffer);
-      break;
-    case 32:
-      if (CGEN_CURRENT_ENDIAN == CGEN_ENDIAN_BIG)
-       bfd_putb32 (x, buffer);
-      else
-       bfd_putl32 (x, buffer);
-      break;
-    default :
-      abort ();
-    }
-#endif
-
+  if (**strp == '#')
+    ++*strp;
   return NULL;
 }
-\f
-/* -- assembler routines inserted here */
-/* -- asm.c */
 
 /* Handle shigh(), high().  */
 
 static const char *
-parse_h_hi16 (strp, opindex, valuep)
+parse_hi16 (strp, opindex, valuep)
      const char **strp;
      int opindex;
      unsigned long *valuep;
@@ -164,11 +71,10 @@ parse_h_hi16 (strp, opindex, valuep)
   const char *errmsg;
   enum cgen_parse_operand_result result_type;
 
-  /* FIXME: Need # in assembler syntax (means '#' is optional).  */
   if (**strp == '#')
     ++*strp;
 
-  if (strncmp (*strp, "high(", 5) == 0)
+  if (strncasecmp (*strp, "high(", 5) == 0)
     {
       *strp += 5;
       errmsg = cgen_parse_address (strp, opindex, BFD_RELOC_M32R_HI16_ULO,
@@ -181,7 +87,7 @@ parse_h_hi16 (strp, opindex, valuep)
        *valuep >>= 16;
       return errmsg;
     }
-  else if (strncmp (*strp, "shigh(", 6) == 0)
+  else if (strncasecmp (*strp, "shigh(", 6) == 0)
     {
       *strp += 6;
       errmsg = cgen_parse_address (strp, opindex, BFD_RELOC_M32R_HI16_SLO,
@@ -203,7 +109,7 @@ parse_h_hi16 (strp, opindex, valuep)
    handles the case where low() isn't present.  */
 
 static const char *
-parse_h_slo16 (strp, opindex, valuep)
+parse_slo16 (strp, opindex, valuep)
      const char **strp;
      int opindex;
      long *valuep;
@@ -211,11 +117,10 @@ parse_h_slo16 (strp, opindex, valuep)
   const char *errmsg;
   enum cgen_parse_operand_result result_type;
 
-  /* FIXME: Need # in assembler syntax (means '#' is optional).  */
   if (**strp == '#')
     ++*strp;
 
-  if (strncmp (*strp, "low(", 4) == 0)
+  if (strncasecmp (*strp, "low(", 4) == 0)
     {
       *strp += 4;
       errmsg = cgen_parse_address (strp, opindex, BFD_RELOC_M32R_LO16,
@@ -229,7 +134,7 @@ parse_h_slo16 (strp, opindex, valuep)
       return errmsg;
     }
 
-  if (strncmp (*strp, "sda(", 4) == 0)
+  if (strncasecmp (*strp, "sda(", 4) == 0)
     {
       *strp += 4;
       errmsg = cgen_parse_address (strp, opindex, BFD_RELOC_M32R_SDA16, NULL, valuep);
@@ -247,7 +152,7 @@ parse_h_slo16 (strp, opindex, valuep)
    handles the case where low() isn't present.  */
 
 static const char *
-parse_h_ulo16 (strp, opindex, valuep)
+parse_ulo16 (strp, opindex, valuep)
      const char **strp;
      int opindex;
      unsigned long *valuep;
@@ -255,11 +160,10 @@ parse_h_ulo16 (strp, opindex, valuep)
   const char *errmsg;
   enum cgen_parse_operand_result result_type;
 
-  /* FIXME: Need # in assembler syntax (means '#' is optional).  */
   if (**strp == '#')
     ++*strp;
 
-  if (strncmp (*strp, "low(", 4) == 0)
+  if (strncasecmp (*strp, "low(", 4) == 0)
     {
       *strp += 4;
       errmsg = cgen_parse_address (strp, opindex, BFD_RELOC_M32R_LO16,
@@ -355,14 +259,17 @@ m32r_cgen_parse_operand (opindex, strp, fields)
       errmsg = cgen_parse_keyword (strp, & m32r_cgen_opval_h_accums, & fields->f_acc);
       break;
 /* end-sanitize-m32rx */
+    case M32R_OPERAND_HASH :
+      errmsg = parse_hash (strp, M32R_OPERAND_HASH, &fields->f_nil);
+      break;
     case M32R_OPERAND_HI16 :
-      errmsg = parse_h_hi16 (strp, M32R_OPERAND_HI16, &fields->f_hi16);
+      errmsg = parse_hi16 (strp, M32R_OPERAND_HI16, &fields->f_hi16);
       break;
     case M32R_OPERAND_SLO16 :
-      errmsg = parse_h_slo16 (strp, M32R_OPERAND_SLO16, &fields->f_simm16);
+      errmsg = parse_slo16 (strp, M32R_OPERAND_SLO16, &fields->f_simm16);
       break;
     case M32R_OPERAND_ULO16 :
-      errmsg = parse_h_ulo16 (strp, M32R_OPERAND_ULO16, &fields->f_uimm16);
+      errmsg = parse_ulo16 (strp, M32R_OPERAND_ULO16, &fields->f_uimm16);
       break;
     case M32R_OPERAND_UIMM24 :
       errmsg = cgen_parse_address (strp, M32R_OPERAND_UIMM24, 0, NULL, & fields->f_uimm24);
@@ -378,7 +285,8 @@ m32r_cgen_parse_operand (opindex, strp, fields)
       break;
 
     default :
-      fprintf (stderr, "Unrecognized field %d while parsing.\n", opindex);
+      /* xgettext:c-format */
+      fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
       abort ();
   }
 
@@ -401,104 +309,113 @@ m32r_cgen_parse_operand (opindex, strp, fields)
 */
 
 const char *
-m32r_cgen_insert_operand (opindex, fields, buffer)
+m32r_cgen_insert_operand (opindex, fields, buffer, pc)
      int opindex;
      CGEN_FIELDS * fields;
      char * buffer;
+     bfd_vma pc;
 {
   const char * errmsg;
 
   switch (opindex)
     {
     case M32R_OPERAND_SR :
-      errmsg = insert_normal (fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_DR :
-      errmsg = insert_normal (fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 4, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_SRC1 :
-      errmsg = insert_normal (fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 4, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_SRC2 :
-      errmsg = insert_normal (fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_SCR :
-      errmsg = insert_normal (fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_DCR :
-      errmsg = insert_normal (fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 4, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_SIMM8 :
-      errmsg = insert_normal (fields->f_simm8, 0, 8, 8, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_simm8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), 8, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_SIMM16 :
-      errmsg = insert_normal (fields->f_simm16, 0, 16, 16, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_simm16, 0|(1<<CGEN_OPERAND_HASH_PREFIX), 16, 16, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_UIMM4 :
-      errmsg = insert_normal (fields->f_uimm4, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_uimm4, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_UIMM5 :
-      errmsg = insert_normal (fields->f_uimm5, 0|(1<<CGEN_OPERAND_UNSIGNED), 11, 5, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_uimm5, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 11, 5, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_UIMM16 :
-      errmsg = insert_normal (fields->f_uimm16, 0|(1<<CGEN_OPERAND_UNSIGNED), 16, 16, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_uimm16, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 16, 16, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
 /* start-sanitize-m32rx */
     case M32R_OPERAND_IMM1 :
       {
-        long value = ((fields->f_imm1) - (1));
-        errmsg = insert_normal (value, 0|(1<<CGEN_OPERAND_UNSIGNED), 15, 1, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+        long value = fields->f_imm1;
+        value = ((value) - (1));
+        errmsg = insert_normal (value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 15, 1, CGEN_FIELDS_BITSIZE (fields), buffer);
       }
       break;
 /* end-sanitize-m32rx */
 /* start-sanitize-m32rx */
     case M32R_OPERAND_ACCD :
-      errmsg = insert_normal (fields->f_accd, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 2, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_accd, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 2, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
 /* end-sanitize-m32rx */
 /* start-sanitize-m32rx */
     case M32R_OPERAND_ACCS :
-      errmsg = insert_normal (fields->f_accs, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 2, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_accs, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 2, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
 /* end-sanitize-m32rx */
 /* start-sanitize-m32rx */
     case M32R_OPERAND_ACC :
-      errmsg = insert_normal (fields->f_acc, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 1, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_acc, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 1, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
 /* end-sanitize-m32rx */
+    case M32R_OPERAND_HASH :
+      errmsg = insert_normal (fields->f_nil, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      break;
     case M32R_OPERAND_HI16 :
-      errmsg = insert_normal (fields->f_hi16, 0|(1<<CGEN_OPERAND_SIGN_OPT)|(1<<CGEN_OPERAND_UNSIGNED), 16, 16, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_hi16, 0|(1<<CGEN_OPERAND_SIGN_OPT)|(1<<CGEN_OPERAND_UNSIGNED), 16, 16, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_SLO16 :
-      errmsg = insert_normal (fields->f_simm16, 0, 16, 16, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_simm16, 0, 16, 16, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_ULO16 :
-      errmsg = insert_normal (fields->f_uimm16, 0|(1<<CGEN_OPERAND_UNSIGNED), 16, 16, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_uimm16, 0|(1<<CGEN_OPERAND_UNSIGNED), 16, 16, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_UIMM24 :
-      errmsg = insert_normal (fields->f_uimm24, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR)|(1<<CGEN_OPERAND_UNSIGNED), 8, 24, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+      errmsg = insert_normal (fields->f_uimm24, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR)|(1<<CGEN_OPERAND_UNSIGNED), 8, 24, CGEN_FIELDS_BITSIZE (fields), buffer);
       break;
     case M32R_OPERAND_DISP8 :
       {
-        long value = ((fields->f_disp8) >> (2));
-        errmsg = insert_normal (value, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 8, 8, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+        long value = fields->f_disp8;
+        value = ((int) (((value) - (((pc) & (-4))))) >> (2));
+        errmsg = insert_normal (value, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 8, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
       }
       break;
     case M32R_OPERAND_DISP16 :
       {
-        long value = ((fields->f_disp16) >> (2));
-        errmsg = insert_normal (value, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 16, 16, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+        long value = fields->f_disp16;
+        value = ((int) (((value) - (pc))) >> (2));
+        errmsg = insert_normal (value, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 16, 16, CGEN_FIELDS_BITSIZE (fields), buffer);
       }
       break;
     case M32R_OPERAND_DISP24 :
       {
-        long value = ((fields->f_disp24) >> (2));
-        errmsg = insert_normal (value, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 8, 24, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
+        long value = fields->f_disp24;
+        value = ((int) (((value) - (pc))) >> (2));
+        errmsg = insert_normal (value, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 8, 24, CGEN_FIELDS_BITSIZE (fields), buffer);
       }
       break;
 
     default :
-      fprintf (stderr, "Unrecognized field %d while building insn.\n",
+      /* xgettext:c-format */
+      fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
               opindex);
       abort ();
   }
@@ -524,10 +441,119 @@ m32r_cgen_init_asm (mach, endian)
      enum cgen_endian endian;
 {
   m32r_cgen_init_tables (mach);
-  cgen_set_cpu (& m32r_cgen_opcode_data, mach, endian);
+  cgen_set_cpu (& m32r_cgen_opcode_table, mach, endian);
   cgen_asm_init ();
 }
 
+\f
+/* Default insertion routine.
+
+   ATTRS is a mask of the boolean attributes.
+   LENGTH is the length of VALUE in bits.
+   TOTAL_LENGTH is the total length of the insn (currently 8,16,32).
+
+   The result is an error message or NULL if success.  */
+
+/* ??? This duplicates functionality with bfd's howto table and
+   bfd_install_relocation.  */
+/* ??? For architectures where insns can be representable as ints,
+   store insn in `field' struct and add registers, etc. while parsing?  */
+
+static const char *
+insert_normal (value, attrs, start, length, total_length, buffer)
+     long value;
+     unsigned int attrs;
+     int start;
+     int length;
+     int total_length;
+     char * buffer;
+{
+  bfd_vma x;
+  static char buf[100];
+  /* Written this way to avoid undefined behaviour.
+     Yes, `long' will be bfd_vma but not yet.  */
+  long mask = (((1L << (length - 1)) - 1) << 1) | 1;
+
+  /* If LENGTH is zero, this operand doesn't contribute to the value.  */
+  if (length == 0)
+    return NULL;
+
+  /* Ensure VALUE will fit.  */
+  if ((attrs & CGEN_ATTR_MASK (CGEN_OPERAND_UNSIGNED)) != 0)
+    {
+      unsigned long max = mask;
+      if ((unsigned long) value > max)
+       {
+         /* xgettext:c-format */
+         sprintf (buf, _("operand out of range (%lu not between 0 and %lu)"),
+                  value, max);
+         return buf;
+       }
+    }
+  else
+    {
+      long min = - (1L << (length - 1));
+      long max = (1L << (length - 1)) - 1;
+      if (value < min || value > max)
+       {
+         sprintf
+           /* xgettext:c-format */
+           (buf, _("operand out of range (%ld not between %ld and %ld)"),
+            value, min, max);
+         return buf;
+       }
+    }
+
+#if 0 /*def CGEN_INT_INSN*/
+  *buffer |= (value & mask) << (total_length - (start + length));
+#else
+  switch (total_length)
+    {
+    case 8:
+      x = * (unsigned char *) buffer;
+      break;
+    case 16:
+      if (CGEN_CURRENT_ENDIAN == CGEN_ENDIAN_BIG)
+       x = bfd_getb16 (buffer);
+      else
+       x = bfd_getl16 (buffer);
+      break;
+    case 32:
+      if (CGEN_CURRENT_ENDIAN == CGEN_ENDIAN_BIG)
+       x = bfd_getb32 (buffer);
+      else
+       x = bfd_getl32 (buffer);
+      break;
+    default :
+      abort ();
+    }
+
+  x |= (value & mask) << (total_length - (start + length));
+
+  switch (total_length)
+    {
+    case 8:
+      * buffer = value;
+      break;
+    case 16:
+      if (CGEN_CURRENT_ENDIAN == CGEN_ENDIAN_BIG)
+       bfd_putb16 (x, buffer);
+      else
+       bfd_putl16 (x, buffer);
+      break;
+    case 32:
+      if (CGEN_CURRENT_ENDIAN == CGEN_ENDIAN_BIG)
+       bfd_putb32 (x, buffer);
+      else
+       bfd_putl32 (x, buffer);
+      break;
+    default :
+      abort ();
+    }
+#endif
+
+  return NULL;
+}
 \f
 /* Default insn parser.
 
@@ -555,6 +581,7 @@ parse_insn_normal (insn, strp, fields)
   const char * p;
   const unsigned char * syn;
 #ifdef CGEN_MNEMONIC_OPERANDS
+  /* FIXME: wip */
   int past_opcode_p;
 #endif
 
@@ -563,8 +590,9 @@ parse_insn_normal (insn, strp, fields)
   p = CGEN_INSN_MNEMONIC (insn);
   while (* p && * p == * str)
     ++ p, ++ str;
+  
   if (* p || (* str && !isspace (* str)))
-    return "unrecognized instruction";
+    return _("unrecognized instruction");
 
   CGEN_INIT_PARSE ();
   cgen_init_parse_operand ();
@@ -585,7 +613,6 @@ parse_insn_normal (insn, strp, fields)
   while (* syn != 0)
     {
       /* Non operand chars must match exactly.  */
-      /* FIXME: Need to better handle whitespace.  */
       if (CGEN_SYNTAX_CHAR_P (* syn))
        {
          if (*str == CGEN_SYNTAX_CHAR (* syn))
@@ -602,7 +629,7 @@ parse_insn_normal (insn, strp, fields)
              /* Syntax char didn't match.  Can't be this insn.  */
              /* FIXME: would like to return something like
                 "expected char `c'" */
-             return "syntax error";
+             return _("syntax error");
            }
          continue;
        }
@@ -628,7 +655,7 @@ parse_insn_normal (insn, strp, fields)
        ++ str;
 
       if (* str != '\0')
-       return "junk at end of line"; /* FIXME: would like to include `str' */
+       return _("junk at end of line"); /* FIXME: would like to include `str' */
 
       return NULL;
     }
@@ -643,10 +670,11 @@ parse_insn_normal (insn, strp, fields)
 /* FIXME: change buffer to char *?  */
 
 static const char *
-insert_insn_normal (insn, fields, buffer)
+insert_insn_normal (insn, fields, buffer, pc)
      const CGEN_INSN * insn;
      CGEN_FIELDS * fields;
      cgen_insn_t * buffer;
+     bfd_vma pc;
 {
   const CGEN_SYNTAX * syntax = CGEN_INSN_SYNTAX (insn);
   bfd_vma value;
@@ -695,7 +723,7 @@ insert_insn_normal (insn, fields, buffer)
        continue;
 
       errmsg = m32r_cgen_insert_operand (CGEN_SYNTAX_FIELD (*syn), fields,
-                                          (char *) buffer);
+                                          (char *) buffer, pc);
       if (errmsg)
        return errmsg;
     }
@@ -707,9 +735,14 @@ insert_insn_normal (insn, fields, buffer)
    This routine is called for each instruction to be assembled.
    STR points to the insn to be assembled.
    We assume all necessary tables have been initialized.
+   The assembled instruction, less any fixups, is stored in buf.
+   [??? What byte order?]
    The result is a pointer to the insn's entry in the opcode table,
    or NULL if an error occured (an error message will have already been
-   printed).  */
+   printed).
+
+   Note that when processing (non-alias) macro-insns,
+   this function recurses.  */
 
 const CGEN_INSN *
 m32r_cgen_assemble_insn (str, fields, buf, errmsg)
@@ -742,13 +775,11 @@ m32r_cgen_assemble_insn (str, fields, buf, errmsg)
        continue;
 #endif
 
-#if 1 /* FIXME: wip */
       /* If the RELAX attribute is set, this is an insn that shouldn't be
         chosen immediately.  Instead, it is used during assembler/linker
         relaxation if possible.  */
       if (CGEN_INSN_ATTR (insn, CGEN_INSN_RELAX) != 0)
        continue;
-#endif
 
       str = start;
 
@@ -759,7 +790,8 @@ m32r_cgen_assemble_insn (str, fields, buf, errmsg)
 
       if (! CGEN_PARSE_FN (insn) (insn, & str, fields))
        {
-         if (CGEN_INSERT_FN (insn) (insn, fields, buf) != NULL)
+         /* ??? 0 is passed for `pc' */
+         if (CGEN_INSERT_FN (insn) (insn, fields, buf, (bfd_vma) 0) != NULL)
            continue;
          /* It is up to the caller to actually output the insn and any
             queued relocs.  */
@@ -773,8 +805,13 @@ m32r_cgen_assemble_insn (str, fields, buf, errmsg)
      Need to track why it failed and pick the right one.  */
   {
     static char errbuf[100];
-    sprintf (errbuf, "bad instruction `%.50s%s'",
-            start, strlen (start) > 50 ? "..." : "");
+    if (strlen (start) > 50)
+      /* xgettext:c-format */
+      sprintf (errbuf, _("bad instruction `%.50s...'"), start);
+    else 
+      /* xgettext:c-format */
+      sprintf (errbuf, _("bad instruction `%.50s'"), start);
+      
     *errmsg = errbuf;
     return NULL;
   }
This page took 0.031723 seconds and 4 git commands to generate.