set_irn_n(node, pos, pred);
}
+type *get_Proj_type(ir_node *n)
+{
+ type *tp = NULL;
+ ir_node *pred = get_Proj_pred(n);
+
+ switch (get_irn_opcode(pred)) {
+ case iro_Proj: {
+ ir_node *pred_pred;
+ /* Deal with Start / Call here: we need to know the Proj Nr. */
+ assert(get_irn_mode(pred) == mode_T);
+ pred_pred = get_Proj_pred(pred);
+ if (get_irn_op(pred_pred) == op_Start) {
+ type *mtp = get_entity_type(get_irg_entity(get_irn_irg(pred_pred)));
+ tp = get_method_param_type(mtp, get_Proj_proj(n));
+ } else if (get_irn_op(pred_pred) == op_Call) {
+ type *mtp = get_Call_type(pred_pred);
+ tp = get_method_res_type(mtp, get_Proj_proj(n));
+ }
+ } break;
+ case iro_Start: break;
+ case iro_Call: break;
+ case iro_Load: {
+ ir_node *a = get_Load_ptr(pred);
+ if (get_irn_op(a) == op_Sel)
+ tp = get_entity_type(get_Sel_entity(a));
+ } break;
+ default:
+ break;
+ }
+ return tp;
+}
+
ir_node *
get_Proj_pred (ir_node *node) {
assert (is_Proj(node));
return is_op_forking(get_irn_op(node));
}
+type *(get_irn_type)(ir_node *node) {
+ return _get_irn_type(node);
+}
+
+/** the get_type operation must be always implemented */
+static type *get_Null_type(ir_node *n) {
+ return NULL;
+}
+
+/* set the get_type operation */
+ir_op *firm_set_default_get_type(ir_op *op)
+{
+ switch (op->code) {
+ case iro_Const: op->get_type = get_Const_type; break;
+ case iro_SymConst: op->get_type = get_SymConst_value_type; break;
+ case iro_Cast: op->get_type = get_Cast_type; break;
+ case iro_Proj: op->get_type = get_Proj_type; break;
+ default: op->get_type = get_Null_type; break;
+ }
+ return op;
+}
#ifdef DEBUG_libfirm
void dump_irn (ir_node *n) {
ir_node *get_Sync_pred (ir_node *node, int pos);
void set_Sync_pred (ir_node *node, int pos, ir_node *pred);
+/** Returns the source language type of a Proj node.
+ * Must be an atomic type. Mode of type must be mode of node.
+ */
+type *get_Proj_type (ir_node *node);
+
+/** Return the predecessor of a Proj node. */
ir_node *get_Proj_pred (ir_node *node);
void set_Proj_pred (ir_node *node, ir_node *pred);
+/** Return the projection number of a Proj node. */
long get_Proj_proj (ir_node *node);
void set_Proj_proj (ir_node *node, long proj);
* operation: Cond. */
int is_forking_op(const ir_node *node);
+/** Return the type associated with the value produced by n
+ * if the node remarks this type as it is the case for
+ * Cast, Const, SymConst and some Proj nodes. */
+type *get_irn_type(ir_node *n);
+
/**
* Access custom node data.
* The data must have been registered with
except_attr get_irn_except_attr (ir_node *node);
/** @} */
-/*
+/**
* The amount of additional space for custom data to be allocated upon creating a new node.
*/
extern unsigned firm_add_node_size;
+/** Set the get_type operation of an ir_op. */
+ir_op *firm_set_default_get_type(ir_op *op);
+
/*-------------------------------------------------------------------*/
/* These function are most used in libfirm. Give them as static */
/* functions so they can be inlined. */
}
static INLINE tarval *_get_Const_tarval (ir_node *node) {
- assert (node->op == op_Const);
+ assert (_get_irn_op(node) == op_Const);
return node->attr.con.tv;
}
-
-static INLINE cnst_classify_t _classify_Const(ir_node *node)
-{
- ir_op *op;
+static INLINE cnst_classify_t _classify_Const(ir_node *node) {
+ ir_op *op;
assert(_is_ir_node(node));
- op = _get_irn_op(node);
+ op = _get_irn_op(node);
- if(op == op_Const)
- return classify_tarval(_get_Const_tarval(node));
- else if(op == op_SymConst)
- return CNST_SYMCONST;
+ if(op == op_Const)
+ return classify_tarval(_get_Const_tarval(node));
+ else if(op == op_SymConst)
+ return CNST_SYMCONST;
- return CNST_NO_CONST;
+ return CNST_NO_CONST;
}
+static INLINE type *_get_irn_type(ir_node *node) {
+ return _get_irn_op(node)->get_type(node);
+}
/* this section MUST contain all inline functions */
#define is_ir_node(thing) _is_ir_node(thing)
#define is_Block(node) _is_Block(node)
#define set_Block_dead(block) _set_Block_dead(block)
#define is_Block_dead(block) _is_Block_dead(block)
-#define get_Const_tarval(node) _get_Const_tarval(node)
-#define classify_Const(node) _classify_Const(node)
+#define get_Const_tarval(node) _get_Const_tarval(node)
+#define classify_Const(node) _classify_Const(node)
+#define get_irn_type(node) _get_irn_type(node)
# endif /* _IRNODE_T_H_ */