Do not emit cld in the CopyB prologue. The ABI mandates that DF is cleared, so do...
[libfirm] / testprograms / inheritance_example.c
1 /*
2  * Project:     libFIRM
3  * File name:   testprograms/inheritance_example.c
4  * Purpose:     Shows ir_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 <libfirm/firm.h>
17
18 /**
19 *  This file constructs ir_type information for the following pseudo-program.
20 *  The procedure code is not constructed.
21 *
22 *  interface I {
23 *    void m1(void);
24 *  }
25 *
26 *  class C implements I {
27 *    void m1(void) {return};
28 *    void m2(int)  {return 0};
29 *  }
30 *
31 *  class D {
32 *    int b;
33 *  }
34 *
35 *  class E extends C, D {
36 *    void m2(int) {return 1};
37 *    int a;
38 *  }
39 *
40 **/
41
42 int main(void)
43 {
44   ident *ii, *ci, *di, *ei, *m1i, *m2i, *inti, *ai, *bi; /* suffix i names identifiers */
45   ir_type  *it, *ct, *dt, *et;                              /*        t names types       */
46   ir_type  *m1t, *m2t;
47   ir_type  *intt;
48   ir_entity *i_m1e, *c_m1e, *c_m2e, *e_m2e, *d_be, *e_ae;   /*        e names entities    */
49
50   printf("\nCreating ir_type information for INHERITANCE_EXAMPLE ...\n");
51
52   /** init library */
53   init_firm(NULL);
54
55   /** make idents for all used identifiers in the program. */
56   ii  = new_id_from_chars("i",  strlen("i"));
57   ci  = new_id_from_chars("c",  strlen("c"));
58   di  = new_id_from_chars("d",  strlen("d"));
59   ei  = new_id_from_chars("e",  strlen("e"));
60   m1i = new_id_from_chars("m1", strlen("m1"));
61   m2i = new_id_from_chars("m2", strlen("m2"));
62   inti= new_id_from_chars("int",strlen("int"));
63   ai  = new_id_from_chars("a",  strlen("a"));
64   bi  = new_id_from_chars("b",  strlen("b"));
65
66   /** make the ir_type information needed */
67   /* Language defined types */
68   intt = new_type_primitive(inti, mode_Iu);
69   /* Program defined types */
70   it = new_type_class(ii);           /* The fact that this is an interface is
71                                         of no interest.  It's just a class without
72                                         fields and implementations.  But the
73                                         implementation will never be needed. */
74   ct = new_type_class(ci);
75   dt = new_type_class(di);
76   et = new_type_class(ei);
77                                      /* Methods with the same ir_type should use the same
78                                         method ir_type information! */
79   m1t = new_type_method(m1i, 0, 0);  /* 0 parameters, 0 results */
80   m2t = new_type_method(m2i, 1, 0);  /* 1 parameter, 0 results */
81
82   /** add structure to ir_type graph **/
83   /* parameters of methods */
84   set_method_param_type(m2t, 0, intt);
85   /* inheritance. The other direction is added automatically. */
86   add_class_subtype(it, ct);
87   add_class_subtype(ct, et);
88   add_class_subtype(dt, et);
89
90   /** make entities **/
91   i_m1e = new_entity(it, m1i, m1t);
92   c_m1e = new_entity(ct, m1i, m1t);
93   c_m2e = new_entity(ct, m2i, m2t);
94   e_m2e = new_entity(et, m2i, m2t);
95   d_be  = new_entity(dt, bi, intt);
96   e_ae  = new_entity(et, ai, intt);
97
98   /** Add overwirtes relation **/
99   /* How these edges are added depends on the source language. */
100   add_entity_overwrites(c_m1e, i_m1e);
101   add_entity_overwrites(e_m2e, c_m2e);
102
103
104   printf("Done building the graph.  Dumping it.\n");
105   dump_all_types(0);
106
107   printf("Use ycomp to view this graph:\n");
108   printf("ycomp GRAPHNAME\n\n");
109
110   return 0;
111 }