1 #ifndef _BABELTRACE_TYPES_H
2 #define _BABELTRACE_TYPES_H
9 * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <babeltrace/format.h>
27 #include <babeltrace/align.h>
31 * Always update stream_pos with move_pos and init_pos.
34 unsigned char *base
; /* Base address */
35 size_t offset
; /* Offset from base, in bits */
36 int dummy
; /* Dummy position, for length calculation */
40 void init_pos(struct stream_pos
*pos
, unsigned char *base
)
42 pos
->base
= base
; /* initial base, page-aligned */
48 * move_pos - move position of a relative bit offset
50 * TODO: allow larger files by updating base too.
53 void move_pos(struct stream_pos
*pos
, size_t offset
)
55 pos
->offset
= pos
->offset
+ offset
;
59 * align_pos - align position on a bit offset (> 0)
61 * TODO: allow larger files by updating base too.
64 void align_pos(struct stream_pos
*pos
, size_t offset
)
66 pos
->offset
+= offset_align(pos
->offset
, offset
);
70 void copy_pos(struct stream_pos
*dest
, struct stream_pos
*src
)
72 memcpy(dest
, src
, sizeof(struct stream_pos
));
76 unsigned char *get_pos_addr(struct stream_pos
*pos
)
78 /* Only makes sense to get the address after aligning on CHAR_BIT */
79 assert(!(pos
->alignment
% CHAR_BIT
));
80 return pos
->base
+ (pos
->offset
/ CHAR_BIT
);
84 GQuark name
; /* type name */
85 size_t alignment
; /* type alignment, in bits */
87 * Type copy function. Knows how to find the child type_class from the
90 size_t (*copy
)(struct stream_pos
*dest
, const struct format
*fdest
,
91 struct stream_pos
*src
, const struct format
*fsrc
,
92 const struct type_class
*type_class
);
93 void (*free
)(struct type_class
*type_class
);
96 struct type_class_integer
{
98 size_t len
; /* length, in bits. */
99 int byte_order
; /* byte order */
104 * Because we address in bits, bitfields end up being exactly the same as
105 * integers, except that their read/write functions must be able to deal with
106 * read/write non aligned on CHAR_BIT.
108 struct type_class_bitfield
{
109 struct type_class_integer p
;
112 struct type_class_float
{
114 struct bitfield_class
*mantissa
;
115 struct bitfield_class
*exp
;
117 /* TODO: we might want to express more info about NaN, +inf and -inf */
121 GHashTable
*value_to_quark
; /* Tuples (value, GQuark) */
122 GHashTable
*quark_to_value
; /* Tuples (GQuark, value) */
125 struct type_class_enum
{
126 struct type_class_bitfield p
; /* inherit from bitfield */
127 struct enum_table table
;
130 struct type_class_string
{
134 struct type_class_struct
{
139 struct type_class
*ctf_lookup_type(GQuark qname
);
140 int ctf_register_type(struct type_class
*type_class
);
142 /* Nameless types can be created by passing a NULL name */
144 struct type_class_integer
*integer_type_new(const char *name
,
146 size_t len
, int byte_order
,
148 void integer_type_free(struct type_class_integer
*int_class
);
150 struct type_class_bitfield
*bitfield_type_new(const char *name
,
152 size_t len
, int byte_order
,
154 void bitfield_type_free(struct type_class_bitfield
*bitfield_class
);
156 struct type_class_float
*float_type_new(const char *name
,
158 size_t exp_len
, int byte_order
,
160 void float_type_free(struct type_class_float
*float_class
);
163 * A GQuark can be translated to/from strings with g_quark_from_string() and
164 * g_quark_to_string().
166 GQuark
enum_uint_to_quark(const struct type_class_enum
*enum_class
, uint64_t v
);
167 GQuark
enum_int_to_quark(const struct type_class_enum
*enum_class
, uint64_t v
);
168 uint64_t enum_quark_to_uint(const struct type_class_enum
*enum_class
,
169 size_t len
, int byte_order
, GQuark q
);
170 int64_t enum_quark_to_int(const struct type_class_enum
*enum_class
,
171 size_t len
, int byte_order
, GQuark q
);
172 void enum_signed_insert(struct type_class_enum
*enum_class
,
173 int64_t v
, GQuark q
);
174 void enum_unsigned_insert(struct type_class_enum
*enum_class
,
175 uint64_t v
, GQuark q
);
177 struct type_class_enum
*enum_type_new(const char *name
,
179 size_t len
, int byte_order
,
182 void enum_type_free(struct type_class_enum
*enum_class
);
184 #endif /* _BABELTRACE_TYPES_H */
This page took 0.035366 seconds and 6 git commands to generate.