This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch for case of max operands > 127


I would like to propose the following patch to handle the case where the
number of CGEN operands ends up being > 127.  The CGEN syntax string uses
characters intermixed with operands by encoding operands as operand_value +128.
When processing, it checks for characters by checking if the value is
<= 127.  In some cases, the number of operands ends up being >127 so there
isn't enough room in a char to store all characters plus operands.

This patch makes a check for MAX_OPERANDS and sets the type of the syntax string 
to be either unsigned char (normal case) or unsigned short when appropriate.
The patch also makes minor modifications to code that accesses the syntax string to
ensure it does not make assumptions about the type.  Included are ChangeLog
entries.

Ok to commit?

-- Jeff J.
Index: opcodes/ChangeLog
===================================================================
RCS file: /cvs/src/src/opcodes/ChangeLog,v
retrieving revision 1.218
diff -u -r1.218 ChangeLog
--- ChangeLog	2001/01/05 11:11:54	1.218
+++ ChangeLog	2001/01/05 23:56:30
@@ -1,3 +1,12 @@
+2001-01-05  Jeff Johnston  <jjohnstn@redhat.com>
+
+	* cgen-asm.in (parse_insn_normal): Changed syn to be
+	CGEN_SYNTAX_CHAR_TYPE.  Changed all references to *syn
+	as character to use CGEN_SYNTAX_CHAR macro and all comparisons
+	to '\0' to use 0 instead.
+	* cgen-dis.in (print_insn_normal): Ditto.
+	* cgen-ibld.in (insert_insn_normal, extract_insn_normal): Ditto.
+
 Fri Jan  5 11:31:07 MET 2001  Jan Hubicka  <jh@suse.cz>
 
 	* i386-dis.c: Add x86_64 support.
Index: opcodes/cgen-asm.in
===================================================================
RCS file: /cvs/src/src/opcodes/cgen-asm.in,v
retrieving revision 1.3
diff -u -r1.3 cgen-asm.in
--- cgen-asm.in	2000/12/28 19:53:54	1.3
+++ cgen-asm.in	2001/01/05 23:56:30
@@ -4,7 +4,7 @@
 THIS FILE IS MACHINE GENERATED WITH CGEN.
 - the resultant file is machine generated, cgen-asm.in isn't
 
-Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+Copyright (C) 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
 
 This file is part of the GNU Binutils and GDB, the GNU debugger.
 
@@ -71,7 +71,7 @@
   const char *str = *strp;
   const char *errmsg;
   const char *p;
-  const unsigned char * syn;
+  const CGEN_SYNTAX_CHAR_TYPE * syn;
 #ifdef CGEN_MNEMONIC_OPERANDS
   /* FIXME: wip */
   int past_opcode_p;
@@ -121,7 +121,7 @@
 	  if (tolower (*str) == tolower (CGEN_SYNTAX_CHAR (* syn)))
 	    {
 #ifdef CGEN_MNEMONIC_OPERANDS
-	      if (* syn == ' ')
+	      if (CGEN_SYNTAX_CHAR(* syn) == ' ')
 		past_opcode_p = 1;
 #endif
 	      ++ syn;
@@ -133,7 +133,7 @@
 	      static char msg [80];
 	      /* xgettext:c-format */
 	      sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
-		       *syn, *str);
+		       CGEN_SYNTAX_CHAR(*syn), *str);
 	      return msg;
 	    }
 	  else
@@ -142,7 +142,7 @@
 	      static char msg [80];
 	      /* xgettext:c-format */
 	      sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
-		       *syn);
+		       CGEN_SYNTAX_CHAR(*syn));
 	      return msg;
 	    }
 	  continue;
@@ -159,7 +159,7 @@
     }
 
   /* If we're at the end of the syntax string, we're done.  */
