public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH/RFC] sim: common: add PRI printf defines
@ 2015-06-21 18:02 Mike Frysinger
  2015-06-22 22:29 ` Doug Evans
  2015-11-22  6:40 ` [PATCH] sim: common: add PRI printf defines [committed] Mike Frysinger
  0 siblings, 2 replies; 8+ messages in thread
From: Mike Frysinger @ 2015-06-21 18:02 UTC (permalink / raw)
  To: gdb-patches

Keeping track of the right printf formats for the various types can be
a pretty big hassle, especially in common code which has to support a
variety of bitsizes.  Take a page from the existing standards and add
a set of PRI macros which hide the details in a common header.
---
 sim/common/ChangeLog   |  8 ++++++++
 sim/common/sim-types.h | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index 722ad98..db67a1d 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,5 +1,13 @@
 2015-06-21  Mike Frysinger  <vapier@gentoo.org>
 
+	* sim-types.h (_SIM_PRI_TB, __SIM_PRI_TB): New helper macros for
+	expanding target bitsizes into standard PRI formats.
+	(PRI_TW, PRIiTW, PRIxTW): New PRI target word defines.
+	(PRI_TA, PRIiTA, PRIxTA): New PRI target address defines.
+	(PRI_TF, PRIiTF, PRIxTF): New PRI target floating point defines.
+
+2015-06-21  Mike Frysinger  <vapier@gentoo.org>
+
 	* sim-model.c (sim_model_init): Assert model is not NULL.
 
 2015-06-21  Mike Frysinger  <vapier@gentoo.org>
diff --git a/sim/common/sim-types.h b/sim/common/sim-types.h
index 862f4e0..a64f644 100644
--- a/sim/common/sim-types.h
+++ b/sim/common/sim-types.h
@@ -87,6 +87,11 @@ typedef unsigned64 unsigned_8;
 typedef unsigned128 unsigned_16;
 
 
+/* Macros for printf.  */
+#define _SIM_PRI_TB(t, b)	__SIM_PRI_TB(t, b)
+#define __SIM_PRI_TB(t, b)	PRI##t##b
+
+
 /* for general work, the following are defined */
 /* unsigned: >= 32 bits */
 /* signed:   >= 32 bits */
@@ -107,6 +112,10 @@ typedef unsigned16 unsigned_word;
 typedef signed16 signed_word;
 #endif
 
+#define PRI_TW(t)	_SIM_PRI_TB(t, WITH_TARGET_WORD_BITSIZE)
+#define PRIiTW	PRI_TW(i)
+#define PRIxTW	PRI_TW(x)
+
 
 /* Other instructions */
 #if (WITH_TARGET_ADDRESS_BITSIZE == 64)
@@ -123,6 +132,10 @@ typedef signed16 signed_address;
 #endif
 typedef unsigned_address address_word;
 
+#define PRI_TA(t)	_SIM_PRI_TB(t, WITH_TARGET_ADDRESS_BITSIZE)
+#define PRIiTA	PRI_TA(i)
+#define PRIxTA	PRI_TA(x)
+
 
 /* IEEE 1275 cell size */
 #if (WITH_TARGET_CELL_BITSIZE == 64)
@@ -135,6 +148,10 @@ typedef signed32 signed_cell;
 #endif
 typedef signed_cell cell_word; /* cells are normally signed */
 
+#define PRI_TC(t)	_SIM_PRI_TB(t, WITH_TARGET_CELL_BITSIZE)
+#define PRIiTC	PRI_TC(i)
+#define PRIxTC	PRI_TC(x)
+
 
 /* Floating point registers */
 #if (WITH_TARGET_FLOATING_POINT_BITSIZE == 64)
@@ -144,4 +161,8 @@ typedef unsigned64 fp_word;
 typedef unsigned32 fp_word;
 #endif
 
+#define PRI_TF(t)	_SIM_PRI_TB(t, WITH_TARGET_FLOATING_POINT_BITSIZE)
+#define PRIiTF	PRI_TF(i)
+#define PRIxTF	PRI_TF(x)
+
 #endif
-- 
2.4.1

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

* Re: [PATCH/RFC] sim: common: add PRI printf defines
  2015-06-21 18:02 [PATCH/RFC] sim: common: add PRI printf defines Mike Frysinger
@ 2015-06-22 22:29 ` Doug Evans
  2015-06-22 23:50   ` Doug Evans
  2015-06-23 16:21   ` Mike Frysinger
  2015-11-22  6:40 ` [PATCH] sim: common: add PRI printf defines [committed] Mike Frysinger
  1 sibling, 2 replies; 8+ messages in thread
