1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
4 * Authors: Christian Schaefer, Goetz Lindenmaier
17 * This file constructs the ir for the following pseudo-program:
35 type *method; /* the type of this method */
37 ir_node *a, *b, *c, *d, *x;
39 printf("\nCreating an IR graph: CONST_EVAL_EXAMPLE...\n");
43 /*** Make basic type information for primitive type int. ***/
44 prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_Is);
46 /* Try both optimizations: */
47 set_opt_constant_folding(1);
49 set_opt_dead_node_elimination (1);
51 owner = new_type_class (id_from_str ("CONST_EVAL_EXAMPLE", 18));
52 method = new_type_method (id_from_str("main", 4), 0, 2);
53 set_method_res_type(method, 0, prim_t_int);
54 set_method_res_type(method, 1, prim_t_int);
55 ent = new_entity (owner, id_from_str ("main", 4), method);
56 get_entity_ld_name(ent);
58 irg = new_ir_graph (ent, 4);
60 a = new_Const (mode_Is, tarval_from_long (mode_Is, 7));
61 b = new_Const (mode_Is, tarval_from_long (mode_Is, 5));
64 mature_block (get_irg_current_block(irg));
66 /* To test const eval on DivMod
67 c = new_DivMod(get_store(), a, b);
68 set_store(new_Proj(c, mode_M, 0));
69 d = new_Proj(c, mode_Is, 3);
70 c = new_Proj(c, mode_Is, 2);
73 c = new_Add (new_Const (mode_Is, tarval_from_long (mode_Is, 5)),
74 new_Const (mode_Is, tarval_from_long (mode_Is, 7)),
76 d = new_Add (new_Const (mode_Is, tarval_from_long (mode_Is, 7)),
77 new_Const (mode_Is, tarval_from_long (mode_Is, 5)),
85 x = new_Return (get_store (), 2, in);
88 add_in_edge (get_irg_end_block(irg), x);
89 mature_block (get_irg_end_block(irg));
93 printf("Optimizing ...\n");
94 dead_node_elimination(irg);
96 /* verify the graph */
99 printf("Done building the graph. Dumping it.\n");
100 dump_ir_block_graph (irg);
102 printf("use xvcg to view this graph:\n");
103 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");