&& 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
&& 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)
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);
{
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);
+}
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);
}
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
</output>
<prototypes>
void _advice(ALL_POINTER_T);
+ void _advice_float(ALL_FP_T, ALL_FP_T);
+ void _advice_int(ALL_SIGNED_T, ALL_UNSIGNED_T);
</prototypes>
</run>
</testcase>
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);
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;
}