This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

genfoo error message improvements


A couple o patches to improve error messages from genoutput
and genrecog.


r~


        * genoutput.c (name_for_index): New function.
        (scan_operands, validate_insn_alternatives): Use it.
        * genrecog.c (insn_name_ptr_size): New variable.
        (make_insn_sequence): Fill in insn_name_ptr.
        (merge_trees): Use it.

Index: genoutput.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/genoutput.c,v
retrieving revision 1.18
diff -c -p -d -r1.18 genoutput.c
*** genoutput.c	1999/01/13 10:46:43	1.18
--- genoutput.c	1999/01/20 04:21:43
*************** int have_constraints;
*** 170,175 ****
--- 170,176 ----
  
  static int have_error;
  
+ static char * name_for_index PROTO((int));
  static void output_prologue PROTO((void));
  static void output_epilogue PROTO((void));
  static void scan_operands PROTO((rtx, int, int));
*************** static void gen_expand PROTO((rtx));
*** 181,186 ****
--- 182,210 ----
  static void gen_split PROTO((rtx));
  static int n_occurrences PROTO((int, char *));
  
+ static char *
+ name_for_index (index)
+      int index;
+ {
+   static char buf[100];
+ 
+   struct data *i, *last_named = NULL;
+   for (i = insn_data; i ; i = i->next)
+     {
+       if (i->index_number == index)
+ 	return i->name;
+       if (i->name)
+ 	last_named = i;
+     }
+ 
+   if (last_named)
+     sprintf(buf, "%s+%d", last_named->name, index - last_named->index_number);
+   else
+     sprintf(buf, "insn %d", index);
+ 
+   return buf;
+ }
+ 
  static void
  output_prologue ()
  {
*************** scan_operands (part, this_address_p, thi
*** 440,452 ****
  	max_opno = opno;
        if (max_opno >= MAX_MAX_OPERANDS)
  	{
! 	  error ("Too many operands (%d) in definition %d.\n",
! 		 max_opno + 1, next_index_number);
  	  return;
  	}
        if (seen[opno])
! 	error ("Definition %d specified operand number %d more than once.\n",
! 	       next_index_number, opno);
        seen[opno] = 1;
        modes[opno] = GET_MODE (part);
        strict_low[opno] = this_strict_low;
--- 464,476 ----
  	max_opno = opno;
        if (max_opno >= MAX_MAX_OPERANDS)
  	{
! 	  error ("Too many operands (%d) in definition %s.\n",
! 		 max_opno + 1, name_for_index (next_index_number));
  	  return;
  	}
        if (seen[opno])
! 	error ("Definition %s specified operand number %d more than once.\n",
! 	       name_for_index (next_index_number), opno);
        seen[opno] = 1;
        modes[opno] = GET_MODE (part);
        strict_low[opno] = this_strict_low;
*************** scan_operands (part, this_address_p, thi
*** 466,478 ****
  	max_opno = opno;
        if (max_opno >= MAX_MAX_OPERANDS)
  	{
! 	  error ("Too many operands (%d) in definition %d.\n",
! 		 max_opno + 1, next_index_number);
  	  return;
  	}
        if (seen[opno])
! 	error ("Definition %d specified operand number %d more than once.\n",
! 	       next_index_number, opno);
        seen[opno] = 1;
        modes[opno] = GET_MODE (part);
        strict_low[opno] = 0;
--- 490,502 ----
  	max_opno = opno;
        if (max_opno >= MAX_MAX_OPERANDS)
  	{
! 	  error ("Too many operands (%d) in definition %s.\n",
! 		 max_opno + 1, name_for_index (next_index_number));
  	  return;
  	}
        if (seen[opno])
! 	error ("Definition %s specified operand number %d more than once.\n",
! 	       name_for_index (next_index_number), opno);
        seen[opno] = 1;
        modes[opno] = GET_MODE (part);
        strict_low[opno] = 0;
*************** scan_operands (part, this_address_p, thi
*** 493,505 ****
  	max_opno = opno;
        if (max_opno >= MAX_MAX_OPERANDS)
  	{
! 	  error ("Too many operands (%d) in definition %d.\n",
! 		 max_opno + 1, next_index_number);
  	  return;
  	}
        if (seen[opno])
! 	error ("Definition %d specified operand number %d more than once.\n",
! 	       next_index_number, opno);
        seen[opno] = 1;
        modes[opno] = GET_MODE (part);
        strict_low[opno] = 0;
--- 517,529 ----
  	max_opno = opno;
        if (max_opno >= MAX_MAX_OPERANDS)
  	{
! 	  error ("Too many operands (%d) in definition %s.\n",
! 		 max_opno + 1, name_for_index (next_index_number));
  	  return;
  	}
        if (seen[opno])
! 	error ("Definition %s specified operand number %d more than once.\n",
! 	       name_for_index (next_index_number), opno);
        seen[opno] = 1;
        modes[opno] = GET_MODE (part);
        strict_low[opno] = 0;
*************** validate_insn_alternatives (d)
*** 644,651 ****
  	if (n == 0)
  	  n = d->op_n_alternatives[start];
  	else if (n != d->op_n_alternatives[start])
! 	  error ("wrong number of alternatives in operand %d of insn number %d",
! 		 start, d->index_number);
        }
    /* Record the insn's overall number of alternatives.  */
    d->n_alternatives = n;
--- 668,675 ----
  	if (n == 0)
  	  n = d->op_n_alternatives[start];
  	else if (n != d->op_n_alternatives[start])
! 	  error ("wrong number of alternatives in operand %d of insn %s",
! 		 start, name_for_index (d->index_number));
        }
    /* Record the insn's overall number of alternatives.  */
    d->n_alternatives = n;
Index: genrecog.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/genrecog.c,v
retrieving revision 1.27
diff -c -p -d -r1.27 genrecog.c
*** genrecog.c	1999/01/13 11:45:30	1.27
--- genrecog.c	1999/01/20 04:21:44
*************** struct obstack *rtl_obstack = &obstack;
*** 60,67 ****
  #define obstack_chunk_alloc xmalloc
  #define obstack_chunk_free free
  
! /* Define this so we can link with print-rtl.o to get debug_rtx function.  */
  char **insn_name_ptr = 0;
  
  /* Data structure for a listhead of decision trees.  The alternatives
     to a node are kept in a doublely-linked list so we can easily add nodes
--- 60,68 ----
  #define obstack_chunk_alloc xmalloc
  #define obstack_chunk_free free
  
! /* Holds an array of names indexed by insn_code_number.  */
  char **insn_name_ptr = 0;
+ int insn_name_ptr_size = 0;
  
  /* Data structure for a listhead of decision trees.  The alternatives
     to a node are kept in a doublely-linked list so we can easily add nodes
*************** make_insn_sequence (insn, type)
*** 210,215 ****
--- 211,247 ----
    struct decision *last;
    struct decision_head head;
  
+   {
+     static char *last_real_name = "insn";
+     static int last_real_code = 0;
+     char *name;
+ 
+     if (insn_name_ptr_size <= next_insn_code)
+       {
+ 	int new_size;
+ 	new_size = (insn_name_ptr_size ? insn_name_ptr_size * 2 : 512);
+ 	insn_name_ptr = xrealloc (insn_name_ptr, sizeof(char *) * new_size);
+ 	bzero (insn_name_ptr + insn_name_ptr_size,
+ 	       sizeof(char *) * (new_size - insn_name_ptr_size));
+ 	insn_name_ptr_size = new_size;
+       }
+ 
+     name = XSTR (insn, 0);
+     if (!name || name[0] == '\0')
+       {
+ 	name = xmalloc (strlen (last_real_name) + 10);
+ 	sprintf (name, "%s+%d", last_real_name,
+ 		 next_insn_code - last_real_code);
+       }
+     else
+       {
+ 	last_real_name = name;
+ 	last_real_code = next_insn_code;
+       }
+   
+     insn_name_ptr[next_insn_code] = name;
+   }  
+ 
    if (XVECLEN (insn, type == RECOG) == 1)
      x = XVECEXP (insn, type == RECOG, 0);
    else
*************** merge_trees (oldh, addh)
*** 896,902 ****
  		      old->num_clobbers_to_add = 0;
  		    }
  		  else
! 		    fatal ("Two actions at one point in tree");
  		}
  
  	      if (old->insn_code_number == -1)
--- 928,938 ----
  		      old->num_clobbers_to_add = 0;
  		    }
  		  else
! 		    fatal ("Two actions at one point in tree for insns \"%s\" (%d) and \"%s\" (%d)",
! 			   insn_name_ptr[old->insn_code_number],
! 			   old->insn_code_number,
! 			   insn_name_ptr[add->insn_code_number],
! 			   add->insn_code_number);
  		}
  
  	      if (old->insn_code_number == -1)


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