added missing initialization
[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 #ifdef HAVE_CONFIG_H
13 # include "config.h"
14 #endif
15
16 # include "xmalloc.h"
17 # include "tpop_t.h"
18 # include "type_t.h"
19
20 tp_op *type_class;         tp_op *get_tpop_class      (void) { return type_class;       }
21 tp_op *type_struct;        tp_op *get_tpop_struct     (void) { return type_struct;      }
22 tp_op *type_method;        tp_op *get_tpop_method     (void) { return type_method;      }
23 tp_op *type_union;         tp_op *get_tpop_union      (void) { return type_union;       }
24 tp_op *type_array;         tp_op *get_tpop_array      (void) { return type_array;       }
25 tp_op *type_enumeration;   tp_op *get_tpop_enumeration(void) { return type_enumeration; }
26 tp_op *type_pointer;       tp_op *get_tpop_pointer    (void) { return type_pointer;     }
27 tp_op *type_primitive;     tp_op *get_tpop_primitive  (void) { return type_primitive;   }
28 tp_op *type_id;            tp_op *get_tpop_id         (void) { return type_id;          }
29 tp_op *tpop_none;          tp_op *get_tpop_none       (void) { return tpop_none;        }
30 tp_op *tpop_unknown;       tp_op *get_tpop_unknown    (void) { return tpop_unknown;     }
31
32 tp_op *
33 new_tpop (tp_opcode code, ident *name, unsigned flags, size_t attr_size)
34 {
35   tp_op *res;
36
37   res = xmalloc(sizeof(*res));
38   res->code      = code;
39   res->name      = name;
40   res->flags     = flags;
41   res->attr_size = attr_size;
42   return res;
43 }
44
45 INLINE void
46 free_tpop(tp_op *tpop) {
47   free(tpop);
48 }
49
50 #define C     TP_OP_FLAG_COMPOUND
51 #define ID(s) new_id_from_chars(s, sizeof(s) - 1)
52 void
53 init_tpop(void)
54 {
55   type_class       = new_tpop(tpo_class      , ID("class"),       C, sizeof (cls_attr));
56   type_struct      = new_tpop(tpo_struct     , ID("struct"),      C, sizeof (stc_attr));
57   type_method      = new_tpop(tpo_method     , ID("method"),      0, sizeof (mtd_attr));
58   type_union       = new_tpop(tpo_union      , ID("union"),       C, sizeof (uni_attr));
59   type_array       = new_tpop(tpo_array      , ID("array"),       C, sizeof (arr_attr));
60   type_enumeration = new_tpop(tpo_enumeration, ID("enumeration"), 0, sizeof (enm_attr));
61   type_pointer     = new_tpop(tpo_pointer    , ID("pointer"),     0, sizeof (ptr_attr));
62   type_primitive   = new_tpop(tpo_primitive  , ID("primitive"),   0, /* sizeof (pri_attr) */ 0);
63   type_id          = new_tpop(tpo_id         , ID("type_id"),     0, /* sizeof (id_attr)  */ 0);
64   tpop_none        = new_tpop(tpo_none       , ID("tpop_none"),   0, /* sizeof (non_attr) */ 0);
65   tpop_unknown     = new_tpop(tpo_unknown    , ID("tpop_unknown"),0, /* sizeof (ukn_attr) */ 0);
66 }
67 #undef ID
68 #undef C
69
70 /* Finalize the tpop module.
71  * Frees all type opcodes.  */
72 void finish_tpop(void) {
73   free_tpop(type_class      ); type_class       = NULL;
74   free_tpop(type_struct     ); type_struct      = NULL;
75   free_tpop(type_method     ); type_method      = NULL;
76   free_tpop(type_union      ); type_union       = NULL;
77   free_tpop(type_array      ); type_array       = NULL;
78   free_tpop(type_enumeration); type_enumeration = NULL;
79   free_tpop(type_pointer    ); type_pointer     = NULL;
80   free_tpop(type_primitive  ); type_primitive   = NULL;
81   free_tpop(type_id         ); type_id          = NULL;
82   free_tpop(tpop_none       ); tpop_none        = NULL;
83   free_tpop(tpop_unknown    ); tpop_unknown     = NULL;
84 }
85
86 /* Returns the string for the tp_opcode. */
87 const char  *get_tpop_name(const tp_op *op) {
88   return get_id_str(op->name);
89 }
90
91 tp_opcode (get_tpop_code)(const tp_op *op){
92   return __get_tpop_code(op);
93 }
94
95 ident *(get_tpop_ident)(const tp_op *op){
96   return __get_tpop_ident(op);
97 }
98
99 /* returns the attribute size of the operator. */
100 int (get_tpop_attr_size)(const tp_op *op) {
101   return __get_tpop_attr_size(op);
102 }