Added the function code for tc_declare_call_symbol.
authorSiddhi Tadpatrikar <siddhi@agora.fsl.cs.sunysb.edu>
Tue, 29 Mar 2011 20:18:15 +0000 (16:18 -0400)
committerSiddhi Tadpatrikar <siddhi@agora.fsl.cs.sunysb.edu>
Tue, 29 Mar 2011 20:18:15 +0000 (16:18 -0400)
src/tracecut.c
src/tracecut.h

index 4015e30cb43a0aa84c6d55672347b65b13467053..bcb526c22c6065258361c5874e63e2c9e42e6803 100644 (file)
@@ -472,7 +472,168 @@ tc_declare_call_symbol (struct tc_tracecut *tc, const char *name,
                        const char *declaration,
                        enum aop_insert_location location)
 {
-  return return_error (tc, TC_SUCCESS);
+  int i = 0, pos = 0;
+  int param_num = 0, space_track = 0;
+  enum tc_error tc_err;
+  char func_name[MAX_FUNC_SIZE], return_param[MAX_PARAM_SIZE], param_name[MAX_PARAM_SIZE];
+
+  if (tc_in_compilation)
+    return return_error (tc, TC_BAD_CONTEXT);
+  
+  strcpy(return_param, "");
+  strcpy(func_name, "");
+  strcpy(param_name, "");
+
+  /* Eliminate white spaces */
+  while (declaration[i] == ' ') 
+    i++;
+
+  /* Check if return parameter is present */
+  if (declaration[i] == '(') 
+    {
+      /* Copy the return param */
+      i++;
+      /* Remove beginning spaces */
+      while (declaration[i] == ' ')
+       i++;
+      while (declaration[i] != ')') 
+       {
+         /* If space, copy the name */
+         if(declaration[i] == ' ') 
+           break;
+         return_param[pos++] = declaration[i++];
+       }
+      return_param[pos] = '\0';
+      pos = 0;
+      if (declaration[i] == ')') 
+         i++;
+      else
+       {
+         while (declaration[i] != ')') 
+           {
+             if(declaration[i] == ' ')
+               i++;
+             else
+               {
+                 return TC_INVAL;
+               }
+           }
+           i++;
+       }
+    }
+
+  /* Ignore the white spaces in between */
+  while (declaration[i] == ' ')
+    i++;
+
+  /* Copy the function name */
+  while(declaration[i] != '(') 
+    {
+      if (declaration[i] == ' ') 
+       break;
+      func_name[pos++] = declaration[i++];
+    }
+    
+  func_name[pos] = '\0';
+  pos = 0;
+
+  if (declaration[i] == '(') 
+    i++;
+  else
+    {
+      while (declaration[i] != '(') 
+       {
+          if (declaration[i] == ' ')
+           i++;
+         else 
+           {
+             return TC_INVAL;
+           }
+       }
+      i++;
+    }
+  /* Add functiona name */
+  if (strcmp(func_name, "")) 
+    {
+      tc_err = tc_add_call_symbol (tc, 
+                               name,
+                               func_name, 
+                               location);
+      if (tc_err != TC_SUCCESS) 
+        {
+          return tc_err;
+        }
+    }
+
+  /* Bind return parameter */
+  if (strcmp(return_param, ""))
+    { 
+      tc_err = tc_bind_to_return_value (tc, 
+                                    return_param,
+                                    name);
+
+       if (tc_err != TC_SUCCESS) 
+         {
+            return tc_err;
+         }
+    }
+
+  /* Skip spaces */
+  while (declaration[i] == ' ')
+    i++;
+
+  /* Parse function parameters and add them */
+  while (declaration[i] != '\0') 
+    {
+      if (declaration[i] == ' ' && pos == 0) 
+        { 
+          /* If it is beginning of the parameter */
+         i++;
+          continue;
+        }
+      else if (declaration[i] == ' '  && pos != 0) 
+       {
+         /* Space while parsing the param name */
+         space_track = 1;
+         i++;
+         continue;
+       }
+      else if ((declaration[i] != ')' && declaration[i] != ',') &&
+             (space_track == 1)) 
+       {
+         return TC_INVAL;
+       }
+      else if (declaration[i] == ',' || declaration[i] == ')') 
+        {
+          /* Store param */
+         space_track = 0;
+          param_name[pos] = '\0';
+        
+         printf("%s\n", param_name);
+         if(strcmp(param_name, "?") && pos != 0)
+           {
+             /* Param found, insert it */
+             tc_err = tc_bind_to_call_param (tc, 
+                                   param_name,
+                                   name, 
+                                   param_num);
+
+             if (tc_err != TC_SUCCESS) 
+                {
+                 return tc_err;
+                }
+           }
+         param_num++;
+          i++;
+          pos = 0;
+          continue;
+        }
+     
+      param_name[pos++] = declaration[i++];
+    }
+
+ return return_error (tc, TC_SUCCESS);
 }
 
 /**
index c04e33fa4447799a53f7f04d2b3e06dc58e1f324..6149dc49ceb525f8e7f5c9c3dd6e733a09d29c87 100644 (file)
  * All tracecut functions have a <code>tc_</code> prefix.
  */
 
+#define MAX_PARAM_IN_DECL 10
+#define MAX_PARAM_SIZE 100
+#define MAX_FUNC_SIZE 100
+
 struct aop_joinpoint;
 struct aop_type;
 struct tc_tracecut;
@@ -80,6 +84,11 @@ enum tc_error {
   TC_NOMEM,
 };
 
+struct param_name_t
+{
+    char param_name[MAX_PARAM_SIZE];
+};
+
 extern enum tc_error tc_error_code (struct tc_tracecut *tc);
 extern void tc_reset_error (struct tc_tracecut *tc);