1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer, Goetz Lindenmaier
15 * a dead block / unreachable code.
19 *** This file constructs a control flow of following shape:
26 *** Block1 scnCondBlock
37 *** This is a program as, e.g.,
40 *** { Jmp label1; } // happens anyways
42 *** { Jmp label1; } // happens anyways
49 int main(int argc, char **argv)
51 ir_graph *irg; /* this variable contains the irgraph */
52 type *owner; /* the class in which this method is defined */
53 type *proc_main; /* type information for the method main */
54 entity *ent; /* represents this method as entity of owner */
55 ir_node *c1, *c2, *cond, *f, *t, *endBlock, *Block1, *jmp,
56 *scndCondBlock, *Block2, *Block3, *x;
63 /* FIRM was designed for oo languages where all methods belong to a class.
64 * For imperative languages like C we view a file as a large class containing
65 * all functions as methods in this file.
66 * This class now is automatically generated.
68 #define METHODNAME "main"
71 printf("\nCreating an IR graph: ...\n");
73 owner = get_glob_type();
74 proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
76 /** @@@ setting of arg/res types misses **/
77 ent = new_entity (owner,
78 id_from_str (METHODNAME, strlen(METHODNAME)),
81 #define NUM_OF_LOCAL_VARS 2
83 irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
85 /* to make a condition */
86 c1 = new_Const (mode_i, tarval_from_long (mode_i, 1));
87 c2 = new_Proj (get_irg_args(irg), mode_i, 0);
90 cond = new_Cond(new_Proj(new_Cmp(c1, c2), mode_b, Eq));
91 set_value(0, new_Const (mode_i, tarval_from_long (mode_i, 6)));
92 f = new_Proj(cond, mode_X, 0);
93 t = new_Proj(cond, mode_X, 1);
94 mature_block(get_irg_current_block(irg));
96 /* end block to add jmps */
97 endBlock = new_immBlock();
100 Block1 = new_immBlock();
101 add_in_edge(Block1, t);
102 mature_block(Block1);
103 set_value(0, new_Const (mode_i, tarval_from_long (mode_i, 5)));
105 add_in_edge(endBlock, jmp);
108 scndCondBlock = new_immBlock();
109 add_in_edge(scndCondBlock, f);
110 mature_block(scndCondBlock);
111 c1 = new_Const (mode_i, tarval_from_long (mode_i, 3));
112 cond = new_Cond(new_Proj(new_Cmp(c1, get_value(1, mode_i)), mode_b, Eq));
113 f = new_Proj(cond, mode_X, 0);
114 t = new_Proj(cond, mode_X, 1);
115 mature_block(get_irg_current_block(irg));
118 Block2 = new_immBlock();
119 add_in_edge(Block2, f);
120 mature_block(Block2);
122 add_in_edge(endBlock, jmp);
125 Block3 = new_immBlock();
126 add_in_edge(Block3, t);
127 mature_block(Block3);
129 add_in_edge(endBlock, jmp);
131 /* finish the end Block */
132 switch_block(endBlock);
135 in[0] = get_value(0, mode_i);
136 x = new_Return (get_store(), 1, in);
138 mature_block (get_irg_current_block(irg));
140 /* finish the Block with the end node */
141 add_in_edge (get_irg_end_block(irg), x);
142 mature_block (get_irg_end_block(irg));
144 printf("Optimizing ...\n");
145 dead_node_elimination(irg);
147 /* verify the graph */
150 printf("Dumping the graph and a control flow graph.\n");
151 dump_ir_block_graph (irg);
153 printf("Use xvcg to view these graphs:\n");
154 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");