Commit 1577fb63 authored by Sebastian Hack's avatar Sebastian Hack
Browse files

Added custom data registration facility.

[r4509]
parent e086d97b
...@@ -84,9 +84,35 @@ const char *symconst_name_arr [] = { ...@@ -84,9 +84,35 @@ const char *symconst_name_arr [] = {
"type_tag", "size", "addr_name", "addr_ent" "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 void
init_irnode (void) init_irnode (void)
{ {
/* Forbid the addition of new data to an ir node. */
forbid_new_data = 1;
} }
/* /*
...@@ -100,11 +126,13 @@ new_ir_node (dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mo ...@@ -100,11 +126,13 @@ new_ir_node (dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mo
int arity, ir_node **in) int arity, ir_node **in)
{ {
ir_node *res; 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); assert(irg && op && mode);
res = (ir_node *) obstack_alloc (irg->obst, node_size); p = obstack_alloc (irg->obst, node_size);
memset((void *)res, 0, node_size); memset(p, 0, node_size);
res = (ir_node *) (p + additional_node_data_size);
res->kind = k_ir_node; res->kind = k_ir_node;
res->op = op; res->op = op;
...@@ -2011,6 +2039,7 @@ is_forking_op(const ir_node *node) { ...@@ -2011,6 +2039,7 @@ is_forking_op(const ir_node *node) {
return is_op_forking(get_irn_op(node)); return is_op_forking(get_irn_op(node));
} }
#ifdef DEBUG_libfirm #ifdef DEBUG_libfirm
void dump_irn (ir_node *n) { void dump_irn (ir_node *n) {
int i, arity = get_irn_arity(n); int i, arity = get_irn_arity(n);
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
# ifndef _IRNODE_H_ # ifndef _IRNODE_H_
# define _IRNODE_H_ # define _IRNODE_H_
#include <stddef.h>
/** /**
* Projection numbers of compare: use for Proj nodes! * Projection numbers of compare: use for Proj nodes!
* @remark there are numbers with normalized names below! * @remark there are numbers with normalized names below!
...@@ -889,6 +891,28 @@ ir_node *get_fragile_op_mem(ir_node *node); ...@@ -889,6 +891,28 @@ ir_node *get_fragile_op_mem(ir_node *node);
* operation: Cond. */ * operation: Cond. */
int is_forking_op(const ir_node *node); 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 **/ /** Debug aides **/
/*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment