another comment after #include
[libfirm] / testprograms / recursions.c
index ccf6bcf..4c92245 100644 (file)
  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
  */
 
-# include <stdio.h>
-# include <string.h>
+#include <stdio.h>
+#include <string.h>
 
-# include "irvrfy.h"
-# include "irdump.h"
-# include "firm.h"
+#include <libfirm/firm.h>
 
 /**
 *
 *
 **/
 
-ir_graph *make_method(char *name, int n_locs) {
-  type *proc_t   = new_type_method(new_id_from_str(name), 0, 0);
-  //set_method_param_type(proc_set_a, 0, class_p_ptr);
-  //set_method_param_type(proc_set_a, 1, prim_t_int);
-  entity *proc_e = new_entity(get_glob_type(), new_id_from_str (name), proc_t);
-  return new_ir_graph (proc_e, n_locs);
+static ir_graph *make_method(char *name, int n_locs) {
+  ir_type *proc_t   = new_type_method(new_id_from_str(name), 0, 0);
+  /*set_method_param_type(proc_set_a, 0, class_p_ptr);*/
+  /*set_method_param_type(proc_set_a, 1, prim_t_int);*/
+  ir_entity *proc_e = new_entity(get_glob_type(), new_id_from_str(name), proc_t);
+  return new_ir_graph(proc_e, n_locs);
 }
 
 
-ir_node *make_Call(ir_graph *c, int n_args, ir_node **args) {
-  entity *ent = get_irg_entity(c);
-  type *mtp = get_entity_type(ent);
+static ir_node *make_Call(ir_graph *c, int n_args, ir_node **args) {
+  ir_entity *ent = get_irg_entity(c);
+  ir_type *mtp = get_entity_type(ent);
+  ir_node *addr;
+  ir_node *call;
   symconst_symbol sym;
   sym.entity_p = ent;
-  ir_node *addr = new_SymConst(sym, symconst_addr_ent);
-  ir_node *call = new_Call(get_store(), addr, n_args, args, mtp);
+  addr = new_SymConst(mode_P, sym, symconst_addr_ent);
+  call = new_Call(get_store(), addr, n_args, args, mtp);
   set_store(new_Proj(call, mode_M, pn_Call_M_regular));
   if (get_method_n_ress(mtp) == 1) {
-    type *restp = get_method_res_type(mtp, 0);
+    ir_type *restp = get_method_res_type(mtp, 0);
     return new_Proj(new_Proj(call, mode_T, pn_Call_T_result), get_type_mode(restp), 0);
   }
   return NULL;
 }
 
-void close_method(int n_ins, ir_node **ins) {
-  ir_node *x =  new_Return (get_store(), n_ins, ins);
-  mature_immBlock (get_cur_block());
-  add_immBlock_pred  (get_cur_end_block(), x);
-  mature_immBlock (get_cur_end_block());
-  finalize_cons(current_ir_graph);
+static void close_method(int n_ins, ir_node **ins) {
+  ir_node *x =  new_Return(get_store(), n_ins, ins);
+  mature_immBlock(get_cur_block());
+  add_immBlock_pred(get_cur_end_block(), x);
+  mature_immBlock(get_cur_end_block());
+  irg_finalize_cons(current_ir_graph);
 }
 
 
 int
 main(void)
 {
-  init_firm (NULL);
+  ir_graph *mainp;
+  ir_graph *hs;
+  ir_graph *ha;
+  ir_graph *insert;
+  ir_graph *remove;
+  ir_graph *unheap;
+  ir_graph *downh;
+  ir_graph *exc;
+  ir_graph *a, *b, *c, *d;
+  ir_graph *self, *self1, *self2, *self3, *self4;
+  ir_entity **free_methods;
+  int arr_len;
+
+  init_firm(NULL);
 
   set_opt_constant_folding(0);
   set_opt_cse(0);
@@ -67,14 +80,14 @@ main(void)
   set_irp_prog_name(new_id_from_str("recursion"));
 
   /** The callgraph of the heapsort excample */
-  ir_graph *mainp  = make_method("main", 0);
-  ir_graph *hs     = make_method("hs", 0);
-  ir_graph *ha     = make_method("ha", 0);
-  ir_graph *insert = make_method("insert", 0);
-  ir_graph *remove = make_method("remove", 0);
-  ir_graph *unheap = make_method("unheap", 0);
-  ir_graph *downh  = make_method("downh", 0);
-  ir_graph *exc    = make_method("exc", 0);
+  mainp  = make_method("main", 0);
+  hs     = make_method("hs", 0);
+  ha     = make_method("ha", 0);
+  insert = make_method("insert", 0);
+  remove = make_method("remove", 0);
+  unheap = make_method("unheap", 0);
+  downh  = make_method("downh", 0);
+  exc    = make_method("exc", 0);
 
   set_irp_main_irg(mainp);
 
@@ -114,10 +127,10 @@ main(void)
 
 
   /* A callgraph with a nested recursion. */
-  ir_graph *a  = make_method("a", 0);
-  ir_graph *b  = make_method("b", 0);
-  ir_graph *c  = make_method("c", 0);
-  ir_graph *d  = make_method("d", 0);
+  a  = make_method("a", 0);
+  b  = make_method("b", 0);
+  c  = make_method("c", 0);
+  d  = make_method("d", 0);
 
   current_ir_graph = a;
   make_Call(b, 0, NULL);
@@ -140,17 +153,17 @@ main(void)
   close_method(0, NULL);
 
   /* A callgraph with a self recursion */
-  ir_graph *self  = make_method("self", 0);
+  self  = make_method("self", 0);
 
   current_ir_graph = self;
   make_Call(self, 0, NULL);
   close_method(0, NULL);
 
   /* A callgraph with a self recursion over several steps*/
-  ir_graph *self1 = make_method("self1", 0);
-  ir_graph *self2 = make_method("self2", 0);
-  ir_graph *self3 = make_method("self3", 0);
-  ir_graph *self4 = make_method("self4", 0);
+  self1 = make_method("self1", 0);
+  self2 = make_method("self2", 0);
+  self3 = make_method("self3", 0);
+  self4 = make_method("self4", 0);
 
   current_ir_graph = self1;
   make_Call(self2, 0, NULL);
@@ -170,15 +183,16 @@ main(void)
 
   printf("Dumping Callgraph.\n");
 
-  entity **free_methods;
-  int arr_len;
-  cgana(&arr_len, &free_methods, 0);
+  cgana(&arr_len, &free_methods);
   compute_callgraph();
   find_callgraph_recursions();
-  dump_callgraph("");
+  /*dump_callgraph("");*/
+  /* Order of edges depends on set.c, which is not deterministic. */
+#ifdef INTERPROCEDURAL_VIEW
   cg_construct(arr_len, free_methods);
+#endif
 
-  printf("Use xvcg to view these graphs:\n");
-  printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");
-  return (0);
+  printf("Use ycomp to view these graphs:\n");
+  printf("ycomp GRAPHNAME\n\n");
+  return 0;
 }