-static inline
-void move_pos(struct stream_pos *pos, size_t offset)
-{
- pos->offset = pos->offset + offset;
-}
-
-/*
- * align_pos - align position on a bit offset (> 0)
- *
- * TODO: allow larger files by updating base too.
- */
-static inline
-void align_pos(struct stream_pos *pos, size_t offset)
-{
- pos->offset += offset_align(pos->offset, offset);
-}
-
-static inline
-void copy_pos(struct stream_pos *dest, struct stream_pos *src)
-{
- memcpy(dest, src, sizeof(struct stream_pos));
-}
-
-static inline
-char *get_pos_addr(struct stream_pos *pos)
-{
- /* Only makes sense to get the address after aligning on CHAR_BIT */
- assert(!(pos->offset % CHAR_BIT));
- return pos->base + (pos->offset / CHAR_BIT);
-}
-
-struct format;
-struct declaration;
-
-/* type scope */
-struct type_scope {
- /* Hash table mapping type name GQuark to struct type */
- GHashTable *types;
- struct type_scope *parent_scope;
-};
-
-/* declaration scope */
-struct declaration_scope {
- /* Hash table mapping field name GQuark to struct declaration */
- GHashTable *declarations;
- struct declaration_scope *parent_scope;
-};
-
-struct type {
- GQuark name; /* type name */
- size_t alignment; /* type alignment, in bits */
- int ref; /* number of references to the type */
- /*
- * type_free called with type ref is decremented to 0.
- */
- void (*type_free)(struct type *type);
- struct declaration *
- (*declaration_new)(struct type *type,
- struct declaration_scope *parent_scope);
- /*
- * declaration_free called with declaration ref is decremented to 0.
- */
- void (*declaration_free)(struct declaration *declaration);
- /*
- * Declaration copy function. Knows how to find the child declaration
- * from the parent declaration.
- */
- void (*copy)(struct stream_pos *dest, const struct format *fdest,
- struct stream_pos *src, const struct format *fsrc,
- struct declaration *declaration);
-};
-
-struct declaration {
- struct type *type;
- int ref; /* number of references to the declaration */
-};
-
-/*
- * Because we address in bits, bitfields end up being exactly the same as
- * integers, except that their read/write functions must be able to deal with
- * read/write non aligned on CHAR_BIT.
- */
-struct type_integer {
- struct type p;
- size_t len; /* length, in bits. */
- int byte_order; /* byte order */
- int signedness;
-};
-
-struct declaration_integer {
- struct declaration p;
- struct type_integer *type;
- /* Last values read */
- union {
- uint64_t _unsigned;
- int64_t _signed;
- } value;
-};
-
-struct type_float {
- struct type p;
- struct type_integer *sign;
- struct type_integer *mantissa;
- struct type_integer *exp;
- int byte_order;
- /* TODO: we might want to express more info about NaN, +inf and -inf */
-};
-
-struct declaration_float {
- struct declaration p;
- struct type_float *type;
- /* Last values read */
- long double value;
-};
-
-/*
- * 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_set; /* (value, GQuark GArray) */
- struct cds_list_head range_to_quark; /* (range, GQuark) */
- GHashTable *quark_to_range_set; /* (GQuark, range GArray) */
-};
-
-struct type_enum {
- struct type p;
- struct type_integer *integer_type;
- struct enum_table table;
-};