1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
17 * a dead block / unreachable code.
21 *** This file constructs a control flow of following shape:
28 *** Block1 scnCondBlock
39 *** This is a program as, e.g.,
42 *** { Jmp label1; } // happens anyways
44 *** { Jmp label1; } // happens anyways
51 int main(int argc, char **argv)
54 ir_graph *irg; /* this variable contains the irgraph */
55 type *owner; /* the class in which this method is defined */
56 type *proc_main; /* type information for the method main */
57 entity *ent; /* represents this method as entity of owner */
58 ir_node *c1, *c2, *cond, *f, *t, *endBlock, *Block1, *jmp,
59 *scndCondBlock, *Block2, *Block3, *x;
66 /*** Make basic type information for primitive type int. ***/
67 prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_Is);
69 /* FIRM was designed for oo languages where all methods belong to a class.
70 * For imperative languages like C we view a file as a large class containing
71 * all functions as methods in this file.
72 * This class now is automatically generated.
74 #define METHODNAME "main"
77 printf("\nCreating an IR graph: ...\n");
79 owner = get_glob_type();
80 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
82 set_method_param_type(proc_main, 0, prim_t_int);
83 set_method_res_type(proc_main, 0, prim_t_int);
85 ent = new_entity (owner,
86 id_from_str (METHODNAME, strlen(METHODNAME)),
89 #define NUM_OF_LOCAL_VARS 2
91 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
93 /* to make a condition */
94 c1 = new_Const (mode_Is, tarval_from_long (mode_Is, 1));
95 c2 = new_Proj (get_irg_args(irg), mode_Is, 0);
98 cond = new_Cond(new_Proj(new_Cmp(c1, c2), mode_b, Eq));
99 set_value(0, new_Const (mode_Is, tarval_from_long (mode_Is, 6)));
100 f = new_Proj(cond, mode_X, 0);
101 t = new_Proj(cond, mode_X, 1);
102 mature_block(get_irg_current_block(irg));
104 /* end block to add jmps */
105 endBlock = new_immBlock();
108 Block1 = new_immBlock();
109 add_in_edge(Block1, t);
110 mature_block(Block1);
111 set_value(0, new_Const (mode_Is, tarval_from_long (mode_Is, 5)));
113 add_in_edge(endBlock, jmp);
116 scndCondBlock = new_immBlock();
117 add_in_edge(scndCondBlock, f);
118 mature_block(scndCondBlock);
119 c1 = new_Const (mode_Is, tarval_from_long (mode_Is, 3));
120 cond = new_Cond(new_Proj(new_Cmp(c1, get_value(1, mode_Is)), mode_b, Eq));
121 f = new_Proj(cond, mode_X, 0);
122 t = new_Proj(cond, mode_X, 1);
123 mature_block(get_irg_current_block(irg));
126 Block2 = new_immBlock();
127 add_in_edge(Block2, f);
128 mature_block(Block2);
130 add_in_edge(endBlock, jmp);
133 Block3 = new_immBlock();
134 add_in_edge(Block3, t);
135 mature_block(Block3);
137 add_in_edge(endBlock, jmp);
139 /* finish the end Block */
140 switch_block(endBlock);
143 in[0] = get_value(0, mode_Is);
144 x = new_Return (get_store(), 1, in);
146 mature_block (get_irg_current_block(irg));
148 /* finish the Block with the end node */
149 add_in_edge (get_irg_end_block(irg), x);
150 mature_block (get_irg_end_block(irg));
152 /* verify the graph */
156 printf("Optimizing ...\n");
157 dead_node_elimination(irg);
159 printf("Dumping the graph and a control flow graph.\n");
160 dump_ir_block_graph (irg);
162 printf("Use xvcg to view these graphs:\n");
163 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");