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;
38 printf("creating an IR graph: IF_EXAMPLE...\n");
42 #define CLASSNAME "IF_EXAMPLE"
43 #define METHODNAME "main"
47 owner = get_glob_type();
48 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
50 ent = new_entity ((type *)owner,
51 id_from_str (METHODNAME, strlen(METHODNAME)),
54 #define RES_NAME "int"
55 typ = new_type_primitive(ID_FROM_STR(RES_NAME, strlen(RES_NAME)), mode_i);
56 set_method_param_type(proc_main, 0, (type*)typ);
57 set_method_res_type(proc_main, 0, (type*)typ);
59 /* Generates start and end blocks and nodes and a first, initial block */
60 irg = new_ir_graph (ent, 1);
62 /* The value position used for a: */
66 /* Generate the constant */
67 set_value (a_pos, new_Proj (get_irg_args(irg), mode_i, 0));
68 /*set_value (a_pos, new_Const (mode_i, tarval_from_long (mode_i, 0)));*/
69 set_value (b_pos, new_Const (mode_i, tarval_from_long (mode_i, 2)));
70 mature_block (irg->current_block);
72 /* Generate a conditional branch */
73 cmp = new_Cmp(get_value(a_pos, mode_i), get_value(b_pos, mode_i));
74 x = new_Cond (new_Proj(cmp, mode_b, Eq));
75 f = new_Proj (x, mode_X, 0);
76 t = new_Proj (x, mode_X, 1);
78 /* generate and fill the then block */
81 a = new_Sub(get_value(a_pos, mode_i),
82 new_Const (mode_i, tarval_from_long (mode_i, 2)),
89 /* generate the fall through block and add all cfg edges */
95 ir_node *in[1], *store ;
96 in[0] = get_value (a_pos, mode_i);
99 x = new_Return (store, 1, in);
102 /* finalize the end block generated in new_ir_graph() */
103 add_in_edge (irg->end_block, x);
104 mature_block (irg->end_block);
106 /* verify the graph */
109 /* output the vcg file */
110 printf("\nDone building the graph. Dumping it.\n");
112 dump_ir_block_graph (irg);
114 printf("use xvcg to view this graph:\n");
115 printf("/ben/goetz/bin/xvcg GRAPHNAME\n");