X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=testprograms%2Fcall_str_example.c;h=57e677e9dcb5f2f74f536c3d2514a7666e811ed5;hb=80fadd53d5cf0feddf63f34d6306e45f8d5de717;hp=74397a57f714ebe86f038787438baf780b2b9eea;hpb=6d36abf323fc5c7fba7ed2f1f6939a84b3e4a932;p=libfirm diff --git a/testprograms/call_str_example.c b/testprograms/call_str_example.c index 74397a57f..57e677e9d 100644 --- a/testprograms/call_str_example.c +++ b/testprograms/call_str_example.c @@ -23,18 +23,23 @@ int main(int argc, char **argv) { - ir_graph *irg; /* this variable contains the irgraph */ - type_class *owner; /* the class in which this method is defined */ - type_method *proc_main; /* type information for the method main */ - type_method *proc_called; /* type information for called method f */ - entity *ent; /* represents this method as entity of owner */ - ir_node *x, *const_str, *proc_ptr, *call; + ir_graph *irg; /* this variable contains the irgraph */ + type *owner; /* the class in which this method is defined */ + type *proc_main; /* type information for the method main */ + type *proc_called; /* type information for called method f */ + type *string_ptr; /* type for pointers to strings. */ + entity *ent; /* represents this method as entity of owner */ + ir_node *x, *const_str, *proc_ptr, *call; printf("\nCreating an IR graph: CALL_STR_EXAMPLE...\n"); /* init library */ init_firm (); + string_ptr = new_type_pointer ( + id_from_str ("ptr_to_string", 13), + new_type_array (id_from_str ("char_arr", 8), 1, + new_type_primitive (id_from_str("char", 4), mode_c))); /* FIRM was designed for oo languages where all methods belong to a class. * For imperative languages like C we view a program as a large class containing * all functions of the program as methods in this class. This class is @@ -56,11 +61,12 @@ int main(int argc, char **argv) owner = get_glob_type(); proc_called = new_type_method(id_from_str(F_METHODNAME, strlen(F_METHODNAME)), F_NRARGS, F_NRES); + set_method_param_type(proc_called, 0, string_ptr); /* Make the entity for main needed for a correct ir_graph. */ #define ENTITYNAME "main" - ent = new_entity ((type *)owner, id_from_str (ENTITYNAME, strlen(ENTITYNAME)), - (type *)proc_main); + ent = new_entity (owner, id_from_str (ENTITYNAME, strlen(ENTITYNAME)), + proc_main); /* Generates the basic graph for the method represented by entity ent, that * is, generates start and end blocks and nodes and a first, initial block. @@ -76,7 +82,7 @@ int main(int argc, char **argv) /* this is how a pointer to be fixed by the linker is represented after lowering a Sel node. */ #define FUNCTIONNAME "f" - proc_ptr = new_SymConst ((type_or_id_p)ID_FROM_STR (FUNCTIONNAME, strlen(FUNCTIONNAME)), + proc_ptr = new_SymConst ((type_or_id_p)id_from_str (FUNCTIONNAME, strlen(FUNCTIONNAME)), linkage_ptr_info); /* call procedure set_a, first built array with parameters */ @@ -95,13 +101,15 @@ int main(int argc, char **argv) } /* Now we generated all instructions for this block and all its predecessor blocks * so we can mature it. */ - mature_block (irg->current_block); + mature_block (get_irg_current_block(irg)); /* This adds the in edge of the end block which originates at the return statement. * The return node passes controlflow to the end block. */ - add_in_edge (irg->end_block, x); + add_in_edge (get_irg_end_block(irg), x); /* Now we can mature the end block as all it's predecessors are known. */ - mature_block (irg->end_block); + mature_block (get_irg_end_block(irg)); + + finalize_cons (irg); printf("Optimizing ...\n"); dead_node_elimination(irg);