Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch 2/4] decimal floating point types
       [not found] <20070323030737.475073862@br.ibm.com>
@ 2007-03-27 16:30 ` Thiago Jung Bauermann
  0 siblings, 0 replies; 6+ messages in thread
From: Thiago Jung Bauermann @ 2007-03-27 16:30 UTC (permalink / raw)
  To: gdb-patches

plain text document attachment (decfloat-types.diff)
2007-03-23  Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* c-lang.c (c_create_fundamental_type): Create fundamental
	types for DFP.
	* c-valprint.c (c_val_print): Call print_decimal_floating to
	print DFP values.
	* dwarf2read.c (read_base_type): Read DW_ATE_decimal_float
	attribute code and return TYPE_CODE_DECFLOAT.
	(dwarf_base_type): Set dwarf2_fundamental_type for DFP values.
	* gdbtypes.c: Add three builtin types for DFP.
	(build_gdbtypes): Build these three builtin types for DFP.
	(gdbtypes_post_init): Initialize builtin_decfloat,
	builtin_decdouble and builtin_declong. 
	* gdbtypes.h: Add three fundamental types for DFP.
	(enum type_code): Add TYPE_CODE_DECFLOAT as a type code for DFP.
	(struct builtin_type): Add builtin_decfloat, builtin_decdouble
	and builtin_declong.
	* valprint.c (print_decimal_floating): New function to print DFP
	values.
	* value.h (print_decimal_floating): Prototype.

Index: gdb/c-lang.c
===================================================================
--- gdb/c-lang.c.orig	2007-03-12 16:55:35.000000000 -0300
+++ gdb/c-lang.c	2007-03-13 13:39:29.000000000 -0300
@@ -322,6 +322,21 @@ c_create_fundamental_type (struct objfil
 			TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
 			0, "long double", objfile);
       break;
+    case FT_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			32 / 8,
+			0, "decimal float", objfile);
+      break;
+    case FT_DBL_PREC_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			64 / 8,
+			0, "decimal double", objfile);
+      break;
+    case FT_EXT_PREC_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			128 / 8,
+			0, "decimal long double", objfile);
+      break;
     case FT_COMPLEX:
       type = init_type (TYPE_CODE_FLT,
 			2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
Index: gdb/c-valprint.c
===================================================================
--- gdb/c-valprint.c.orig	2007-03-12 16:55:35.000000000 -0300
+++ gdb/c-valprint.c	2007-03-13 13:39:29.000000000 -0300
@@ -436,6 +436,13 @@ c_val_print (struct type *type, const gd
 	}
       break;
 
+    case TYPE_CODE_DECFLOAT:
+      if (format)
+	print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
+      else
+	print_decimal_floating (valaddr + embedded_offset, type, stream);
+      break;
+
     case TYPE_CODE_VOID:
       fprintf_filtered (stream, "void");
       break;
Index: gdb/dwarf2read.c
===================================================================
--- gdb/dwarf2read.c.orig	2007-03-12 16:55:35.000000000 -0300
+++ gdb/dwarf2read.c	2007-03-13 13:39:29.000000000 -0300
@@ -4851,6 +4851,9 @@ read_base_type (struct die_info *die, st
 	case DW_ATE_complex_float:
 	  code = TYPE_CODE_COMPLEX;
 	  break;
+	case DW_ATE_decimal_float:
+	  code = TYPE_CODE_DECFLOAT;
+	  break;
 	case DW_ATE_float:
 	  code = TYPE_CODE_FLT;
 	  break;
@@ -7710,6 +7713,18 @@ dwarf_base_type (int encoding, int size,
 	  type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
 	}
       return type;
+    case DW_ATE_decimal_float:
+      if (size == 16)
+	{
+	  type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_DECFLOAT, cu);
+	}
+      else if (size == 8)
+	{
+	  type = dwarf2_fundamental_type (objfile, FT_EXT_PREC_DECFLOAT, cu);
+	}
+      else
+	type = dwarf2_fundamental_type (objfile, FT_DECFLOAT, cu);
+      return type;
     case DW_ATE_signed:
       switch (size)
 	{
Index: gdb/gdbtypes.c
===================================================================
--- gdb/gdbtypes.c.orig	2007-03-12 16:55:35.000000000 -0300
+++ gdb/gdbtypes.c	2007-03-13 13:39:29.000000000 -0300
@@ -76,6 +76,12 @@ struct type *builtin_type_int128;
 struct type *builtin_type_uint128;
 struct type *builtin_type_bool;
 
+/* The following three are about decimal floating point types, which are now
+   considered as potential extension to C99 standard.  */
+struct type *builtin_type_decfloat;
+struct type *builtin_type_decdouble;
+struct type *builtin_type_declong;
+
 /* 128 bit long vector types */
 struct type *builtin_type_v2_double;
 struct type *builtin_type_v4_float;
@@ -3450,6 +3456,20 @@ build_gdbtypes (void)
   builtin_type_long_double = build_flt (TARGET_LONG_DOUBLE_BIT, "long double",
 					TARGET_LONG_DOUBLE_FORMAT);
 
+  /* Builtin types for decimal floating point types.  */
+  builtin_type_decfloat =
+    init_type (TYPE_CODE_DECFLOAT, 32 / 8,
+	       0,
+	       "decimal float", (struct objfile *) NULL);
+  builtin_type_decdouble =
+    init_type (TYPE_CODE_DECFLOAT, 64 / 8,
+               0,
+               "decimal double", (struct objfile *) NULL);
+  builtin_type_declong =
+    init_type (TYPE_CODE_DECFLOAT, 128 / 8,
+	       0,
+	       "decimal long double", (struct objfile *) NULL);
+
   builtin_type_complex =
     init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
 	       0,
@@ -3660,6 +3680,21 @@ gdbtypes_post_init (struct gdbarch *gdba
 	       0,
 	       "bool", (struct objfile *) NULL);
 
+  /* The following three are about decimal floating point types, which are
+     32-bits, 64-bits and 128-bits respectively.  */
+  builtin_type->builtin_decfloat =
+   init_type (TYPE_CODE_DECFLOAT, 32 / 8,
+               0,
+               "decimal float", (struct objfile *) NULL);
+  builtin_type->builtin_decdouble =
+    init_type (TYPE_CODE_DECFLOAT, 64 / 8,
+               0,
+               "decimal double", (struct objfile *) NULL);
+  builtin_type->builtin_declong =
+    init_type (TYPE_CODE_DECFLOAT, 128 / 8,
+               0,
+               "decimal long double", (struct objfile *) NULL);
+
   /* Pointer/Address types. */
 
   /* NOTE: on some targets, addresses and pointers are not necessarily
@@ -3807,6 +3842,9 @@ _initialize_gdbtypes (void)
   DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
   DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
   DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
+  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_decfloat);
+  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_decdouble);
+  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_declong);
   deprecated_register_gdbarch_swap (NULL, 0, build_gdbtypes);
 
   /* Note: These types do not need to be swapped - they are target
Index: gdb/gdbtypes.h
===================================================================
--- gdb/gdbtypes.h.orig	2007-03-12 16:55:35.000000000 -0300
+++ gdb/gdbtypes.h	2007-03-13 13:39:29.000000000 -0300
@@ -67,7 +67,12 @@ struct block;
 #define FT_UNSIGNED_BYTE	27
 #define FT_TEMPLATE_ARG		28
 
-#define FT_NUM_MEMBERS		29	/* Highest FT_* above, plus one. */
+/* The following three fundamental types are for decimal floating point.  */
+#define FT_DECFLOAT		29
+#define FT_DBL_PREC_DECFLOAT	30
+#define FT_EXT_PREC_DECFLOAT	31
+
+#define FT_NUM_MEMBERS		32	/* Highest FT_* above, plus one. */
 
 /* Some macros for char-based bitfields.  */
 
@@ -171,7 +176,9 @@ enum type_code
     TYPE_CODE_TEMPLATE,		/* C++ template */
     TYPE_CODE_TEMPLATE_ARG,	/* C++ template arg */
 
-    TYPE_CODE_NAMESPACE		/* C++ namespace.  */
+    TYPE_CODE_NAMESPACE,	/* C++ namespace.  */
+
+    TYPE_CODE_DECFLOAT		/* Decimal floating point.  */
   };
 
 /* For now allow source to use TYPE_CODE_CLASS for C++ classes, as an
@@ -1019,6 +1026,9 @@ struct builtin_type
   struct type *builtin_bool;
   struct type *builtin_long_long;
   struct type *builtin_unsigned_long_long;
+  struct type *builtin_decfloat;
+  struct type *builtin_decdouble;
+  struct type *builtin_declong;
 };
 
 /* Return the type table for the specified architecture.  */
@@ -1042,6 +1052,9 @@ extern struct type *builtin_type_complex
 extern struct type *builtin_type_double_complex;
 extern struct type *builtin_type_string;
 extern struct type *builtin_type_bool;
+extern struct type *builtin_type_decfloat;
+extern struct type *builtin_type_decdouble;
+extern struct type *builtin_type_declong;
 
 /* Address/pointer types: */
 /* (C) Language `pointer to data' type.  Some target platforms use an
