changeset 13:708921504d6d

Find CALL_EXPR and show information of the call
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 09 Sep 2010 18:16:50 +0800
parents 6fdb0cfdc2a7
children 566b62a49462
files src/cospy.c
diffstat 1 files changed, 257 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/cospy.c	Thu Sep 09 16:06:55 2010 +0800
+++ b/src/cospy.c	Thu Sep 09 18:16:50 2010 +0800
@@ -4,6 +4,7 @@
 #include "coretypes.h"
 #include "tree-pass.h"
 #include "tree.h"
+#include "tree-iterator.h"
 #include "gimple.h"
 #include "cgraph.h"
 #include <stdio.h>
@@ -109,6 +110,260 @@
     }
 }
 
+static void
+walk_code_tree(tree expr, int accept_code,
+	  void (*cb)(tree, void *), void *data) {
+    int code;
+    tree child;
+    int i, sz;
+    tree_stmt_iterator stmt_itr;
+
+    if(expr == NULL)
+	return;
+    
+    code = TREE_CODE(expr);
+
+    if(accept_code && code == accept_code)
+	cb(expr, data);
+
+    switch(code) {
+    case ERROR_MARK:		/* 0 */
+    case IDENTIFIER_NODE:
+    case TREE_LIST:
+    case TREE_VEC:
+    case BLOCK:
+    case OFFSET_TYPE:
+    case ENUMERAL_TYPE:
+    case BOOLEAN_TYPE:
+    case INTEGER_TYPE:
+    case REAL_TYPE:
+    case POINTER_TYPE:
+    case FIXED_POINT_TYPE:
+    case REFERENCE_TYPE:
+    case COMPLEX_TYPE:
+    case VECTOR_TYPE:
+    case ARRAY_TYPE:
+    case RECORD_TYPE:
+    case UNION_TYPE:
+    case QUAL_UNION_TYPE:
+    case VOID_TYPE:
+    case FUNCTION_TYPE:
+    case METHOD_TYPE:
+    case LANG_TYPE:
+    case INTEGER_CST:
+    case REAL_CST:
+    case FIXED_CST:		/* 25 */
+    case COMPLEX_CST:
+    case VECTOR_CST:
+    case STRING_CST:
+    case FUNCTION_DECL:
+    case LABEL_DECL:
+    case FIELD_DECL:
+    case VAR_DECL:
+    case CONST_DECL:
+    case PARM_DECL:
+    case TYPE_DECL:
+    case RESULT_DECL:
+    case DEBUG_EXPR_DECL:
+    case NAMESPACE_DECL:
+    case IMPORTED_DECL:
+    case TRANSLATION_UNIT_DECL:
+    case COMPONENT_REF:
+    case BIT_FIELD_REF:
+    case REALPART_EXPR:
+    case IMAGPART_EXPR:
+    case ARRAY_REF:
+    case ARRAY_RANGE_REF:
+    case INDIRECT_REF:
+    case ALIGN_INDIRECT_REF:
+    case MISALIGNED_INDIRECT_REF:
+    case OBJ_TYPE_REF:		/* 50 */
+    case CONSTRUCTOR:
+    case COMPOUND_EXPR:
+    case MODIFY_EXPR:
+    case INIT_EXPR:
+    case TARGET_EXPR:
+    case COND_EXPR:
+    case VEC_COND_EXPR:
+	sz = TREE_OPERAND_LENGTH(expr);
+	for(i = 0; i < sz; i++) {
+	    child = TREE_OPERAND(expr, i);
+	    walk_code_tree(child, accept_code, cb, data);
+	}
+	break;
+	
+    case BIND_EXPR:
+	child = BIND_EXPR_BODY(expr);
+	walk_code_tree(child, accept_code, cb, data);
+	break;
+	
+    case CALL_EXPR:
+    case WITH_CLEANUP_EXPR:
+    case CLEANUP_POINT_EXPR:
+    case PLACEHOLDER_EXPR:
+    case PLUS_EXPR:
+    case MINUS_EXPR:
+    case MULT_EXPR:
+    case POINTER_PLUS_EXPR:
+    case TRUNC_DIV_EXPR:
+    case CEIL_DIV_EXPR:
+    case FLOOR_DIV_EXPR:
+    case ROUND_DIV_EXPR:
+    case TRUNC_MOD_EXPR:
+    case CEIL_MOD_EXPR:
+    case FLOOR_MOD_EXPR:
+    case ROUND_MOD_EXPR:
+    case RDIV_EXPR:		/* 75 */
+    case EXACT_DIV_EXPR:
+    case FIX_TRUNC_EXPR:
+    case FLOAT_EXPR:
+    case NEGATE_EXPR:
+    case MIN_EXPR:
+    case MAX_EXPR:
+    case ABS_EXPR:
+    case LSHIFT_EXPR:
+    case RSHIFT_EXPR:
+    case LROTATE_EXPR:
+    case RROTATE_EXPR:
+    case BIT_IOR_EXPR:
+    case BIT_XOR_EXPR:
+    case BIT_AND_EXPR:
+    case BIT_NOT_EXPR:
+    case TRUTH_ANDIF_EXPR:
+    case TRUTH_ORIF_EXPR:
+    case TRUTH_AND_EXPR:
+    case TRUTH_OR_EXPR:
+    case TRUTH_XOR_EXPR:
+    case TRUTH_NOT_EXPR:
+    case LT_EXPR:
+    case LE_EXPR:
+    case GT_EXPR:
+    case GE_EXPR:		/* 100 */
+    case EQ_EXPR:
+    case NE_EXPR:
+    case UNORDERED_EXPR:
+    case ORDERED_EXPR:
+    case UNLT_EXPR:
+    case UNLE_EXPR:
+    case UNGT_EXPR:
+    case UNGE_EXPR:
+    case UNEQ_EXPR:
+    case LTGT_EXPR:
+    case RANGE_EXPR:
+    case PAREN_EXPR:
+    case CONVERT_EXPR:
+    case ADDR_SPACE_CONVERT_EXPR:
+    case FIXED_CONVERT_EXPR:
+    case NOP_EXPR:
+    case NON_LVALUE_EXPR:
+    case VIEW_CONVERT_EXPR:
+    case COMPOUND_LITERAL_EXPR:
+    case SAVE_EXPR:
+    case ADDR_EXPR:
+    case FDESC_EXPR:
+    case COMPLEX_EXPR:
+    case CONJ_EXPR:
+    case PREDECREMENT_EXPR:	/* 125 */
+    case PREINCREMENT_EXPR:
+    case POSTDECREMENT_EXPR:
+    case POSTINCREMENT_EXPR:
+    case VA_ARG_EXPR:
+    case TRY_CATCH_EXPR:
+    case TRY_FINALLY_EXPR:
+    case DECL_EXPR:
+    case LABEL_EXPR:
+    case GOTO_EXPR:
+    case RETURN_EXPR:
+    case EXIT_EXPR:
+    case LOOP_EXPR:
+    case SWITCH_EXPR:
+    case CASE_LABEL_EXPR:
+    case ASM_EXPR:
+    case SSA_NAME:
+    case CATCH_EXPR:
+    case EH_FILTER_EXPR:
+    case SCEV_KNOWN:
+    case SCEV_NOT_KNOWN:
+    case POLYNOMIAL_CHREC:
+	sz = TREE_OPERAND_LENGTH(expr);
+	for(i = 0; i < sz; i++) {
+	    child = TREE_OPERAND(expr, i);
+	    walk_code_tree(child, accept_code, cb, data);
+	}
+	break;
+	
+    case STATEMENT_LIST:
+	for(stmt_itr = tsi_start(expr);
+	    !tsi_end_p(stmt_itr);
+	    tsi_next(&stmt_itr)) {
+	    child = tsi_stmt(stmt_itr);
+	    walk_code_tree(child, accept_code, cb, data);
+	}
+	break;
+	
+    case ASSERT_EXPR:
+    case TREE_BINFO:
+    case WITH_SIZE_EXPR:	/* 150 */
+    case REALIGN_LOAD_EXPR:
+    case TARGET_MEM_REF:
+    case OMP_PARALLEL:
+    case OMP_TASK:
+    case OMP_FOR:
+    case OMP_SECTIONS:
+    case OMP_SINGLE:
+    case OMP_SECTION:
+    case OMP_MASTER:
+    case OMP_ORDERED:
+    case OMP_CRITICAL:
+    case OMP_ATOMIC:
+    case OMP_CLAUSE:
+    case REDUC_MAX_EXPR:
+    case REDUC_MIN_EXPR:
+    case REDUC_PLUS_EXPR:
+    case DOT_PROD_EXPR:
+    case WIDEN_SUM_EXPR:
+    case WIDEN_MULT_EXPR:
+    case VEC_LSHIFT_EXPR:
+    case VEC_RSHIFT_EXPR:
+    case VEC_WIDEN_MULT_HI_EXPR:
+    case VEC_WIDEN_MULT_LO_EXPR:
+    case VEC_UNPACK_HI_EXPR:
+    case VEC_UNPACK_LO_EXPR:	/* 175 */
+    case VEC_UNPACK_FLOAT_HI_EXPR:
+    case VEC_UNPACK_FLOAT_LO_EXPR:
+    case VEC_PACK_TRUNC_EXPR:
+    case VEC_PACK_SAT_EXPR:
+    case VEC_PACK_FIX_TRUNC_EXPR:
+    case VEC_EXTRACT_EVEN_EXPR:
+    case VEC_EXTRACT_ODD_EXPR:
+    case VEC_INTERLEAVE_HIGH_EXPR:
+    case VEC_INTERLEAVE_LOW_EXPR:
+    case PREDICT_EXPR:
+    case OPTIMIZATION_NODE:
+    case TARGET_OPTION_NODE:
+	sz = TREE_OPERAND_LENGTH(expr);
+	for(i = 0; i < sz; i++) {
+	    child = TREE_OPERAND(expr, i);
+	    walk_code_tree(child, accept_code, cb, data);
+	}
+	break;
+    }
+}
+
+static void
+found_call(tree expr, void *data) {
+    tree addr;
+    tree fn, fn_name;
+
+    addr = TREE_OPERAND(expr, 1);
+    fn = TREE_OPERAND(addr, 0);
+    fn_name = DECL_NAME(fn);
+    
+    printf("    CALL %s:%s:%d\n", IDENTIFIER_POINTER(fn_name),
+	   EXPR_FILENAME(expr),
+	   EXPR_LINENO(expr));
+}
+
 /*! \brief Find all call expression in a code block.
  *
  * This function find CALL_EXPR in body of a function that represented
@@ -121,6 +376,7 @@
     
     bind = DECL_SAVED_TREE(fn);	/* BIND_EXPR */
     body = BIND_EXPR_BODY(bind);
+    walk_code_tree(body, CALL_EXPR, found_call, NULL);
     printf("%d:%d\n", TREE_CODE(body), BIND_EXPR);
 }
 
@@ -234,3 +490,4 @@
 		      handle_pre_genericize, NULL);
     return 0;
 }
+