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]

Re: patch to print large constants as hex values


Hi Guys,

: From: Richard Henderson <rth@cygnus.com>
: 
: I don't really like this so much for one reason -- it's now easy to 
: lose track of when a constant is negative and when it isn't.  This
: is important to 64-bit host cross 32-bit target situations.

: Date: Thu, 01 Apr 1999 03:09:37 -0700
:
: Maybe we could print the number in both hex & decimal in the
: debugging dumps.

OK, Here is a revised patch.  This one displays both decimal and
hexadecimal values in RTL dumps, like this:

  (insn 27 26 28 (set (reg:SI 44)
        (const_int -1021 or 0xfffffc03)) 176 {*movsi_insn} (nil)
    (expr_list:REG_EQUAL (const_int -1021 or 0xfffffc03)
        (nil)))

It still has the dynamic switching between decimal and hex values for
assembler output, since there is no easy way to display both values at
the same time.

Is this version OK to apply ?

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): Use both HOST_WIDE_INT_PRINT_DEC
	and HOST_WIDE_INT_PRINT_DEC_OR_HEX to display constants.


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/04/01 22:56:58
***************
*** 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/04/01 22:56:58
*************** 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/04/01 22:56:58
*************** print_rtx (in_rtx)
*** 231,236 ****
--- 231,238 ----
        case 'w':
  	fprintf (outfile, " ");
  	fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, XWINT (in_rtx, i));
+ 	fprintf (outfile, " or ");
+ 	fprintf (outfile, HOST_WIDE_INT_PRINT_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]