Index: gdb/valprint.c
===================================================================
--- gdb/valprint.c.orig	2007-03-12 16:55:35.000000000 -0300
+++ gdb/valprint.c	2007-03-13 13:39:29.000000000 -0300
@@ -35,6 +35,7 @@
 #include "floatformat.h"
 #include "doublest.h"
 #include "exceptions.h"
+#include "dfp.h"
 
 #include <errno.h>
 
@@ -496,6 +497,18 @@ print_floating (const gdb_byte *valaddr,
 }
 
 void
+print_decimal_floating (const gdb_byte *valaddr, struct type *type,
+			struct ui_file *stream)
+{
+  char decstr[128];
+  unsigned len = TYPE_LENGTH (type);
+
+  decimal_to_string (valaddr, len, decstr);
+  fputs_filtered (decstr, stream);
+  return;
+}
+
+void
 print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
 		    unsigned len)
 {
Index: gdb/value.h
===================================================================
--- gdb/value.h.orig	2007-03-12 16:55:35.000000000 -0300
+++ gdb/value.h	2007-03-13 13:39:29.000000000 -0300
@@ -482,6 +482,9 @@ extern void print_longest (struct ui_fil
 extern void print_floating (const gdb_byte *valaddr, struct type *type,
 			    struct ui_file *stream);
 
+extern void print_decimal_floating (const gdb_byte *valaddr, struct type *type,
+				    struct ui_file *stream);
+
 extern int value_print (struct value *val, struct ui_file *stream, int format,
 			enum val_prettyprint pretty);
 

--


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2/4] decimal floating point types
  2007-10-24 20:11       ` Daniel Jacobowitz
@ 2007-10-25 18:24         ` Thiago Jung Bauermann
  0 siblings, 0 replies; 6+ messages in thread
From: Thiago Jung Bauermann @ 2007-10-25 18:24 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

On Wed, 2007-10-24 at 16:09 -0400, Daniel Jacobowitz wrote:
> This version looks good to me.

Commited. Thanks!
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2/4] decimal floating point types
  2007-10-15 18:12     ` Thiago Jung Bauermann
@ 2007-10-24 20:11       ` Daniel Jacobowitz
  2007-10-25 18:24         ` Thiago Jung Bauermann
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-10-24 20:11 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches

On Mon, Oct 15, 2007 at 04:11:49PM -0200, Thiago Jung Bauermann wrote:
> 2007-10-15  Wu Zhou  <woodzltc@cn.ibm.com> 
> 	    Thiago Jung Bauermann  <bauerman@br.ibm.com>
> 
> 	* c-lang.c (c_create_fundamental_type): Create fundamental
> 	types for DFP.
> 	* c-typeprint.c (c_type_print_varspec_prefix): Add
> 	TYPE_CODE_DECFLOAT to no prefix needed case.
> 	(c_type_print_varspec_suffix): Add TYPE_CODE_DECFLOAT to no
> 	suffix needed case.
> 	* c-valprint.c (c_val_print): Call print_decimal_floating to
> 	print DFP values.
> 	* dwarf2read.c (read_base_type): Read DW_ATE_decimal_float
> 	attribute code and return TYPE_CODE_DECFLOAT.
> 	(dwarf_base_type): Set dwarf2_fundamental_type for DFP values.
> 	* gdbtypes.c (gdbtypes_post_init): Initialize builtin_decfloat,
> 	builtin_decdouble and builtin_declong. 
> 	* gdbtypes.h (enum type_code): Add TYPE_CODE_DECFLOAT as a
> 	type code for DFP.
> 	(FT_DECFLOAT, FT_DBL_PREC_DECFLOAT, FT_EXT_PREC_DECFLOAT): New
> 	types, for decimal floating point.
> 	(FT_NUM_MEMBERS):  Increment, new types added.
> 	(struct builtin_type): Add builtin_decfloat, builtin_decdouble
> 	and builtin_declong.
> 	* valprint.c (print_decimal_floating): New function to print DFP
> 	values.
> 	* value.h (print_decimal_floating): Prototype.

This version looks good to me.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2/4] decimal floating point types
  2007-10-11 16:00   ` Daniel Jacobowitz
