do not check for the entity type, simpl check the the initialier entity
[libfirm] / ir / tr / tpop_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/tr/tpop_t.h
4  * Purpose:     Opcode of types -- private header.
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 #ifndef _TPOP_T_H_
13 #define _TPOP_T_H_
14
15 #include "firm_types.h"
16 #include "tpop.h"
17 #include "irmode.h"
18
19 /**
20  * @file tpop_t.h
21  *
22  * This file contains the datatypes hidden in tpop.h.
23  *
24  * @author Goetz Lindenmaier
25  * @see  tpop.h
26  */
27
28 /** A function called to free attributes of a type. */
29 typedef void (*free_attrs_func)(type *tp);
30
31 /** A function called to free owned entities of a type. */
32 typedef void (*free_entities_func)(type *tp);
33
34 /** A function called to free all automatic allocated entities of a type. */
35 typedef void (*free_auto_entities_func)(type *tp);
36
37 /** A function called to set the mode of a type. */
38 typedef void (*set_type_mode_func)(type *tp, ir_mode *m);
39
40 /** A function called to set the size of a type in bits */
41 typedef void (*set_type_size_func)(type *tp, int size);
42
43 /** A function called to get the number of compound members */
44 typedef int (*get_n_members_func)(const type *tp);
45
46 /** A function called to get the pos'th compound member */
47 typedef entity *(*get_member_func)(const type *tp, int pos);
48
49 /** A function called to insert an entity into the type */
50 typedef void (*insert_entity_func)(type *tp, entity *member);
51
52
53 /**
54  * tp_op operations.
55  */
56 typedef struct _tp_op_ops {
57   free_attrs_func         free_attrs;         /**< called to free the attributes of a type */
58   free_entities_func      free_entities;      /**< called to free the owned entities of a type */
59   free_auto_entities_func free_auto_entities; /**< called to free the automatic allocated entities of a type */
60   set_type_mode_func      set_type_mode;      /**< called to set a ir_mode of a type */
61   set_type_size_func      set_type_size;      /**< called to set the bit size of a type */
62   get_n_members_func      get_n_members;      /**< called to return the number of compound members */
63   get_member_func         get_member;         /**< called to get the pos'th compound member */
64 } tp_op_ops;
65
66 /** possible flags for a type opcode */
67 enum tp_op_flags_t {
68   TP_OP_FLAG_COMPOUND = 1   /**< is a compound type */
69 };
70
71 /** The type opcode */
72 struct tp_op {
73   tp_opcode code;                     /**< the tpop code */
74   ident     *name;                    /**< the name of the type opcode */
75   size_t    attr_size;                /**< the attribute size for a type of this opcode */
76   unsigned  flags;                    /**< flags for this opcode */
77   tp_op_ops ops;                      /**< tp_op operations */
78 };
79
80 /**
81  *   Returns a new type opcode.
82  *
83  *   Allocates a new tp_op struct and initializes it's fields with
84  *   the passed values.  This function is only to be used during
85  *   initialization of the library.
86  *
87  *   @param code        the enum for this type opcode.
88  *   @param name        an ident for the name of the type opcode.
89  *   @param flags       additional flags
90  *   @param attr_size   the size of the attributes necessary for a type with
91  *                      this opcode
92  *   @param ops         the tp_op operations for this type
93  *   @return A new type opcode.
94  */
95 tp_op *new_tpop (tp_opcode code, ident *name, unsigned flags, size_t attr_size,
96                  const tp_op_ops *ops);
97
98 /**
99  * Free a tpop datastructure.
100  */
101 void free_tpop(tp_op *tpop);
102
103 /**
104  *   Initialize the tpop module.
105  *
106  *   Must be called during the initialization of the library. Allocates
107  *   opcodes and sets the globals that are external visible as specified
108  *   in tpop.h.
109  *   Allocates opcodes for classes, struct, method, union, array,
110  *   enumeration, pointer and primitive and sets the according values.
111  */
112 void init_tpop (void);
113
114 /**
115  *  Finalize the tpop module.
116  *
117  *  Frees all type opcodes.
118  */
119 void finish_tpop(void);
120
121 /**
122  *   Returns the size of the attribute to this kind
123  *   of type.
124  *
125  *   Internal feature.
126  *
127  *   @param op  The type opcode to get the size for.
128  *   @return The size of the attribute of types with this opcode.
129  *
130  */
131 int get_tpop_attr_size (const tp_op *op);
132
133
134 /* ---------------- *
135  * inline functions *
136  * -----------------*/
137
138 static INLINE tp_opcode
139 _get_tpop_code(const tp_op *op) {
140   return op->code;
141 }
142
143 static INLINE ident *
144 _get_tpop_ident(const tp_op *op){
145   return op->name;
146 }
147
148 static INLINE int
149 _get_tpop_attr_size(const tp_op *op) {
150   return op->attr_size;
151 }
152
153 #define get_tpop_code(op)      _get_tpop_code(op)
154 #define get_tpop_ident(op)     _get_tpop_ident(op)
155 #define get_tpop_attr_size(op) _get_tpop_attr_size(op)
156
157 #endif /* _TPOP_T_H_ */