3dea99e54b012d7fffc68640af8705f28249b1b8
[babeltrace.git] / include / babeltrace / types.h
1 #ifndef _BABELTRACE_TYPES_H
2 #define _BABELTRACE_TYPES_H
3
4 /*
5 * BabelTrace
6 *
7 * Type Header
8 *
9 * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
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.
15 *
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.
20 *
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
24 */
25
26 #include <babeltrace/format.h>
27
28 struct type_class {
29 GQuark name; /* type name */
30 size_t alignment; /* type alignment, in bits */
31 /*
32 * Type copy function. Knows how to find the child type_class from the
33 * parent type_class.
34 */
35 size_t (*copy)(unsigned char *dest, const struct format *fdest,
36 const unsigned char *src, const struct format *fsrc,
37 const struct type_class *type_class);
38 };
39
40 struct type_class_integer {
41 struct type_class p;
42 size_t len; /* length, in bits. */
43 int byte_order; /* byte order */
44 int signedness;
45 };
46
47 struct type_class_bitfield {
48 struct type_class_integer p;
49 size_t start_offset; /* offset from base address, in bits */
50 };
51
52 struct type_class_float {
53 struct type_class p;
54 size_t mantissa_len;
55 size_t exp_len;
56 int byte_order;
57 /* TODO: we might want to express more info about NaN, +inf and -inf */
58 };
59
60 struct enum_table {
61 GHashTable *value_to_quark; /* Tuples (value, GQuark) */
62 GHashTable *quark_to_value; /* Tuples (GQuark, value) */
63 };
64
65 struct type_class_enum {
66 struct type_class_bitfield p; /* inherit from bitfield */
67 struct enum_table table;
68 };
69
70 struct type_class_struct {
71 struct type_class p;
72 /* TODO */
73 };
74
75 struct type_class *ctf_lookup_type(GQuark qname);
76 int ctf_register_type(struct type_class *type_class);
77
78 /* Nameless types can be created by passing a NULL name */
79
80 struct type_class_integer *integer_type_new(const char *name,
81 size_t start_offset,
82 size_t len, int byte_order,
83 int signedness);
84 void integer_type_free(struct type_class_integer *int_class);
85
86 struct type_class_bitfield *bitfield_type_new(const char *name,
87 size_t start_offset,
88 size_t len, int byte_order,
89 int signedness);
90 void bitfield_type_free(struct type_class_bitfield *bitfield_class);
91
92 struct type_class_float *float_type_new(const char *name,
93 size_t mantissa_len,
94 size_t exp_len, int byte_order,
95 size_t alignment);
96 void float_type_free(struct type_class_float *float_class);
97
98 /*
99 * A GQuark can be translated to/from strings with g_quark_from_string() and
100 * g_quark_to_string().
101 */
102 GQuark enum_uint_to_quark(const struct type_class_enum *enum_class, uint64_t v);
103 GQuark enum_int_to_quark(const struct type_class_enum *enum_class, uint64_t v);
104 uint64_t enum_quark_to_uint(const struct type_class_enum *enum_class,
105 size_t len, int byte_order, GQuark q);
106 int64_t enum_quark_to_int(const struct type_class_enum *enum_class,
107 size_t len, int byte_order, GQuark q);
108 void enum_signed_insert(struct type_class_enum *enum_class,
109 int64_t v, GQuark q);
110 void enum_unsigned_insert(struct type_class_enum *enum_class,
111 uint64_t v, GQuark q);
112
113 struct type_class_enum *enum_type_new(const char *name,
114 size_t start_offset,
115 size_t len, int byte_order,
116 int signedness,
117 size_t alignment);
118 void enum_type_free(struct type_class_enum *enum_class);
119
120 #endif /* _BABELTRACE_TYPES_H */
This page took 0.044066 seconds and 3 git commands to generate.