fixed bug in irgopt -- optimize_cf
[libfirm] / testprograms / oo_program_example.c
index dfdc752..8339fa1 100644 (file)
@@ -6,6 +6,10 @@
 ** testprogram.
 */
 
+# include <stdio.h>
+# include <string.h>
+
+# include "irvrfy.h"
 # include "irdump.h"
 # include "firm.h"
 
@@ -47,7 +51,7 @@ main(void)
   ir_node      *self, *par1, *a_ptr;
   ir_node      *a_val;
 
-  int o_pos, self_pos, e_pos, d_pos;
+  int o_pos, self_pos, e_pos;
 
   int i;
 
@@ -58,7 +62,7 @@ main(void)
   set_opt_dead_node_elimination(1);
 
   /*** Make basic type information for primitive type int. ***/
-  prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_i);
+  prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_Is);
 
   /*** Make type information for the class (PRIMA). ***/
   /* The type of the class */
@@ -83,7 +87,6 @@ main(void)
   set_method_res_type(proc_c, 0, prim_t_int);
   proc_c_e = new_entity(class_prima, id_from_str ("c", 1), proc_c);
 
-
   /*** Now build procedure main. ***/
   /** Type information for main. **/
   printf("\nCreating an IR graph: OO_PROGRAM_EXAMPLE...\n");
@@ -107,26 +110,26 @@ main(void)
   set_irp_main_irg(main_irg);
 
   /* Make the constants.  They are independent of a block. */
-  c2 = new_Const (mode_i, tarval_from_long (mode_i, 2));
-  c5 = new_Const (mode_i, tarval_from_long (mode_i, 5));
+  c2 = new_Const (mode_Is, tarval_from_long (mode_Is, 2));
+  c5 = new_Const (mode_Is, tarval_from_long (mode_Is, 5));
 
   /* There is only one block in main, it contains the allocation and the calls. */
   /* Allocate the defined object and generate the type information. */
   obj_size = new_SymConst((type_or_id_p)class_prima, size);
   obj_o    = new_Alloc(get_store(), obj_size, class_prima, heap_alloc);
   set_store(new_Proj(obj_o, mode_M, 0));  /* make the changed memory visible */
-  obj_o    = new_Proj(obj_o, mode_p, 1);  /* remember the pointer to the object */
+  obj_o    = new_Proj(obj_o, mode_P, 2);  /* remember the pointer to the object */
   set_value(o_pos, obj_o);
 
   /* Get the pointer to the procedure from the object.  */
   proc_ptr = new_simpleSel(get_store(),             /* The memory containing the object. */
-                          get_value(o_pos, mode_p),/* The pointer to the object. */
+                          get_value(o_pos, mode_P),/* The pointer to the object. */
                           proc_set_a_e );            /* The feature to select. */
 
   /* Call procedure set_a, first built array with parameters. */
   {
     ir_node *in[2];
-    in[0] = get_value(o_pos, mode_p);
+    in[0] = get_value(o_pos, mode_P);
     in[1] = c2;
     call = new_Call(get_store(), proc_ptr, 2, in, proc_set_a);
   }
@@ -134,12 +137,12 @@ main(void)
   set_store(new_Proj(call, mode_M, 0));
 
   /* Get the pointer to the nest procedure from the object. */
-  proc_ptr = new_simpleSel(get_store(), get_value(o_pos, mode_p), proc_c_e);
+  proc_ptr = new_simpleSel(get_store(), get_value(o_pos, mode_P), proc_c_e);
 
   /* call procedure c, first built array with parameters */
   {
     ir_node *in[2];
-    in[0] = get_value(o_pos, mode_p);
+    in[0] = get_value(o_pos, mode_P);
     in[1] = c5;
     call = new_Call(get_store(), proc_ptr, 2, in, proc_c);
   }
@@ -147,7 +150,7 @@ main(void)
   set_store(new_Proj(call, mode_M, 0));
   /* Get the result of the procedure: select the result tuple from the call,
      then the proper result from the tuple. */
-  res = new_Proj(new_Proj(call, mode_T, 1), mode_I, 0);
+  res = new_Proj(new_Proj(call, mode_T, 2), mode_Is, 0);
 
   /* return the results of procedure main */
   {
@@ -162,6 +165,7 @@ main(void)
   mature_block (get_irg_end_block(main_irg));
 
   irg_vrfy(main_irg);
+  finalize_cons (main_irg);
 
   /****************************************************************************/
 
@@ -172,9 +176,9 @@ main(void)
   self_pos = 0; e_pos = 1;
 
   /* get the procedure parameter */
-  self = new_Proj(get_irg_args(set_a_irg), mode_p, 0);
+  self = new_Proj(get_irg_args(set_a_irg), mode_P, 0);
   set_value(self_pos, self);
-  par1 = new_Proj(get_irg_args(set_a_irg), mode_I, 1);
+  par1 = new_Proj(get_irg_args(set_a_irg), mode_Is, 1);
   set_value(e_pos, par1);
   /* Create and select the entity to set */
   a_ptr = new_simpleSel(get_store(), self, a_e);
@@ -191,6 +195,7 @@ main(void)
 
   /* verify the graph */
   irg_vrfy(set_a_irg);
+  finalize_cons (set_a_irg);
 
   /****************************************************************************/
 
@@ -200,19 +205,19 @@ main(void)
   c_irg = new_ir_graph (proc_c_e, 2);
 
   /* get the procedure parameter */
-  self = new_Proj(get_irg_args(c_irg), mode_p, 0);
-  par1 = new_Proj(get_irg_args(c_irg), mode_I, 1);
+  self = new_Proj(get_irg_args(c_irg), mode_P, 0);
+  par1 = new_Proj(get_irg_args(c_irg), mode_Is, 1);
 
   /* Select the entity and load the value */
   a_ptr = new_simpleSel(get_store(), self, a_e);
   a_val = new_Load(get_store(), a_ptr);
   set_store(new_Proj(a_val, mode_M, 0));
-  a_val = new_Proj(a_val, mode_I, 1);
+  a_val = new_Proj(a_val, mode_Is, 2);
 
   /* return the result */
   {
     ir_node *in[1];
-    in[0] = new_Add(par1, a_val, mode_I);
+    in[0] = new_Add(par1, a_val, mode_Is);
 
     x = new_Return (get_store (), 1, in);
   }
@@ -224,6 +229,7 @@ main(void)
 
   /* verify the graph */
   irg_vrfy(c_irg);
+  finalize_cons (c_irg);
 
   /****************************************************************************/
 
@@ -240,5 +246,5 @@ main(void)
 
   printf("Use xvcg to view these graphs:\n");
   printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");
-  return (1);
+  return (0);
 }