--- /dev/null
+/*
+ * Project: libFIRM
+ * File name: testprograms/recursion.c
+ * Purpose: Empty methods that recur.
+ * Author: Goetz Lindenmaier
+ * Modified by:
+ * Created:
+ * CVS-ID: $Id$
+ * Copyright: (c) 2004 Universität Karlsruhe
+ * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
+ */
+
+# include <stdio.h>
+# include <string.h>
+
+# include "irvrfy.h"
+# include "irdump.h"
+# include "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);
+}
+
+
+ir_node *make_Call(ir_graph *c, int n_args, ir_node **args) {
+ entity *ent = get_irg_ent(c);
+ type *mtp = get_entity_type(ent);
+ 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);
+ 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);
+ 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_block (get_cur_block());
+ add_in_edge (get_cur_end_block(), x);
+ mature_block (get_cur_end_block());
+ finalize_cons(current_ir_graph);
+}
+
+
+int
+main(void)
+{
+ init_firm (NULL);
+
+ set_opt_constant_folding(0);
+ set_opt_cse(0);
+
+ 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);
+
+ set_irp_main_irg(mainp);
+
+ current_ir_graph = mainp;
+ make_Call(hs, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = hs;
+ make_Call(ha, 0, NULL);
+ make_Call(remove, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = ha;
+ make_Call(insert, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = insert;
+ make_Call(unheap, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = remove;
+ make_Call(unheap, 0, NULL);
+ make_Call(downh, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = unheap;
+ make_Call(exc, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = downh;
+ make_Call(downh, 0, NULL);
+ make_Call(exc, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = exc;
+ close_method(0, NULL);
+
+
+ /* 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);
+
+ current_ir_graph = a;
+ make_Call(b, 0, NULL);
+ make_Call(c, 0, NULL);
+ make_Call(b, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = b;
+ close_method(0, NULL);
+
+ current_ir_graph = c;
+ make_Call(b, 0, NULL);
+ make_Call(d, 0, NULL);
+ make_Call(a, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = d;
+ make_Call(a, 0, NULL);
+ make_Call(d, 0, NULL);
+ close_method(0, NULL);
+
+ /* A callgraph with a self recursion */
+ ir_graph *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);
+
+ current_ir_graph = self1;
+ make_Call(self2, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = self2;
+ make_Call(self3, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = self3;
+ make_Call(self4, 0, NULL);
+ close_method(0, NULL);
+
+ current_ir_graph = self4;
+ make_Call(self1, 0, NULL);
+ close_method(0, NULL);
+
+ printf("Dumping Callgraph.\n");
+
+ entity **free_methods;
+ int arr_len;
+ cgana(&arr_len, &free_methods, 0);
+ compute_callgraph();
+ find_callgraph_recursions();
+ dump_callgraph("");
+ cg_construct(arr_len, free_methods);
+
+ printf("Use xvcg to view these graphs:\n");
+ printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");
+ return (0);
+}
--- /dev/null
+graph: { title: "ir graph of Callgraph"
+display_edge_labels: yes
+layoutalgorithm: mindepth
+manhattan_edges: yes
+port_sharing: no
+orientation: bottom_to_top
+classname 1: "intrablock Data"
+classname 16: "interblock Data"
+classname 2: "Block"
+classname 13: "Control Flow"
+classname 14: "intrablock Memory"
+classname 17: "interblock Memory"
+classname 15: "Dominators"
+classname 3: "Entity type"
+classname 4: "Entity owner"
+classname 5: "Method Param"
+classname 6: "Method Res"
+classname 7: "Super"
+classname 8: "Union"
+classname 9: "Points-to"
+classname 10: "Array Element Type"
+classname 11: "Overwrites"
+classname 12: "Member"
+infoname 1: "Attribute"
+infoname 2: "Verification errors"
+
+node: {title: "e12" label: "ent main" color: yellow
+ info1: "
+id: e12
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: main
+ld_name: no yet set
+offset(bits): -1
+irg = g24"
+}
+edge: { sourcename: "e12" targetname: "e28"label:"calls"}
+node: {title: "e28" label: "ent hs" color: yellow
+ info1: "
+id: e28
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: hs
+ld_name: no yet set
+offset(bits): -1
+irg = g40"
+}
+edge: { sourcename: "e28" targetname: "e76"label:"calls"}
+edge: { sourcename: "e28" targetname: "e44"label:"calls"}
+node: {title: "e44" label: "ent ha" color: yellow
+ info1: "
+id: e44
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: ha
+ld_name: no yet set
+offset(bits): -1
+irg = g56"
+}
+edge: { sourcename: "e44" targetname: "e60"label:"calls"}
+node: {title: "e60" label: "ent insert" color: yellow
+ info1: "
+id: e60
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: insert
+ld_name: no yet set
+offset(bits): -1
+irg = g72"
+}
+edge: { sourcename: "e60" targetname: "e92"label:"calls"}
+node: {title: "e76" label: "ent remove" color: yellow
+ info1: "
+id: e76
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: remove
+ld_name: no yet set
+offset(bits): -1
+irg = g88"
+}
+edge: { sourcename: "e76" targetname: "e108"label:"calls"}
+edge: { sourcename: "e76" targetname: "e92"label:"calls"}
+node: {title: "e92" label: "ent unheap" color: yellow
+ info1: "
+id: e92
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: unheap
+ld_name: no yet set
+offset(bits): -1
+irg = g104"
+}
+edge: { sourcename: "e92" targetname: "e124"label:"calls"}
+node: {title: "e108" label: "ent downh" color: yellow
+ info1: "
+id: e108
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: downh
+ld_name: no yet set
+offset(bits): -1
+irg = g120"
+}
+edge: { sourcename: "e108" targetname: "e124"label:"calls"}
+backedge: { sourcename: "e108" targetname: "e108"label:"recursion" color:red}
+node: {title: "e124" label: "ent exc" color: yellow
+ info1: "
+id: e124
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: exc
+ld_name: no yet set
+offset(bits): -1
+irg = g136"
+}
+node: {title: "e204" label: "ent a" color: yellow
+ info1: "
+id: e204
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: a
+ld_name: no yet set
+offset(bits): -1
+irg = g216"
+}
+edge: { sourcename: "e204" targetname: "e236"label:"calls"}
+edge: { sourcename: "e204" targetname: "e220"label:"calls"}
+node: {title: "e220" label: "ent b" color: yellow
+ info1: "
+id: e220
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: b
+ld_name: no yet set
+offset(bits): -1
+irg = g232"
+}
+node: {title: "e236" label: "ent c" color: yellow
+ info1: "
+id: e236
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: c
+ld_name: no yet set
+offset(bits): -1
+irg = g248"
+}
+backedge: { sourcename: "e236" targetname: "e252"label:"recursion" color:red}
+edge: { sourcename: "e236" targetname: "e220"label:"calls"}
+backedge: { sourcename: "e236" targetname: "e204"label:"recursion" color:red}
+node: {title: "e252" label: "ent d" color: yellow
+ info1: "
+id: e252
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: d
+ld_name: no yet set
+offset(bits): -1
+irg = g264"
+}
+backedge: { sourcename: "e252" targetname: "e252"label:"recursion" color:red}
+edge: { sourcename: "e252" targetname: "e204"label:"calls"}
+node: {title: "e312" label: "ent self" color: yellow
+ info1: "
+id: e312
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: self
+ld_name: no yet set
+offset(bits): -1
+irg = g324"
+}
+backedge: { sourcename: "e312" targetname: "e312"label:"recursion" color:red}
+node: {title: "e335" label: "ent self1" color: yellow
+ info1: "
+id: e335
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: self1
+ld_name: no yet set
+offset(bits): -1
+irg = g347"
+}
+edge: { sourcename: "e335" targetname: "e351"label:"calls"}
+node: {title: "e351" label: "ent self2" color: yellow
+ info1: "
+id: e351
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: self2
+ld_name: no yet set
+offset(bits): -1
+irg = g363"
+}
+edge: { sourcename: "e351" targetname: "e367"label:"calls"}
+node: {title: "e367" label: "ent self3" color: yellow
+ info1: "
+id: e367
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: self3
+ld_name: no yet set
+offset(bits): -1
+irg = g379"
+}
+backedge: { sourcename: "e367" targetname: "e383"label:"recursion" color:red}
+node: {title: "e383" label: "ent self4" color: yellow
+ info1: "
+id: e383
+allocation: allocation_static
+visibility: visibility_local
+variability: variability_constant
+volatility: volatility_non_volatile
+peculiarity: peculiarity_existent
+name: self4
+ld_name: no yet set
+offset(bits): -1
+irg = g395"
+}
+edge: { sourcename: "e383" targetname: "e335"label:"calls"}
+}