/* Make types visible to allow most efficient access */
#include "entity_t.h"
+/**
+ * Returns the tarval of a Const node or tarval_bad for all other nodes.
+ */
+static tarval *default_value_of(const ir_node *n) {
+ if (is_Const(n))
+ return get_Const_tarval(n); /* might return tarval_bad */
+ else
+ return tarval_bad;
+}
+
+value_of_func value_of_ptr = default_value_of;
+
+void set_value_of_func(value_of_func func) {
+ if (func != NULL)
+ value_of_ptr = func;
+ else
+ value_of_ptr = default_value_of;
+}
+
/**
* Return the value of a Constant.
*/
ir_node *left, *right;
ir_mode *mode;
tarval *tv1, *tv2, *res;
+ ir_node *in[2], *irn, *block;
left = get_binop_left(n);
}
/* ok, we can replace it */
- ir_node *in[2], *irn, *block = get_irn_n(n, -1);
+ block = get_nodes_block(n);
in[0] = get_binop_left(left);
in[1] = new_r_Const(current_ir_graph, block, get_tarval_mode(res), res);
ir_node *optimize_in_place_2(ir_node *n);
/**
- * Returns the tarval of a Const node or tarval_bad for all other nodes.
+ * The value_of operation.
+ * This operation returns for every IR node an associated tarval if existing,
+ * returning tarval_bad otherwise.
+ * No calculations are done here, just a lookup.
+ */
+typedef tarval *(*value_of_func)(const ir_node *self);
+
+extern value_of_func value_of_ptr;
+
+/**
+ * Set a new value_of function.
+ *
+ * @param func the function, NULL restores the default behavior
+ */
+void set_value_of_func(value_of_func func);
+
+/**
+ * Returns the associated tarval of a node.
*/
static INLINE tarval *
-value_of(ir_node *n) {
- if ((n != NULL) && is_Const(n))
- return get_Const_tarval(n); /* might return tarval_bad */
- else
- return tarval_bad;
+value_of(const ir_node *n) {
+ return value_of_ptr(n);
}
/**