qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] tcg: Add consistency checks for op definitions
@ 2010-02-15 16:17 Stefan Weil
  2010-02-18 19:30 ` Blue Swirl
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Weil @ 2010-02-15 16:17 UTC (permalink / raw)
  To: QEMU Developers

When compiled with CONFIG_DEBUG_TCG, this code looks
for missing, duplicate and wrong entries in the
op definitions.

Errors will raise an assertion at program start
(all checks are done in the initial phase).

The current code contains such errors, at least for
i386 guest on i386 host.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 tcg/tcg.c |   21 +++++++++++++++++++++
 tcg/tcg.h |    3 +++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/tcg/tcg.c b/tcg/tcg.c
index 9949814..e6a1caf 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -981,9 +981,16 @@ void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs)
         op = tdefs->op;
         assert(op >= 0 && op < NB_OPS);
         def = &tcg_op_defs[op];
+#if defined(CONFIG_DEBUG_TCG)
+        /* Duplicate entry in op definitions? */
+        assert(!def->used);
+        def->used = 1;
+#endif
         nb_args = def->nb_iargs + def->nb_oargs;
         for(i = 0; i < nb_args; i++) {
             ct_str = tdefs->args_ct_str[i];
+            /* Incomplete TCGTargetOpDef entry? */
+            assert(ct_str != NULL);
             tcg_regset_clear(def->args_ct[i].u.regs);
             def->args_ct[i].ct = 0;
             if (ct_str[0] >= '0' && ct_str[0] <= '9') {
@@ -1018,6 +1025,9 @@ void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs)
             }
         }
 
+        /* TCGTargetOpDef entry with too much information? */
+        assert(i == TCG_MAX_OP_ARGS || tdefs->args_ct_str[i] == NULL);
+
         /* sort the constraints (XXX: this is just an heuristic) */
         sort_constraints(def, 0, def->nb_oargs);
         sort_constraints(def, def->nb_oargs, def->nb_iargs);
@@ -1035,6 +1045,17 @@ void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs)
         tdefs++;
     }
 
+#if defined(CONFIG_DEBUG_TCG)
+    for (op = 0; op < ARRAY_SIZE(tcg_op_defs); op++) {
+        if (op < INDEX_op_call || op == INDEX_op_debug_insn_start) {
+            /* Wrong entry in op definitions? */
+            assert(!tcg_op_defs[op].used);
+        } else {
+            /* Missing entry in op definitions? */
+            assert(tcg_op_defs[op].used);
+        }
+    }
+#endif
 }
 
 #ifdef USE_LIVENESS_ANALYSIS
diff --git a/tcg/tcg.h b/tcg/tcg.h
index b218abe..aca9f27 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -404,6 +404,9 @@ typedef struct TCGOpDef {
     uint16_t copy_size;
     TCGArgConstraint *args_ct;
     int *sorted_args;
+#if defined(CONFIG_DEBUG_TCG)
+    int used;
+#endif
 } TCGOpDef;
         
 typedef struct TCGTargetOpDef {
-- 
1.6.6.1

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

* Re: [Qemu-devel] [PATCH] tcg: Add consistency checks for op definitions
  2010-02-15 16:17 [Qemu-devel] [PATCH] tcg: Add consistency checks for op definitions Stefan Weil
@ 2010-02-18 19:30 ` Blue Swirl
  0 siblings, 0 replies; 2+ messages in thread
From: Blue Swirl @ 2010-02-18 19:30 UTC (permalink / raw)
  To: Stefan Weil; +Cc: qemu-devel

Thanks, applied.

On Mon, Feb 15, 2010 at 6:17 PM, Stefan Weil <weil@mail.berlios.de> wrote:
> When compiled with CONFIG_DEBUG_TCG, this code looks
> for missing, duplicate and wrong entries in the
> op definitions.
>
> Errors will raise an assertion at program start
> (all checks are done in the initial phase).
>
> The current code contains such errors, at least for
> i386 guest on i386 host.
>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  tcg/tcg.c |   21 +++++++++++++++++++++
>  tcg/tcg.h |    3 +++
>  2 files changed, 24 insertions(+), 0 deletions(-)
>
> diff --git a/tcg/tcg.c b/tcg/tcg.c
> index 9949814..e6a1caf 100644
> --- a/tcg/tcg.c
> +++ b/tcg/tcg.c
> @@ -981,9 +981,16 @@ void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs)
>         op = tdefs->op;
>         assert(op >= 0 && op < NB_OPS);
>         def = &tcg_op_defs[op];
> +#if defined(CONFIG_DEBUG_TCG)
> +        /* Duplicate entry in op definitions? */
> +        assert(!def->used);
> +        def->used = 1;
> +#endif
>         nb_args = def->nb_iargs + def->nb_oargs;
>         for(i = 0; i < nb_args; i++) {
>             ct_str = tdefs->args_ct_str[i];
> +            /* Incomplete TCGTargetOpDef entry? */
> +            assert(ct_str != NULL);
>             tcg_regset_clear(def->args_ct[i].u.regs);
>             def->args_ct[i].ct = 0;
>             if (ct_str[0] >= '0' && ct_str[0] <= '9') {
> @@ -1018,6 +1025,9 @@ void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs)
>             }
>         }
>
> +        /* TCGTargetOpDef entry with too much information? */
> +        assert(i == TCG_MAX_OP_ARGS || tdefs->args_ct_str[i] == NULL);
> +
>         /* sort the constraints (XXX: this is just an heuristic) */
>         sort_constraints(def, 0, def->nb_oargs);
>         sort_constraints(def, def->nb_oargs, def->nb_iargs);
> @@ -1035,6 +1045,17 @@ void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs)
>         tdefs++;
>     }
>
> +#if defined(CONFIG_DEBUG_TCG)
> +    for (op = 0; op < ARRAY_SIZE(tcg_op_defs); op++) {
> +        if (op < INDEX_op_call || op == INDEX_op_debug_insn_start) {
> +            /* Wrong entry in op definitions? */
> +            assert(!tcg_op_defs[op].used);
> +        } else {
> +            /* Missing entry in op definitions? */
> +            assert(tcg_op_defs[op].used);
> +        }
> +    }
> +#endif
>  }
>
>  #ifdef USE_LIVENESS_ANALYSIS
> diff --git a/tcg/tcg.h b/tcg/tcg.h
> index b218abe..aca9f27 100644
> --- a/tcg/tcg.h
> +++ b/tcg/tcg.h
> @@ -404,6 +404,9 @@ typedef struct TCGOpDef {
>     uint16_t copy_size;
>     TCGArgConstraint *args_ct;
>     int *sorted_args;
> +#if defined(CONFIG_DEBUG_TCG)
> +    int used;
> +#endif
>  } TCGOpDef;
>
>  typedef struct TCGTargetOpDef {
> --
> 1.6.6.1
>
>
>
>

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

end of thread, other threads:[~2010-02-18 19:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-15 16:17 [Qemu-devel] [PATCH] tcg: Add consistency checks for op definitions Stefan Weil
2010-02-18 19:30 ` Blue Swirl

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).