1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
13 *** This file constructs the ir for the following pseudo-program:
22 *** while (0 == 0) loop {
37 ir_node *b, *x, *r, *t, *f;
39 printf("creating an IR graph: IF_WHILE_EXAMPLE...\n");
43 owner = new_type_class (id_from_str ("IF_WHILE_EXAMPLE", 16));
44 ent = new_entity ((type *)owner, id_from_str ("main", 4), NULL);
46 /* Generates start and end blocks and nodes and a first, initial block */
47 irg = new_ir_graph (ent, 4);
49 /* Generate two constants */
50 set_value (0, new_Const (mode_I, tarval_from_long (mode_i, 0)));
51 set_value (1, new_Const (mode_I, tarval_from_long (mode_i, 1)));
52 mature_block (irg->current_block);
54 /* Generate a conditional branch */
55 x = new_Cond (new_Proj(new_Cmp(new_Const (mode_I, tarval_from_long (mode_i, 0)),
56 new_Const (mode_I, tarval_from_long (mode_i, 0))),
58 f = new_Proj (x, mode_X, 0);
59 t = new_Proj (x, mode_X, 1);
61 /* generate and fill the then block */
64 set_value (0, new_Const (mode_I, tarval_from_long (mode_i, 2)));
68 /* generate the fall through block and add all cfg edges */
75 /* generate a block for the loop header and the conditional branch */
78 x = new_Cond (new_Proj(new_Cmp(new_Const (mode_I, tarval_from_long (mode_i, 0)),
79 new_Const (mode_I, tarval_from_long (mode_i, 0))),
81 f = new_Proj (x, mode_X, 0);
82 t = new_Proj (x, mode_X, 1);
84 /* generate the block for the loop body */
91 /* the code in the loop body,
92 as we are dealing with local variable only the dataflow edges are manipulated */
93 set_value (2, get_value (0, mode_I));
94 set_value (0, get_value (1, mode_I));
95 set_value (1, get_value (2, mode_I));
98 /* generate the return block */
105 in[0] = new_Sub (get_value (0, mode_I), get_value (1, mode_I), mode_I);
107 x = new_Return (get_store (), 1, in);
110 /* finalize the end block generated in new_ir_graph() */
111 add_in_edge (irg->end_block, x);
112 mature_block (irg->end_block);
114 /* output the vcg file */
115 printf("\nDone building the graph. Dumping it.\n");
116 dump_ir_block_graph (irg);
118 printf("use xvcg to view this graph:\n");
119 printf("/ben/trapp/bin/i486/xvcg GRAPHNAME\n");