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]
Other format: [Raw text]

PATCH to read-rtl.c


Hi,

  This patchlet converts gcc/read-rtl.c to the common subset of C and C++.
The issues here mostly have to do with the implicit conversion
integer -> enumerations.  I post it seperately only to explain the
"extreme" case of mechanical conversion involved.

  read-rtl.c implements polymorphism here through the use of the
underlying integer type of enum rtx_code and enum machine_mode, which
it assumes to be int or unsigned depending on the circumstances.
Doing so, allows it to define only one kind of structure (macro_group)
that contains pointer to various functions (to mimic virtual
functions).  In C++ speak, the game would be that of a class template
with virtual functions -- though I'm no sure I would actually use
virtual functios :-).  Notice that if we were not doing that game,
then

   Notice find_mode() would have been declared to return an enum
   machine_mode. 

  apply_mode_macro() would have been declared to take an enum machine_mode

  apply_code_macro() would have been declared to take an enum rtx_mode

Anyway, enough for digression.

  The conversion consists in essentially making the conversion 
integer -> enumeration explicit, and since there are quite a few of
them in the GCC, I'm using two new macros: to_machine_mode() and
to_rtx_code(). 

Bootstrapped and regtested on an i686-pc-linux.gnu

-- Gaby
2005-06-09  Gabriel Dos Reis  <gdr@integrable-solutions.edu>

	* machmode.h (to_machine_mode): New.
	* rtl.h (to_rtx_code): Likewise.
	* read-rtl.c (apply_mode_macro): Convert mode to machine_mode.
	(print_c_condition): Convert return value of htab_find().
	(apply_code_macro): Add explicit cast when convertin to enums.
	(apply_mode_maps): Likewise.
	(check_code_macro): Likewise.
	(read_rtx_1): Likewise.

Index: machmode.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/machmode.h,v
retrieving revision 1.39
diff -u -r1.39 machmode.h
--- machmode.h	1 Jun 2005 00:20:13 -0000	1.39
+++ machmode.h	9 Jun 2005 16:51:54 -0000
@@ -25,6 +25,10 @@
 /* Make an enum class that gives all the machine modes.  */
 #include "insn-modes.h"
 
+/* Given MODE as integer value, get the corresponding enum machine_mode
+   enumeration value.  */
+#define to_machine_mode(MODE)  ((enum machine_mode) (MODE))
+
 /* Get the name of mode MODE as a string.  */
 
 extern const char * const mode_name[NUM_MACHINE_MODES];
Index: read-rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/read-rtl.c,v
retrieving revision 1.40
diff -u -r1.40 read-rtl.c
--- read-rtl.c	6 Jun 2005 21:14:29 -0000	1.40
+++ read-rtl.c	9 Jun 2005 16:51:54 -0000
@@ -243,7 +243,7 @@
 static void
 apply_mode_macro (rtx x, int mode)
 {
-  PUT_MODE (x, mode);
+  PUT_MODE (x, to_machine_mode (mode));
 }
 
 /* Implementations of the macro_group callbacks for codes.  */
@@ -269,7 +269,7 @@
 static void
 apply_code_macro (rtx x, int code)
 {
-  PUT_CODE (x, code);
+  PUT_CODE (x, to_rtx_code (code));
 }
 
 /* Map a code or mode attribute string P to the underlying string for
@@ -363,7 +363,7 @@
 
 	  v = map_attr_string (pm->string, macro, value);
 	  if (v)
-	    PUT_MODE (x, find_mode (v->string, infile));
+	    PUT_MODE (x, to_machine_mode (find_mode (v->string, infile)));
 	  else
 	    *unknown = pm->string;
 	  return;
@@ -798,7 +798,7 @@
 void
 print_c_condition (const char *cond)
 {
-  const void **halves = htab_find (joined_conditions, &cond);
+  const char **halves = (const char **) htab_find (joined_conditions, &cond);
   if (halves != 0)
     {
       printf ("(");
@@ -1311,7 +1311,7 @@
   struct map_value *v;
   enum rtx_code bellwether;
 
-  bellwether = macro->values->number;
+  bellwether = to_rtx_code (macro->values->number);
   for (v = macro->values->next; v != 0; v = v->next)
     if (strcmp (GET_RTX_FORMAT (bellwether), GET_RTX_FORMAT (v->number)) != 0)
       fatal_with_file_and_line (infile, "code macro `%s' combines "
@@ -1449,7 +1449,7 @@
       check_code_macro (read_mapping (&codes, codes.macros, infile), infile);
       goto again;
     }
-  real_code = find_macro (&codes, tmp_char, infile);
+  real_code = to_rtx_code (find_macro (&codes, tmp_char, infile));
   bellwether_code = BELLWETHER_CODE (real_code);
 
   /* If we end up with an insn expression then we free this space below.  */
@@ -1470,7 +1470,7 @@
 	mode = find_macro (&modes, tmp_char, infile);
       else
 	mode = mode_attr_index (mode_maps, tmp_char);
-      PUT_MODE (return_rtx, mode);
+      PUT_MODE (return_rtx, to_machine_mode (mode));
       if (GET_MODE (return_rtx) != mode)
 	fatal_with_file_and_line (infile, "mode too large");
     }
Index: rtl.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.h,v
retrieving revision 1.551
diff -u -r1.551 rtl.h
--- rtl.h	1 Jun 2005 11:38:49 -0000	1.551
+++ rtl.h	9 Jun 2005 16:51:55 -0000
@@ -51,6 +51,8 @@
 #define NUM_RTX_CODE ((int) LAST_AND_UNUSED_RTX_CODE)
 				/* The cast here, saves many elsewhere.  */
 
+#define to_rtx_code(CODE)    ((enum rtx_code) (CODE))
+
 /* Register Transfer Language EXPRESSIONS CODE CLASSES */
 
 enum rtx_class  {


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