diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | type.c | 21 | ||||
-rw-r--r-- | type.h | 5 |
3 files changed, 30 insertions, 0 deletions
@@ -1,3 +1,7 @@ +2012-09-08 Petr Machata <pmachata@redhat.com> + + * type.c, type.h (type_aggregate_size): New function. + 2012-09-13 Petr Machata <pmachata@redhat.com> * fetch.c (arch_fetch_param_pack_start): New declaration or @@ -460,6 +460,27 @@ type_element(struct arg_type_info *info, size_t emt) } } +size_t +type_aggregate_size(struct arg_type_info *info) +{ + assert(info->type == ARGTYPE_STRUCT + || info->type == ARGTYPE_ARRAY); + + switch (info->type) { + long ret; + case ARGTYPE_ARRAY: + if (expr_eval_constant(info->u.array_info.length, &ret) < 0) + return (size_t)-1; + return (size_t)ret; + + case ARGTYPE_STRUCT: + return type_struct_size(info); + + default: + abort(); + } +} + int type_is_integral(enum arg_type type) { @@ -87,6 +87,11 @@ struct arg_type_info *type_struct_get(struct arg_type_info *info, size_t idx); /* Return number of fields of structure type INFO. */ size_t type_struct_size(struct arg_type_info *info); +/* Return number of elements of an aggregate type INFO. This can be + * either ARGTYPE_STRUCT or ARGTYPE_ARRAY of constant length. If + * ARGTYPE_ARRAY does not have a constant length, this returns -1. */ +size_t type_aggregate_size(struct arg_type_info *info); + /* Initialize INFO so it becomes ARGTYPE_ARRAY. The element type is * passed in ELEMENT_INFO, and array length in LENGTH_EXPR. If, * respectively, OWN_INFO and OWN_LENGTH are true, the pointee and |