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