1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
4 * Authors: Christian Schaefer, Goetz Lindenmaier
17 * This file constructs the ir for the following pseudo-program:
34 type *proc_main; /* type information for the method main */
36 ir_node *x, *r, *t, *f, *a, *cmp;
39 printf("\nCreating an IR graph: IF_EXAMPLE...\n");
43 #define CLASSNAME "IF_EXAMPLE"
44 #define METHODNAME "IF_EXAMPLE_main"
48 /** Type information for the procedure **/
50 owner = get_glob_type();
51 /* Type information for the procedure */
52 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
54 /* The entity for the procedure */
55 ent = new_entity (owner,
56 id_from_str (METHODNAME, strlen(METHODNAME)),
58 /* The type int. This type is necessary to model the result and parameters
60 #define PRIM_NAME "int"
61 typ = new_type_primitive(id_from_str(PRIM_NAME, strlen(PRIM_NAME)), mode_Is);
62 /* The parameter and result types of the procedure. */
63 set_method_param_type(proc_main, 0, typ);
64 set_method_res_type(proc_main, 0, typ);
66 /** The code of the procedure **/
68 /* Generates start and end blocks and nodes, and a first, initial block */
70 irg = new_ir_graph (ent, NRLOCS);
72 /* The value position used for: */
76 /* Get the procedure parameter and assign it to the parameter variable
78 set_value (a_pos, new_Proj (get_irg_args(irg), mode_Is, 0));
79 /* Generate the constant and assign it to b. The assignment is resovled to a
81 set_value (b_pos, new_Const (mode_Is, new_tarval_from_long (2, mode_Is)));
82 /* We know all predecessors of the block and all set_values and set_stores are
83 preformed. We can mature the block. */
84 mature_block (get_irg_current_block(irg));
86 /* Generate a conditional branch */
87 cmp = new_Cmp(get_value(a_pos, mode_Is), get_value(b_pos, mode_Is));
88 x = new_Cond (new_Proj(cmp, mode_b, Eq));
89 f = new_Proj (x, mode_X, 0);
90 t = new_Proj (x, mode_X, 1);
92 /* generate and fill the then block */
95 a = new_Sub(get_value(a_pos, mode_Is),
96 new_Const (mode_Is, new_tarval_from_long (3, mode_Is)),
103 /* generate the fall through block and add all cfg edges */
108 /* The Return statement */
110 ir_node *in[1], *store ;
111 in[0] = get_value (a_pos, mode_Is);
114 x = new_Return (store, 1, in);
117 /* finalize the end block generated in new_ir_graph() */
118 add_in_edge (get_irg_end_block(irg), x);
119 mature_block (get_irg_end_block(irg));
121 /* verify the graph */
125 /* output the vcg file */
126 printf("Done building the graph. Dumping it.\n");
127 dump_ir_block_graph (irg);
128 printf("use xvcg to view this graph:\n");
129 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");