First implementation of lowering for calls with compound return values
[libfirm] / testprograms / inheritance_example.c
1 /*
2  * Project:     libFIRM
3  * File name:   testprograms/inheritance_example.c
4  * Purpose:     Shows type graph with inheritance.
5  * Author:      Christian Schaefer, Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1999-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 # include <stdio.h>
14 # include <string.h>
15
16 # include "irvrfy.h"
17 # include "irdump.h"
18 # include "firm.h"
19
20 /**
21 *  This file constructs type information for the following pseudo-program.
22 *  The procedure code is not constructed.
23 *
24 *  interface I {
25 *    void m1 (void);
26 *  }
27 *
28 *  class C implements I {
29 *    void m1 (void) {return};
30 *    void m2 (int)  {return 0};
31 *  }
32 *
33 *  class D {
34 *    int b;
35 *  }
36 *
37 *  class E extends C, D {
38 *    void m2 (int) {return 1};
39 *    int a;
40 *  }
41 *
42 **/
43
44 int main(int argc, char **argv)
45 {
46   ident *ii, *ci, *di, *ei, *m1i, *m2i, *inti, *ai, *bi; /* suffix i names identifiers */
47   type  *it, *ct, *dt, *et;                              /*        t names types       */
48   type  *m1t, *m2t;
49   type  *intt;
50   entity *i_m1e, *c_m1e, *c_m2e, *e_m2e, *d_be, *e_ae;   /*        e names entities    */
51
52   printf("\nCreating type information for INHERITANCE_EXAMPLE ...\n");
53
54   /** init library */
55   init_firm (NULL);
56
57   /** make idents for all used identifiers in the program. */
58   ii  = new_id_from_chars("i",  strlen("i"));
59   ci  = new_id_from_chars("c",  strlen("c"));
60   di  = new_id_from_chars("d",  strlen("d"));
61   ei  = new_id_from_chars("e",  strlen("e"));
62   m1i = new_id_from_chars("m1", strlen("m1"));
63   m2i = new_id_from_chars("m2", strlen("m2"));
64   inti= new_id_from_chars("int",strlen("int"));
65   ai  = new_id_from_chars("a",  strlen("a"));
66   bi  = new_id_from_chars("b",  strlen("b"));
67
68   /** make the type information needed */
69   /* Language defined types */
70   intt = new_type_primitive(inti, mode_Iu);
71   /* Program defined types */
72   it = new_type_class(ii);           /* The fact that this is an interface is
73                                         of no interest.  It's just a class without
74                                         fields and implementations.  But the
75                                         implementation will never be needed. */
76   ct = new_type_class(ci);
77   dt = new_type_class(di);
78   et = new_type_class(ei);
79                                      /* Methods with the same type should use the same
80                                         method type information! */
81   m1t = new_type_method(m1i, 0, 0);  /* 0 parameters, 0 results */
82   m2t = new_type_method(m2i, 1, 0);  /* 1 parameter, 0 results */
83
84   /** add structure to type graph **/
85   /* parameters of methods */
86   set_method_param_type(m2t, 0, intt);
87   /* inheritance. The other direction is added automatically. */
88   add_class_subtype(it, ct);
89   add_class_subtype(ct, et);
90   add_class_subtype(dt, et);
91
92   /** make entities **/
93   i_m1e = new_entity(it, m1i, m1t);
94   c_m1e = new_entity(ct, m1i, m1t);
95   c_m2e = new_entity(ct, m2i, m2t);
96   e_m2e = new_entity(et, m2i, m2t);
97   d_be  = new_entity(dt, bi, intt);
98   e_ae  = new_entity(et, ai, intt);
99
100   /** Add overwirtes relation **/
101   /* How these edges are added depends on the source language. */
102   add_entity_overwrites (c_m1e, i_m1e);
103   add_entity_overwrites (e_m2e, c_m2e);
104
105
106   printf("Done building the graph.  Dumping it.\n");
107   dump_all_types(0);
108
109   printf("use xvcg to view this graph:\n");
110   printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");
111
112   return (0);
113 }