-  if (* syn == '\0')
+  if (* syn == 0)
     {
       /* FIXME: For the moment we assume a valid `str' can only contain
 	 blanks now.  IE: We needn't try again with a longer version of
Index: opcodes/cgen-dis.in
===================================================================
RCS file: /cvs/src/src/opcodes/cgen-dis.in,v
retrieving revision 1.4
diff -u -r1.4 cgen-dis.in
--- cgen-dis.in	2001/01/03 15:10:26	1.4
+++ cgen-dis.in	2001/01/05 23:56:30
@@ -4,7 +4,7 @@
 THIS FILE IS MACHINE GENERATED WITH CGEN.
 - the resultant file is machine generated, cgen-dis.in isn't
 
-Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+Copyright (C) 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
 
 This file is part of the GNU Binutils and GDB, the GNU debugger.
 
@@ -164,7 +164,7 @@
 {
   const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
   disassemble_info *info = (disassemble_info *) dis_info;
-  const unsigned char *syn;
+  const CGEN_SYNTAX_CHAR_TYPE *syn;
 
   CGEN_INIT_PRINT (cd);
 
Index: opcodes/cgen-ibld.in
===================================================================
RCS file: /cvs/src/src/opcodes/cgen-ibld.in,v
retrieving revision 1.3
diff -u -r1.3 cgen-ibld.in
--- cgen-ibld.in	2001/01/02 16:34:07	1.3
+++ cgen-ibld.in	2001/01/05 23:56:30
@@ -3,7 +3,7 @@
 THIS FILE IS MACHINE GENERATED WITH CGEN: Cpu tools GENerator.
 - the resultant file is machine generated, cgen-ibld.in isn't
 
-Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
 
 This file is part of the GNU Binutils and GDB, the GNU debugger.
 
@@ -218,7 +218,7 @@
 {
   const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
   unsigned long value;
-  const unsigned char * syn;
+  const CGEN_SYNTAX_CHAR_TYPE * syn;
 
   CGEN_INIT_INSERT (cd);
   value = CGEN_INSN_BASE_VALUE (insn);
@@ -244,7 +244,7 @@
      e.g. storing a branch displacement that got resolved later.
      Needs more thought first.  */
 
-  for (syn = CGEN_SYNTAX_STRING (syntax); * syn != '\0'; ++ syn)
+  for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn)
     {
       const char *errmsg;
 
@@ -488,7 +488,7 @@
      bfd_vma pc;
 {
   const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
-  const unsigned char *syn;
+  const CGEN_SYNTAX_CHAR_TYPE *syn;
 
   CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
 
Index: include/opcode/ChangeLog
===================================================================
RCS file: /cvs/src/src/include/opcode/ChangeLog,v
retrieving revision 1.103
diff -u -r1.103 ChangeLog
--- ChangeLog	2001/01/05 12:30:12	1.103
+++ ChangeLog	2001/01/05 23:56:30
@@ -1,3 +1,10 @@
+2001-01-05  Jeff Johnston  <jjohnstn@redhat.com>
+
+	* cgen.h (CGEN_SYNTAX_CHAR_TYPE): New typedef based on max number
+	of operands (unsigned char or unsigned short).
+	(CGEN_SYNTAX): Changed to make array CGEN_SYNTAX_CHAR_TYPE.
+	(CGEN_SYNTAX_CHAR): Changed to cast to unsigned char.
+
 Fri Jan  5 13:22:23 MET 2001  Jan Hubicka  <jh@suse.cz>
 
 	* i386.h (i386_optab): Make [sml]fence template to use immext field.
Index: include/opcode/cgen.h
===================================================================
RCS file: /cvs/src/src/include/opcode/cgen.h,v
retrieving revision 1.7
diff -u -r1.7 cgen.h
--- cgen.h	2000/07/26 22:44:42	1.7
+++ cgen.h	2001/01/05 23:56:31
@@ -1,6 +1,6 @@
 /* Header file for targets using CGEN: Cpu tools GENerator.
 
-Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
 
 This file is part of GDB, the GNU debugger, and the GNU Binutils.
 
@@ -746,15 +746,20 @@
 #endif
 #endif
 
+#if !defined(MAX_OPERANDS) || MAX_OPERANDS <= 127
+typedef unsigned char CGEN_SYNTAX_CHAR_TYPE
+#else
+typedef unsigned short CGEN_SYNTAX_CHAR_TYPE
+#endif
 
 typedef struct
 {
-  unsigned char syntax[CGEN_MAX_SYNTAX_BYTES];
+  CGEN_SYNTAX_CHAR_TYPE syntax[CGEN_MAX_SYNTAX_BYTES];
 } CGEN_SYNTAX;
 
 #define CGEN_SYNTAX_STRING(syn) (syn->syntax)
 #define CGEN_SYNTAX_CHAR_P(c) ((c) < 128)
-#define CGEN_SYNTAX_CHAR(c) (c)
+#define CGEN_SYNTAX_CHAR(c) ((unsigned char)c)
 #define CGEN_SYNTAX_FIELD(c) ((c) - 128)
 #define CGEN_SYNTAX_MAKE_FIELD(c) ((c) + 128)
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]