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:
15 *** Doesn't work for some reason!!!!
32 type_method *proc_main; /* type information for the method main */
34 ir_node *x, *r, *t, *f, *a, *cmp;
37 printf("\nCreating an IR graph: IF_EXAMPLE...\n");
41 #define CLASSNAME "IF_EXAMPLE"
42 #define METHODNAME "main"
46 owner = get_glob_type();
47 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
49 ent = new_entity ((type *)owner,
50 id_from_str (METHODNAME, strlen(METHODNAME)),
53 #define RES_NAME "int"
54 typ = new_type_primitive(id_from_str(RES_NAME, strlen(RES_NAME)), mode_i);
55 set_method_param_type(proc_main, 0, (type*)typ);
56 set_method_res_type(proc_main, 0, (type*)typ);
58 /* Generates start and end blocks and nodes and a first, initial block */
59 irg = new_ir_graph (ent, 2);
61 /* The value position used for a: */
65 /* Generate the constant */
66 set_value (a_pos, new_Proj (get_irg_args(irg), mode_i, 0));
67 /*set_value (a_pos, new_Const (mode_i, tarval_from_long (mode_i, 0)));*/
68 set_value (b_pos, new_Const (mode_i, tarval_from_long (mode_i, 2)));
69 mature_block (get_irg_current_block(irg));
71 /* Generate a conditional branch */
72 cmp = new_Cmp(get_value(a_pos, mode_i), get_value(b_pos, mode_i));
73 x = new_Cond (new_Proj(cmp, mode_b, Eq));
74 f = new_Proj (x, mode_X, 0);
75 t = new_Proj (x, mode_X, 1);
77 /* generate and fill the then block */
80 a = new_Sub(get_value(a_pos, mode_i),
81 new_Const (mode_i, tarval_from_long (mode_i, 2)),
88 /* generate the fall through block and add all cfg edges */
94 ir_node *in[1], *store ;
95 in[0] = get_value (a_pos, mode_i);
98 x = new_Return (store, 1, in);
101 /* finalize the end block generated in new_ir_graph() */
102 add_in_edge (get_irg_end_block(irg), x);
103 mature_block (get_irg_end_block(irg));
106 printf("Optimizing ...\n");
107 dead_node_elimination(irg);
109 /* verify the graph */
112 /* output the vcg file */
113 printf("Done building the graph. Dumping it.\n");
114 dump_ir_block_graph (irg);
115 printf("use xvcg to view this graph:\n");
116 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");