1 /* (C) 1998 - 2000 by Universitaet Karlsruhe
4 * Authors: Christian Schaefer, Goetz Lindenmaier
17 * This file constructs the ir for the following pseudo-program:
27 * while (0 == 0) loop {
45 ir_node *b, *x, *r, *t, *f;
47 printf("\nCreating an IR graph: IF_WHILE_EXAMPLE...\n");
50 turn_off_edge_labels();
53 set_opt_constant_folding(0); /* so that the stupid tests are not optimized. */
54 /* if optimized no path to End remains!! */
56 set_opt_dead_node_elimination (1);
58 /*** Make basic type information for primitive type int. ***/
59 prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_Iu);
61 #define METHODNAME "main"
65 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
67 set_method_res_type(proc_main, 0, prim_t_int);
68 owner = new_type_class (id_from_str ("IF_WHILE_EXAMPLE", 16));
69 ent = new_entity (owner, id_from_str ("main", 4), proc_main);
70 get_entity_ld_name(ent);
72 /* Generates start and end blocks and nodes and a first, initial block */
73 irg = new_ir_graph (ent, 4);
75 /* Generate two constants */
76 set_value (0, new_Const (mode_Iu, tarval_from_long (mode_Iu, 0)));
77 set_value (1, new_Const (mode_Iu, tarval_from_long (mode_Iu, 1)));
78 mature_block (get_irg_current_block(irg));
80 /* Generate a conditional branch */
83 /* generate the fall through block and add all cfg edges */
89 /* generate a block for the loop header and the conditional branch */
92 x = new_Cond (new_Proj(new_Cmp(new_Const (mode_Iu, tarval_from_long (mode_Is, 0)),
93 new_Const (mode_Iu, tarval_from_long (mode_Is, 0))),
95 f = new_Proj (x, mode_X, 0);
96 t = new_Proj (x, mode_X, 1);
98 /* generate the block for the loop body */
105 /* the code in the loop body,
106 as we are dealing with local variables only the dataflow edges
108 set_value (2, get_value (0, mode_Iu));
109 set_value (0, get_value (1, mode_Iu));
110 set_value (1, get_value (2, mode_Iu));
113 /* generate the return block */
120 in[0] = new_Sub (get_value (0, mode_Iu), get_value (1, mode_Iu), mode_Iu);
122 x = new_Return (get_store (), 1, in);
125 /* finalize the end block generated in new_ir_graph() */
126 add_in_edge (get_irg_end_block(irg), x);
127 mature_block (get_irg_end_block(irg));
131 printf("Optimizing ...\n");
133 local_optimize_graph(irg);
134 dead_node_elimination(irg);
138 /* verify the graph */
141 /* output the vcg file */
142 printf("Done building the graph. Dumping it with out-edges.\n");
145 printf("Use xvcg to view this graph:\n");
146 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");