From: Ketan Dixit Date: Tue, 27 Jul 2010 22:34:41 +0000 (-0400) Subject: Added support for capturing lhs var scope X-Git-Tag: release-v1.0~79 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=c25187bf21a6bb64992c35e888a81ffd039b668e;p=interaspect.git Added support for capturing lhs var scope --- diff --git a/src/aop-pc-assign.c b/src/aop-pc-assign.c index 44f167f..1212d1a 100644 --- a/src/aop-pc-assign.c +++ b/src/aop-pc-assign.c @@ -43,6 +43,27 @@ * \{ */ +static tree +get_lhs_var (struct aop_joinpoint *jp) +{ + gimple stmt; + tree lhs; + + aop_assert (jp->pc->kind == ATP_ASSIGN); + + stmt = gsi_stmt (*jp->gsi); + aop_assert (gimple_has_lhs (stmt)); + lhs = gimple_get_lhs (stmt); + + if (TREE_CODE (lhs) == SSA_NAME) + lhs = SSA_NAME_VAR (lhs); + + if (lhs != NULL) + return lhs; + else + return NULL; +} + /** * Get the name of the variable being assigned to in an assignment * joinpoint. @@ -54,18 +75,11 @@ const char * aop_capture_lhs_name (struct aop_joinpoint *jp) { - gimple stmt; tree lhs; aop_assert (jp->pc->kind == ATP_ASSIGN); - stmt = gsi_stmt (*jp->gsi); - aop_assert (gimple_has_lhs (stmt)); - lhs = gimple_get_lhs (stmt); - - if (TREE_CODE (lhs) == SSA_NAME) - lhs = SSA_NAME_VAR (lhs); - + lhs = get_lhs_var (jp); if (lhs != NULL && DECL_P (lhs)) { tree name = DECL_NAME (lhs); @@ -80,6 +94,7 @@ aop_capture_lhs_name (struct aop_joinpoint *jp) } } + /* Given an expression from the lhs of an assignment, return true unless it is a temporary variable created by the compiler. @@ -363,6 +378,44 @@ aop_match_assignment_by_type (const struct aop_type *type) return pc; } +/** + * Returns scope of the LHS variable of the assignment statement. + * \param jp The joinpoint corresponding to the assignment statement. + * \return The scope of the LHS variable. + */ +enum aop_scope +aop_capture_lhs_var_scope (struct aop_joinpoint *jp) +{ + tree lhs; + lhs = get_lhs_var (jp); + if (lhs != NULL_TREE) + { + if (DECL_FILE_SCOPE_P (lhs)) + { + if (!TREE_PUBLIC (lhs)) + { + return AOP_FILE_SCOPE; + } + else + { + return AOP_GLOBAL_SCOPE; + } + } + else if (TREE_CODE (DECL_CONTEXT (lhs)) == FUNCTION_DECL) + { + return AOP_FUNCTION_SCOPE; + } + else + { + return AOP_MEMORY_SCOPE; + } + } + else + { + return AOP_MEMORY_SCOPE; + } +} + /* Close Doxygen defgroup block. */ /** * /} diff --git a/src/aop.h b/src/aop.h index b74f080..1e3a7de 100644 --- a/src/aop.h +++ b/src/aop.h @@ -263,4 +263,11 @@ extern struct aop_dynval *aop_capture_lhs_addr (struct aop_joinpoint *jp); extern const char *aop_capture_lhs_name (struct aop_joinpoint *jp); extern struct aop_dynval *aop_capture_assigned_value (struct aop_joinpoint *jp); +enum aop_scope { + AOP_GLOBAL_SCOPE, + AOP_FILE_SCOPE, + AOP_FUNCTION_SCOPE, + AOP_MEMORY_SCOPE, +}; +enum aop_scope aop_capture_lhs_var_scope (struct aop_joinpoint *jp); #endif