Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Cagney <ac131313@redhat.com>
To: Daniel Jacobowitz <drow@mvista.com>
Cc: gdb-patches@sources.redhat.com, binutils@sources.redhat.com,
	gcc-patches@gcc.gnu.org
Subject: Re: [libiberty and gdb] floatformat_is_valid
Date: Tue, 16 Sep 2003 02:57:00 -0000	[thread overview]
Message-ID: <3F667C15.50203@redhat.com> (raw)
In-Reply-To: <20030915205815.GA4563@nevyn.them.org>

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

> On Mon, Sep 15, 2003 at 04:54:17PM -0400, Andrew Cagney wrote:
> 
>> >+/* Return non-zero iff the data at FROM is a valid number in format FMT.  
>> >*/
>> >+
>> >+int
>> >+floatformat_is_valid (fmt, from)
>> >+     const struct floatformat *fmt;
>> >+     char *from;
>> >+{
> 
>> 
>> Shouldn't this be a new virtual method in floatformat?

The attached implements this.  Any objections?

> Floatformats don't have any virtual methods right now; if you want to
> add them, be my guest.  Besides, this is more in line with the
> libiberty policy of backwards compatibility, since it does not change
> the structure layout.

There didn't seem to be a problem when "name" was added, or arm_ext was 
deleted.

enjoy,
Andrew


[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 8986 bytes --]

Index: include/ChangeLog
2003-09-15  Andrew Cagney  <cagney@redhat.com>

	* floatformat.h (struct floatformat): Add field "is_valid".

Index: libiberty/ChangeLog
2003-09-15  Andrew Cagney  <cagney@redhat.com>

	* floatformat.c (floatformat_i387_ext_is_valid): New function.
	(floatformat_always_valid): New function.
	(floatformat_m68881_ext): Initialize new "is_valid" field to
	"floatformat_i387_ext_is_valid".
	(floatformat_ieee_single_little): Initialize "is_valid" field to
	floatformat_always_valid.
	(floatformat_ieee_double_big): Ditto.
	(floatformat_ieee_double_little): Ditto.
	(floatformat_ieee_double_little): Ditto.
	(floatformat_ieee_double_littlebyte_bigword): Ditto.
	(floatformat_i960_ext): Ditto.
	(floatformat_m88110_ext): Ditto.
	(floatformat_m88110_harris_ext): Ditto.
	(floatformat_arm_ext_big): Ditto.
	(floatformat_arm_ext_littlebyte_bigword): Ditto.
	(floatformat_ia64_spill_big): Ditto.
	(floatformat_ia64_spill_little): Ditto.
	(floatformat_ia64_quad_big): Ditto.
	(floatformat_ia64_quad_little): Ditto.
	(floatformat_ia64_quad_little): Ditto.
	(floatformat_is_valid): Call "is_valid".

Index: include/floatformat.h
===================================================================
RCS file: /cvs/src/src/include/floatformat.h,v
retrieving revision 1.8
diff -u -r1.8 floatformat.h
--- include/floatformat.h	16 Sep 2003 01:47:53 -0000	1.8
+++ include/floatformat.h	16 Sep 2003 02:24:45 -0000
@@ -80,6 +80,9 @@
 
   /* Internal name for debugging. */
   const char *name;
+
+  /* Validator method.  */
+  int (*is_valid) PARAMS ((const struct floatformat *fmt, const char *from));
 };
 
 /* floatformats for IEEE single and double, big and little endian.  */
Index: libiberty/floatformat.c
===================================================================
RCS file: /cvs/src/src/libiberty/floatformat.c,v
retrieving revision 1.9
diff -u -r1.9 floatformat.c
--- libiberty/floatformat.c	16 Sep 2003 01:47:54 -0000	1.9
+++ libiberty/floatformat.c	16 Sep 2003 02:25:42 -0000
@@ -29,6 +29,22 @@
 extern char *memset ();
 #endif
 
+static unsigned long get_field PARAMS ((const unsigned char *,
+					enum floatformat_byteorders,
+					unsigned int,
+					unsigned int,
+					unsigned int));
+static int floatformat_always_valid PARAMS ((const struct floatformat *fmt,
+					     const char *from));
+
+static int
+floatformat_always_valid (fmt, from)
+     const struct floatformat *fmt;
+     const char *from;
+{
+  return 1;
+}
+
 /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
    going to bother with trying to muck around with whether it is defined in
    a system header, what we do if not, etc.  */
