Types "own" entities, so they should also free them when they get freed.
*/
FIRM_API int tr_verify(void);
-/** Frees all entities associated with a type.
- * Does not free the array entity.
- * Warning: ensure these entities are not referenced anywhere else.
- */
-FIRM_API void free_type_entities(ir_type *tp);
-
-/** Frees the memory used by the type.
+/**
+ * Frees the memory used by the type.
*
- * Removes the type from the type list. Does not free the entities
- * belonging to the type, except for the array element entity. Does
- * not free if tp is "none" or "unknown". Frees entities in value
- * param subtypes of method types!!! Make sure these are not
- * referenced any more. Further make sure there is no pointer type
- * that refers to this type.
+ * Removes the type from the type list and frees all entities
+ * belonging to the type.
*/
FIRM_API void free_type(ir_type *tp);
for (i = get_irp_n_irgs(); i > 0;)
free_ir_graph(get_irp_irg(--i));
- free_type_entities(get_glob_type());
- /* must iterate backwards here */
+ /* free entities first to avoid entity types being destroyed before
+ * the entities using them */
for (i = get_irp_n_types(); i > 0;)
free_type_entities(get_irp_type(--i));
return res;
}
+void free_type_entities(ir_type *tp)
+{
+ const tp_op *op = get_type_tpop(tp);
+ if (op->ops.free_entities != NULL)
+ op->ops.free_entities(tp);
+}
+
+static void free_type_attrs(ir_type *tp)
+{
+ const tp_op *tpop = get_type_tpop(tp);
+
+ if (tpop->ops.free_attrs)
+ tpop->ops.free_attrs(tp);
+}
+
void free_type(ir_type *tp)
{
const tp_op *op = get_type_tpop(tp);
+ free_type_entities(tp);
/* Remove from list of all types */
remove_irp_type(tp);
/* Free the attributes of the type. */
free(tp);
}
-void free_type_entities(ir_type *tp)
-{
- const tp_op *tpop = get_type_tpop(tp);
-
- if (tpop->ops.free_entities)
- tpop->ops.free_entities(tp);
-}
-
-void free_type_attrs(ir_type *tp)
-{
- const tp_op *tpop = get_type_tpop(tp);
-
- if (tpop->ops.free_attrs)
- tpop->ops.free_attrs(tp);
-}
-
void *(get_type_link)(const ir_type *tp)
{
return _get_type_link(tp);
* initialized. The type is in state layout_undefined.
*/
ir_type *new_type(const tp_op *type_op, ir_mode *mode, type_dbg_info *db);
-void free_type_attrs(ir_type *tp);
+
+void free_type_entities(ir_type *tp);
void free_class_entities (ir_type *clss);
void free_struct_entities (ir_type *strct);