-
- init_firm ();
-
- set_opt_constant_folding(0);
- set_opt_cse(0);
-
- /* make basic type information for primitive type int.*/
- prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_i);
-
- /* first build procedure main */
- printf("creating an IR graph: OO_PROGRAM_EXAMPLE...\n");
- owner = new_type_class (id_from_str ("OO_PROGRAM_EXAMPLE", 18));
- proc_main = new_type_method(id_from_str("main", 4), 0, 1);
- set_method_res_type(proc_main, 0, (type *)prim_t_int);
-
- proc_main_e = new_entity ((type *)owner, id_from_str ("main", 4),
- (type *)proc_main);
- main_irg = new_ir_graph (proc_main_e, 4);
-
- /* There is only one block in main, it contains the constants and the calls. */
- c2 = new_Const (mode_i, tarval_from_long (mode_i, 2));
- c5 = new_Const (mode_i, tarval_from_long (mode_i, 5));
-
- /* allocate the defined object and generate the type information */
- class_prima = new_type_class(id_from_str ("PRIMA", 5));
- obj_size = new_SymConst((type *)class_prima, size);
- obj_o = new_Alloc(get_store(), obj_size, (type *)class_prima, heap_alloc);
- set_store(new_Proj(obj_o, mode_M, 0)); /* make the changed memory visible */
- obj_o = new_Proj(obj_o, mode_p, 1); /* remember the pointer to the object */
- /* we need type information for pointers to the class: */
- class_p_ptr = new_type_pointer (id_from_str ("class_prima_ptr", 15),
- (type *)class_prima);
-
- /* get the pointer to the procedure from the class type */
- proc_set = new_type_method(id_from_str("set_a", 5), 2, 0);
- set_method_param_type(proc_set, 0, (type *)class_p_ptr);
- set_method_param_type(proc_set, 1, (type *)prim_t_int);
- proc_set_e = new_entity((type *)class_prima, id_from_str ("set_a", 5),
- (type*)proc_set);
- proc_ptr = new_simpleSel(get_store(), /* The memory the object is allocated in */
- obj_o, /* The pointer to the object */
- proc_set_e ); /* The feature to select */
-
- /* call procedure set_a, first built array with parameters */
+ symconst_symbol sym;
+ ir_entity **free_methods;
+ int arr_len;
+
+ int o_pos, self_pos, e_pos;
+
+ int i;
+
+ init_firm(NULL);
+
+ set_opt_constant_folding(1);
+ set_opt_cse(1);
+
+ /*** Make basic ir_type information for primitive ir_type int. ***/
+ prim_t_int = new_type_primitive(new_id_from_chars("int", 3), mode_Is);
+
+ /*** Make ir_type information for the class (PRIMA). ***/
+ /* The ir_type of the class */
+ class_prima = new_type_class(new_id_from_chars("PRIMA", 5));
+ /* We need ir_type information for pointers to the class: */
+ class_p_ptr = new_type_pointer(new_id_from_chars("class_prima_ptr", 15),
+ class_prima, mode_P);
+ /* An ir_entity for the field (a). The ir_entity constructor automatically adds
+ the ir_entity as member of the owner. */
+ a_e = new_entity(class_prima, new_id_from_chars("a", 1), prim_t_int);
+ /* An ir_entity for the method set_a. But first we need ir_type information
+ for the method. */
+ proc_set_a = new_type_method(new_id_from_chars("set_a", 5), 2, 0);
+ set_method_param_type(proc_set_a, 0, class_p_ptr);
+ set_method_param_type(proc_set_a, 1, prim_t_int);
+ proc_set_a_e = new_entity(class_prima, new_id_from_chars("set_a", 5), proc_set_a);
+ /* An ir_entity for the method c. Implicit argument "self" must be modeled
+ explicit! */
+ proc_c = new_type_method(new_id_from_chars("c", 1 ), 2, 1);
+ set_method_param_type(proc_c, 0, class_p_ptr);
+ set_method_param_type(proc_c, 1, prim_t_int);
+ set_method_res_type(proc_c, 0, prim_t_int);
+ proc_c_e = new_entity(class_prima, new_id_from_chars("c", 1), proc_c);
+
+ /*** Now build procedure main. ***/
+ /** Type information for main. **/
+ printf("\nCreating an IR graph: OO_PROGRAM_EXAMPLE...\n");
+ /* Main is not modeled as part of an explicit class here. Therefore the
+ owner is the global ir_type. */
+ owner = get_glob_type();
+ /* Main has zero parameters and one result. */
+ proc_main = new_type_method(new_id_from_chars("OO_PROGRAM_EXAMPLE_main", 23), 0, 1);
+ /* The result ir_type is int. */
+ set_method_res_type(proc_main, 0, prim_t_int);
+
+ /* The ir_entity for main. */
+ proc_main_e = new_entity(owner, new_id_from_chars("OO_PROGRAM_EXAMPLE_main", 23), proc_main);
+
+ /** Build code for procedure main. **/
+ /* We need one local variable (for "o"). */
+ main_irg = new_ir_graph(proc_main_e, 1);
+ o_pos = 0;
+
+ /* Remark that this irg is the main routine of the program. */
+ set_irp_main_irg(main_irg);
+
+ /* Make the constants. They are independent of a block. */
+ c2 = new_Const(mode_Is, new_tarval_from_long(2, mode_Is));
+ c5 = new_Const(mode_Is, new_tarval_from_long(5, mode_Is));
+
+ /* There is only one block in main, it contains the allocation and the calls. */
+ /* Allocate the defined object and generate the ir_type information. */
+ sym.type_p = class_prima;
+ obj_size = new_SymConst(mode_Iu, sym, symconst_type_size);
+ obj_o = new_Alloc(get_store(), obj_size, class_prima, heap_alloc);
+ set_store(new_Proj(obj_o, mode_M, pn_Alloc_M)); /* make the changed memory visible */
+ obj_o = new_Proj(obj_o, mode_P, pn_Alloc_res); /* remember the pointer to the object */
+ set_value(o_pos, obj_o);
+
+ /* Get the pointer to the procedure from the object. */
+ proc_ptr = new_simpleSel(get_store(), /* The memory containing the object. */
+ get_value(o_pos, mode_P),/* The pointer to the object. */
+ proc_set_a_e ); /* The feature to select. */
+
+ /* Call procedure set_a, first built array with parameters. */