From: Doug Evans @ 2015-06-22 22:29 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: gdb-patches

On Sun, Jun 21, 2015 at 1:02 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> Keeping track of the right printf formats for the various types can be
> a pretty big hassle, especially in common code which has to support a
> variety of bitsizes.  Take a page from the existing standards and add
> a set of PRI macros which hide the details in a common header.
> ---
>  sim/common/ChangeLog   |  8 ++++++++
>  sim/common/sim-types.h | 21 +++++++++++++++++++++
>  2 files changed, 29 insertions(+)
>
> diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
> index 722ad98..db67a1d 100644
> --- a/sim/common/ChangeLog
> +++ b/sim/common/ChangeLog
> @@ -1,5 +1,13 @@
>  2015-06-21  Mike Frysinger  <vapier@gentoo.org>
>
> +       * sim-types.h (_SIM_PRI_TB, __SIM_PRI_TB): New helper macros for
> +       expanding target bitsizes into standard PRI formats.
> +       (PRI_TW, PRIiTW, PRIxTW): New PRI target word defines.
> +       (PRI_TA, PRIiTA, PRIxTA): New PRI target address defines.
> +       (PRI_TF, PRIiTF, PRIxTF): New PRI target floating point defines.
> +

It's not that big a deal, but _[_A-Z]+ is reserved for the compiler.

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

* Re: [PATCH/RFC] sim: common: add PRI printf defines
  2015-06-22 22:29 ` Doug Evans
@ 2015-06-22 23:50   ` Doug Evans
  2015-06-23 16:21   ` Mike Frysinger
  1 sibling, 0 replies; 8+ messages in thread
From: Doug Evans @ 2015-06-22 23:50 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: gdb-patches

On Mon, Jun 22, 2015 at 5:29 PM, Doug Evans <dje@google.com> wrote:
> On Sun, Jun 21, 2015 at 1:02 PM, Mike Frysinger <vapier@gentoo.org> wrote:
>> Keeping track of the right printf formats for the various types can be
>> a pretty big hassle, especially in common code which has to support a
>> variety of bitsizes.  Take a page from the existing standards and add
>> a set of PRI macros which hide the details in a common header.
>> ---
>>  sim/common/ChangeLog   |  8 ++++++++
>>  sim/common/sim-types.h | 21 +++++++++++++++++++++
>>  2 files changed, 29 insertions(+)
>>
>> diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
>> index 722ad98..db67a1d 100644
>> --- a/sim/common/ChangeLog
>> +++ b/sim/common/ChangeLog
>> @@ -1,5 +1,13 @@
>>  2015-06-21  Mike Frysinger  <vapier@gentoo.org>
>>
>> +       * sim-types.h (_SIM_PRI_TB, __SIM_PRI_TB): New helper macros for
>> +       expanding target bitsizes into standard PRI formats.
>> +       (PRI_TW, PRIiTW, PRIxTW): New PRI target word defines.
>> +       (PRI_TA, PRIiTA, PRIxTA): New PRI target address defines.
>> +       (PRI_TF, PRIiTF, PRIxTF): New PRI target floating point defines.
>> +
>
> It's not that big a deal, but _[_A-Z]+ is reserved for the compiler.

Hmmm.
I'm sure most people know what I meant, but to be precise,
that's _[_A-Z].*
Hope I've got that right now.

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

* Re: [PATCH/RFC] sim: common: add PRI printf defines
  2015-06-22 22:29 ` Doug Evans
  2015-06-22 23:50   ` Doug Evans
@ 2015-06-23 16:21   ` Mike Frysinger
  2015-06-23 16:28     ` Doug Evans
  1 sibling, 1 reply; 8+ messages in thread
From: Mike Frysinger @ 2015-06-23 16:21 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

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

On 22 Jun 2015 17:29, Doug Evans wrote:
> On Sun, Jun 21, 2015 at 1:02 PM, Mike Frysinger wrote:
> > Keeping track of the right printf formats for the various types can be
> > a pretty big hassle, especially in common code which has to support a
> > variety of bitsizes.  Take a page from the existing standards and add
> > a set of PRI macros which hide the details in a common header.
> > ---
> >  sim/common/ChangeLog   |  8 ++++++++
> >  sim/common/sim-types.h | 21 +++++++++++++++++++++
> >  2 files changed, 29 insertions(+)
> >
> > diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
> > index 722ad98..db67a1d 100644
> > --- a/sim/common/ChangeLog
> > +++ b/sim/common/ChangeLog
> > @@ -1,5 +1,13 @@
> >  2015-06-21  Mike Frysinger  <vapier@gentoo.org>
> >
> > +       * sim-types.h (_SIM_PRI_TB, __SIM_PRI_TB): New helper macros for
> > +       expanding target bitsizes into standard PRI formats.
> > +       (PRI_TW, PRIiTW, PRIxTW): New PRI target word defines.
> > +       (PRI_TA, PRIiTA, PRIxTA): New PRI target address defines.
> > +       (PRI_TF, PRIiTF, PRIxTF): New PRI target floating point defines.
> > +
> 
> It's not that big a deal, but _[_A-Z]+ is reserved for the compiler.

i'm aware of that rule, but it hasn't really stopped us in the code base from 
using the _xxx namespace.  the sim-bits.h header in particular uses this to mark 
the internal macros as such.

i'm certainly open to a diff convention of clearly conveying "this is internal" 
if gdb has such a thing.  although it too uses _xxx in a few places :).
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH/RFC] sim: common: add PRI printf defines
  2015-06-23 16:21   ` Mike Frysinger