@ 2007-10-15 18:12     ` Thiago Jung Bauermann
  2007-10-24 20:11       ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Thiago Jung Bauermann @ 2007-10-15 18:12 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1888 bytes --]

On Thu, 2007-10-11 at 11:57 -0400, Daniel Jacobowitz wrote: 
> On Thu, Sep 20, 2007 at 06:54:12PM -0300, Thiago Jung Bauermann wrote:
> > +    case DW_ATE_decimal_float:
> > +      if (size == 16)
> > +	{
> > +	  type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_DECFLOAT, cu);
> > +	}
> > +      else if (size == 8)
> > +	{
> > +	  type = dwarf2_fundamental_type (objfile, FT_EXT_PREC_DECFLOAT, cu);
> > +	}
> > + else 
> > +	type = dwarf2_fundamental_type (objfile, FT_DECFLOAT, cu);
> > +      return type;
> 
> You don't need a bunch of those extra braces.

Right. Removed.

> > +  /* The following three are about decimal floating point types, which
> > +     are 32-bits, 64-bits and 128-bits respectively.  */
> > +  builtin_type->builtin_decfloat =
> > +    init_type (TYPE_CODE_DECFLOAT, 32 / 8,
> > +	        0,
> > +	       "decimal float", (struct objfile *) NULL);
> 
> I think our convention is to put the equals sign after the line break.

Most of the types in gdbtypes_post_init have the equals sign at the end
of the line, so this code was being consistent with them. But you're
right, the GNU Coding Standards say to break a line before an operator.
Changed.

> >  void
> > +print_decimal_floating (const gdb_byte *valaddr, struct type *type,
> > +			struct ui_file *stream)
> > +{
> > +  char decstr[128];
> > +  unsigned len = TYPE_LENGTH (type);
> > +
> > +  decimal_to_string (valaddr, len, decstr);
> > +  fputs_filtered (decstr, stream);
> > +  return;
> > +}
> 
> Does the libdecnumber API specify that 128 bytes is enough?  If so
> this should be a constant in dfp.h.

Actually, I just found out that libdecnumber specifies a lower limit: 43
(including the '\0' at the end), so I created a MAX_DECIMAL_STRING
constant in dfp.h and use that here.

What do you think of this version?
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center

[-- Attachment #2: decfloat-types.diff --]
[-- Type: text/x-patch, Size: 8234 bytes --]

Subject: decimal floating point types

2007-10-15  Wu Zhou  <woodzltc@cn.ibm.com> 
	    Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* c-lang.c (c_create_fundamental_type): Create fundamental
	types for DFP.
	* c-typeprint.c (c_type_print_varspec_prefix): Add
	TYPE_CODE_DECFLOAT to no prefix needed case.
	(c_type_print_varspec_suffix): Add TYPE_CODE_DECFLOAT to no
	suffix needed case.
	* c-valprint.c (c_val_print): Call print_decimal_floating to
	print DFP values.
	* dwarf2read.c (read_base_type): Read DW_ATE_decimal_float
	attribute code and return TYPE_CODE_DECFLOAT.
	(dwarf_base_type): Set dwarf2_fundamental_type for DFP values.
	* gdbtypes.c (gdbtypes_post_init): Initialize builtin_decfloat,
	builtin_decdouble and builtin_declong. 
	* gdbtypes.h (enum type_code): Add TYPE_CODE_DECFLOAT as a
	type code for DFP.
	(FT_DECFLOAT, FT_DBL_PREC_DECFLOAT, FT_EXT_PREC_DECFLOAT): New
	types, for decimal floating point.
	(FT_NUM_MEMBERS):  Increment, new types added.
	(struct builtin_type): Add builtin_decfloat, builtin_decdouble
	and builtin_declong.
	* valprint.c (print_decimal_floating): New function to print DFP
	values.
	* value.h (print_decimal_floating): Prototype.

Index: gdb/c-lang.c
===================================================================
--- gdb/c-lang.c.orig	2007-09-25 23:45:17.000000000 -0300
+++ gdb/c-lang.c	2007-10-15 14:35:18.000000000 -0200
@@ -325,6 +325,21 @@ c_create_fundamental_type (struct objfil
 			  / TARGET_CHAR_BIT,
 			0, "long double", objfile);
       break;
+    case FT_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			32 / 8,
+			0, "decimal float", objfile);
+      break;
+    case FT_DBL_PREC_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			64 / 8,
+			0, "decimal double", objfile);
+      break;
+    case FT_EXT_PREC_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			128 / 8,
+			0, "decimal long double", objfile);
+      break;
     case FT_COMPLEX:
       type = init_type (TYPE_CODE_FLT,
 			2 * gdbarch_float_bit (current_gdbarch)
Index: gdb/c-valprint.c
===================================================================
--- gdb/c-valprint.c.orig	2007-09-25 23:45:18.000000000 -0300
+++ gdb/c-valprint.c	2007-10-15 14:35:18.000000000 -0200
@@ -474,6 +474,13 @@ c_val_print (struct type *type, const gd
 	}
       break;
 
+    case TYPE_CODE_DECFLOAT:
+      if (format)
+	print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
+      else
+	print_decimal_floating (valaddr + embedded_offset, type, stream);
+      break;
+
     case TYPE_CODE_VOID:
       fprintf_filtered (stream, "void");
       break;
Index: gdb/dwarf2read.c
===================================================================
--- gdb/dwarf2read.c.orig	2007-09-27 20:26:54.000000000 -0300
+++ gdb/dwarf2read.c	2007-10-15 14:35:18.000000000 -0200
@@ -4869,6 +4869,9 @@ read_base_type (struct die_info *die, st
 	case DW_ATE_complex_float:
 	  code = TYPE_CODE_COMPLEX;
 	  break;
+	case DW_ATE_decimal_float:
+	  code = TYPE_CODE_DECFLOAT;
+	  break;
 	case DW_ATE_float:
 	  code = TYPE_CODE_FLT;
 	  break;
@@ -7756,6 +7759,14 @@ dwarf_base_type (int encoding, int size,
 	  type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
 	}
       return type;
+    case DW_ATE_decimal_float:
+      if (size == 16)
+	type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_DECFLOAT, cu);
+      else if (size == 8)
+	type = dwarf2_fundamental_type (objfile, FT_EXT_PREC_DECFLOAT, cu);
+      else
+	type = dwarf2_fundamental_type (objfile, FT_DECFLOAT, cu);
+      return type;
     case DW_ATE_signed:
       switch (size)
 	{
Index: gdb/gdbtypes.c
===================================================================
--- gdb/gdbtypes.c.orig	2007-10-09 11:22:47.000000000 -0300
+++ gdb/gdbtypes.c	2007-10-15 14:35:18.000000000 -0200
@@ -3506,6 +3506,21 @@ gdbtypes_post_init (struct gdbarch *gdba
 	       0,
 	       "bool", (struct objfile *) NULL);
 
+  /* The following three are about decimal floating point types, which
+     are 32-bits, 64-bits and 128-bits respectively.  */
+  builtin_type->builtin_decfloat
+    = init_type (TYPE_CODE_DECFLOAT, 32 / 8,
+	        0,
+	       "decimal float", (struct objfile *) NULL);
+  builtin_type->builtin_decdouble
+    = init_type (TYPE_CODE_DECFLOAT, 64 / 8,
+	       0,
+	       "decimal double", (struct objfile *) NULL);
+  builtin_type->builtin_declong
+    = init_type (TYPE_CODE_DECFLOAT, 128 / 8,
+	       0,
+	       "decimal long double", (struct objfile *) NULL);
+
   /* Pointer/Address types.  */
 
   /* NOTE: on some targets, addresses and pointers are not necessarily
Index: gdb/gdbtypes.h
===================================================================
--- gdb/gdbtypes.h.orig	2007-09-25 23:45:18.000000000 -0300
+++ gdb/gdbtypes.h	2007-10-15 14:35:18.000000000 -0200
@@ -65,7 +65,12 @@ struct block;
 #define FT_UNSIGNED_BYTE	27
 #define FT_TEMPLATE_ARG		28
 
-#define FT_NUM_MEMBERS		29	/* Highest FT_* above, plus one. */
+/* The following three fundamental types are for decimal floating point.  */
+#define FT_DECFLOAT		29
+#define FT_DBL_PREC_DECFLOAT	30
+#define FT_EXT_PREC_DECFLOAT	31
+
+#define FT_NUM_MEMBERS		32	/* Highest FT_* above, plus one. */
 
 /* Some macros for char-based bitfields.  */
 
@@ -169,7 +174,9 @@ enum type_code
     TYPE_CODE_TEMPLATE,		/* C++ template */
     TYPE_CODE_TEMPLATE_ARG,	/* C++ template arg */
 
-    TYPE_CODE_NAMESPACE		/* C++ namespace.  */
+    TYPE_CODE_NAMESPACE,	/* C++ namespace.  */
+
+    TYPE_CODE_DECFLOAT		/* Decimal floating point.  */
   };
 
 /* For now allow source to use TYPE_CODE_CLASS for C++ classes, as an
@@ -1041,6 +1048,9 @@ struct builtin_type
   struct type *builtin_bool;
   struct type *builtin_long_long;
   struct type *builtin_unsigned_long_long;
+  struct type *builtin_decfloat;
+  struct type *builtin_decdouble;
+  struct type *builtin_declong;
 };
 
 /* Return the type table for the specified architecture.  */
Index: gdb/valprint.c
===================================================================
--- gdb/valprint.c.orig	2007-09-25 23:45:23.000000000 -0300
+++ gdb/valprint.c	2007-10-15 14:35:18.000000000 -0200
@@ -33,6 +33,7 @@
 #include "floatformat.h"
 #include "doublest.h"
 #include "exceptions.h"
+#include "dfp.h"
 
 #include <errno.h>
 
@@ -506,6 +507,18 @@ print_floating (const gdb_byte *valaddr,
 }
 
 void
+print_decimal_floating (const gdb_byte *valaddr, struct type *type,
+			struct ui_file *stream)
+{
+  char decstr[MAX_DECIMAL_STRING];
+  unsigned len = TYPE_LENGTH (type);
+
+  decimal_to_string (valaddr, len, decstr);
+  fputs_filtered (decstr, stream);
+  return;
+}
+
+void
 print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
 		    unsigned len)
 {
Index: gdb/value.h
===================================================================
--- gdb/value.h.orig	2007-10-15 14:25:14.000000000 -0200
+++ gdb/value.h	2007-10-15 14:35:46.000000000 -0200
@@ -492,6 +492,9 @@ extern void print_longest (struct ui_fil
 extern void print_floating (const gdb_byte *valaddr, struct type *type,
 			    struct ui_file *stream);
 
+extern void print_decimal_floating (const gdb_byte *valaddr, struct type *type,
+				    struct ui_file *stream);
+
 extern int value_print (struct value *val, struct ui_file *stream, int format,
 			enum val_prettyprint pretty);
 
Index: gdb/c-typeprint.c
===================================================================
--- gdb/c-typeprint.c.orig	2007-09-25 23:45:18.000000000 -0300
+++ gdb/c-typeprint.c	2007-10-15 14:35:18.000000000 -0200
@@ -277,6 +277,7 @@ c_type_print_varspec_prefix (struct type
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_TEMPLATE:
     case TYPE_CODE_NAMESPACE:
+    case TYPE_CODE_DECFLOAT:
       /* These types need no prefix.  They are listed here so that
          gcc -Wall will reveal any types that haven't been handled.  */
       break;
@@ -599,6 +600,7 @@ c_type_print_varspec_suffix (struct type
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_TEMPLATE:
     case TYPE_CODE_NAMESPACE:
+    case TYPE_CODE_DECFLOAT:
       /* These types do not need a suffix.  They are listed so that
          gcc -Wall will report types that may not have been considered.  */
       break;

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2/4] decimal floating point types
  2007-09-20 21:57 ` [patch 2/4] decimal floating point types Thiago Jung Bauermann
