qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <andreas.faerber@web.de>
To: qemu-devel@nongnu.org
Cc: "Andreas Färber" <andreas.faerber@web.de>
Subject: [Qemu-devel] [PATCH 4/4] tcg: Allow to detect TCGv misuses
Date: Sat, 10 Dec 2011 10:02:27 +0100	[thread overview]
Message-ID: <1323507747-16261-5-git-send-email-andreas.faerber@web.de> (raw)
In-Reply-To: <1323507747-16261-1-git-send-email-andreas.faerber@web.de>

It's easy to omit _i32 somewhere if working on one 32-bit target,
despite DEBUG_TCGV, because TCGv is simply aliased to TCGv_i32/i64.

If DEBUG_TCGV_TL is defined, use a new struct TCGv with distinguished
accessors to catch mixups.

This cannot be done unconditionally for DEBUG_TCGV because some targets
use TCGv and TCGv_i32/i64 interchangeably depending on TARGET_*.

Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
 def-helper.h |   13 ++++++++-----
 tcg/tcg-op.h |   14 ++++++++++++++
 tcg/tcg.h    |    1 +
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/def-helper.h b/def-helper.h
index 8a822c7..5be1110 100644
--- a/def-helper.h
+++ b/def-helper.h
@@ -22,8 +22,11 @@
 
 #define GET_TCGV_i32 GET_TCGV_I32
 #define GET_TCGV_i64 GET_TCGV_I64
+#define GET_TCGV_tl  GET_TCGV_TL
 #define GET_TCGV_ptr GET_TCGV_PTR
 
+#define TCGv_tl TCGv
+
 /* Some types that make sense in C, but not for TCG.  */
 #define dh_alias_i32 i32
 #define dh_alias_s32 i32
@@ -32,11 +35,7 @@
 #define dh_alias_s64 i64
 #define dh_alias_f32 i32
 #define dh_alias_f64 i64
-#if TARGET_LONG_BITS == 32
-#define dh_alias_tl i32
-#else
-#define dh_alias_tl i64
-#endif
+#define dh_alias_tl tl
 #define dh_alias_ptr ptr
 #define dh_alias_void void
 #define dh_alias_env ptr
@@ -60,24 +59,28 @@
 #define dh_retvar_decl0_void void
 #define dh_retvar_decl0_i32 TCGv_i32 retval
 #define dh_retvar_decl0_i64 TCGv_i64 retval
+#define dh_retvar_decl0_tl  TCGv retval
 #define dh_retvar_decl0_ptr TCGv_ptr retval
 #define dh_retvar_decl0(t) glue(dh_retvar_decl0_, dh_alias(t))
 
 #define dh_retvar_decl_void
 #define dh_retvar_decl_i32 TCGv_i32 retval,
 #define dh_retvar_decl_i64 TCGv_i64 retval,
+#define dh_retvar_decl_tl  TCGv retval,
 #define dh_retvar_decl_ptr TCGv_ptr retval,
 #define dh_retvar_decl(t) glue(dh_retvar_decl_, dh_alias(t))
 
 #define dh_retvar_void TCG_CALL_DUMMY_ARG
 #define dh_retvar_i32 GET_TCGV_i32(retval)
 #define dh_retvar_i64 GET_TCGV_i64(retval)
+#define dh_retvar_tl  GET_TCGV_tl(retval)
 #define dh_retvar_ptr GET_TCGV_ptr(retval)
 #define dh_retvar(t) glue(dh_retvar_, dh_alias(t))
 
 #define dh_is_64bit_void 0
 #define dh_is_64bit_i32 0
 #define dh_is_64bit_i64 1
+#define dh_is_64bit_tl (TARGET_LONG_BITS == 64)
 #define dh_is_64bit_ptr (TCG_TARGET_REG_BITS == 64)
 #define dh_is_64bit(t) glue(dh_is_64bit_, dh_alias(t))
 
diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h
index a6c3d5f..d065e74 100644
--- a/tcg/tcg-op.h
+++ b/tcg/tcg-op.h
@@ -2125,6 +2125,18 @@ static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
 #error must include QEMU headers
 #endif
 
+#if defined(DEBUG_TCGV) && defined(DEBUG_TCGV_TL)
+
+typedef struct {
+    int itl;
+} TCGv;
+
+#define MAKE_TCGV_TL(i) __extension__                  \
+    ({ TCGv make_tcgv_tmp = {i}; make_tcgv_tmp; })
+#define GET_TCGV_TL(t) ((t).itl)
+
+#else /* !DEBUG_TCGV_TL */
+
 #if TARGET_LONG_BITS == 32
 #define TCGv TCGv_i32
 #define MAKE_TCGV_TL(x) MAKE_TCGV_I32(x)
@@ -2135,6 +2147,8 @@ static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
 #define GET_TCGV_TL(t) GET_TCGV_I64(t)
 #endif
 
+#endif /* !DEBUG_TCGV_TL */
+
 #define TCGV_UNUSED(x) x = MAKE_TCGV_TL(-1)
 #define TCGV_EQUAL(a, b) (GET_TCGV_TL(a) == GET_TCGV_TL(b))
 
diff --git a/tcg/tcg.h b/tcg/tcg.h
index 175000f..01bf74b 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -189,6 +189,7 @@ typedef tcg_target_ulong TCGArg;
 
 #ifdef CONFIG_DEBUG_TCG
 #define DEBUG_TCGV 1
+//#define DEBUG_TCGV_TL
 #endif
 
 #ifdef DEBUG_TCGV
-- 
1.7.7

  parent reply	other threads:[~2011-12-10  9:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-10  9:02 [Qemu-devel] [PATCH 0/4] tcg: Add debug facilities for TCGv Andreas Färber
2011-12-10  9:02 ` [Qemu-devel] [PATCH 1/4] tcg: Introduce {MAKE,GET}_TCGV_TL macros Andreas Färber
2011-12-10  9:02 ` [Qemu-devel] [PATCH 2/4] tcg: Convert *_tl*() macros to inline functions Andreas Färber
2011-12-10 21:06   ` [Qemu-devel] [PATCH v2] " Andreas Färber
2011-12-10  9:02 ` [Qemu-devel] [PATCH 3/4] tcg: Update TCGV_{UNUSED,EQUAL}() macros Andreas Färber
2011-12-10  9:02 ` Andreas Färber [this message]
2011-12-10 10:07 ` [Qemu-devel] [PATCH 0/4] tcg: Add debug facilities for TCGv Peter Maydell
2011-12-10 11:14   ` Andreas Färber
2011-12-11 23:28     ` Paul Brook
2011-12-12 10:39       ` Andreas Färber
2011-12-12 15:58         ` Paul Brook
2011-12-13 12:43           ` Andreas Färber
2011-12-13 16:26             ` Paul Brook
2011-12-14 11:41               ` Andreas Färber
2011-12-13 13:11           ` Andreas Färber
2011-12-13 16:23             ` Paul Brook

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=1323507747-16261-5-git-send-email-andreas.faerber@web.de \
    --to=andreas.faerber@web.de \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).