X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=testprograms%2Fconst_ent_example.c;h=4c59d8984b29deb5f9d72785f93c42f43e7a8ca9;hb=e67421b6765e71019d44bf189a15951266c34373;hp=f2e16d1a96d6db1cf0552c8be2957a787fae7691;hpb=6ed168c29789db8edf25c87f2da9164c49a5512c;p=libfirm diff --git a/testprograms/const_ent_example.c b/testprograms/const_ent_example.c index f2e16d1a9..4c59d8984 100644 --- a/testprograms/const_ent_example.c +++ b/testprograms/const_ent_example.c @@ -1,12 +1,17 @@ -/* 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" @@ -14,32 +19,32 @@ # 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; @@ -48,20 +53,20 @@ int main(int argc, char **argv) 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")); - ai = id_from_str("a", strlen("a")); - fi = id_from_str("f", strlen("f")); - fti = id_from_str("f_type", strlen("f_type")); - gi = id_from_str("g", strlen("g")); - gti = id_from_str("g_type", strlen("g_type")); - inti = id_from_str("int", strlen("int")); - dipti = id_from_str("C_dispatch_table_type", strlen("C_dispatch_table_type")); - diptei = id_from_str("C_dispatch_table", strlen("C_dispatch_table")); - diptpi = id_from_str("C_dispatch_table_p_type", strlen("C_dispatch_table_p_type")); - diptpei = id_from_str("C_dispatch_table_p", strlen("C_dispatch_table_p")); + Ci = new_id_from_chars("C", strlen("C")); + ai = new_id_from_chars("a", strlen("a")); + fi = new_id_from_chars("f", strlen("f")); + fti = new_id_from_chars("f_type", strlen("f_type")); + gi = new_id_from_chars("g", strlen("g")); + gti = new_id_from_chars("g_type", strlen("g_type")); + inti = new_id_from_chars("int", strlen("int")); + dipti = new_id_from_chars("C_dispatch_table_type", strlen("C_dispatch_table_type")); + diptei = new_id_from_chars("C_dispatch_table", strlen("C_dispatch_table")); + diptpi = new_id_from_chars("C_dispatch_table_p_type", strlen("C_dispatch_table_p_type")); + diptpei = new_id_from_chars("C_dispatch_table_p", strlen("C_dispatch_table_p")); /** make the type information needed */ @@ -89,12 +94,14 @@ 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); + symconst_symbol sym; + sym.entity_p = dipte; + n = new_SymConst(sym, symconst_addr_ent); + 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); @@ -104,8 +111,8 @@ int main(int argc, char **argv) type *arrt; entity *arre, *arrelte; - arrei = id_from_str("arr", strlen("arr")); - arrti = id_from_str("arr_t", strlen("arr_t")); + arrei = new_id_from_chars("arr", strlen("arr")); + arrti = new_id_from_chars("arr_t", strlen("arr_t")); /** The array type **/ /* Don't reuse int type so that graph layout is better readable */ @@ -116,19 +123,19 @@ int main(int argc, char **argv) /** 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_Is, tarval_from_long (mode_Is, 7)); + n = new_Const(mode_Is, new_tarval_from_long (7, mode_Is)); add_compound_ent_value(arre, n, arrelte); - n = new_Const(mode_Is, tarval_from_long (mode_Is, 2)); + n = new_Const(mode_Is, new_tarval_from_long (2, mode_Is)); add_compound_ent_value(arre, n, arrelte); - n = new_Const(mode_Is, tarval_from_long (mode_Is, 13)); + n = new_Const(mode_Is, new_tarval_from_long (13, mode_Is)); add_compound_ent_value(arre, n, arrelte); - n = new_Const(mode_Is, tarval_from_long (mode_Is, 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"); - dump_all_types(); + dump_all_types(0); printf("use xvcg to view this graph:\n"); printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");