@ 2007-10-11 16:00   ` Daniel Jacobowitz
  2007-10-15 18:12     ` Thiago Jung Bauermann
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-10-11 16:00 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches

On Thu, Sep 20, 2007 at 06:54:12PM -0300, Thiago Jung Bauermann wrote:
> +    case DW_ATE_decimal_float:
> +      if (size == 16)
> +	{
> +	  type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_DECFLOAT, cu);
> +	}
> +      else if (size == 8)
> +	{
> +	  type = dwarf2_fundamental_type (objfile, FT_EXT_PREC_DECFLOAT, cu);
> +	}
> +      else
> +	type = dwarf2_fundamental_type (objfile, FT_DECFLOAT, cu);
> +      return type;

You don't need a bunch of those extra braces.

> +  /* The following three are about decimal floating point types, which
> +     are 32-bits, 64-bits and 128-bits respectively.  */
> +  builtin_type->builtin_decfloat =
> +    init_type (TYPE_CODE_DECFLOAT, 32 / 8,
> +	        0,
> +	       "decimal float", (struct objfile *) NULL);

I think our convention is to put the equals sign after the line break.

>  void
> +print_decimal_floating (const gdb_byte *valaddr, struct type *type,
> +			struct ui_file *stream)
> +{
> +  char decstr[128];
> +  unsigned len = TYPE_LENGTH (type);
> +
> +  decimal_to_string (valaddr, len, decstr);
> +  fputs_filtered (decstr, stream);
> +  return;
> +}

