typo removed
[libfirm] / ir / ir / irvrfy.c
index ff8447d..0f852aa 100644 (file)
@@ -1,13 +1,15 @@
-/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
- * All rights reserved.
- *
- * Authors: Christian Schaefer
- *
- *
+/*
+ * Project:     libFIRM
+ * File name:   ir/ir/irvrfy.c
+ * Purpose:     Check irnodes for correctness.
+ * Author:      Christian Schaefer
+ * Modified by: Goetz Lindenmaier. Till Riedel
+ * Created:
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 1998-2003 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
  */
 
-/* $Id$ */
-
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
 # include "irgwalk.h"
 
 #ifdef NDEBUG
-#define ASSERT_AND_RET(expr, string, ret)  if (!(expr)) return (ret)
+/*
+ * in RELEASE mode, returns ret if the expression expr evaluates to zero
+ * in ASSERT mode, asserts the expression expr (and the string string).
+ */
+#define ASSERT_AND_RET(expr, string, ret)              if (!(expr)) return (ret)
+
+/*
+ * in RELEASE mode, returns ret if the expression expr evaluates to zero
+ * in ASSERT mode, executes blk if the expression expr evaluates to zero and asserts
+ */
+#define ASSERT_AND_RET_DBG(expr, string, ret, blk)     if (!(expr)) return (ret)
 #else
-#define ASSERT_AND_RET(expr, string, ret)  do { assert((expr) && string); if (!(expr)) return (ret); } while(0)
+#define ASSERT_AND_RET(expr, string, ret)              do { assert((expr) && string); if (!(expr)) return (ret); } while(0)
+#define ASSERT_AND_RET_DBG(expr, string, ret, blk)     do { if (!(expr)) { { blk } assert(0 && string); return (ret); } } while(0)
 #endif
 
 /* @@@ replace use of array "in" by access functions. */
@@ -211,8 +224,8 @@ int irn_vrfy_irg(ir_node *n, ir_graph *irg)
   int opcode, opcode1;
   ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
   int op_is_symmetric = 1;  /*  0: asymmetric
-1: operands have identical modes
-2: modes of operands == mode of this node */
+                               1: operands have identical modes
+                               2: modes of operands == mode of this node */
   type *mt; /* A method type */
 
   ir_node **in;
@@ -241,6 +254,26 @@ int irn_vrfy_irg(ir_node *n, ir_graph *irg)
 
   switch (opcode)
   {
+
+    case iro_Block:
+      for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
+       ir_node *pred =  get_Block_cfgpred(n, i);
+       ASSERT_AND_RET((is_Bad(pred) || (get_irn_mode(pred) == mode_X)), "Block node", 0);
+      }
+      // End block may only have Return, Raise or fragile ops as preds.
+      if (n == get_irg_end_block(irg))
+       for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
+         ir_node *pred =  skip_Proj(get_Block_cfgpred(n, i));
+         if (is_Proj(pred) || get_irn_op(pred) == op_Tuple)
+           break;   // We can not test properly.  How many tuples are there?
+         ASSERT_AND_RET(((get_irn_op(pred) == op_Return) ||
+                         is_Bad(pred)                    ||
+                         (get_irn_op(pred) == op_Raise)  ||
+                         is_fragile_op(pred)               ),
+                        "End Block node", 0);
+       }
+      break;
+
     case iro_Start:
       ASSERT_AND_RET(
           /* Start: BB --> X x M x ref x data1 x ... x datan x ref */
@@ -352,7 +385,7 @@ int irn_vrfy_irg(ir_node *n, ir_graph *irg)
       /* Compare arguments of node with those of type */
       mt = get_Call_type(n);
 
-      if (get_method_variadicity(mt) == variadic) {
+      if (get_method_variadicity(mt) == variadicity_variadic) {
         ASSERT_AND_RET(
             get_Call_n_params(n) >= get_method_n_params(mt),
             "Number of args for Call doesn't match number of args in variadic type.",
@@ -366,9 +399,25 @@ int irn_vrfy_irg(ir_node *n, ir_graph *irg)
       }
 
       for (i = 0; i < get_method_n_params(mt); i++) {
-        ASSERT_AND_RET(
+        ASSERT_AND_RET_DBG(
             get_irn_mode(get_Call_param(n, i)) == get_type_mode(get_method_param_type(mt, i)),
-            "Mode of arg for Call doesn't match mode of arg type.", 0);
+            "Mode of arg for Call doesn't match mode of arg type.", 0,
+           {
+             int i;
+
+             fprintf(stderr, "Assertion for Call type-check failed: %s(", get_type_name(mt));
+             for (i = 0; i < get_method_n_params(mt); ++i) {
+               fprintf(stderr, "%s ", get_mode_name(get_type_mode(get_method_param_type(mt, i))));
+             }
+             fprintf(stderr, ") != CALL(");
+
+             for (i = 0; i < get_Call_n_params(n); ++i) {
+               fprintf(stderr, "%s ", get_mode_name(get_irn_mode(get_Call_param(n, i))));
+             }
+             fprintf(stderr, ")\n");
+
+           }
+           );
       }
       break;
 
@@ -388,7 +437,7 @@ int irn_vrfy_irg(ir_node *n, ir_graph *irg)
           );
       if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
         /* BB x ref x int --> ref or BB x int x ref --> ref */
-        op_is_symmetric = 0; /* ArmRoq */
+        op_is_symmetric = 0;
       } else {
         /* BB x num x num --> num or BB x ref x ref */
         op_is_symmetric = 2;
@@ -410,7 +459,7 @@ int irn_vrfy_irg(ir_node *n, ir_graph *irg)
           "Sub node", 0
           );
       if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
-        op_is_symmetric = 0; /* ArmRoq */
+        op_is_symmetric = 0;
       } else {
         op_is_symmetric = 2;
       }
@@ -568,6 +617,15 @@ int irn_vrfy_irg(ir_node *n, ir_graph *irg)
           );
       break;
 
+    case iro_Cast:
+      op1mode = get_irn_mode(in[1]);
+      ASSERT_AND_RET(
+          /* Conv: BB x datab1 --> datab2 */
+          mode_is_data(op1mode) && op1mode == mymode,
+          "Cast node", 0
+          );
+      break;
+
     case iro_Phi:
       /* Phi: BB x dataM^n --> dataM */
       /* for some reason "<=" aborts. int there a problem with get_store? */