@ 2015-06-23 16:28     ` Doug Evans
  2015-06-23 19:58       ` Mike Frysinger
  0 siblings, 1 reply; 8+ messages in thread
From: Doug Evans @ 2015-06-23 16:28 UTC (permalink / raw)
  To: gdb-patches

On Tue, Jun 23, 2015 at 11:21 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On 22 Jun 2015 17:29, Doug Evans wrote:
>> On Sun, Jun 21, 2015 at 1:02 PM, Mike Frysinger wrote:
>> > Keeping track of the right printf formats for the various types can be
>> > a pretty big hassle, especially in common code which has to support a
>> > variety of bitsizes.  Take a page from the existing standards and add
>> > a set of PRI macros which hide the details in a common header.
>> > ---
>> >  sim/common/ChangeLog   |  8 ++++++++
>> >  sim/common/sim-types.h | 21 +++++++++++++++++++++
>> >  2 files changed, 29 insertions(+)
>> >
>> > diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
>> > index 722ad98..db67a1d 100644
>> > --- a/sim/common/ChangeLog
>> > +++ b/sim/common/ChangeLog
>> > @@ -1,5 +1,13 @@
>> >  2015-06-21  Mike Frysinger  <vapier@gentoo.org>
>> >
>> > +       * sim-types.h (_SIM_PRI_TB, __SIM_PRI_TB): New helper macros for
>> > +       expanding target bitsizes into standard PRI formats.
>> > +       (PRI_TW, PRIiTW, PRIxTW): New PRI target word defines.
>> > +       (PRI_TA, PRIiTA, PRIxTA): New PRI target address defines.
>> > +       (PRI_TF, PRIiTF, PRIxTF): New PRI target floating point defines.
>> > +
>>
>> It's not that big a deal, but _[_A-Z]+ is reserved for the compiler.
>
> i'm aware of that rule, but it hasn't really stopped us in the code base from
> using the _xxx namespace.  the sim-bits.h header in particular uses this to mark
> the internal macros as such.
>
> i'm certainly open to a diff convention of clearly conveying "this is internal"
> if gdb has such a thing.  although it too uses _xxx in a few places :).
> -mike

How about a rule saying to avoid _[_A-Z] going forward,
and we'll fix the existing cases if/when we get to them.
?

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

