Commit | Line | Data |
---|---|---|
5cd6d0e5 PP |
1 | #ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H |
2 | #define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H | |
3 | ||
4 | /* | |
5 | * BabelTrace - Trace IR: Event field classes internal | |
6 | * | |
7 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
8 | * | |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
28 | */ | |
29 | ||
30 | #include <babeltrace/assert-pre-internal.h> | |
31 | #include <babeltrace/trace-ir/clock-class.h> | |
32 | #include <babeltrace/trace-ir/field-classes.h> | |
33 | #include <babeltrace/babeltrace-internal.h> | |
34 | #include <babeltrace/object-internal.h> | |
35 | #include <babeltrace/types.h> | |
36 | #include <stdint.h> | |
37 | #include <glib.h> | |
38 | ||
39 | #define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \ | |
40 | BT_ASSERT_PRE( \ | |
864cad70 PP |
41 | ((struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \ |
42 | ((struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \ | |
43 | ((struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \ | |
44 | ((struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \ | |
5cd6d0e5 PP |
45 | _name " is not an integer field class: %![fc-]+F", (_fc)) |
46 | ||
47 | #define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \ | |
48 | BT_ASSERT_PRE( \ | |
864cad70 PP |
49 | ((struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \ |
50 | ((struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, \ | |
5cd6d0e5 PP |
51 | _name " is not an unsigned integer field class: %![fc-]+F", (_fc)) |
52 | ||
53 | #define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \ | |
54 | BT_ASSERT_PRE( \ | |
864cad70 PP |
55 | ((struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \ |
56 | ((struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \ | |
5cd6d0e5 PP |
57 | _name " is not an enumeration field class: %![fc-]+F", (_fc)) |
58 | ||
59 | #define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \ | |
60 | BT_ASSERT_PRE( \ | |
864cad70 PP |
61 | ((struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \ |
62 | ((struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, \ | |
5cd6d0e5 PP |
63 | _name " is not an array field class: %![fc-]+F", (_fc)) |
64 | ||
864cad70 PP |
65 | #define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name) \ |
66 | BT_ASSERT_PRE(((struct bt_field_class *) (_fc))->type == (_type), \ | |
67 | _name " has the wrong type: expected-type=%s, " \ | |
68 | "%![fc-]+F", bt_common_field_class_type_string(_type), (_fc)) | |
5cd6d0e5 PP |
69 | |
70 | #define BT_ASSERT_PRE_FC_HOT(_fc, _name) \ | |
71 | BT_ASSERT_PRE_HOT((struct bt_field_class *) (_fc), \ | |
72 | (_name), ": %!+F", (_fc)) | |
73 | ||
74 | #define BT_FIELD_CLASS_NAMED_FC_AT_INDEX(_fc, _index) \ | |
75 | (&g_array_index(((struct bt_field_class_named_field_class_container *) (_fc))->named_fcs, \ | |
76 | struct bt_named_field_class, (_index))) | |
77 | ||
78 | #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \ | |
79 | (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \ | |
80 | struct bt_field_class_enumeration_mapping, (_index))) | |
81 | ||
82 | #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \ | |
83 | (&g_array_index((_mapping)->ranges, \ | |
84 | struct bt_field_class_enumeration_mapping_range, (_index))) | |
85 | ||
86 | struct bt_field; | |
87 | struct bt_field_class; | |
88 | ||
89 | struct bt_field_class { | |
90 | struct bt_object base; | |
864cad70 | 91 | enum bt_field_class_type type; |
5cd6d0e5 PP |
92 | bool frozen; |
93 | ||
94 | /* | |
95 | * Only used in developer mode, this flag indicates whether or | |
96 | * not this field class is part of a trace. | |
97 | */ | |
98 | bool part_of_trace; | |
99 | }; | |
100 | ||
101 | struct bt_field_class_integer { | |
102 | struct bt_field_class common; | |
103 | ||
104 | /* | |
105 | * Value range of fields built from this integer field class: | |
106 | * this is an equivalent integer size in bits. More formally, | |
107 | * `range` is `n` in: | |
108 | * | |
109 | * Unsigned range: [0, 2^n - 1] | |
110 | * Signed range: [-2^(n - 1), 2^(n - 1) - 1] | |
111 | */ | |
112 | uint64_t range; | |
113 | ||
114 | enum bt_field_class_integer_preferred_display_base base; | |
115 | }; | |
116 | ||
117 | struct bt_field_class_enumeration_mapping_range { | |
118 | union { | |
119 | uint64_t u; | |
120 | int64_t i; | |
121 | } lower; | |
122 | ||
123 | union { | |
124 | uint64_t u; | |
125 | int64_t i; | |
126 | } upper; | |
127 | }; | |
128 | ||
129 | struct bt_field_class_enumeration_mapping { | |
130 | GString *label; | |
131 | ||
132 | /* Array of `struct bt_field_class_enumeration_mapping_range` */ | |
133 | GArray *ranges; | |
134 | }; | |
135 | ||
136 | struct bt_field_class_enumeration { | |
137 | struct bt_field_class_integer common; | |
138 | ||
139 | /* Array of `struct bt_field_class_enumeration_mapping *` */ | |
140 | GArray *mappings; | |
141 | ||
142 | /* | |
143 | * This is an array of `const char *` which acts as a temporary | |
144 | * (potentially growing) buffer for | |
145 | * bt_field_class_unsigned_enumeration_get_mapping_labels_by_value() | |
146 | * and | |
147 | * bt_field_class_signed_enumeration_get_mapping_labels_by_value(). | |
148 | * | |
149 | * The actual strings are owned by the mappings above. | |
150 | */ | |
151 | GPtrArray *label_buf; | |
152 | }; | |
153 | ||
154 | struct bt_field_class_real { | |
155 | struct bt_field_class common; | |
156 | bool is_single_precision; | |
157 | }; | |
158 | ||
159 | struct bt_field_class_string { | |
160 | struct bt_field_class common; | |
161 | }; | |
162 | ||
163 | /* A named field class is a (name, field class) pair */ | |
164 | struct bt_named_field_class { | |
165 | GString *name; | |
166 | ||
167 | /* Owned by this */ | |
168 | struct bt_field_class *fc; | |
169 | }; | |
170 | ||
171 | /* | |
172 | * This is the base field class for a container of named field classes. | |
173 | * Structure and variant field classes inherit this. | |
174 | */ | |
175 | struct bt_field_class_named_field_class_container { | |
176 | struct bt_field_class common; | |
177 | ||
178 | /* | |
179 | * Key: `const char *`, not owned by this (owned by named field | |
180 | * type objects contained in `named_fcs` below). | |
181 | */ | |
182 | GHashTable *name_to_index; | |
183 | ||
184 | /* Array of `struct bt_named_field_class` */ | |
185 | GArray *named_fcs; | |
186 | }; | |
187 | ||
188 | struct bt_field_class_structure { | |
189 | struct bt_field_class_named_field_class_container common; | |
190 | }; | |
191 | ||
192 | struct bt_field_class_array { | |
193 | struct bt_field_class common; | |
194 | ||
195 | /* Owned by this */ | |
196 | struct bt_field_class *element_fc; | |
197 | }; | |
198 | ||
199 | struct bt_field_class_static_array { | |
200 | struct bt_field_class_array common; | |
201 | uint64_t length; | |
202 | }; | |
203 | ||
204 | struct bt_field_class_dynamic_array { | |
205 | struct bt_field_class_array common; | |
206 | ||
207 | /* Weak: never dereferenced, only use to find it elsewhere */ | |
208 | struct bt_field_class *length_fc; | |
209 | ||
210 | /* Owned by this */ | |
211 | struct bt_field_path *length_field_path; | |
212 | }; | |
213 | ||
214 | struct bt_field_class_variant { | |
215 | struct bt_field_class_named_field_class_container common; | |
216 | ||
217 | /* Weak: never dereferenced, only use to find it elsewhere */ | |
218 | struct bt_field_class *selector_fc; | |
219 | ||
220 | /* Owned by this */ | |
221 | struct bt_field_path *selector_field_path; | |
222 | }; | |
223 | ||
224 | static inline | |
864cad70 | 225 | bool bt_field_class_has_known_type(struct bt_field_class *fc) |
5cd6d0e5 | 226 | { |
864cad70 PP |
227 | return fc->type >= BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER && |
228 | fc->type <= BT_FIELD_CLASS_TYPE_VARIANT; | |
5cd6d0e5 PP |
229 | } |
230 | ||
231 | BT_HIDDEN | |
232 | void _bt_field_class_freeze(struct bt_field_class *field_class); | |
233 | ||
234 | #ifdef BT_DEV_MODE | |
235 | # define bt_field_class_freeze _bt_field_class_freeze | |
236 | #else | |
237 | # define bt_field_class_freeze(_fc) | |
238 | #endif | |
239 | ||
240 | /* | |
241 | * This function recursively marks `field_class` and its children as | |
242 | * being part of a trace. This is used to validate that all field classes | |
243 | * are used at a single location within trace objects even if they are | |
244 | * shared objects for other purposes. | |
245 | */ | |
246 | BT_HIDDEN | |
247 | void _bt_field_class_make_part_of_trace(struct bt_field_class *field_class); | |
248 | ||
249 | #ifdef BT_DEV_MODE | |
250 | # define bt_field_class_make_part_of_trace _bt_field_class_make_part_of_trace | |
251 | #else | |
252 | # define bt_field_class_make_part_of_trace(_fc) ((void) _fc) | |
253 | #endif | |
254 | ||
255 | #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */ |