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:
31 type *method; /* the type of this method */
33 ir_node *a, *b, *c, *d, *x;
35 printf("\nCreating an IR graph: CONST_EVAL_EXAMPLE...\n");
39 /*** Make basic type information for primitive type int. ***/
40 prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_i);
42 /* Try both optimizations: */
43 set_opt_constant_folding(1);
45 set_opt_dead_node_elimination (1);
47 owner = new_type_class (id_from_str ("CONST_EVAL_EXAMPLE", 18));
48 method = new_type_method (id_from_str("main", 4), 0, 2);
49 set_method_res_type(method, 0, prim_t_int);
50 set_method_res_type(method, 1, prim_t_int);
51 ent = new_entity (owner, id_from_str ("main", 4), method);
53 irg = new_ir_graph (ent, 4);
55 a = new_Const (mode_i, tarval_from_long (mode_i, 7));
56 b = new_Const (mode_i, tarval_from_long (mode_i, 5));
59 mature_block (get_irg_current_block(irg));
61 /* To test const eval on DivMod
62 c = new_DivMod(get_store(), a, b);
63 set_store(new_Proj(c, mode_M, 0));
64 d = new_Proj(c, mode_i, 3);
65 c = new_Proj(c, mode_i, 2);
68 c = new_Add (new_Const (mode_i, tarval_from_long (mode_i, 5)),
69 new_Const (mode_i, tarval_from_long (mode_i, 7)),
71 d = new_Add (new_Const (mode_i, tarval_from_long (mode_i, 7)),
72 new_Const (mode_i, tarval_from_long (mode_i, 5)),
80 x = new_Return (get_store (), 2, in);
83 add_in_edge (get_irg_end_block(irg), x);
84 mature_block (get_irg_end_block(irg));
88 printf("Optimizing ...\n");
89 dead_node_elimination(irg);
91 /* verify the graph */
94 printf("Done building the graph. Dumping it.\n");
95 dump_ir_block_graph (irg);
97 printf("use xvcg to view this graph:\n");
98 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");