type_primitive *typ;
ir_node *x, *r, *t, *f, *a, *cmp;
int a_pos, b_pos;
- FILE *outfile;
- printf("creating an IR graph: IF_EXAMPLE...\n");
+ printf("\nCreating an IR graph: IF_EXAMPLE...\n");
init_firm ();
(type *)proc_main);
#define RES_NAME "int"
- typ = new_type_primitive(ID_FROM_STR(RES_NAME, strlen(RES_NAME)), mode_i);
+ typ = new_type_primitive(id_from_str(RES_NAME, strlen(RES_NAME)), mode_i);
set_method_param_type(proc_main, 0, (type*)typ);
set_method_res_type(proc_main, 0, (type*)typ);
/* Generates start and end blocks and nodes and a first, initial block */
- irg = new_ir_graph (ent, 1);
+ irg = new_ir_graph (ent, 2);
/* The value position used for a: */
a_pos = 0;
set_value (a_pos, new_Proj (get_irg_args(irg), mode_i, 0));
/*set_value (a_pos, new_Const (mode_i, tarval_from_long (mode_i, 0)));*/
set_value (b_pos, new_Const (mode_i, tarval_from_long (mode_i, 2)));
- mature_block (irg->current_block);
+ mature_block (get_irg_current_block(irg));
/* Generate a conditional branch */
cmp = new_Cmp(get_value(a_pos, mode_i), get_value(b_pos, mode_i));
t = new_Proj (x, mode_X, 1);
/* generate and fill the then block */
- r = new_Block ();
+ r = new_immBlock ();
add_in_edge (r, t);
a = new_Sub(get_value(a_pos, mode_i),
new_Const (mode_i, tarval_from_long (mode_i, 2)),
x = new_Jmp ();
/* generate the fall through block and add all cfg edges */
- r = new_Block ();
+ r = new_immBlock ();
add_in_edge (r, f);
add_in_edge (r, x);
mature_block (r);
}
/* finalize the end block generated in new_ir_graph() */
- add_in_edge (irg->end_block, x);
- mature_block (irg->end_block);
+ add_in_edge (get_irg_end_block(irg), x);
+ mature_block (get_irg_end_block(irg));
+
+
+ printf("Optimizing ...\n");
+ dead_node_elimination(irg);
/* verify the graph */
- vrfy_graph(irg);
+ irg_vrfy(irg);
/* output the vcg file */
- printf("\nDone building the graph. Dumping it.\n");
-
+ printf("Done building the graph. Dumping it.\n");
dump_ir_block_graph (irg);
-
printf("use xvcg to view this graph:\n");
- printf("/ben/goetz/bin/xvcg GRAPHNAME\n");
+ printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");
return (0);
}