*** empty log message ***
[libfirm] / testprograms / oo_program_example.c
index def051e..7600861 100644 (file)
@@ -34,8 +34,6 @@
 ***
 **/
 
-#define OPTIMIZE_NODE 0
-
 int
 main(void)
 {
@@ -50,16 +48,19 @@ main(void)
   ir_node      *self, *par1, *a_ptr;
   ir_node      *a_val;
 
+  int i;
+
   init_firm ();
 
-  set_opt_constant_folding(0);
-  set_opt_cse(0);
+  set_opt_constant_folding(1);
+  set_opt_cse(1);
+  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);
 
   /* first build procedure main */
-  printf("creating an IR graph: OO_PROGRAM_EXAMPLE...\n");
+  printf("\nCreating an IR graph: OO_PROGRAM_EXAMPLE...\n");
   owner = get_glob_type();
   proc_main = new_type_method(id_from_str("main", 4), 0, 1);
   set_method_res_type(proc_main, 0, (type *)prim_t_int);
@@ -67,6 +68,8 @@ main(void)
   proc_main_e = new_entity ((type *)owner, id_from_str ("main", 4),
                             (type *)proc_main);
   main_irg = new_ir_graph (proc_main_e, 4);
+  /* Remark that this irg is the main routine of the program. */
+  set_irp_main_irg(main_irg);
 
   /* There is only one block in main, it contains the constants and the calls. */
   c2 = new_Const (mode_i, tarval_from_long (mode_i, 2));
@@ -74,7 +77,7 @@ main(void)
 
   /* allocate the defined object and generate the type information */
   class_prima = new_type_class(id_from_str ("PRIMA", 5));
-  obj_size = new_SymConst((type_or_id *)class_prima, size);
+  obj_size = new_SymConst((type_or_id_p)class_prima, size);
   obj_o    = new_Alloc(get_store(), obj_size, (type *)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 */
@@ -130,27 +133,23 @@ main(void)
 
      x = new_Return (get_store (), 1, in);
   }
-  mature_block (main_irg->current_block);
+  mature_block (get_irg_current_block(main_irg));
 
   /* complete the end_block */
-  add_in_edge (main_irg->end_block, x);
-  mature_block (main_irg->end_block);
+  add_in_edge (get_irg_end_block(main_irg), x);
+  mature_block (get_irg_end_block(main_irg));
 
-  printf("\nDone building the graph.\n");
-  vrfy_graph(main_irg);
-  printf("Dumping the graph and a type graph.\n");
-  dump_ir_block_graph (main_irg);
-  dump_type_graph(main_irg);
+  irg_vrfy(main_irg);
 
   /****************************************************************************/
 
-  printf("\ncreating IR graph for set_a: \n");
+  printf("Creating IR graph for set_a: \n");
 
   set_a_irg = new_ir_graph (proc_set_e, 4);
 
   /* get the procedure parameter */
-  self = new_Proj(set_a_irg->args, mode_p, 0);
-  par1 = new_Proj(set_a_irg->args, mode_I, 1);
+  self = new_Proj(get_irg_args(set_a_irg), mode_p, 0);
+  par1 = new_Proj(get_irg_args(set_a_irg), mode_I, 1);
   /* Create and select the entity to set */
   class_langint = new_type_class(id_from_str ("Int", 3));
   a_e = new_entity((type *)class_prima, id_from_str ("a", 1),
@@ -161,27 +160,23 @@ main(void)
 
   /* return nothing */
   x = new_Return (get_store (), 0, NULL);
-  mature_block (set_a_irg->current_block);
+  mature_block (get_irg_current_block(set_a_irg));
 
   /* complete the end_block */
-  add_in_edge (set_a_irg->end_block, x);
-  mature_block (set_a_irg->end_block);
+  add_in_edge (get_irg_end_block(set_a_irg), x);
+  mature_block (get_irg_end_block(set_a_irg));
 
-  printf("\nDone building the graph.\n");
-  vrfy_graph(set_a_irg);
-  printf("Dumping the graph and a type graph.\n");
-  dump_ir_block_graph (set_a_irg);
-  dump_type_graph(set_a_irg);
+  irg_vrfy(set_a_irg);
 
   /****************************************************************************/
 
-  printf("\ncreating IR graph for c: \n");
+  printf("Creating IR graph for c: \n");
 
   c_irg = new_ir_graph (proc_c_e, 4);
 
   /* get the procedure parameter */
-  self = new_Proj(c_irg->args, mode_p, 0);
-  par1 = new_Proj(c_irg->args, mode_I, 1);
+  self = new_Proj(get_irg_args(c_irg), mode_p, 0);
+  par1 = new_Proj(get_irg_args(c_irg), mode_I, 1);
 
   /* Select the entity and load the value */
   a_ptr = new_simpleSel(get_store(), self, a_e);
@@ -196,24 +191,36 @@ main(void)
 
     x = new_Return (get_store (), 1, in);
   }
-  mature_block (c_irg->current_block);
+  mature_block (get_irg_current_block(c_irg));
 
   /* complete the end_block */
-  add_in_edge (c_irg->end_block, x);
-  mature_block (c_irg->end_block);
+  add_in_edge (get_irg_end_block(c_irg), x);
+  mature_block (get_irg_end_block(c_irg));
 
   /* verify the graph */
   irg_vrfy(main_irg);
 
-  printf("\nDone building the graph.\n");
-  printf("Dumping the graph and a type graph.\n");
-  dump_ir_block_graph (c_irg);
-  dump_type_graph(c_irg);
+  printf("Optimizing ...\n");
+  for (i = 0; i < get_irp_n_irgs(); i++)
+    dead_node_elimination(get_irp_irg(i));
 
   /****************************************************************************/
 
-  printf("\nuse xvcg to view these graphs:\n");
-  printf("/ben/goetz/bin/xvcg GRAPHNAME\n");
+  printf("Dumping graphs of all procedures.\n");
+
+  dump_all_ir_graphs(dump_ir_block_graph);
+  dump_all_ir_graphs(dump_type_graph);
+
+  /*
+  for (i = 0; i < get_irp_n_irgs(); i++) {
+    dump_ir_block_graph (get_irp_irg(i));
+    dump_type_graph(get_irp_irg(i));
+  }
+  */
+  //CS
+  dump_all_types();
 
+  printf("Use xvcg to view these graphs:\n");
+  printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");
   return (1);
 }