From: Siddhi Tadpatrikar Date: Wed, 2 Mar 2011 22:13:26 +0000 (-0500) Subject: Adds casting for integer and fp types. X-Git-Tag: release-v1.1~9^2~13^2 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=d23aa48c46efd944ae376e326f56779a3d301252;p=interaspect.git Adds casting for integer and fp types. --- diff --git a/src/aop-type.c b/src/aop-type.c index f88a670..6f9c35d 100644 --- a/src/aop-type.c +++ b/src/aop-type.c @@ -748,6 +748,42 @@ aop_is_all_unsigned_subtype (const struct aop_type *type) && type->pointer_levels == 0 && type->size <= 8); } +/** + * Modify an #aop_dynval object so that it will be passed to advice as + * if it were matched and captured using the aop_t_all_signed() type. + * + * Only use this function on dynvals whose type passes + * aop_is_all_signed_subtype(). Casting a non-signed sub type with + * this function will raise a fatal compiler error. + * \param dv The #aop_dynval to cast. + */ +void +aop_cast_to_all_signed(struct aop_dynval *dv) +{ + if (!aop_is_all_signed_subtype(dv->type)) + fatal_error ("(InterAsepct) Illegal cast to all signed subtype type."); + + dv->type = aop_t_all_signed(); +} + +/** + * Modify an #aop_dynval object so that it will be passed to advice as + * if it were matched and captured using the aop_t_all_unsigned() + * type. + * + * Only use this function on dynvals whose type passes + * aop_is_all_unsigned_subtype(). Casting a non-unsigned sub type + * with this function will raise a fatal compiler error. + * \param dv The #aop_dynval to cast. + */ +void +aop_cast_to_all_unsigned(struct aop_dynval *dv) +{ + if (!aop_is_all_unsigned_subtype(dv->type)) + fatal_error ("(InterAsepct) Illegal cast to all unsigned sub type."); + + dv->type = aop_t_all_unsigned(); +} /* Returns true if specified type is an "all fp" type. */ bool @@ -757,6 +793,33 @@ is_all_fp_type (const struct aop_type *type) && type->size <= 0); } +/* Returns true if the specified type is a "float" which is NOT 128 + bits float */ +int +aop_is_all_fp_subtype (const struct aop_type *type) +{ + return (type->kind == ATK_FP + && type->pointer_levels == 0 && type->size <= 8); +} + +/** + * Modify an #aop_dynval object so that it will be passed to advice as + * if it were matched and captured using the aop_t_all_fp() type. + * + * Only use this function on dynvals whose type passes + * aop_is_all_fp_subtype(). Casting a non-float type with this + * function will raise a fatal compiler error. + * param dv The #aop_dynval to cast. + */ +void +aop_cast_to_all_fp(struct aop_dynval *dv) +{ + if (!aop_is_all_fp_subtype(dv->type)) + fatal_error("(InterAsepct) Illegal cast to all float type."); + + dv->type = aop_t_all_fp(); +} + /* Given a type node, get that type node's identifier. */ static tree get_type_identifier (tree gcc_type) diff --git a/src/aop.h b/src/aop.h index a0d1549..818b2b6 100644 --- a/src/aop.h +++ b/src/aop.h @@ -209,10 +209,13 @@ extern const struct aop_type *aop_t_enum (const char *tag); extern const struct aop_type *aop_t_pointer_to (const struct aop_type *type); extern int aop_is_pointer_type (const struct aop_type *type); -extern int aop_is_all_signed_integer_type (const struct aop_type *type); -extern int aop_is_all_unsigned_integer_type (const struct aop_type *type); +extern int aop_is_all_signed_subtype(const struct aop_type *type); +extern int aop_is_all_unsigned_subtype(const struct aop_type *type); extern void aop_cast_to_all_pointer (struct aop_dynval *dv); - +extern void aop_cast_to_all_signed(struct aop_dynval *dv); +extern void aop_cast_to_all_unsigned(struct aop_dynval *dv); +extern int aop_is_all_fp_subtype (const struct aop_type *type); +extern void aop_cast_to_all_fp(struct aop_dynval *dv); extern const struct aop_type *aop_get_dynval_type (struct aop_dynval *dv); extern void aop_register_pass (const char *pass_name, pass_callback callback); diff --git a/test/cast-hooks.c b/test/cast-hooks.c index 81ce142..aadb90b 100644 --- a/test/cast-hooks.c +++ b/test/cast-hooks.c @@ -5,3 +5,15 @@ void _advice(void *param) { printf("In advice function: %s\n", *(const char **)param); } + +/* Advice function to print signed and unsigned integer values */ +void _advice_int(int64_t param, uint64_t u_param) +{ + printf("In signed advice function: %ld %ld\n", param, u_param); +} + +/* Advice function to print float and double values */ +void _advice_float(float param, double d_param) +{ + printf("In float advice function: %f %e\n", param, d_param); +} diff --git a/test/cast-target.c b/test/cast-target.c index 1547bb7..ccd12b9 100644 --- a/test/cast-target.c +++ b/test/cast-target.c @@ -20,11 +20,27 @@ void print_bar(struct bar *bar) printf("bar: %f\n", bar->a); } +void print_int(int int_val, unsigned unsigned_int_val) +{ + printf("int_val: %d %d\n", int_val, unsigned_int_val); +} + +void print_fp(float fp_val, double dbl_val) +{ + printf("float_val: %f %e\n", fp_val, dbl_val); +} + void run_test() { struct foo foo = { "l33t", 1337 }; struct bar bar = { "h4x0r", 1.337 }; + int int_val = 10; + unsigned unsigned_int_val = 10; + float fp_val = 10.5; + double dbl_val = 10e+5; print_foo(&foo); print_bar(&bar); + print_int(int_val, unsigned_int_val); + print_fp(fp_val, dbl_val); } diff --git a/test/cast.xml b/test/cast.xml index 7e2528c..00335aa 100644 --- a/test/cast.xml +++ b/test/cast.xml @@ -9,9 +9,15 @@ foo: 1337 In advice function: h4x0r bar: 1.337000 + In signed advice function: 10 10 + int_val: 10 10 + In float advice function: 0.000000 1.000000e+06 + float_val: 10.500000 1.000000e+06 void _advice(ALL_POINTER_T); + void _advice_float(ALL_FP_T, ALL_FP_T); + void _advice_int(ALL_SIGNED_T, ALL_UNSIGNED_T); diff --git a/test/plugin-cast.c b/test/plugin-cast.c index 4c5f587..01378c5 100644 --- a/test/plugin-cast.c +++ b/test/plugin-cast.c @@ -15,16 +15,56 @@ static void plugin_join_on_call(struct aop_joinpoint *jp, void *data) aop_insert_advice(jp, "_advice", AOP_INSERT_BEFORE, AOP_DYNVAL(param), AOP_TERM_ARG); } +static void plugin_join_on_int_call(struct aop_joinpoint *jp, void *data) +{ + struct aop_dynval *param; + struct aop_dynval *param_1; + + param = aop_capture_call_param(jp, 0); + param_1 = aop_capture_call_param(jp, 1); + + aop_assert(aop_is_all_signed_subtype(aop_get_dynval_type(param))); + aop_assert(aop_is_all_unsigned_subtype(aop_get_dynval_type(param_1))); + aop_cast_to_all_signed(param); + aop_cast_to_all_unsigned(param_1); + aop_insert_advice(jp, "_advice_int", AOP_INSERT_BEFORE, AOP_DYNVAL(param), AOP_DYNVAL(param_1), AOP_TERM_ARG); +} + +static void plugin_join_on_fp_call(struct aop_joinpoint *jp, void *data) +{ + struct aop_dynval *param; + struct aop_dynval *param_1; + + param = aop_capture_call_param(jp, 0); + param_1 = aop_capture_call_param(jp, 1); + + aop_assert(aop_is_all_fp_subtype(aop_get_dynval_type(param))); + aop_assert(aop_is_all_fp_subtype(aop_get_dynval_type(param_1))); + aop_cast_to_all_fp(param); + aop_cast_to_all_fp(param_1); + aop_insert_advice(jp, "_advice_float", AOP_INSERT_BEFORE, AOP_DYNVAL(param), AOP_DYNVAL(param_1), AOP_TERM_ARG); +} + static unsigned int plugin_cast() { struct aop_pointcut *pc; const struct aop_type *foo_type; const struct aop_type *bar_type; + const struct aop_type *int_val; + const struct aop_type *unsigned_int_val; + const struct aop_type *fp_val; + const struct aop_type *dbl_val; foo_type = aop_t_struct_ptr("foo"); bar_type = aop_t_struct_ptr("bar"); + int_val = aop_t_signed32("int_val"); + unsigned_int_val = aop_t_unsigned32("unsigned_int_val"); + + fp_val = aop_t_float32("fp_val"); + dbl_val = aop_t_float64("dbl_val"); + pc = aop_match_function_call(); aop_filter_call_pc_by_param(pc, 0, foo_type); aop_join_on(pc, plugin_join_on_call, NULL); @@ -33,6 +73,16 @@ static unsigned int plugin_cast() aop_filter_call_pc_by_param(pc, 0, bar_type); aop_join_on(pc, plugin_join_on_call, NULL); + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, int_val); + aop_filter_call_pc_by_param(pc, 1, unsigned_int_val); + aop_join_on(pc, plugin_join_on_int_call, NULL); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, fp_val); + aop_filter_call_pc_by_param(pc, 1, dbl_val); + aop_join_on(pc, plugin_join_on_fp_call, NULL); + return 0; }