3 * File name: testprograms/const_eval_example.c
4 * Purpose: Test constant evaluation.
5 * Author: Christian Schaefer, Goetz Lindenmaier
9 * Copyright: (c) 1999-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
21 * This file constructs the ir for the following pseudo-program:
39 type *method; /* the type of this method */
41 ir_node *a, *b, *c, *d, *x;
43 printf("\nCreating an IR graph: CONST_EVAL_EXAMPLE...\n");
47 /*** Make basic type information for primitive type int. ***/
48 prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_Is);
50 /* Try both optimizations: */
51 set_opt_constant_folding(1);
53 set_opt_dead_node_elimination (1);
55 owner = new_type_class (id_from_str ("CONST_EVAL_EXAMPLE", 18));
56 method = new_type_method (id_from_str("main", 4), 0, 2);
57 set_method_res_type(method, 0, prim_t_int);
58 set_method_res_type(method, 1, prim_t_int);
59 ent = new_entity (owner, id_from_str ("main", 4), method);
60 get_entity_ld_name(ent);
62 irg = new_ir_graph (ent, 4);
64 a = new_Const (mode_Is, new_tarval_from_long (7, mode_Is));
65 b = new_Const (mode_Is, new_tarval_from_long (5, mode_Is));
68 mature_block (get_irg_current_block(irg));
70 /* To test const eval on DivMod
71 c = new_DivMod(get_store(), a, b);
72 set_store(new_Proj(c, mode_M, 0));
73 d = new_Proj(c, mode_Is, 3);
74 c = new_Proj(c, mode_Is, 2);
77 c = new_Add (new_Const (mode_Is, new_tarval_from_long (5, mode_Is)),
78 new_Const (mode_Is, new_tarval_from_long (7, mode_Is)),
80 d = new_Add (new_Const (mode_Is, new_tarval_from_long (7, mode_Is)),
81 new_Const (mode_Is, new_tarval_from_long (5, mode_Is)),
89 x = new_Return (get_store (), 2, in);
92 add_in_edge (get_irg_end_block(irg), x);
93 mature_block (get_irg_end_block(irg));
97 printf("Optimizing ...\n");
98 dead_node_elimination(irg);
100 /* verify the graph */
103 printf("Done building the graph. Dumping it.\n");
104 dump_ir_block_graph (irg);
106 printf("use xvcg to view this graph:\n");
107 printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");