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