1 /* Copyright (C) 2001 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Goetz Lindenmaier
13 *** This file constructs the ir for the following pseudo-program:
15 *** main(int a) { // pos 0
16 *** int b = 1; // pos 1
19 *** while (0 == 2) loop {
32 type_primitive *prim_t_int;
35 type_method *proc_main;
37 ir_node *b, *x, *r, *t, *f;
39 printf("\nCreating an IR graph: WHILE_EXAMPLE...\n");
42 //turn_of_edge_labels();
45 set_opt_constant_folding(1);
47 set_opt_dead_node_elimination (1);
49 prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_i);
51 #define METHODNAME "main"
55 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
57 set_method_param_type(proc_main, 0, (type *)prim_t_int);
59 owner = new_type_class (id_from_str ("WHILE_EXAMPLE", 16));
60 ent = new_entity ((type *)owner, id_from_str ("main", 4), (type *)proc_main);
62 /* Generates start and end blocks and nodes and a first, initial block */
63 irg = new_ir_graph (ent, 4);
65 /* Generate two constants */
66 set_value (0, new_Proj(get_irg_args(irg), mode_I, 0));
67 set_value (1, new_Const (mode_I, tarval_from_long (mode_I, 1)));
69 mature_block (get_irg_current_block(irg));
71 /* generate a block for the loop header and the conditional branch */
74 x = new_Cond (new_Proj(new_Cmp(new_Const (mode_I, tarval_from_long (mode_i, 0)),
75 new_Const (mode_I, tarval_from_long (mode_i, 0))),
77 f = new_Proj (x, mode_X, 0);
78 t = new_Proj (x, mode_X, 1);
80 /* generate the block for the loop body */
86 /* The code in the loop body,
87 as we are dealing with local variables only the dataflow edges
89 set_value (2, get_value (0, mode_I));
90 set_value (0, get_value (1, mode_I));
91 set_value (1, get_value (2, mode_I));
95 /* generate the return block */
102 in[0] = new_Sub (get_value (0, mode_I), get_value (1, mode_I), mode_I);
104 x = new_Return (get_store (), 1, in);
107 /* finalize the end block generated in new_ir_graph() */
108 add_in_edge (get_irg_end_block(irg), x);
109 mature_block (get_irg_end_block(irg));
111 printf("Optimizing ...\n");
113 local_optimize_graph(irg),
114 dead_node_elimination(irg);
116 /* verify the graph */
119 /* output the vcg file */
120 printf("Done building the graph. Dumping it.\n");
121 dump_ir_block_graph (irg);
122 printf("Use xvcg to view this graph:\n");
123 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");