@@ -39,25 +55,29 @@
 {
   floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23,
   floatformat_intbit_no,
-  "floatformat_ieee_single_big"
+  "floatformat_ieee_single_big",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_ieee_single_little =
 {
   floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23,
   floatformat_intbit_no,
-  "floatformat_ieee_single_little"
+  "floatformat_ieee_single_little",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_ieee_double_big =
 {
   floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52,
   floatformat_intbit_no,
-  "floatformat_ieee_double_big"
+  "floatformat_ieee_double_big",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_ieee_double_little =
 {
   floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52,
   floatformat_intbit_no,
-  "floatformat_ieee_double_little"
+  "floatformat_ieee_double_little",
+  floatformat_always_valid
 };
 
 /* floatformat for IEEE double, little endian byte order, with big endian word
@@ -67,34 +87,64 @@
 {
   floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52,
   floatformat_intbit_no,
-  "floatformat_ieee_double_littlebyte_bigword"
+  "floatformat_ieee_double_littlebyte_bigword",
+  floatformat_always_valid
 };
 
+static int floatformat_i387_ext_is_valid PARAMS ((const struct floatformat *fmt, const char *from));
+
+static int
+floatformat_i387_ext_is_valid (fmt, from)
+     const struct floatformat *fmt;
+     const char *from;
+{
+  /* In the i387 double-extended format, if the exponent is all ones,
+     then the integer bit must be set.  If the exponent is neither 0
+     nor ~0, the intbit must also be set.  Only if the exponent is
+     zero can it be zero, and then it must be zero.  */
+  unsigned long exponent, int_bit;
+  const unsigned char *ufrom = (const unsigned char *) from;
+  
+  exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
+			fmt->exp_start, fmt->exp_len);
+  int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize,
+		       fmt->man_start, 1);
+  
+  if ((exponent == 0) != (int_bit == 0))
+    return 0;
+  else
+    return 1;
+}
+
 const struct floatformat floatformat_i387_ext =
 {
   floatformat_little, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
   floatformat_intbit_yes,
-  "floatformat_i387_ext"
+  "floatformat_i387_ext",
+  floatformat_i387_ext_is_valid
 };
 const struct floatformat floatformat_m68881_ext =
 {
   /* Note that the bits from 16 to 31 are unused.  */
   floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64,
   floatformat_intbit_yes,
-  "floatformat_m68881_ext"
+  "floatformat_m68881_ext",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_i960_ext =
 {
   /* Note that the bits from 0 to 15 are unused.  */
   floatformat_little, 96, 16, 17, 15, 0x3fff, 0x7fff, 32, 64,
   floatformat_intbit_yes,
-  "floatformat_i960_ext"
+  "floatformat_i960_ext",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_m88110_ext =
 {
   floatformat_big, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
   floatformat_intbit_yes,
-  "floatformat_m88110_ext"
+  "floatformat_m88110_ext",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_m88110_harris_ext =
 {
@@ -102,53 +152,54 @@
      double, and the last 64 bits are wasted. */
   floatformat_big,128, 0, 1, 11,  0x3ff,  0x7ff, 12, 52,
   floatformat_intbit_no,
-  "floatformat_m88110_ext_harris"
+  "floatformat_m88110_ext_harris",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_arm_ext_big =
 {
   /* Bits 1 to 16 are unused.  */
   floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
   floatformat_intbit_yes,
-  "floatformat_arm_ext_big"
+  "floatformat_arm_ext_big",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_arm_ext_littlebyte_bigword =
 {
   /* Bits 1 to 16 are unused.  */
   floatformat_littlebyte_bigword, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
   floatformat_intbit_yes,
-  "floatformat_arm_ext_littlebyte_bigword"
+  "floatformat_arm_ext_littlebyte_bigword",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_ia64_spill_big =
 {
   floatformat_big, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
   floatformat_intbit_yes,
-  "floatformat_ia64_spill_big"
+  "floatformat_ia64_spill_big",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_ia64_spill_little =
 {
   floatformat_little, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
   floatformat_intbit_yes,
-  "floatformat_ia64_spill_little"
+  "floatformat_ia64_spill_little",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_ia64_quad_big =
 {
   floatformat_big, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
   floatformat_intbit_no,
-  "floatformat_ia64_quad_big"
+  "floatformat_ia64_quad_big",
+  floatformat_always_valid
 };
 const struct floatformat floatformat_ia64_quad_little =
 {
   floatformat_little, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
   floatformat_intbit_no,
-  "floatformat_ia64_quad_little"
+  "floatformat_ia64_quad_little",
+  floatformat_always_valid
 };
 \f
-static unsigned long get_field PARAMS ((const unsigned char *,
-					enum floatformat_byteorders,
-					unsigned int,
-					unsigned int,
-					unsigned int));
-
 /* Extract a field which starts at START and is LEN bits long.  DATA and
    TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER.  */
 static unsigned long
@@ -411,30 +462,7 @@
      const struct floatformat *fmt;
      const char *from;
 {
-  if (fmt == &floatformat_i387_ext)
-    {
-      /* In the i387 double-extended format, if the exponent is all
-	 ones, then the integer bit must be set.  If the exponent
-	 is neither 0 nor ~0, the intbit must also be set.  Only
-	 if the exponent is zero can it be zero, and then it must
-	 be zero.  */
-      unsigned long exponent, int_bit;
-      const unsigned char *ufrom = (const unsigned char *) from;
-
-      exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
-			    fmt->exp_start, fmt->exp_len);
-      int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize,
-			   fmt->man_start, 1);
-
-      if ((exponent == 0) != (int_bit == 0))
-	return 0;
-      else
-	return 1;
-    }
-
-  /* Other formats with invalid representations should be added
-     here.  */
-  return 1;
+  return fmt->is_valid (fmt, from);
 }
 
 

  parent reply	other threads:[~2003-09-16  2:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-15 14:39 Daniel Jacobowitz
2003-09-15 17:57 ` DJ Delorie
2003-09-15 20:33 ` Daniel Jacobowitz
2003-09-15 20:54 ` Andrew Cagney
2003-09-15 20:58   ` Daniel Jacobowitz
2003-09-15 21:04     ` Andrew Cagney
2003-09-15 21:48       ` DJ Delorie
2003-09-16  2:57     ` Andrew Cagney [this message]
2003-09-16  3:10       ` DJ Delorie
2003-09-22 17:43       ` Andrew Cagney
2003-09-15 21:22 ` Andrew Cagney
2003-09-15 21:52 ` Mark Kettenis
2003-09-18 20:31 ` Daniel Jacobowitz
2003-09-18 22:59   ` Andrew Cagney
2003-09-21 19:11     ` Daniel Jacobowitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3F667C15.50203@redhat.com \
    --to=ac131313@redhat.com \
    --cc=binutils@sources.redhat.com \
    --cc=drow@mvista.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox