More doxygen docu
[libfirm] / ir / ir / irvrfy.c
index a3f420f..d479378 100644 (file)
@@ -1,9 +1,9 @@
 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-** All rights reserved.
-**
-** Authors: Christian Schaefer
-**
-**
+* All rights reserved.
+*
+* Authors: Christian Schaefer
+*
+*
 */
 
 /* $Id$ */
@@ -20,7 +20,7 @@
 ir_node **get_irn_in (ir_node *node);
 
 INLINE static void
-vrfy_Proj_proj(ir_node *p) {
+vrfy_Proj_proj(ir_node *p, ir_graph *irg) {
   ir_node *pred;
   ir_mode *mode;
   int proj;
@@ -34,8 +34,8 @@ vrfy_Proj_proj(ir_node *p) {
   case iro_Start:
     assert (((proj == 0 && mode == mode_X) ||
             (proj == 1 && mode == mode_M) ||
-            (proj == 2 && mode == mode_p) ||
-            (proj == 3 && mode == mode_p) ||
+            (proj == 2 && mode == mode_P) ||
+            (proj == 3 && mode == mode_P) ||
             (proj == 4 && mode == mode_T))   &&
            "wrong Proj from Start"  );
     break;
@@ -68,15 +68,15 @@ vrfy_Proj_proj(ir_node *p) {
   case iro_DivMod:
     assert (((proj == 0 && mode == mode_M) ||
             (proj == 1 && mode == mode_X) ||
-            (proj == 2 && mode == mode_i) ||
-            (proj == 3 && mode == mode_i))   &&
+            (proj == 2 && mode == mode_Is) ||
+            (proj == 3 && mode == mode_Is))   &&
            "wrong Proj from DivMod" );
     break;
   case iro_Div:
   case iro_Mod:
     assert (((proj == 0 && mode == mode_M) ||
             (proj == 1 && mode == mode_X) ||
-            (proj == 2 && mode == mode_i))   &&
+            (proj == 2 && mode == mode_Is))   &&
             "wrong Proj from Div or Mod" );
     break;
   case iro_Cmp:
@@ -97,7 +97,7 @@ vrfy_Proj_proj(ir_node *p) {
   case iro_Alloc:
     assert (((proj == 0 && mode == mode_M) ||
             (proj == 1 /* && mode == mode_X*/) ||
-            (proj == 2 && mode == mode_p))      &&
+            (proj == 2 && mode == mode_P))      &&
            "wrong Proj from Alloc");
     break;
   case iro_Proj: {
@@ -108,9 +108,11 @@ vrfy_Proj_proj(ir_node *p) {
     case iro_Start: {
       assert (proj >= 0 && mode_is_data(mode) &&
              "wrong Proj from Proj from Start");
-      mt = get_entity_type(get_irg_ent(current_ir_graph));
+      mt = get_entity_type(get_irg_ent(irg));
       assert(proj < get_method_n_params(mt) &&
             "More Projs for args than args in type");
+      if ((mode == mode_P) && is_compound_type(get_method_param_type(mt, proj)))
+       /* value argument */ break;
       assert(mode == get_type_mode(get_method_param_type(mt, proj)) &&
       "Mode of Proj from Start doesn't match mode of param type.");
     } break;
@@ -120,6 +122,8 @@ vrfy_Proj_proj(ir_node *p) {
       mt = get_Call_type(pred);
       assert(proj < get_method_n_ress(mt) &&
             "More Projs for results than results in type.");
+      if ((mode == mode_P) && is_compound_type(get_method_res_type(mt, proj)))
+       /* value result */ break;
       assert(mode == get_type_mode(get_method_res_type(mt, proj)) &&
       "Mode of Proj from Call doesn't match mode of result type.");
     } break;
@@ -143,10 +147,10 @@ vrfy_Proj_proj(ir_node *p) {
 }
 
 void
-irn_vrfy (ir_node *n)
+irn_vrfy_irg (ir_node *n, ir_graph *irg)
 {
   int i;
-  int opcode;
+  int opcode, opcode1;
   ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
   int op_is_symmetric = 1;     /* 0: asymmetric
                                   1: operands have identical modes
@@ -155,13 +159,22 @@ irn_vrfy (ir_node *n)
 
   ir_node **in;
 
+  if (! interprocedural_view) {
+    /*
+     * do NOT check placement in interprocedural view, as we don't always know
+     * the "right" graph ...
+     */
+    assert(node_is_in_irgs_storage(irg, n) && "Node is not stored on proper IR graph!");
+  }
+
   opcode = get_irn_opcode (n);
 
   if (opcode != iro_Phi && opcode != iro_Block)
-    for (i = 0; i < get_irn_arity(n); i++)
-      if (get_irn_opcode(get_irn_n(n, i)) == iro_Bad
-         || get_irn_opcode(get_irn_n(n, i)) == iro_Unknown)
+    for (i = 0; i < get_irn_arity(n); i++) {
+      opcode1 = get_irn_opcode(get_irn_n(n, i));
+      if (opcode1 == iro_Bad || opcode1 == iro_Unknown)
        return;
+    }
 
   mymode = get_irn_mode (n);
   in = get_irn_in (n);
@@ -192,7 +205,7 @@ irn_vrfy (ir_node *n)
            /* Cond: BB x b --> X x X */
            (op1mode == mode_b
            /* Cond: BB x Iu --> X^n */
-           || op1mode == mode_I) && "Cond node"
+           || op1mode == mode_Iu) && "Cond node"
            );
     assert (mymode == mode_T);
     break;
@@ -206,7 +219,7 @@ irn_vrfy (ir_node *n)
     };
     assert ( mymode == mode_X );   /* result X */
     /* Compare returned results with result types of method type */
-    mt = get_entity_type(get_irg_ent(current_ir_graph));
+    mt = get_entity_type(get_irg_ent(irg));
     assert(get_Return_n_ress(n) == get_method_n_ress(mt) &&
             "Number of results for Return doesn't match number of results in type.");
     for (i = 0; i < get_Return_n_ress(n); i++)
@@ -220,7 +233,7 @@ irn_vrfy (ir_node *n)
     op2mode = get_irn_mode(in[2]);
     assert (
            /* Sel: BB x M x P --> X x M */
-           op1mode == mode_M && op2mode == mode_p
+           op1mode == mode_M && op2mode == mode_P
            && mymode == mode_T && "Raise node"
           );
     break;
@@ -236,7 +249,7 @@ irn_vrfy (ir_node *n)
     assert (
            /* SymConst: BB --> Iu or
                          BB --> P */
-           ((mymode == mode_I) || (mymode == mode_p))  && "SymConst node"
+           ((mymode == mode_Iu) || (mymode == mode_P))  && "SymConst node"
           );
     break;
   case iro_Sel:
@@ -244,11 +257,11 @@ irn_vrfy (ir_node *n)
     op2mode = get_irn_mode(in[2]);
     assert (
            /* Sel: BB x M x P x Iu^n --> P */
-           op1mode == mode_M && op2mode == mode_p
-            && mymode == mode_p && "Sel node"
+           op1mode == mode_M && op2mode == mode_P
+            && mymode == mode_P && "Sel node"
           );
     for (i=3; i < get_irn_arity(n); i++) {
-           assert (get_irn_mode(in[i]) == mode_I && "Sel node"); }
+           assert (get_irn_mode(in[i]) == mode_Iu && "Sel node"); }
     break;
   case iro_InstOf:
        assert (mode_T == mymode);
@@ -259,19 +272,31 @@ irn_vrfy (ir_node *n)
     op2mode = get_irn_mode(in[2]);
       /* Call: BB x M x P x data1 x ... x datan
                  --> M x datan+1 x ... x data n+m */
-    assert ( op1mode == mode_M && op2mode == mode_p  && "Call node");  /* operand M x P */
+    assert ( op1mode == mode_M && op2mode == mode_P  && "Call node");  /* operand M x P */
     for (i=3; i < get_irn_arity(n); i++) {
       assert ( mode_is_data(get_irn_mode(in[i])) && "Call node");  /* operand datai */
     };
     assert ( mymode == mode_T );   /* result T */
     /* Compare arguments of node with those of type */
-      mt = get_Call_type(n);
-      assert(get_Call_n_params(n) == get_method_n_params(mt) &&
-            "Number of args for Call doesn't match number of args in type.");
-      for (i = 0; i < get_Call_n_params(n); i++)
-       assert((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.");
+    mt = get_Call_type(n);
+
+    if(get_method_variadicity(mt) == variadic)
+      {
+       assert(get_Call_n_params(n) >= get_method_n_params(mt) &&
+              "Number of args for Call doesn't match number of args in " \
+              " variadic type.");
+      }
+    else
+      {
+       assert(get_Call_n_params(n) == get_method_n_params(mt) &&
+              "Number of args for Call doesn't match number of args in " \
+              "non variadic type.");
+      }
+
+    for (i = 0; i < get_method_n_params(mt); i++)
+      assert((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.");
     break;
   case iro_Add:
     op1mode = get_irn_mode(in[1]);
@@ -279,14 +304,14 @@ irn_vrfy (ir_node *n)
     assert (
            /* common Add: BB x num x num --> num */
            ((mymode == op1mode && mymode == op2mode
-             && mode_is_num(mymode))
+             && (mode_is_num(mymode) || mymode == mode_P))
             ||  /* Pointer Add: BB x P x Is --> P */
-            (op1mode == mode_p && op2mode == mode_i && mymode == mode_p)
+            (op1mode == mode_P && op2mode == mode_Is && mymode == mode_P)
             ||  /* Pointer Add: BB x Is x P --> P */
-            (op1mode == mode_i && op2mode == mode_p && mymode == mode_p))
+            (op1mode == mode_Is && op2mode == mode_P && mymode == mode_P))
            && "Add node"
            );
-      if (op1mode == mode_p || op2mode == mode_p) {
+      if (op1mode == mode_P || op2mode == mode_P) {
        /* BB x P x Is --> P or BB x Is x P --> P */
         op_is_symmetric = 0; /* ArmRoq */
       } else {
@@ -302,16 +327,16 @@ irn_vrfy (ir_node *n)
            ((mymode ==op1mode && mymode == op2mode
              && mode_is_num(op1mode))
             ||  /* Pointer Sub: BB x P x Is --> P */
-            (op1mode == mode_p && op2mode == mode_i && mymode == mode_p)
+            (op1mode == mode_P && op2mode == mode_Is && mymode == mode_P)
             ||  /* Pointer Sub: BB x Is x P --> P */
-            (op1mode == mode_i && op2mode == mode_p && mymode == mode_p)
+            (op1mode == mode_Is && op2mode == mode_P && mymode == mode_P)
             ||  /* Pointer Sub: BB x P x P --> Is */
-            (op1mode == mode_p && op2mode == mode_p && mymode == mode_i))
+            (op1mode == mode_P && op2mode == mode_P && mymode == mode_Is))
            && "Sub node"
            );
-      if (op1mode == mode_p && op2mode == mode_p) {
+      if (op1mode == mode_P && op2mode == mode_P) {
         op_is_symmetric = 1; /* ArmRoq */
-      } else if (op1mode == mode_p || op2mode == mode_p) {
+      } else if (op1mode == mode_P || op2mode == mode_P) {
         op_is_symmetric = 0; /* ArmRoq */
       } else {
         op_is_symmetric = 2;
@@ -416,7 +441,7 @@ irn_vrfy (ir_node *n)
     op2mode = get_irn_mode(in[2]);
     assert(
           /* Shl, Shr, Shrs or Rot: BB x int x Iu --> int */
-          mode_is_int (op1mode) && op2mode == mode_I
+          mode_is_int (op1mode) && op2mode == mode_Iu
            && op1mode == mymode && "Shl, Shr, Shr or Rot node"
          );
     break;
@@ -442,7 +467,7 @@ irn_vrfy (ir_node *n)
     op2mode = get_irn_mode(in[2]);
     assert(
            /* Load: BB x M x P --> M x X x data */
-           op1mode == mode_M && op2mode == mode_p  && "Load node"
+           op1mode == mode_M && op2mode == mode_P  && "Load node"
          );
     assert ( mymode == mode_T  && "Load node");
     break;
@@ -452,7 +477,7 @@ irn_vrfy (ir_node *n)
     op3mode = get_irn_mode(in[3]);
     assert(
            /* Load: BB x M x P x data --> M x X */
-           op1mode == mode_M && op2mode == mode_p
+           op1mode == mode_M && op2mode == mode_P
            && mode_is_data (op3mode) && "Store node"
          );
     assert(mymode == mode_T && "Store node");
@@ -462,7 +487,7 @@ irn_vrfy (ir_node *n)
     op2mode = get_irn_mode(in[2]);
     assert(
            /* Alloc: BB x M x Iu --> M x X x P */
-           op1mode == mode_M && op2mode == mode_I
+           op1mode == mode_M && op2mode == mode_Iu
            && mymode == mode_T && "Alloc node"
          );
     break;
@@ -472,7 +497,7 @@ irn_vrfy (ir_node *n)
     op3mode = get_irn_mode(in[3]);
     assert(
            /* Free: BB x M x P x Iu --> M */
-           op1mode == mode_M && op2mode == mode_p && op3mode == mode_I
+           op1mode == mode_M && op2mode == mode_P && op3mode == mode_Iu
            && mymode == mode_M && "Free node"
          );
     break;
@@ -484,18 +509,23 @@ irn_vrfy (ir_node *n)
     assert ( mymode == mode_M  && "Sync node");
     break;
   case iro_Proj:
-    vrfy_Proj_proj(n);
+    vrfy_Proj_proj(n, irg);
     break;
   default: ;
   }
 }
 
+void
+irn_vrfy (ir_node *n)
+{
+  irn_vrfy_irg(n, current_ir_graph);
+}
 
 /*******************************************************************/
 /* Verify the whole graph.                                         */
 /*******************************************************************/
 
-void
+static void
 vrfy_wrap (ir_node *node, void *env) {
   irn_vrfy(node);
 }