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!!!!
20 *** if ( a == a ) // a constant condition would be eliminated,
21 *** // a realistic condition would no more be a small example
24 *** // return a, bla; // das ist hier kein korrekter graph
34 type_method *proc_main; /* typeinformation for the method main */
36 ir_node *x, *r, *t, *f, *a;
40 printf("creating an IR graph: IF_EXAMPLE...\n");
44 #define CLASSNAME "IF_EXAMPLE"
45 #define METHODNAME "main"
49 owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
50 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)), NRARGS, NRES);
51 ent = new_entity ((type *)owner,
52 id_from_str (METHODNAME, strlen(METHODNAME)),
55 #define RES_NAME "res1"
56 typ = new_type_primitive(ID_FROM_STR(RES_NAME, strlen(RES_NAME)), mode_i);
57 set_method_res_type(proc_main, 0, (type*)typ);
60 #define RES_NAME "res2"
61 typ = new_type_primitive(ID_FROM_STR(RES_NAME, strlen(RES_NAME)), mode_i);
62 set_method_res_type(proc_main, 1, (type*)typ);
66 /* Generates start and end blocks and nodes and a first, initial block */
67 irg = new_ir_graph (ent, 1);
69 /* The value position used for a: */
73 /* Generate the constant */
74 set_value (a_pos, new_Const (mode_i, tarval_from_long (mode_i, 0)));
75 set_value (b_pos, new_Const (mode_i, tarval_from_long (mode_i, 2)));
76 mature_block (irg->current_block);
78 /* Generate a conditional branch */
79 x = new_Cond (new_Proj(new_Cmp(get_value(a_pos, mode_i),
80 get_value(a_pos, mode_i)),
82 f = new_Proj (x, mode_X, 0);
83 t = new_Proj (x, mode_X, 1);
85 /* generate and fill the then block */
89 a = new_Sub(get_value(a_pos, mode_i),
90 new_Const (mode_i, tarval_from_long (mode_i, 2)),
97 /* generate the fall through block and add all cfg edges */
103 ir_node *in[3], *store ;
104 in[0] = get_value (a_pos, mode_i);
106 in[2] = get_value (b_pos, mode_i);
109 x = new_Return (store, 2, in);
112 /* finalize the end block generated in new_ir_graph() */
113 add_in_edge (irg->end_block, x);
114 mature_block (irg->end_block);
116 /* output the vcg file */
117 printf("\nDone building the graph. Dumping it.\n");
119 dump_ir_block_graph (irg);
121 printf("use xvcg to view this graph:\n");
122 printf("/ben/trapp/bin/i486/xvcg GRAPHNAME\n");