"type_tag", "size", "addr_name", "addr_ent"
};
+/**
+ * Indicates, whether additional data can be registered to ir nodes.
+ * If set to 1, this is not possible anymore.
+ */
+static int forbid_new_data = 0;
+
+/**
+ * The amount of additional space for custom data to be allocated upon
+ * creating a new node.
+ */
+static size_t additional_node_data_size = 0;
+
+
+size_t register_additional_node_data(size_t size)
+{
+ assert(!forbid_new_data && "Too late to register additional node data");
+
+ if(forbid_new_data)
+ return 0;
+
+ return additional_node_data_size += size;
+}
+
+
void
init_irnode (void)
{
+ /* Forbid the addition of new data to an ir node. */
+ forbid_new_data = 1;
}
/*
int arity, ir_node **in)
{
ir_node *res;
- int node_size = offsetof (ir_node, attr) + op->attr_size;
+ size_t node_size = offsetof(ir_node, attr) + op->attr_size + additional_node_data_size;
+ char *p;
assert(irg && op && mode);
- res = (ir_node *) obstack_alloc (irg->obst, node_size);
- memset((void *)res, 0, node_size);
+ p = obstack_alloc (irg->obst, node_size);
+ memset(p, 0, node_size);
+ res = (ir_node *) (p + additional_node_data_size);
res->kind = k_ir_node;
res->op = op;
return is_op_forking(get_irn_op(node));
}
+
#ifdef DEBUG_libfirm
void dump_irn (ir_node *n) {
int i, arity = get_irn_arity(n);
# ifndef _IRNODE_H_
# define _IRNODE_H_
+#include <stddef.h>
+
/**
* Projection numbers of compare: use for Proj nodes!
* @remark there are numbers with normalized names below!
* operation: Cond. */
int is_forking_op(const ir_node *node);
+/**
+ * Access custom node data.
+ * The data must have been registered with
+ * register_additional_node_data() before.
+ * @param node The ir node to get the data from.
+ * @param type The type of the data you registered.
+ * @param off The value returned by register_additional_node_data.
+ * @return A pointer of type @p type.
+ */
+#define get_irn_data(node,type,off) \
+ (assert(off > 0 && "Invalid node data offset"), (type *) ((char *) (node) - (off)))
+
+/**
+ * Request additional data to be allocated with an ir node.
+ * @param size The size of the additional data required.
+ * @return A positive number, if the opration was successful, which
+ * must be passed to the access macro get_irn_data(), 0 if the
+ * registration failed.
+ */
+size_t register_additional_node_data(size_t size);
+
+
/*-----------------------------------------------------------------*/
/** Debug aides **/
/*-----------------------------------------------------------------*/