1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
15 * irregular control flow
19 *** This file constructs a control flow of following shape:
35 *** This is a program as, e.g.,
46 int main(int argc, char **argv)
48 ir_graph *irg; /* this variable contains the irgraph */
49 type_class *owner; /* the class in which this method is defined */
50 type_method *proc_main; /* typeinformation for the method main */
51 entity *ent; /* represents this method as entity of owner */
52 ir_node *expr, *c1, *c2, *cond, *f, *t, *jmp, *x;
54 printf("creating an IR graph: IRR_CF...\n");
59 /* FIRM was designed for oo languages where all methods belong to a class.
60 * For imperative languages like C we view a file as a large class containing
61 * all functions as methods in this file.
62 * Therefore we define a class "empty" according to the file name
63 * with a method main as an entity.
65 #define CLASSNAME "IRREGULAR_CF"
66 #define METHODNAME "main"
70 owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
71 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
73 ent = new_entity ((type *)owner,
74 id_from_str (METHODNAME, strlen(METHODNAME)),
77 #define NUM_OF_LOCAL_VARS 0
79 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
81 /* two make two conditionals that represent a switch */
82 expr = new_Const (mode_i, tarval_from_long (mode_i, 0));
83 c1 = new_Const (mode_i, tarval_from_long (mode_i, 1));
84 c2 = new_Const (mode_i, tarval_from_long (mode_i, 2));
86 cond = new_Cond(new_Proj(new_Cmp(expr, c1), mode_b, Eq));
87 f = new_Proj(cond, mode_X, 0);
88 t = new_Proj(cond, mode_X, 1);
89 mature_block(irg->current_block);
92 add_in_edge(irg->current_block, t);
94 mature_block(irg->current_block);
97 add_in_edge(irg->current_block, f);
98 cond = new_Cond(new_Proj(new_Cmp(expr, c2), mode_b, Eq));
99 f = new_Proj(cond, mode_X, 0);
100 t = new_Proj(cond, mode_X, 1);
101 mature_block(irg->current_block);
104 add_in_edge(irg->current_block, t);
105 add_in_edge(irg->current_block, jmp);
107 mature_block(irg->current_block);
110 add_in_edge(irg->current_block, f);
112 mature_block(irg->current_block);
115 add_in_edge(irg->current_block, t);
116 add_in_edge(irg->current_block, jmp);
118 ir_node *in[0]; /* this is the array containing the return parameters */
119 x = new_Return (get_store(), 0, in);
121 mature_block (irg->current_block);
123 add_in_edge (irg->end_block, x);
124 mature_block (irg->end_block);
126 /* verify the graph */
129 printf("\nDone building the graph.\n");
130 printf("Dumping the graph and a control flow graph.\n");
131 dump_ir_block_graph (irg);
134 printf("use xvcg to view these graphs:\n");
135 printf("/ben/goetz/bin/xvcg GRAPHNAME\n");