From: Sebastian Hack Date: Tue, 30 Nov 2004 13:27:34 +0000 (+0000) Subject: Added custom data registration facility. X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=1577fb63998cc7d3a638950262ef82cb2eea9ce7;p=libfirm Added custom data registration facility. [r4509] --- diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index 02000747b..87bc6061a 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -84,9 +84,35 @@ const char *symconst_name_arr [] = { "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; } /* @@ -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) { 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; @@ -2011,6 +2039,7 @@ is_forking_op(const ir_node *node) { return is_op_forking(get_irn_op(node)); } + #ifdef DEBUG_libfirm void dump_irn (ir_node *n) { int i, arity = get_irn_arity(n); diff --git a/ir/ir/irnode.h b/ir/ir/irnode.h index 04391d968..739a56b3d 100644 --- a/ir/ir/irnode.h +++ b/ir/ir/irnode.h @@ -13,6 +13,8 @@ # ifndef _IRNODE_H_ # define _IRNODE_H_ +#include + /** * Projection numbers of compare: use for Proj nodes! * @remark there are numbers with normalized names below! @@ -889,6 +891,28 @@ ir_node *get_fragile_op_mem(ir_node *node); * 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 **/ /*-----------------------------------------------------------------*/