* Re: [PATCH/RFC] sim: common: add PRI printf defines
  2015-06-23 16:28     ` Doug Evans
@ 2015-06-23 19:58       ` Mike Frysinger
  2015-06-23 20:07         ` Doug Evans
  0 siblings, 1 reply; 8+ messages in thread
From: Mike Frysinger @ 2015-06-23 19:58 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

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

On 23 Jun 2015 11:28, Doug Evans wrote:
> On Tue, Jun 23, 2015 at 11:21 AM, Mike Frysinger wrote:
> > On 22 Jun 2015 17:29, Doug Evans wrote:
> >> On Sun, Jun 21, 2015 at 1:02 PM, Mike Frysinger wrote:
> >> > Keeping track of the right printf formats for the various types can be
> >> > a pretty big hassle, especially in common code which has to support a
> >> > variety of bitsizes.  Take a page from the existing standards and add
> >> > a set of PRI macros which hide the details in a common header.
> >> > ---
> >> >  sim/common/ChangeLog   |  8 ++++++++
> >> >  sim/common/sim-types.h | 21 +++++++++++++++++++++
> >> >  2 files changed, 29 insertions(+)
> >> >
> >> > diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
> >> > index 722ad98..db67a1d 100644
> >> > --- a/sim/common/ChangeLog
> >> > +++ b/sim/common/ChangeLog
> >> > @@ -1,5 +1,13 @@
> >> >  2015-06-21  Mike Frysinger  <vapier@gentoo.org>
> >> >
> >> > +       * sim-types.h (_SIM_PRI_TB, __SIM_PRI_TB): New helper macros for
> >> > +       expanding target bitsizes into standard PRI formats.
> >> > +       (PRI_TW, PRIiTW, PRIxTW): New PRI target word defines.
> >> > +       (PRI_TA, PRIiTA, PRIxTA): New PRI target address defines.
> >> > +       (PRI_TF, PRIiTF, PRIxTF): New PRI target floating point defines.
> >> > +
> >>
> >> It's not that big a deal, but _[_A-Z]+ is reserved for the compiler.
> >
> > i'm aware of that rule, but it hasn't really stopped us in the code base from
> > using the _xxx namespace.  the sim-bits.h header in particular uses this to mark
> > the internal macros as such.
> >
> > i'm certainly open to a diff convention of clearly conveying "this is internal"
> > if gdb has such a thing.  although it too uses _xxx in a few places :).
> 
> How about a rule saying to avoid _[_A-Z] going forward,
> and we'll fix the existing cases if/when we get to them.
> ?

what's the proposed replacement ? :)

GDB__XXX & SIM__XXX ?
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH/RFC] sim: common: add PRI printf defines
  2015-06-23 19:58       ` Mike Frysinger
@ 2015-06-23 20:07         ` Doug Evans
  0 siblings, 0 replies; 8+ messages in thread
From: Doug Evans @ 2015-06-23 20:07 UTC (permalink / raw)
  To: gdb-patches

On Tue, Jun 23, 2015 at 2:58 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> On 23 Jun 2015 11:28, Doug Evans wrote:
>> On Tue, Jun 23, 2015 at 11:21 AM, Mike Frysinger wrote:
>> > On 22 Jun 2015 17:29, Doug Evans wrote:
>> >> On Sun, Jun 21, 2015 at 1:02 PM, Mike Frysinger wrote:
>> >> > Keeping track of the right printf formats for the various types can be
>> >> > a pretty big hassle, especially in common code which has to support a
>> >> > variety of bitsizes.  Take a page from the existing standards and add
>> >> > a set of PRI macros which hide the details in a common header.
>> >> > ---
>> >> >  sim/common/ChangeLog   |  8 ++++++++
>> >> >  sim/common/sim-types.h | 21 +++++++++++++++++++++
>> >> >  2 files changed, 29 insertions(+)
>> >> >
>> >> > diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
>> >> > index 722ad98..db67a1d 100644
>> >> > --- a/sim/common/ChangeLog
>> >> > +++ b/sim/common/ChangeLog
>> >> > @@ -1,5 +1,13 @@
>> >> >  2015-06-21  Mike Frysinger  <vapier@gentoo.org>
>> >> >
>> >> > +       * sim-types.h (_SIM_PRI_TB, __SIM_PRI_TB): New helper macros for
>> >> > +       expanding target bitsizes into standard PRI formats.
>> >> > +       (PRI_TW, PRIiTW, PRIxTW): New PRI target word defines.
>> >> > +       (PRI_TA, PRIiTA, PRIxTA): New PRI target address defines.
>> >> > +       (PRI_TF, PRIiTF, PRIxTF): New PRI target floating point defines.
>> >> > +
>> >>
>> >> It's not that big a deal, but _[_A-Z]+ is reserved for the compiler.
>> >
>> > i'm aware of that rule, but it hasn't really stopped us in the code base from
>> > using the _xxx namespace.  the sim-bits.h header in particular uses this to mark
>> > the internal macros as such.
>> >
>> > i'm certainly open to a diff convention of clearly conveying "this is internal"
>> > if gdb has such a thing.  although it too uses _xxx in a few places :).
>>
>> How about a rule saying to avoid _[_A-Z] going forward,
>> and we'll fix the existing cases if/when we get to them.
>> ?
>
> what's the proposed replacement ? :)
>
> GDB__XXX & SIM__XXX ?
> -mike

Hi.
I didn't want to impose anything, sometimes the leading _ can just be removed.

For the current patch, SIM__XXX is fine with me.
[if it's important to use something that denotes these as being local
to the file.
Anything beginning with SIM_ would be fine I think.]

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

* [PATCH] sim: common: add PRI printf defines [committed]
  2015-06-21 18:02 [PATCH/RFC] sim: common: add PRI printf defines Mike Frysinger
  2015-06-22 22:29 ` Doug Evans
