From: Justin Seyster Date: Tue, 24 Aug 2010 21:26:44 +0000 (-0400) Subject: Added specific types for different sized integers. X-Git-Tag: release-v1.0~62 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=6631ca8e4fee0a91de953fc8f74d051a16e21506;p=interaspect.git Added specific types for different sized integers. --- diff --git a/src/aop-type.c b/src/aop-type.c index bf70f32..38d095d 100644 --- a/src/aop-type.c +++ b/src/aop-type.c @@ -34,27 +34,115 @@ #include "aop-type.h" static struct aop_type _aop_t_all_signed = { - .kind = ATK_ALL_SIGNED, + .kind = ATK_SIGNED_INT, .pointer_levels = 0, .tag = NULL, + + .size = 0, }; static struct aop_type _aop_t_all_unsigned = { - .kind = ATK_ALL_UNSIGNED, + .kind = ATK_UNSIGNED_INT, .pointer_levels = 0, .tag = NULL, + + .size = 0, }; static struct aop_type _aop_t_all_fp = { .kind = ATK_ALL_FP, .pointer_levels = 0, .tag = NULL, + + .size = 0, }; static struct aop_type _aop_t_all_pointer = { .kind = ATK_ALL_POINTER, .pointer_levels = 0, .tag = NULL, + + .size = 0, +}; + +static struct aop_type _aop_t_signed8 = { + .kind = ATK_SIGNED_INT, + .pointer_levels = 0, + .tag = NULL, + + .size = 1, +}; + +static struct aop_type _aop_t_signed16 = { + .kind = ATK_SIGNED_INT, + .pointer_levels = 0, + .tag = NULL, + + .size = 2, +}; + +static struct aop_type _aop_t_signed32 = { + .kind = ATK_SIGNED_INT, + .pointer_levels = 0, + .tag = NULL, + + .size = 4, +}; + +static struct aop_type _aop_t_signed64 = { + .kind = ATK_SIGNED_INT, + .pointer_levels = 0, + .tag = NULL, + + .size = 8, +}; + +static struct aop_type _aop_t_signed128 = { + .kind = ATK_SIGNED_INT, + .pointer_levels = 0, + .tag = NULL, + + .size = 16, +}; + +static struct aop_type _aop_t_unsigned8 = { + .kind = ATK_UNSIGNED_INT, + .pointer_levels = 0, + .tag = NULL, + + .size = 1, +}; + +static struct aop_type _aop_t_unsigned16 = { + .kind = ATK_UNSIGNED_INT, + .pointer_levels = 0, + .tag = NULL, + + .size = 2, +}; + +static struct aop_type _aop_t_unsigned32 = { + .kind = ATK_UNSIGNED_INT, + .pointer_levels = 0, + .tag = NULL, + + .size = 4, +}; + +static struct aop_type _aop_t_unsigned64 = { + .kind = ATK_UNSIGNED_INT, + .pointer_levels = 0, + .tag = NULL, + + .size = 8, +}; + +static struct aop_type _aop_t_unsigned128 = { + .kind = ATK_UNSIGNED_INT, + .pointer_levels = 0, + .tag = NULL, + + .size = 16, }; /** @@ -119,20 +207,101 @@ aop_t_all_pointer () return &_aop_t_all_pointer; } -/* True if this is an integer type (signed or unsigned) between int8 - and int64. */ +const struct aop_type * +aop_t_signed8 () +{ + return &_aop_t_signed8; +} + +const struct aop_type * +aop_t_signed16 () +{ + return &_aop_t_signed16; +} + +const struct aop_type * +aop_t_signed32 () +{ + return &_aop_t_signed32; +} + +const struct aop_type * +aop_t_signed64 () +{ + return &_aop_t_signed64; +} + +const struct aop_type * +aop_t_signed128 () +{ + return &_aop_t_signed128; +} + +const struct aop_type * +aop_t_unsigned8 () +{ + return &_aop_t_unsigned8; +} + +const struct aop_type * +aop_t_unsigned16 () +{ + return &_aop_t_unsigned16; +} + +const struct aop_type * +aop_t_unsigned32 () +{ + return &_aop_t_unsigned32; +} + +const struct aop_type * +aop_t_unsigned64 () +{ + return &_aop_t_unsigned64; +} + +const struct aop_type * +aop_t_unsigned128 () +{ + return &_aop_t_unsigned128; +} + +/* Returns true if specified type is an "all signed" or "all unsigned" + type. */ +bool +is_all_integer_type (const struct aop_type *type) +{ + return ((type->kind == ATK_SIGNED_INT || type->kind == ATK_UNSIGNED_INT) + && type->size <= 0); +} + static bool -is_stdint_type (tree gcc_type) +does_int_type_match (tree gcc_type, enum aop_tykind kind, int aop_size) { - if (TREE_CODE (gcc_type) == INTEGER_TYPE) - { - HOST_WIDE_INT size = int_size_in_bytes (gcc_type); - return (size > 0 && size <= 8); - } + HOST_WIDE_INT gcc_size; + + aop_assert (kind == ATK_SIGNED_INT || kind == ATK_UNSIGNED_INT); + + if (TREE_CODE (gcc_type) != INTEGER_TYPE) + return false; + + gcc_size = int_size_in_bytes (gcc_type); + + /* Types do not match if one is unsigned and one is signed. */ + if (kind == ATK_SIGNED_INT && TYPE_UNSIGNED (gcc_type)) + return false; + else if (kind == ATK_UNSIGNED_INT && !TYPE_UNSIGNED (gcc_type)) + return false; + + /* If aop_size is zero (or negative) we treat it as the "all signed" + or all "all unsigned" type, which will match any "standard" size + integer. int64_t and uint64_t are the largest standard size + integer. */ + if (aop_size > 0) + return (aop_size == gcc_size); else - { - return false; - } + return (gcc_size > 0 && gcc_size <= 8); } /* Match an actual GCC type with an AOP type specification. */ @@ -149,10 +318,9 @@ does_type_match (tree gcc_type, const struct aop_type *aop_type) { switch (aop_type->kind) { - case ATK_ALL_SIGNED: - return (is_stdint_type (gcc_type) && !TYPE_UNSIGNED (gcc_type)); - case ATK_ALL_UNSIGNED: - return (is_stdint_type (gcc_type) && TYPE_UNSIGNED (gcc_type)); + case ATK_SIGNED_INT: + case ATK_UNSIGNED_INT: + return does_int_type_match (gcc_type, aop_type->kind, aop_type->size); case ATK_ALL_FP: return (TREE_CODE (gcc_type) == REAL_TYPE); default: diff --git a/src/aop-type.h b/src/aop-type.h index 7b88c8b..a8c5754 100644 --- a/src/aop-type.h +++ b/src/aop-type.h @@ -19,8 +19,8 @@ client plug-ins. */ enum aop_tykind { - ATK_ALL_SIGNED, - ATK_ALL_UNSIGNED, + ATK_SIGNED_INT, + ATK_UNSIGNED_INT, ATK_ALL_FP, ATK_ALL_POINTER, @@ -33,8 +33,11 @@ struct aop_type { int pointer_levels; const char *tag; + + int size; }; -bool does_type_match (tree gcc_type, const struct aop_type *aop_type); +extern bool is_all_integer_type (const struct aop_type *type); +extern bool does_type_match (tree gcc_type, const struct aop_type *aop_type); #endif diff --git a/src/aop-weave.c b/src/aop-weave.c index 6235a41..745aa2f 100644 --- a/src/aop-weave.c +++ b/src/aop-weave.c @@ -103,7 +103,7 @@ cast_to_all_integer (tree val) size = int_size_in_bytes (gcc_type); aop_assert (size > 0 && size <= 8); - if (size < 8) + if (size != 8) { tree cast_type = TYPE_UNSIGNED (gcc_type) ? long_long_unsigned_type_node : long_long_integer_type_node; @@ -121,13 +121,11 @@ cast_to_all_integer (tree val) static tree build_dynval (struct aop_dynval *dv) { - const struct aop_type *type; tree val; val = dv->get_dynval (dv); - type = dv->type; - if (type->kind == ATK_ALL_SIGNED || type->kind == ATK_ALL_UNSIGNED) + if (is_all_integer_type (dv->type)) val = cast_to_all_integer (val); return val; diff --git a/src/aop.h b/src/aop.h index 35d3648..edf1ebd 100644 --- a/src/aop.h +++ b/src/aop.h @@ -167,6 +167,17 @@ extern const struct aop_type *aop_t_all_unsigned (); extern const struct aop_type *aop_t_all_fp (); extern const struct aop_type *aop_t_all_pointer (); +extern const struct aop_type *aop_t_signed8 (); +extern const struct aop_type *aop_t_signed16 (); +extern const struct aop_type *aop_t_signed32 (); +extern const struct aop_type *aop_t_signed64 (); +extern const struct aop_type *aop_t_signed128 (); +extern const struct aop_type *aop_t_unsigned8 (); +extern const struct aop_type *aop_t_unsigned16 (); +extern const struct aop_type *aop_t_unsigned32 (); +extern const struct aop_type *aop_t_unsigned64 (); +extern const struct aop_type *aop_t_unsigned128 (); + extern void aop_register_pass (const char *pass_name, pass_callback callback); extern void aop_join_on (struct aop_pointcut *pc, join_callback callback, void *callback_param);