2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Opcode of types -- private header.
9 * @author Goetz Lindenmaier, Michael Beck
11 #ifndef FIRM_TR_TPOP_T_H
12 #define FIRM_TR_TPOP_T_H
16 #include "firm_types.h"
20 #define get_tpop_code(op) _get_tpop_code(op)
21 #define get_tpop_ident(op) _get_tpop_ident(op)
23 /** A function called to free attributes of a type. */
24 typedef void (*free_attrs_func)(ir_type *tp);
26 /** A function called to free owned entities of a type. */
27 typedef void (*free_entities_func)(ir_type *tp);
29 /** A function called to free all automatic allocated entities of a type. */
30 typedef void (*free_auto_entities_func)(ir_type *tp);
32 /** A function called to set the mode of a type. */
33 typedef void (*set_type_mode_func)(ir_type *tp, ir_mode *m);
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);
38 /** A function called to get the number of compound members */
39 typedef size_t (*get_n_members_func)(const ir_type *tp);
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);
44 typedef size_t (*get_member_index_func)(const ir_type *tp, ir_entity *member);
46 /** A function called to insert an entity into the type */
47 typedef void (*insert_entity_func)(ir_type *tp, ir_entity *member);
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. */
63 /** possible flags for a type opcode */
65 TP_OP_FLAG_COMPOUND = 1 /**< is a compound type */
68 /** The type opcode. */
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. */
78 * Returns a new type opcode.
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.
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
89 * @param ops the tp_op operations for this type
90 * @return A new type opcode.
92 const tp_op *new_tpop (tp_opcode code, ident *name, unsigned flags, size_t attr_size, const tp_op_ops *ops);
95 * Free a tpop data structure.
97 void free_tpop(const tp_op *tpop);
100 * Initialize the tpop module.
102 * Must be called during the initialization of the library. Allocates
103 * opcodes and sets the globals that are external visible as specified
105 * Allocates opcodes for classes, struct, method, union, array,
106 * enumeration, pointer and primitive and sets the according values.
108 void init_tpop(void);
111 * Finalize the tpop module.
113 * Frees all type opcodes.
115 void finish_tpop(void);
118 * Returns the size of the attribute to this kind
123 * @param op The type opcode to get the size for.
124 * @return The size of the attribute of types with this opcode.
126 static inline size_t get_tpop_attr_size(const tp_op *op)
128 return op->attr_size;
131 /* ---------------- *
133 * -----------------*/
135 static inline tp_opcode _get_tpop_code(const tp_op *op)
140 static inline ident *_get_tpop_ident(const tp_op *op)
145 #endif /* FIRM_TR_TPOP_T_H */