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