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:
30 type *proc_main; /* type information for the method main */
32 ir_node *x, *r, *t, *f, *a, *cmp;
35 printf("\nCreating an IR graph: IF_EXAMPLE...\n");
39 #define CLASSNAME "IF_EXAMPLE"
40 #define METHODNAME "main"
44 /** Type information for the procedure **/
46 owner = get_glob_type();
47 /* Type information for the procedure */
48 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
50 /* The entity for the procedure */
51 ent = new_entity (owner,
52 id_from_str (METHODNAME, strlen(METHODNAME)),
54 /* The type int. This type is necessary to model the result and parameters
56 #define PRIM_NAME "int"
57 typ = new_type_primitive(id_from_str(PRIM_NAME, strlen(PRIM_NAME)), mode_i);
58 /* The parameter and result types of the procedure. */
59 set_method_param_type(proc_main, 0, typ);
60 set_method_res_type(proc_main, 0, typ);
62 /** The code of the procedure **/
64 /* Generates start and end blocks and nodes, and a first, initial block */
66 irg = new_ir_graph (ent, NRLOCS);
68 /* The value position used for: */
72 /* Get the procedure parameter and assign it to the parameter variable
74 set_value (a_pos, new_Proj (get_irg_args(irg), mode_i, 0));
75 /* Generate the constant and assign it to b. The assignment is resovled to a
77 set_value (b_pos, new_Const (mode_i, tarval_from_long (mode_i, 2)));
78 /* We know all predecessors of the block and all set_values and set_stores are
79 preformed. We can mature the block. */
80 mature_block (get_irg_current_block(irg));
82 /* Generate a conditional branch */
83 cmp = new_Cmp(get_value(a_pos, mode_i), get_value(b_pos, mode_i));
84 x = new_Cond (new_Proj(cmp, mode_b, Eq));
85 f = new_Proj (x, mode_X, 0);
86 t = new_Proj (x, mode_X, 1);
88 /* generate and fill the then block */
91 a = new_Sub(get_value(a_pos, mode_i),
92 new_Const (mode_i, tarval_from_long (mode_i, 3)),
99 /* generate the fall through block and add all cfg edges */
104 /* The Return statement */
106 ir_node *in[1], *store ;
107 in[0] = get_value (a_pos, mode_i);
110 x = new_Return (store, 1, in);
113 /* finalize the end block generated in new_ir_graph() */
114 add_in_edge (get_irg_end_block(irg), x);
115 mature_block (get_irg_end_block(irg));
117 /* verify the graph */
121 /* output the vcg file */
122 printf("Done building the graph. Dumping it.\n");
123 dump_ir_block_graph (irg);
124 printf("use xvcg to view this graph:\n");
125 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");