New inlining schema implemented:
[libfirm] / ir / tr / tpop.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/tr/tpop.c
4  * Purpose:     Opcode of types.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2001-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14 #ifdef HAVE_CONFIG_H
15 # include <config.h>
16 #endif
17
18 # include "xmalloc.h"
19 # include "tpop_t.h"
20 # include "type_t.h"
21
22 tp_op *type_class;         tp_op *get_tpop_class      (void) { return type_class;       }
23 tp_op *type_struct;        tp_op *get_tpop_struct     (void) { return type_struct;      }
24 tp_op *type_method;        tp_op *get_tpop_method     (void) { return type_method;      }
25 tp_op *type_union;         tp_op *get_tpop_union      (void) { return type_union;       }
26 tp_op *type_array;         tp_op *get_tpop_array      (void) { return type_array;       }
27 tp_op *type_enumeration;   tp_op *get_tpop_enumeration(void) { return type_enumeration; }
28 tp_op *type_pointer;       tp_op *get_tpop_pointer    (void) { return type_pointer;     }
29 tp_op *type_primitive;     tp_op *get_tpop_primitive  (void) { return type_primitive;   }
30 tp_op *type_id;            tp_op *get_tpop_id         (void) { return type_id;          }
31 tp_op *tpop_none;          tp_op *get_tpop_none       (void) { return tpop_none;        }
32 tp_op *tpop_unknown;       tp_op *get_tpop_unknown    (void) { return tpop_unknown;     }
33
34 tp_op *
35 new_tpop (tp_opcode code, ident *name, size_t attr_size)
36 {
37   tp_op *res;
38
39   res = (tp_op *) xmalloc (sizeof (tp_op));
40   res->code = code;
41   res->name = name;
42   res->attr_size = attr_size;
43   return res;
44 }
45
46 INLINE void
47 free_tpop(tp_op* tpop) {
48   free(tpop);
49 }
50
51 void
52 init_tpop(void)
53 {
54   type_class       = new_tpop (tpo_class      , id_from_str("class"       , 5), sizeof (cls_attr));
55   type_struct      = new_tpop (tpo_struct     , id_from_str("struct"      , 6), sizeof (stc_attr));
56   type_method      = new_tpop (tpo_method     , id_from_str("method"      , 6), sizeof (mtd_attr));
57   type_union       = new_tpop (tpo_union      , id_from_str("union"       , 5), sizeof (uni_attr));
58   type_array       = new_tpop (tpo_array      , id_from_str("array"       , 5), sizeof (arr_attr));
59   type_enumeration = new_tpop (tpo_enumeration, id_from_str("enumeration" ,11), sizeof (enm_attr));
60   type_pointer     = new_tpop (tpo_pointer    , id_from_str("pointer"     , 7), sizeof (ptr_attr));
61   type_primitive   = new_tpop (tpo_primitive  , id_from_str("primitive"   , 9), /* sizeof (pri_attr) */ 0);
62   type_id          = new_tpop (tpo_id         , id_from_str("type_id"     , 7), /* sizeof (id_attr)  */ 0);
63   tpop_none        = new_tpop (tpo_none       , id_from_str("tpop_none"   , 9), /* sizeof (non_attr) */ 0);
64   tpop_unknown     = new_tpop (tpo_unknown    , id_from_str("tpop_unknown",12), /* sizeof (ukn_attr) */ 0);
65 }
66
67 /* Finalize the topo module.
68  * Frees all type opcodes.  */
69 void finish_tpop(void) {
70   free_tpop(type_class      ); type_class       = NULL;
71   free_tpop(type_struct     ); type_struct      = NULL;
72   free_tpop(type_method     ); type_method      = NULL;
73   free_tpop(type_union      ); type_union       = NULL;
74   free_tpop(type_array      ); type_array       = NULL;
75   free_tpop(type_enumeration); type_enumeration = NULL;
76   free_tpop(type_pointer    ); type_pointer     = NULL;
77   free_tpop(type_primitive  ); type_primitive   = NULL;
78   free_tpop(type_id         ); type_id          = NULL;
79   free_tpop(tpop_none       ); tpop_none        = NULL;
80   free_tpop(tpop_unknown    ); tpop_unknown     = NULL;
81 }
82
83 /* Returns the string for the tp_opcode. */
84 const char  *get_tpop_name      (tp_op *op) {
85   return get_id_str(op->name);
86 }
87
88 tp_opcode (get_tpop_code)(tp_op *op){
89   return __get_tpop_code(op);
90 }
91
92 ident *(get_tpop_ident)(tp_op *op){
93   return __get_tpop_ident(op);
94 }
95
96 /* returns the attribute size of the operator. */
97 int (get_tpop_attr_size)(tp_op *op) {
98   return __get_tpop_attr_size(op);
99 }