Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: gdb-patches@sourceware.org
Subject: [PATCH] sim: common: add PRI printf defines [committed]
Date: Sun, 22 Nov 2015 06:40:00 -0000	[thread overview]
Message-ID: <1448174429-3980-1-git-send-email-vapier@gentoo.org> (raw)
In-Reply-To: <1434909729-6766-1-git-send-email-vapier@gentoo.org>

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


      parent reply	other threads:[~2015-11-22  6:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Mike Frysinger [this message]

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=1448174429-3980-1-git-send-email-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gdb-patches@sourceware.org \
    /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