Adds casting for integer and fp types.
authorSiddhi Tadpatrikar <siddhi@agora.fsl.cs.sunysb.edu>
Wed, 2 Mar 2011 22:13:26 +0000 (17:13 -0500)
committerSiddhi Tadpatrikar <siddhi@agora.fsl.cs.sunysb.edu>
Wed, 2 Mar 2011 22:13:26 +0000 (17:13 -0500)
src/aop-type.c
src/aop.h
test/cast-hooks.c
test/cast-target.c
test/cast.xml
test/plugin-cast.c

index f88a6705c954eea0d5528c1c39889b285979adfc..6f9c35d9d43410e375ac8fb88f26b26b1c966768 100644 (file)
@@ -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)
index a0d154900cb189f07bd096e45216692b35f5e5f2..818b2b6cf0d991cc8d755effd098903e892b9223 100644 (file)
--- 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);
index 81ce1421343c3a9af3a92e9e1ce85105e14836d0..aadb90b40fde8e7dc347047c2ae7543bb6491289 100644 (file)
@@ -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);
+}
index 1547bb7f6bf66376d41937ffb818e1359915e7d0..ccd12b9e114ed7ce28211829103530524dcdd71b 100644 (file)
@@ -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);
 }
index 7e2528c27c9a5c459e067eb4fe830dfb0cf764b5..00335aa6e9603c3453bd7d72efff15583b36f251 100644 (file)
@@ -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  
     </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>
index 4c5f5870c5c47bb3fc77ad8eae920c6f222001c2..01378c573a2705f3937891a3a2e5619db0df803f 100644 (file)
@@ -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;
 }