X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=testprograms%2Frecursions.c;h=4c9224554afe66d33fc7b7b521c78b20c234e544;hb=1903d4aaf86cbe04ee725c97de1f77ca276f9b0c;hp=ccf6bcfdb9bb4e4ce3d21c5c17f6081e5755216f;hpb=dddcc630819f338c3b45e2bc646233e6872d5bb6;p=libfirm diff --git a/testprograms/recursions.c b/testprograms/recursions.c index ccf6bcfdb..4c9224554 100644 --- a/testprograms/recursions.c +++ b/testprograms/recursions.c @@ -10,12 +10,10 @@ * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. */ -# include -# include +#include +#include -# include "irvrfy.h" -# include "irdump.h" -# include "firm.h" +#include /** * @@ -23,43 +21,58 @@ * **/ -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; }