Does the libdecnumber API specify that 128 bytes is enough?  If so
this should be a constant in dfp.h.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patch 2/4] decimal floating point types
  2007-09-20 21:57 [patch 0/4] decimal floating point support Thiago Jung Bauermann
@ 2007-09-20 21:57 ` Thiago Jung Bauermann
  2007-10-11 16:00   ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Thiago Jung Bauermann @ 2007-09-20 21:57 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: decfloat-types.diff --]
[-- Type: text/plain, Size: 8206 bytes --]

2007-09-20  Wu Zhou  <woodzltc@cn.ibm.com> 
	    Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* c-lang.c (c_create_fundamental_type): Create fundamental
	types for DFP.
	* c-typeprint.c (c_type_print_varspec_prefix): Add
	TYPE_CODE_DECFLOAT to no prefix needed case.
	(c_type_print_varspec_suffix): Add TYPE_CODE_DECFLOAT to no
	suffix needed case.
	* c-valprint.c (c_val_print): Call print_decimal_floating to
	print DFP values.
	* dwarf2read.c (read_base_type): Read DW_ATE_decimal_float
	attribute code and return TYPE_CODE_DECFLOAT.
	(dwarf_base_type): Set dwarf2_fundamental_type for DFP values.
	* gdbtypes.c (gdbtypes_post_init): Initialize builtin_decfloat,
	builtin_decdouble and builtin_declong. 
	* gdbtypes.h (enum type_code): Add TYPE_CODE_DECFLOAT as a
	type code for DFP.
	(FT_DECFLOAT, FT_DBL_PREC_DECFLOAT, FT_EXT_PREC_DECFLOAT): New
	types, for decimal floating point.
	(FT_NUM_MEMBERS):  Increment, new types added.
	(struct builtin_type): Add builtin_decfloat, builtin_decdouble
	and builtin_declong.
	* valprint.c (print_decimal_floating): New function to print DFP
	values.
	* value.h (print_decimal_floating): Prototype.

Index: gdb/c-lang.c
===================================================================
--- gdb/c-lang.c.orig	2007-09-18 02:41:10.000000000 -0300
+++ gdb/c-lang.c	2007-09-18 02:44:26.000000000 -0300
@@ -325,6 +325,21 @@ c_create_fundamental_type (struct objfil
 			  / TARGET_CHAR_BIT,
 			0, "long double", objfile);
       break;
+    case FT_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			32 / 8,
+			0, "decimal float", objfile);
+      break;
+    case FT_DBL_PREC_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			64 / 8,
+			0, "decimal double", objfile);
+      break;
+    case FT_EXT_PREC_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			128 / 8,
+			0, "decimal long double", objfile);
+      break;
     case FT_COMPLEX:
       type = init_type (TYPE_CODE_FLT,
 			2 * gdbarch_float_bit (current_gdbarch)
Index: gdb/c-valprint.c
===================================================================
--- gdb/c-valprint.c.orig	2007-09-18 02:41:10.000000000 -0300
+++ gdb/c-valprint.c	2007-09-18 02:44:26.000000000 -0300
@@ -474,6 +474,13 @@ c_val_print (struct type *type, const gd
 	}
       break;
 
+    case TYPE_CODE_DECFLOAT:
+      if (format)
+	print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
+      else
+	print_decimal_floating (valaddr + embedded_offset, type, stream);
+      break;
+
     case TYPE_CODE_VOID:
       fprintf_filtered (stream, "void");
       break;
Index: gdb/dwarf2read.c
===================================================================
--- gdb/dwarf2read.c.orig	2007-09-18 02:41:10.000000000 -0300
+++ gdb/dwarf2read.c	2007-09-18 02:44:26.000000000 -0300
@@ -4868,6 +4868,9 @@ read_base_type (struct die_info *die, st
 	case DW_ATE_complex_float:
 	  code = TYPE_CODE_COMPLEX;
 	  break;
+	case DW_ATE_decimal_float:
+	  code = TYPE_CODE_DECFLOAT;
+	  break;
 	case DW_ATE_float:
 	  code = TYPE_CODE_FLT;
 	  break;
@@ -7755,6 +7758,18 @@ dwarf_base_type (int encoding, int size,
 	  type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
 	}
       return type;
+    case DW_ATE_decimal_float:
+      if (size == 16)
+	{
+	  type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_DECFLOAT, cu);
+	}
+      else if (size == 8)
+	{
+	  type = dwarf2_fundamental_type (objfile, FT_EXT_PREC_DECFLOAT, cu);
+	}
+      else
+	type = dwarf2_fundamental_type (objfile, FT_DECFLOAT, cu);
+      return type;
     case DW_ATE_signed:
       switch (size)
 	{
Index: gdb/gdbtypes.c
===================================================================
--- gdb/gdbtypes.c.orig	2007-09-18 02:41:11.000000000 -0300
+++ gdb/gdbtypes.c	2007-09-18 02:50:06.000000000 -0300
@@ -3508,6 +3508,21 @@ gdbtypes_post_init (struct gdbarch *gdba
 	       0,
 	       "bool", (struct objfile *) NULL);
 
+  /* The following three are about decimal floating point types, which
+     are 32-bits, 64-bits and 128-bits respectively.  */
+  builtin_type->builtin_decfloat =
+    init_type (TYPE_CODE_DECFLOAT, 32 / 8,
+	        0,
+	       "decimal float", (struct objfile *) NULL);
+  builtin_type->builtin_decdouble =
+    init_type (TYPE_CODE_DECFLOAT, 64 / 8,
+	       0,
+	       "decimal double", (struct objfile *) NULL);
+  builtin_type->builtin_declong =
+    init_type (TYPE_CODE_DECFLOAT, 128 / 8,
+	       0,
+	       "decimal long double", (struct objfile *) NULL);
+
   /* Pointer/Address types.  */
 
   /* NOTE: on some targets, addresses and pointers are not necessarily
Index: gdb/gdbtypes.h
===================================================================
--- gdb/gdbtypes.h.orig	2007-09-18 02:41:11.000000000 -0300
+++ gdb/gdbtypes.h	2007-09-18 02:44:26.000000000 -0300
@@ -65,7 +65,12 @@ struct block;
 #define FT_UNSIGNED_BYTE	27
 #define FT_TEMPLATE_ARG		28
 
-#define FT_NUM_MEMBERS		29	/* Highest FT_* above, plus one. */
+/* The following three fundamental types are for decimal floating point.  */
+#define FT_DECFLOAT		29
+#define FT_DBL_PREC_DECFLOAT	30
+#define FT_EXT_PREC_DECFLOAT	31
+
+#define FT_NUM_MEMBERS		32	/* Highest FT_* above, plus one. */
 
 /* Some macros for char-based bitfields.  */
 
@@ -169,7 +174,9 @@ enum type_code
     TYPE_CODE_TEMPLATE,		/* C++ template */
     TYPE_CODE_TEMPLATE_ARG,	/* C++ template arg */
 
-    TYPE_CODE_NAMESPACE		/* C++ namespace.  */
+    TYPE_CODE_NAMESPACE,	/* C++ namespace.  */
+
+    TYPE_CODE_DECFLOAT		/* Decimal floating point.  */
   };
 
 /* For now allow source to use TYPE_CODE_CLASS for C++ classes, as an
@@ -1041,6 +1048,9 @@ struct builtin_type
   struct type *builtin_bool;
   struct type *builtin_long_long;
   struct type *builtin_unsigned_long_long;
+  struct type *builtin_decfloat;
+  struct type *builtin_decdouble;
+  struct type *builtin_declong;
 };
 
 /* Return the type table for the specified architecture.  */
Index: gdb/valprint.c
===================================================================
--- gdb/valprint.c.orig	2007-09-18 02:41:16.000000000 -0300
+++ gdb/valprint.c	2007-09-18 02:44:26.000000000 -0300
@@ -33,6 +33,7 @@
 #include "floatformat.h"
 #include "doublest.h"
 #include "exceptions.h"
+#include "dfp.h"
 
 #include <errno.h>
 
@@ -506,6 +507,18 @@ print_floating (const gdb_byte *valaddr,
 }
 
 void
+print_decimal_floating (const gdb_byte *valaddr, struct type *type,
+			struct ui_file *stream)
+{
+  char decstr[128];
+  unsigned len = TYPE_LENGTH (type);
+
+  decimal_to_string (valaddr, len, decstr);
+  fputs_filtered (decstr, stream);
+  return;
+}
+
+void
 print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
 		    unsigned len)
 {
Index: gdb/value.h
===================================================================
--- gdb/value.h.orig	2007-09-18 02:41:16.000000000 -0300
+++ gdb/value.h	2007-09-18 02:44:26.000000000 -0300
@@ -488,6 +488,9 @@ extern void print_longest (struct ui_fil
 extern void print_floating (const gdb_byte *valaddr, struct type *type,
 			    struct ui_file *stream);
 
+extern void print_decimal_floating (const gdb_byte *valaddr, struct type *type,
+				    struct ui_file *stream);
+
 extern int value_print (struct value *val, struct ui_file *stream, int format,
 			enum val_prettyprint pretty);
 
Index: gdb/c-typeprint.c
===================================================================
--- gdb/c-typeprint.c.orig	2007-09-18 02:41:10.000000000 -0300
+++ gdb/c-typeprint.c	2007-09-18 02:44:26.000000000 -0300
@@ -277,6 +277,7 @@ c_type_print_varspec_prefix (struct type
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_TEMPLATE:
     case TYPE_CODE_NAMESPACE:
+    case TYPE_CODE_DECFLOAT:
       /* These types need no prefix.  They are listed here so that
          gcc -Wall will reveal any types that haven't been handled.  */
       break;
@@ -599,6 +600,7 @@ c_type_print_varspec_suffix (struct type
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_TEMPLATE:
     case TYPE_CODE_NAMESPACE:
+    case TYPE_CODE_DECFLOAT:
       /* These types do not need a suffix.  They are listed so that
          gcc -Wall will report types that may not have been considered.  */
       break;

-- 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-10-25 18:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20070323030737.475073862@br.ibm.com>
2007-03-27 16:30 ` [patch 2/4] decimal floating point types Thiago Jung Bauermann
2007-09-20 21:57 [patch 0/4] decimal floating point support Thiago Jung Bauermann
2007-09-20 21:57 ` [patch 2/4] decimal floating point types Thiago Jung Bauermann
2007-10-11 16:00   ` Daniel Jacobowitz
2007-10-15 18:12     ` Thiago Jung Bauermann
2007-10-24 20:11       ` Daniel Jacobowitz
2007-10-25 18:24         ` Thiago Jung Bauermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox