X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=testprograms%2Fconst_ent_example.c;h=6e003fc143e8af7b2eb4a3654ab484edeae52f07;hb=95730664ee5ec63be34b1142222b6704300666f5;hp=4a5590634a630056fa68b9763404fcba2880f5b8;hpb=5052f2d2fc507aefb5d39aa7d6cc41ca55b3a2c9;p=libfirm diff --git a/testprograms/const_ent_example.c b/testprograms/const_ent_example.c index 4a5590634..6e003fc14 100644 --- a/testprograms/const_ent_example.c +++ b/testprograms/const_ent_example.c @@ -1,51 +1,59 @@ -/* Copyright (C) 2000 by Universitaet Karlsruhe -** All rights reserved. -** -** Author: Goetz Lindenmaier -** -** testprogram. -*/ - -#include - +/* + * Project: libFIRM + * File name: testprograms/const_ent_example.c + * Purpose: Shows how to construct type information for constant entities. + * Author: Goetz Lindenmaier + * Modified by: + * Created: + * CVS-ID: $Id$ + * Copyright: (c) 1999-2003 Universität Karlsruhe + * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + */ + + +# include +# include + +# include "irvrfy.h" # include "irdump.h" # include "firm.h" /** -*** This file constructs type information for constant entities. -*** -*** It constructs the information for a class type with a dispatch -*** table. The class has a field a, and two methods f and g. The -*** class is represented by a class type with two entities for the -*** field a and the reference to the dispatch table. This reference -*** is a constant entity. Ther dispatch table is also represented -*** by a class type that contains the two methods. There is one entity -*** of the dispatch table which is constant. -*** -*** Further the example shows the representation of a constant global -*** array. -*** -*** class C { -*** int a; -*** void f(); -*** void g(int); -*** } -*** int[4] arre = (7, 2, 13, 92); -**/ + * This file constructs type information for constant entities. + * + * It constructs the information for a class type with a dispatch + * table. The class has a field a, and two methods f and g. The + * class is represented by a class type with two entities for the + * field a and the reference to the dispatch table. This reference + * is a constant entity. Ther dispatch table is also represented + * by a class type that contains the two methods. There is one entity + * of the dispatch table which is constant. + * + * Further the example shows the representation of a constant global + * array. + * + * class C { + * int a; + * void f(); + * void g(int); + * } + * int[4] arre = (7, 2, 13, 92); + **/ int main(int argc, char **argv) { ident *Ci, *ai, *fi, *fti, *gi, *gti, *inti, *dipti, *diptpi, *diptpei, *diptei; /* suffix i names identifiers */ - type *Ct, *intt, *at, *ft, *gt, *diptt, *diptpt; + type *Ct, *intt, *ft, *gt, *diptt, *diptpt; /* t names types */ entity *ae, *fe, *ge, *dipte, *diptpe; /* e names entities */ ir_node *n; - printf("\nCreating type information...\n"); + printf("\nExample program for constant entites.\n"); + printf("Creating type information...\n"); /** init library */ - init_firm (); + init_firm (NULL); /** make idents for all used identifiers in the program. */ Ci = id_from_str("C", strlen("C")); @@ -63,7 +71,7 @@ int main(int argc, char **argv) /** make the type information needed */ /* Language defined types */ - intt = new_type_primitive(inti, mode_i); + intt = new_type_primitive(inti, mode_Is); /* Program defined types */ Ct = new_type_class(Ci); ft = new_type_method(fti, 0, 0); /* 0 parameters, 0 results */ @@ -86,12 +94,12 @@ int main(int argc, char **argv) current_ir_graph = get_const_code_irg(); /* The pointer to the dispatch table is constant. */ /* The constant is the address of the given entity */ - n = new_Const(mode_p, tarval_p_from_entity(dipte)); - set_entity_variability(diptpe, constant); + n = new_Const(mode_P, new_tarval_from_entity(dipte, mode_P)); + set_entity_variability(diptpe, variability_constant); set_atomic_ent_value(diptpe, n); /* The entity representing the dispatch table is constant, too. */ - set_entity_variability(dipte, constant); + set_entity_variability(dipte, variability_constant); add_compound_ent_value(dipte, get_atomic_ent_value(fe), fe); add_compound_ent_value(dipte, get_atomic_ent_value(ge), ge); @@ -106,22 +114,22 @@ int main(int argc, char **argv) /** The array type **/ /* Don't reuse int type so that graph layout is better readable */ - intt = new_type_primitive(inti, mode_i); + intt = new_type_primitive(inti, mode_Is); arrt = new_type_array(arrti, 1, intt); set_array_bounds_int(arrt, 0, 0, 4); arrelte = get_array_element_entity(arrt); /** The constant array entity **/ arre = new_entity(get_glob_type(), arrei, arrt); - set_entity_variability(arre, constant); + set_entity_variability(arre, variability_constant); current_ir_graph = get_const_code_irg(); - n = new_Const(mode_i, tarval_from_long (mode_i, 7)); + n = new_Const(mode_Is, new_tarval_from_long (7, mode_Is)); add_compound_ent_value(arre, n, arrelte); - n = new_Const(mode_i, tarval_from_long (mode_i, 2)); + n = new_Const(mode_Is, new_tarval_from_long (2, mode_Is)); add_compound_ent_value(arre, n, arrelte); - n = new_Const(mode_i, tarval_from_long (mode_i, 13)); + n = new_Const(mode_Is, new_tarval_from_long (13, mode_Is)); add_compound_ent_value(arre, n, arrelte); - n = new_Const(mode_i, tarval_from_long (mode_i, 92)); + n = new_Const(mode_Is, new_tarval_from_long (92, mode_Is)); add_compound_ent_value(arre, n, arrelte); } printf("Done building the graph. Dumping it.\n");