@ 2015-11-22  6:40 ` Mike Frysinger
  1 sibling, 0 replies; 8+ messages in thread
From: Mike Frysinger @ 2015-11-22  6:40 UTC (permalink / raw)
  To: gdb-patches

Keeping track of the right printf formats for the various types can be
a pretty big hassle, especially in common code which has to support a
variety of bitsizes.  Take a page from the existing standards and add
a set of PRI macros which hide the details in a common header.
---
Note: This version I switched to the XCONCAT defines.

 sim/common/ChangeLog   |  8 ++++++++
 sim/common/sim-types.h | 20 ++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index ddf4558..464fd80 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,3 +1,11 @@
+2015-11-21  Mike Frysinger  <vapier@gentoo.org>
+
+	* sim-types.h (SIM_PRI_TB): Define.
+	(PRI_TW, PRIiTW, PRIxTW): New PRI target word defines.
+	(PRI_TA, PRIiTA, PRIxTA): New PRI target address defines.
+	(PRI_TC, PRIiTC, PRIxTC): New PRI target cell defines.
+	(PRI_TF, PRIiTF, PRIxTF): New PRI target floating point defines.
+
 2015-11-17  Mike Frysinger  <vapier@gentoo.org>
 
 	* sim-main.h (WITH_MODULO_MEMORY): Delete.
diff --git a/sim/common/sim-types.h b/sim/common/sim-types.h
index 862f4e0..7e0a34a 100644
--- a/sim/common/sim-types.h
+++ b/sim/common/sim-types.h
@@ -87,6 +87,10 @@ typedef unsigned64 unsigned_8;
 typedef unsigned128 unsigned_16;
 
 
+/* Macros for printf.  Usage is restricted to this header.  */
+#define SIM_PRI_TB(t, b)	XCONCAT3 (PRI,t,b)
+
+
 /* for general work, the following are defined */
 /* unsigned: >= 32 bits */
 /* signed:   >= 32 bits */
@@ -107,6 +111,10 @@ typedef unsigned16 unsigned_word;
 typedef signed16 signed_word;
 #endif
 
+#define PRI_TW(t)	SIM_PRI_TB (t, WITH_TARGET_WORD_BITSIZE)
+#define PRIiTW	PRI_TW (i)
+#define PRIxTW	PRI_TW (x)
+
 
 /* Other instructions */
 #if (WITH_TARGET_ADDRESS_BITSIZE == 64)
@@ -123,6 +131,10 @@ typedef signed16 signed_address;
 #endif
 typedef unsigned_address address_word;
 
+#define PRI_TA(t)	SIM_PRI_TB (t, WITH_TARGET_ADDRESS_BITSIZE)
+#define PRIiTA	PRI_TA (i)
+#define PRIxTA	PRI_TA (x)
+
 
 /* IEEE 1275 cell size */
 #if (WITH_TARGET_CELL_BITSIZE == 64)
@@ -135,6 +147,10 @@ typedef signed32 signed_cell;
 #endif
 typedef signed_cell cell_word; /* cells are normally signed */
 
+#define PRI_TC(t)	SIM_PRI_TB (t, WITH_TARGET_CELL_BITSIZE)
+#define PRIiTC	PRI_TC (i)
+#define PRIxTC	PRI_TC (x)
+
 
 /* Floating point registers */
 #if (WITH_TARGET_FLOATING_POINT_BITSIZE == 64)
@@ -144,4 +160,8 @@ typedef unsigned64 fp_word;
 typedef unsigned32 fp_word;
 #endif
 
+#define PRI_TF(t)	SIM_PRI_TB (t, WITH_TARGET_FLOATING_POINT_BITSIZE)
+#define PRIiTF	PRI_TF (i)
+#define PRIxTF	PRI_TF (x)
+
 #endif
-- 
2.6.2

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

end of thread, other threads:[~2015-11-22  6:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-21 18:02 [PATCH/RFC] sim: common: add PRI printf defines Mike Frysinger
2015-06-22 22:29 ` Doug Evans
2015-06-22 23:50   ` Doug Evans
2015-06-23 16:21   ` Mike Frysinger
2015-06-23 16:28     ` Doug Evans
2015-06-23 19:58       ` Mike Frysinger
2015-06-23 20:07         ` Doug Evans
2015-11-22  6:40 ` [PATCH] sim: common: add PRI printf defines [committed] Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).