From 96701d3fc9347378df74411281c2643ff6838096 Mon Sep 17 00:00:00 2001 From: Siddhi Tadpatrikar Date: Tue, 29 Mar 2011 16:18:15 -0400 Subject: [PATCH] Added the function code for tc_declare_call_symbol. --- src/tracecut.c | 163 ++++++++++++++++++++++++++++++++++++++++++++++++- src/tracecut.h | 9 +++ 2 files changed, 171 insertions(+), 1 deletion(-) diff --git a/src/tracecut.c b/src/tracecut.c index 4015e30..bcb526c 100644 --- a/src/tracecut.c +++ b/src/tracecut.c @@ -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); } /** diff --git a/src/tracecut.h b/src/tracecut.h index c04e33f..6149dc4 100644 --- a/src/tracecut.h +++ b/src/tracecut.h @@ -40,6 +40,10 @@ * All tracecut functions have a tc_ 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); -- 2.34.1