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]

patch to print large constants as hex values


Hi Guys,

  I would like to submit the following patch for consideration.  It
creates a new HOST_WIDE_INT printing macro which will either print a
value as a decimal number or a hexadecimal number depending upon its
magnitude.  I find this to be useful when looking at RTL dumps or
assembler output since most large constants tend to be simpler to
understand as hex values rather than as decimal values.

Cheers
	Nick

Wed Mar 31 11:38:52 1999  Nick Clifton  <nickc@cygnus.com>

	* hwint.h (HOST_WIDE_INT_PRINT_DEC_OR_HEX): New macro.  Choose
	whether to print a value as a decimal or a hexadecimal
	quantity.

	* final.c (output_asm_insn): Replace HOST_WIDE_INT_PRINT_DEC
	with HOST_WIDE_INT_PRINT_DEC_OR_HEX.

	* print-rtl.c (print_rtx): Replace HOST_WIDE_INT_PRINT_DEC
	with HOST_WIDE_INT_PRINT_DEC_OR_HEX.


Index: gcc/hwint.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/hwint.h,v
retrieving revision 1.1
diff -p -r1.1 hwint.h
*** hwint.h	1998/12/17 13:09:00	1.1
--- hwint.h	1999/03/31 19:37:46
***************
*** 91,96 ****
--- 91,121 ----
  # endif
  #endif /* ! HOST_WIDE_INT_PRINT_DOUBLE_HEX */
  
+ #ifndef HOST_WIDE_INT_PRINT_DEC_OR_HEX
+ /* This is a utility macro the chooses whether to print a value as
+    either a decimal or a hexadecimal quantity.  The choice of 1000
+    as the switching point is arbitary.  The reason for doing this
+    is to help debugging since most large constant values that turn
+    up in output files tend to be easier to understand as hex values
+    than as decimal values.  Since this macro is always used inside
+    (f)printf statements it also appends its argument to printf's
+    parameter list.  ie if the macro is invoked as:
+ 
+       printf (HOST_WIDE_INT_PRINT_DEC_OR_HEX (ARG));
+ 
+   it will expand to:
+ 
+       printf (ARG > 1000 || ARG < -1000 ? "0x%x" : "%d", ARG);
+                                                        ^^^^^
+   so there is no need to repeat ARG as a parameter:
+   
+       printf (HOST_WIDE_INT_PRINT_DEC_OR_HEX (ARG), ARG);  // BAD!
+       
+   */
+ #define HOST_WIDE_INT_PRINT_DEC_OR_HEX(x) \
+   (((x) > 1000 || (x) < -1000) ? HOST_WIDE_INT_PRINT_HEX : HOST_WIDE_INT_PRINT_DEC), (x)
+ #endif
+ 
  #endif /* HOST_BITS_PER_LONG && HOST_BITS_PER_INT */
  
  #endif /* __HWINT_H__ */

Index: gcc/final.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/final.c,v
retrieving revision 1.75
diff -p -r1.75 final.c
*** final.c	1999/03/22 07:56:06	1.75
--- final.c	1999/03/31 19:37:57
*************** output_asm_insn (template, operands)
*** 3460,3467 ****
  	    else if (letter == 'n')
  	      {
  		if (GET_CODE (operands[c]) == CONST_INT)
! 		  fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
! 			   - INTVAL (operands[c]));
  		else
  		  {
  		    putc ('-', asm_out_file);
--- 3460,3467 ----
  	    else if (letter == 'n')
  	      {
  		if (GET_CODE (operands[c]) == CONST_INT)
! 		  fprintf (asm_out_file,
! 			   HOST_WIDE_INT_PRINT_DEC_OR_HEX (- INTVAL (operands[c])));
  		else
  		  {
  		    putc ('-', asm_out_file);
*************** output_addr_const (file, x)
*** 3596,3602 ****
        break;
  
      case CONST_INT:
!       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
        break;
  
      case CONST:
--- 3596,3602 ----
        break;
  
      case CONST_INT:
!       fprintf (file, HOST_WIDE_INT_PRINT_DEC_OR_HEX (INTVAL (x)));
        break;
  
      case CONST:
Index: gcc/print-rtl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/print-rtl.c,v
retrieving revision 1.25
diff -p -r1.25 print-rtl.c
*** print-rtl.c	1999/02/25 23:45:26	1.25
--- print-rtl.c	1999/03/31 19:38:05
*************** print_rtx (in_rtx)
*** 230,236 ****
  
        case 'w':
  	fprintf (outfile, " ");
! 	fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
  	break;
  
        case 'i':
--- 230,236 ----
  
        case 'w':
  	fprintf (outfile, " ");
! 	fprintf (outfile, HOST_WIDE_INT_PRINT_DEC_OR_HEX (XWINT (in_rtx, i)));
  	break;
  
        case 'i':


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