Added support for capturing lhs var scope
authorKetan Dixit <ketan.dixit@gmail.com>
Tue, 27 Jul 2010 22:34:41 +0000 (18:34 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Wed, 28 Jul 2010 00:33:26 +0000 (20:33 -0400)
src/aop-pc-assign.c
src/aop.h

index 44f167fe7e77b2074cd22120d8cfe032d9aff4a2..1212d1ad511a419961dd65e2a3febb00171aecb7 100644 (file)
  * \{
  */
 
+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.
 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. */
 /**
  * /}
index b74f0800f974786af0fb41e895c36a833f3ffbdd..1e3a7de0e16cdefb4e2f451bfd50baff368938f7 100644 (file)
--- 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