From 979546f33f8aad64a3691dee631b5539e008cba2 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Fri, 16 Apr 2004 11:44:03 +0000 Subject: [PATCH] Added additional functions and verifiers for FuncCalls [r2659] --- ir/ir/ircons.c | 2 +- ir/ir/irnode.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ ir/ir/irnode.h | 27 +++++++++++++++ ir/ir/irvrfy.c | 30 +++++++++++++++++ 4 files changed, 147 insertions(+), 1 deletion(-) diff --git a/ir/ir/ircons.c b/ir/ir/ircons.c index eef865976..b05813aa6 100644 --- a/ir/ir/ircons.c +++ b/ir/ir/ircons.c @@ -826,7 +826,7 @@ new_rd_FuncCall (dbg_info* db, ir_graph *irg, ir_node *block, res = new_ir_node (db, irg, block, op_FuncCall, mode_T, r_arity, r_in); assert(is_method_type(tp)); - set_Call_type(res, tp); + set_FuncCall_type(res, tp); res->attr.call.callee_arr = NULL; res = optimize_node (res); irn_vrfy_irg (res, irg); diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index a8d6568f8..1cf28158b 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -1210,6 +1210,95 @@ void set_CallBegin_call (ir_node *node, ir_node *call) { node->attr.callbegin.call = call; } +INLINE ir_node * +get_FuncCall_ptr (ir_node *node) { + assert (node->op == op_FuncCall); + return get_irn_n(node, 0); +} + +INLINE void +set_FuncCall_ptr (ir_node *node, ir_node *ptr) { + assert (node->op == op_FuncCall); + set_irn_n(node, 0, ptr); +} + +INLINE ir_node ** +get_FuncCall_param_arr (ir_node *node) { + assert (node->op == op_FuncCall); + return (ir_node **)&get_irn_in(node)[CALL_PARAM_OFFSET]; +} + +INLINE int +get_FuncCall_n_params (ir_node *node) { + assert (node->op == op_FuncCall); + return (get_irn_arity(node) - CALL_PARAM_OFFSET); +} + +INLINE int +get_FuncCall_arity (ir_node *node) { + assert (node->op == op_FuncCall); + return get_FuncCall_n_params(node); +} + +/* INLINE void +set_FuncCall_arity (ir_node *node, ir_node *arity) { + assert (node->op == op_FuncCall); +} +*/ + +INLINE ir_node * +get_FuncCall_param (ir_node *node, int pos) { + assert (node->op == op_FuncCall); + return get_irn_n(node, pos + CALL_PARAM_OFFSET); +} + +INLINE void +set_FuncCall_param (ir_node *node, int pos, ir_node *param) { + assert (node->op == op_FuncCall); + set_irn_n(node, pos + CALL_PARAM_OFFSET, param); +} + +INLINE type * +get_FuncCall_type (ir_node *node) { + assert (node->op == op_FuncCall); + return node->attr.call.cld_tp = skip_tid(node->attr.call.cld_tp); +} + +INLINE void +set_FuncCall_type (ir_node *node, type *tp) { + assert (node->op == op_FuncCall); + assert (is_method_type(tp)); + node->attr.call.cld_tp = tp; +} + +int FuncCall_has_callees(ir_node *node) { + return (node->attr.call.callee_arr != NULL); +} + +int get_FuncCall_n_callees(ir_node * node) { + assert(node->op == op_FuncCall && node->attr.call.callee_arr); + return ARR_LEN(node->attr.call.callee_arr); +} + +entity * get_FuncCall_callee(ir_node * node, int pos) { + assert(node->op == op_FuncCall && node->attr.call.callee_arr); + return node->attr.call.callee_arr[pos]; +} + +void set_FuncCall_callee_arr(ir_node * node, int n, entity ** arr) { + assert(node->op == op_FuncCall); + if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) { + node->attr.call.callee_arr = NEW_ARR_D(entity *, current_ir_graph->obst, n); + } + memcpy(node->attr.call.callee_arr, arr, n * sizeof(entity *)); +} + +void remove_FuncCall_callee_arr(ir_node * node) { + assert(node->op == op_FuncCall); + node->attr.call.callee_arr = NULL; +} + + #define BINOP(OP) \ ir_node * get_##OP##_left(ir_node *node) { \ assert(node->op == op_##OP); \ diff --git a/ir/ir/irnode.h b/ir/ir/irnode.h index d9d334ce7..697ee92da 100644 --- a/ir/ir/irnode.h +++ b/ir/ir/irnode.h @@ -466,6 +466,33 @@ ir_graph *get_CallBegin_irg (ir_node *node); ir_node *get_CallBegin_call (ir_node *node); void set_CallBegin_call (ir_node *node, ir_node *call); +INLINE ir_node *get_FuncCall_ptr (ir_node *node); +INLINE void set_FuncCall_ptr (ir_node *node, ir_node *ptr); +INLINE ir_node **get_FuncCall_param_arr (ir_node *node); +/** Gets the number of parameters of a func call. */ +INLINE int get_FuncCall_n_params (ir_node *node); +/** Gets the func call parameter at position pos. */ +INLINE ir_node *get_FuncCall_param (ir_node *node, int pos); +/** Sets the func call parameter at position pos. */ +INLINE void set_FuncCall_param (ir_node *node, int pos, ir_node *param); +/** Gets the type of a func call. */ +INLINE type *get_FuncCall_type (ir_node *node); +/** Sets the type of a func call. */ +INLINE void set_FuncCall_type (ir_node *node, type *tp); +/** Gets the arity of a func call. Identical to get_FuncCall_n_params(). */ +INLINE int get_FuncCall_arity (ir_node *node); + +/* Set, get and remove the callee-analysis. + The array is only accessible if information is valid. + It contains NULL for called methods that are not within + the compilation unit. */ +int FuncCall_has_callees (ir_node *node); +int get_FuncCall_n_callees (ir_node * node); +entity *get_FuncCall_callee (ir_node * node, int pos); +/* assumes current_ir_graph set properly! */ +void set_FuncCall_callee_arr (ir_node * node, int n, entity ** arr); +void remove_FuncCall_callee_arr(ir_node * node); + /* For unary and binary arithmetic operations the access to the operands can be factored out. Left is the first, right the second arithmetic value as listed in tech report 1999-44. diff --git a/ir/ir/irvrfy.c b/ir/ir/irvrfy.c index 3a3458465..1ed1c8e57 100644 --- a/ir/ir/irvrfy.c +++ b/ir/ir/irvrfy.c @@ -277,6 +277,18 @@ vrfy_Proj_proj(ir_node *p, ir_graph *irg) { ); break; + case iro_FuncCall: + ASSERT_AND_RET_DBG( + ((proj == pn_Call_M_regular && mode == mode_M) || + (proj == pn_Call_X_except && mode == mode_X) || + (proj == pn_Call_T_result && mode == mode_T) || + (proj == pn_Call_M_except && mode == mode_M) || + (proj == pn_Call_P_value_res_base && mode == mode_P)), + "wrong Proj from FuncCall", 0, + show_proj_failure(p); + ); + break; + case iro_Quot: ASSERT_AND_RET_DBG( ((proj == pn_Quot_M && mode == mode_M) || @@ -428,6 +440,24 @@ vrfy_Proj_proj(ir_node *p, ir_graph *irg) { } break; + case iro_FuncCall: + { + ASSERT_AND_RET( + (proj >= 0 && mode_is_data(mode)), + "wrong Proj from Proj from FuncCall", 0); + mt = get_FuncCall_type(pred); + ASSERT_AND_RET( + (proj < get_method_n_ress(mt)), + "More Projs for results than results in type.", 0); + if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj))) + /* value result */ break; + + ASSERT_AND_RET( + (mode == get_type_mode(get_method_res_type(mt, proj))), + "Mode of Proj from FuncCall doesn't match mode of result type.", 0); + } + break; + case iro_Tuple: /* We don't test */ break; -- 2.20.1