X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=include%2Fbabeltrace%2Ftypes.h;h=d6ac792438bf5573b6f4eb103687e43370656614;hb=380d60b1bd3c5d1a709dca3eeb8e718598fed235;hp=cc5cc89c45012c608b1a4c796de25c203852f61c;hpb=ccd7e1c86f36342b0b06651cc52df86bb663c271;p=babeltrace.git diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index cc5cc89c..d6ac7924 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -19,9 +19,14 @@ * all copies or substantial portions of the Software. */ -#include #include +#include +#include +#include +#include #include +#include +#include /* Preallocate this many fields for structures */ #define DEFAULT_NR_STRUCT_FIELDS 8 @@ -30,13 +35,13 @@ * Always update stream_pos with move_pos and init_pos. */ struct stream_pos { - unsigned char *base; /* Base address */ + char *base; /* Base address */ size_t offset; /* Offset from base, in bits */ int dummy; /* Dummy position, for length calculation */ }; static inline -void init_pos(struct stream_pos *pos, unsigned char *base) +void init_pos(struct stream_pos *pos, char *base) { pos->base = base; /* initial base, page-aligned */ pos->offset = 0; @@ -72,23 +77,26 @@ void copy_pos(struct stream_pos *dest, struct stream_pos *src) } static inline -unsigned char *get_pos_addr(struct stream_pos *pos) +char *get_pos_addr(struct stream_pos *pos) { /* Only makes sense to get the address after aligning on CHAR_BIT */ - assert(!(pos->alignment % CHAR_BIT)); + assert(!(pos->offset % CHAR_BIT)); return pos->base + (pos->offset / CHAR_BIT); } +struct format; + struct type_class { GQuark name; /* type name */ size_t alignment; /* type alignment, in bits */ + int ref; /* number of references to the type */ /* * Type copy function. Knows how to find the child type_class from the * parent type_class. */ - size_t (*copy)(struct stream_pos *dest, const struct format *fdest, - struct stream_pos *src, const struct format *fsrc, - const struct type_class *type_class); + void (*copy)(struct stream_pos *dest, const struct format *fdest, + struct stream_pos *src, const struct format *fsrc, + const struct type_class *type_class); void (*free)(struct type_class *type_class); }; @@ -106,20 +114,53 @@ struct type_class_integer { struct type_class_float { struct type_class p; - struct int_class *sign; - struct int_class *mantissa; - struct int_class *exp; + struct type_class_integer *sign; + struct type_class_integer *mantissa; + struct type_class_integer *exp; int byte_order; /* TODO: we might want to express more info about NaN, +inf and -inf */ }; +/* + * enum_val_equal assumes that signed and unsigned memory layout overlap. + */ +struct enum_range { + union { + int64_t _signed; + uint64_t _unsigned; + } start; /* lowest range value */ + union { + int64_t _signed; + uint64_t _unsigned; + } end; /* highest range value */ +}; + +struct enum_range_to_quark { + struct cds_list_head node; + struct enum_range range; + GQuark quark; +}; + +/* + * We optimize the common case (range of size 1: single value) by creating a + * hash table mapping values to quark sets. We then lookup the ranges to + * complete the quark set. + * + * TODO: The proper structure to hold the range to quark set mapping would be an + * interval tree, with O(n) size, O(n*log(n)) build time and O(log(n)) query + * time. Using a simple O(n) list search for now for implementation speed and + * given that we can expect to have a _relatively_ small number of enumeration + * ranges. This might become untrue if we are fed with symbol tables often + * required to lookup function names from instruction pointer value. + */ struct enum_table { - GHashTable *value_to_quark; /* Tuples (value, GQuark) */ - GHashTable *quark_to_value; /* Tuples (GQuark, value) */ + GHashTable *value_to_quark_set; /* (value, GQuark GArray) */ + struct cds_list_head range_to_quark; /* (range, GQuark) */ + GHashTable *quark_to_range_set; /* (GQuark, range GArray) */ }; struct type_class_enum { - struct type_class_int p; /* inherit from integer */ + struct type_class_integer p; /* inherit from integer */ struct enum_table table; }; @@ -150,8 +191,11 @@ struct type_class_sequence { struct type_class *elem; }; -struct type_class *ctf_lookup_type(GQuark qname); -int ctf_register_type(struct type_class *type_class); +struct type_class *lookup_type(GQuark qname); +int register_type(struct type_class *type_class); + +void type_ref(struct type_class *type_class); +void type_unref(struct type_class *type_class); /* Nameless types can be created by passing a NULL name */ @@ -175,16 +219,31 @@ void float_type_free(struct type_class_float *float_class); * A GQuark can be translated to/from strings with g_quark_from_string() and * g_quark_to_string(). */ -GQuark enum_uint_to_quark(const struct type_class_enum *enum_class, uint64_t v); -GQuark enum_int_to_quark(const struct type_class_enum *enum_class, uint64_t v); -uint64_t enum_quark_to_uint(const struct type_class_enum *enum_class, - size_t len, int byte_order, GQuark q); -int64_t enum_quark_to_int(const struct type_class_enum *enum_class, - size_t len, int byte_order, GQuark q); + +/* + * Returns a GArray of GQuark or NULL. + * Caller must release the GArray with g_array_unref(). + */ +GArray *enum_uint_to_quark_set(const struct type_class_enum *enum_class, + uint64_t v); + +/* + * Returns a GArray of GQuark or NULL. + * Caller must release the GArray with g_array_unref(). + */ +GArray *enum_int_to_quark_set(const struct type_class_enum *enum_class, + uint64_t v); + +/* + * Returns a GArray of struct enum_range or NULL. + * Caller must release the GArray with g_array_unref(). + */ +GArray *enum_quark_to_range_set(const struct type_class_enum *enum_class, + GQuark q); void enum_signed_insert(struct type_class_enum *enum_class, - int64_t v, GQuark q); + int64_t start, int64_t end, GQuark q); void enum_unsigned_insert(struct type_class_enum *enum_class, - uint64_t v, GQuark q); + uint64_t start, uint64_t end, GQuark q); struct type_class_enum *enum_type_new(const char *name, size_t len, int byte_order, @@ -195,7 +254,7 @@ void enum_type_free(struct type_class_enum *enum_class); struct type_class_struct *struct_type_new(const char *name); void struct_type_free(struct type_class_struct *struct_class); void struct_type_add_field(struct type_class_struct *struct_class, - GQuark field_name, + const char *field_name, struct type_class *type_class); /* * Returns the index of a field within a structure.