Commit | Line | Data |
---|---|---|
57553dfd MD |
1 | // SPDX-License-Identifier: MIT |
2 | /* | |
3 | * Copyright 2022-2023 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
4 | */ | |
5 | ||
6 | #ifndef SIDE_INSTRUMENTATION_C_API_H | |
7 | #define SIDE_INSTRUMENTATION_C_API_H | |
8 | ||
9 | #include <stdint.h> | |
10 | #include <side/macros.h> | |
11 | #include <side/endian.h> | |
12 | ||
b8dfb348 MD |
13 | #include <side/abi/type-value.h> |
14 | #include <side/abi/attribute.h> | |
15 | #include <side/abi/type-description.h> | |
57553dfd MD |
16 | |
17 | #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN) | |
18 | # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE | |
19 | #else | |
20 | # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE | |
21 | #endif | |
22 | ||
23 | #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN) | |
24 | # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE | |
25 | #else | |
26 | # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE | |
27 | #endif | |
28 | ||
29 | /* Event and type attributes */ | |
30 | ||
31 | #define side_attr(_key, _value) \ | |
32 | { \ | |
33 | .key = { \ | |
34 | .p = SIDE_PTR_INIT(_key), \ | |
35 | .unit_size = sizeof(uint8_t), \ | |
36 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ | |
37 | }, \ | |
38 | .value = SIDE_PARAM(_value), \ | |
39 | } | |
40 | ||
41 | #define side_attr_list(...) \ | |
42 | SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__) | |
43 | ||
44 | #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL } | |
45 | #define side_attr_bool(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_BOOL), .u = { .bool_value = !!(_val) } } | |
46 | #define side_attr_u8(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U8), .u = { .integer_value = { .side_u8 = (_val) } } } | |
47 | #define side_attr_u16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U16), .u = { .integer_value = { .side_u16 = (_val) } } } | |
48 | #define side_attr_u32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U32), .u = { .integer_value = { .side_u32 = (_val) } } } | |
49 | #define side_attr_u64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U64), .u = { .integer_value = { .side_u64 = (_val) } } } | |
50 | #define side_attr_s8(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S8), .u = { .integer_value = { .side_s8 = (_val) } } } | |
51 | #define side_attr_s16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S16), .u = { .integer_value = { .side_s16 = (_val) } } } | |
52 | #define side_attr_s32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S32), .u = { .integer_value = { .side_s32 = (_val) } } } | |
53 | #define side_attr_s64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S64), .u = { .integer_value = { .side_s64 = (_val) } } } | |
54 | #define side_attr_float_binary16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY16), .u = { .float_value = { .side_float_binary16 = (_val) } } } | |
55 | #define side_attr_float_binary32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY32), .u = { .float_value = { .side_float_binary32 = (_val) } } } | |
56 | #define side_attr_float_binary64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY64), .u = { .float_value = { .side_float_binary64 = (_val) } } } | |
57 | #define side_attr_float_binary128(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY128), .u = { .float_value = { .side_float_binary128 = (_val) } } } | |
58 | ||
59 | #define _side_attr_string(_val, _byte_order, _unit_size) \ | |
60 | { \ | |
61 | .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_STRING), \ | |
62 | .u = { \ | |
63 | .string_value = { \ | |
64 | .p = SIDE_PTR_INIT(_val), \ | |
65 | .unit_size = _unit_size, \ | |
66 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ | |
67 | }, \ | |
68 | }, \ | |
69 | } | |
70 | ||
71 | #define side_attr_string(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t)) | |
72 | #define side_attr_string16(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t)) | |
73 | #define side_attr_string32(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t)) | |
74 | ||
75 | /* Stack-copy enumeration type definitions */ | |
76 | ||
77 | #define side_define_enum(_identifier, _mappings, _attr...) \ | |
78 | const struct side_enum_mappings _identifier = { \ | |
79 | .mappings = SIDE_PTR_INIT(_mappings), \ | |
80 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
81 | .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ | |
82 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
83 | } | |
84 | ||
85 | #define side_enum_mapping_list(...) \ | |
86 | SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__) | |
87 | ||
88 | #define side_enum_mapping_range(_label, _begin, _end) \ | |
89 | { \ | |
90 | .range_begin = _begin, \ | |
91 | .range_end = _end, \ | |
92 | .label = { \ | |
93 | .p = SIDE_PTR_INIT(_label), \ | |
94 | .unit_size = sizeof(uint8_t), \ | |
95 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ | |
96 | }, \ | |
97 | } | |
98 | ||
99 | #define side_enum_mapping_value(_label, _value) \ | |
100 | { \ | |
101 | .range_begin = _value, \ | |
102 | .range_end = _value, \ | |
103 | .label = { \ | |
104 | .p = SIDE_PTR_INIT(_label), \ | |
105 | .unit_size = sizeof(uint8_t), \ | |
106 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ | |
107 | }, \ | |
108 | } | |
109 | ||
110 | #define side_define_enum_bitmap(_identifier, _mappings, _attr...) \ | |
111 | const struct side_enum_bitmap_mappings _identifier = { \ | |
112 | .mappings = SIDE_PTR_INIT(_mappings), \ | |
113 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
114 | .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ | |
115 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
116 | } | |
117 | ||
118 | #define side_enum_bitmap_mapping_list(...) \ | |
119 | SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__) | |
120 | ||
121 | #define side_enum_bitmap_mapping_range(_label, _begin, _end) \ | |
122 | { \ | |
123 | .range_begin = _begin, \ | |
124 | .range_end = _end, \ | |
125 | .label = { \ | |
126 | .p = SIDE_PTR_INIT(_label), \ | |
127 | .unit_size = sizeof(uint8_t), \ | |
128 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ | |
129 | }, \ | |
130 | } | |
131 | ||
132 | #define side_enum_bitmap_mapping_value(_label, _value) \ | |
133 | { \ | |
134 | .range_begin = _value, \ | |
135 | .range_end = _value, \ | |
136 | .label = { \ | |
137 | .p = SIDE_PTR_INIT(_label), \ | |
138 | .unit_size = sizeof(uint8_t), \ | |
139 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ | |
140 | }, \ | |
141 | } | |
142 | ||
143 | /* Stack-copy field and type definitions */ | |
144 | ||
145 | #define side_type_null(_attr...) \ | |
146 | { \ | |
147 | .type = SIDE_ENUM_INIT(SIDE_TYPE_NULL), \ | |
148 | .u = { \ | |
149 | .side_null = { \ | |
150 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
151 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
152 | }, \ | |
153 | }, \ | |
154 | } | |
155 | ||
156 | #define side_type_bool(_attr...) \ | |
157 | { \ | |
158 | .type = SIDE_ENUM_INIT(SIDE_TYPE_BOOL), \ | |
159 | .u = { \ | |
160 | .side_bool = { \ | |
161 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
162 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
163 | .bool_size = sizeof(uint8_t), \ | |
164 | .len_bits = 0, \ | |
165 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ | |
166 | }, \ | |
167 | }, \ | |
168 | } | |
169 | ||
170 | #define side_type_byte(_attr...) \ | |
171 | { \ | |
172 | .type = SIDE_ENUM_INIT(SIDE_TYPE_BYTE), \ | |
173 | .u = { \ | |
174 | .side_byte = { \ | |
175 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
176 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
177 | }, \ | |
178 | }, \ | |
179 | } | |
180 | ||
181 | #define _side_type_string(_type, _byte_order, _unit_size, _attr) \ | |
182 | { \ | |
183 | .type = SIDE_ENUM_INIT(_type), \ | |
184 | .u = { \ | |
185 | .side_string = { \ | |
186 | .attr = SIDE_PTR_INIT(_attr), \ | |
187 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ | |
188 | .unit_size = _unit_size, \ | |
189 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ | |
190 | }, \ | |
191 | }, \ | |
192 | } | |
193 | ||
194 | #define side_type_dynamic() \ | |
195 | { \ | |
196 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC), \ | |
197 | } | |
198 | ||
199 | #define _side_type_integer(_type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \ | |
200 | { \ | |
201 | .type = SIDE_ENUM_INIT(_type), \ | |
202 | .u = { \ | |
203 | .side_integer = { \ | |
204 | .attr = SIDE_PTR_INIT(_attr), \ | |
205 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ | |
206 | .integer_size = _integer_size, \ | |
207 | .len_bits = _len_bits, \ | |
208 | .signedness = _signedness, \ | |
209 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ | |
210 | }, \ | |
211 | }, \ | |
212 | } | |
213 | ||
214 | #define _side_type_float(_type, _byte_order, _float_size, _attr) \ | |
215 | { \ | |
216 | .type = SIDE_ENUM_INIT(_type), \ | |
217 | .u = { \ | |
218 | .side_float = { \ | |
219 | .attr = SIDE_PTR_INIT(_attr), \ | |
220 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ | |
221 | .float_size = _float_size, \ | |
222 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ | |
223 | }, \ | |
224 | }, \ | |
225 | } | |
226 | ||
227 | #define _side_field(_name, _type) \ | |
228 | { \ | |
229 | .field_name = SIDE_PTR_INIT(_name), \ | |
230 | .side_type = _type, \ | |
231 | } | |
232 | ||
233 | #define side_option_range(_range_begin, _range_end, _type) \ | |
234 | { \ | |
235 | .range_begin = _range_begin, \ | |
236 | .range_end = _range_end, \ | |
237 | .side_type = _type, \ | |
238 | } | |
239 | ||
240 | #define side_option(_value, _type) \ | |
241 | side_option_range(_value, _value, SIDE_PARAM(_type)) | |
242 | ||
243 | /* Host endian */ | |
244 | #define side_type_u8(_attr...) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
245 | #define side_type_u16(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
246 | #define side_type_u32(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
247 | #define side_type_u64(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
248 | #define side_type_s8(_attr...) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
249 | #define side_type_s16(_attr...) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
250 | #define side_type_s32(_attr...) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
251 | #define side_type_s64(_attr...) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
252 | #define side_type_pointer(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
253 | #define side_type_float_binary16(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
254 | #define side_type_float_binary32(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
255 | #define side_type_float_binary64(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
256 | #define side_type_float_binary128(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
257 | #define side_type_string(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF8, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
258 | #define side_type_string16(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
259 | #define side_type_string32(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
260 | ||
261 | #define side_field_null(_name, _attr...) _side_field(_name, side_type_null(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
262 | #define side_field_bool(_name, _attr...) _side_field(_name, side_type_bool(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
263 | #define side_field_u8(_name, _attr...) _side_field(_name, side_type_u8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
264 | #define side_field_u16(_name, _attr...) _side_field(_name, side_type_u16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
265 | #define side_field_u32(_name, _attr...) _side_field(_name, side_type_u32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
266 | #define side_field_u64(_name, _attr...) _side_field(_name, side_type_u64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
267 | #define side_field_s8(_name, _attr...) _side_field(_name, side_type_s8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
268 | #define side_field_s16(_name, _attr...) _side_field(_name, side_type_s16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
269 | #define side_field_s32(_name, _attr...) _side_field(_name, side_type_s32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
270 | #define side_field_s64(_name, _attr...) _side_field(_name, side_type_s64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
271 | #define side_field_byte(_name, _attr...) _side_field(_name, side_type_byte(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
272 | #define side_field_pointer(_name, _attr...) _side_field(_name, side_type_pointer(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
273 | #define side_field_float_binary16(_name, _attr...) _side_field(_name, side_type_float_binary16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
274 | #define side_field_float_binary32(_name, _attr...) _side_field(_name, side_type_float_binary32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
275 | #define side_field_float_binary64(_name, _attr...) _side_field(_name, side_type_float_binary64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
276 | #define side_field_float_binary128(_name, _attr...) _side_field(_name, side_type_float_binary128(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
277 | #define side_field_string(_name, _attr...) _side_field(_name, side_type_string(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
278 | #define side_field_string16(_name, _attr...) _side_field(_name, side_type_string16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
279 | #define side_field_string32(_name, _attr...) _side_field(_name, side_type_string32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
280 | #define side_field_dynamic(_name) _side_field(_name, side_type_dynamic()) | |
281 | ||
282 | /* Little endian */ | |
283 | #define side_type_u16_le(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
284 | #define side_type_u32_le(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
285 | #define side_type_u64_le(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
286 | #define side_type_s16_le(_attr...) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
287 | #define side_type_s32_le(_attr...) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
288 | #define side_type_s64_le(_attr...) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
289 | #define side_type_pointer_le(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
290 | #define side_type_float_binary16_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
291 | #define side_type_float_binary32_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
292 | #define side_type_float_binary64_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
293 | #define side_type_float_binary128_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
294 | #define side_type_string16_le(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
295 | #define side_type_string32_le(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
296 | ||
297 | #define side_field_u16_le(_name, _attr...) _side_field(_name, side_type_u16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
298 | #define side_field_u32_le(_name, _attr...) _side_field(_name, side_type_u32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
299 | #define side_field_u64_le(_name, _attr...) _side_field(_name, side_type_u64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
300 | #define side_field_s16_le(_name, _attr...) _side_field(_name, side_type_s16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
301 | #define side_field_s32_le(_name, _attr...) _side_field(_name, side_type_s32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
302 | #define side_field_s64_le(_name, _attr...) _side_field(_name, side_type_s64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
303 | #define side_field_pointer_le(_name, _attr...) _side_field(_name, side_type_pointer_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
304 | #define side_field_float_binary16_le(_name, _attr...) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
305 | #define side_field_float_binary32_le(_name, _attr...) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
306 | #define side_field_float_binary64_le(_name, _attr...) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
307 | #define side_field_float_binary128_le(_name, _attr...) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
308 | #define side_field_string16_le(_name, _attr...) _side_field(_name, side_type_string16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
309 | #define side_field_string32_le(_name, _attr...) _side_field(_name, side_type_string32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
310 | ||
311 | /* Big endian */ | |
312 | #define side_type_u16_be(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
313 | #define side_type_u32_be(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
314 | #define side_type_u64_be(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
315 | #define side_type_s16_be(_attr...) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
316 | #define side_type_s32_be(_attr...) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
317 | #define side_type_s64_be(_attr...) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
318 | #define side_type_pointer_be(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
319 | #define side_type_float_binary16_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
320 | #define side_type_float_binary32_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
321 | #define side_type_float_binary64_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
322 | #define side_type_float_binary128_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
323 | #define side_type_string16_be(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
324 | #define side_type_string32_be(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
325 | ||
326 | #define side_field_u16_be(_name, _attr...) _side_field(_name, side_type_u16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
327 | #define side_field_u32_be(_name, _attr...) _side_field(_name, side_type_u32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
328 | #define side_field_u64_be(_name, _attr...) _side_field(_name, side_type_u64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
329 | #define side_field_s16_be(_name, _attr...) _side_field(_name, side_type_s16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
330 | #define side_field_s32_be(_name, _attr...) _side_field(_name, side_type_s32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
331 | #define side_field_s64_be(_name, _attr...) _side_field(_name, side_type_s64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
332 | #define side_field_pointer_be(_name, _attr...) _side_field(_name, side_type_pointer_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
333 | #define side_field_float_binary16_be(_name, _attr...) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
334 | #define side_field_float_binary32_be(_name, _attr...) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
335 | #define side_field_float_binary64_be(_name, _attr...) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
336 | #define side_field_float_binary128_be(_name, _attr...) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
337 | #define side_field_string16_be(_name, _attr...) _side_field(_name, side_type_string16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
338 | #define side_field_string32_be(_name, _attr...) _side_field(_name, side_type_string32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
339 | ||
340 | #define side_type_enum(_mappings, _elem_type) \ | |
341 | { \ | |
342 | .type = SIDE_ENUM_INIT(SIDE_TYPE_ENUM), \ | |
343 | .u = { \ | |
344 | .side_enum = { \ | |
345 | .mappings = SIDE_PTR_INIT(_mappings), \ | |
346 | .elem_type = SIDE_PTR_INIT(_elem_type), \ | |
347 | }, \ | |
348 | }, \ | |
349 | } | |
350 | #define side_field_enum(_name, _mappings, _elem_type) \ | |
351 | _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type))) | |
352 | ||
353 | #define side_type_enum_bitmap(_mappings, _elem_type) \ | |
354 | { \ | |
355 | .type = SIDE_ENUM_INIT(SIDE_TYPE_ENUM_BITMAP), \ | |
356 | .u = { \ | |
357 | .side_enum_bitmap = { \ | |
358 | .mappings = SIDE_PTR_INIT(_mappings), \ | |
359 | .elem_type = SIDE_PTR_INIT(_elem_type), \ | |
360 | }, \ | |
361 | }, \ | |
362 | } | |
363 | #define side_field_enum_bitmap(_name, _mappings, _elem_type) \ | |
364 | _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type))) | |
365 | ||
366 | #define side_type_struct(_struct) \ | |
367 | { \ | |
368 | .type = SIDE_ENUM_INIT(SIDE_TYPE_STRUCT), \ | |
369 | .u = { \ | |
370 | .side_struct = SIDE_PTR_INIT(_struct), \ | |
371 | }, \ | |
372 | } | |
373 | #define side_field_struct(_name, _struct) \ | |
374 | _side_field(_name, side_type_struct(SIDE_PARAM(_struct))) | |
375 | ||
376 | #define _side_type_struct_define(_fields, _attr) \ | |
377 | { \ | |
378 | .fields = SIDE_PTR_INIT(_fields), \ | |
379 | .attr = SIDE_PTR_INIT(_attr), \ | |
380 | .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ | |
381 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ | |
382 | } | |
383 | ||
384 | #define side_define_struct(_identifier, _fields, _attr...) \ | |
385 | const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
386 | ||
387 | #define side_struct_literal(_fields, _attr...) \ | |
388 | SIDE_COMPOUND_LITERAL(const struct side_type_struct, \ | |
389 | _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
390 | ||
391 | #define side_type_variant(_variant) \ | |
392 | { \ | |
393 | .type = SIDE_ENUM_INIT(SIDE_TYPE_VARIANT), \ | |
394 | .u = { \ | |
395 | .side_variant = SIDE_PTR_INIT(_variant), \ | |
396 | }, \ | |
397 | } | |
398 | #define side_field_variant(_name, _variant) \ | |
399 | _side_field(_name, side_type_variant(SIDE_PARAM(_variant))) | |
400 | ||
401 | #define _side_type_variant_define(_selector, _options, _attr) \ | |
402 | { \ | |
403 | .selector = _selector, \ | |
404 | .options = SIDE_PTR_INIT(_options), \ | |
405 | .attr = SIDE_PTR_INIT(_attr), \ | |
406 | .nr_options = SIDE_ARRAY_SIZE(SIDE_PARAM(_options)), \ | |
407 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ | |
408 | } | |
409 | ||
410 | #define side_define_variant(_identifier, _selector, _options, _attr...) \ | |
411 | const struct side_type_variant _identifier = \ | |
412 | _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
413 | ||
414 | #define side_variant_literal(_selector, _options, _attr...) \ | |
415 | SIDE_COMPOUND_LITERAL(const struct side_type_variant, \ | |
416 | _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
417 | ||
418 | #define side_type_array(_elem_type, _length, _attr...) \ | |
419 | { \ | |
420 | .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), \ | |
421 | .u = { \ | |
422 | .side_array = { \ | |
423 | .elem_type = SIDE_PTR_INIT(_elem_type), \ | |
424 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
425 | .length = _length, \ | |
426 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
427 | }, \ | |
428 | }, \ | |
429 | } | |
430 | #define side_field_array(_name, _elem_type, _length, _attr...) \ | |
431 | _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
432 | ||
433 | #define side_type_vla(_elem_type, _attr...) \ | |
434 | { \ | |
435 | .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), \ | |
436 | .u = { \ | |
437 | .side_vla = { \ | |
438 | .elem_type = SIDE_PTR_INIT(_elem_type), \ | |
439 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
440 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
441 | }, \ | |
442 | }, \ | |
443 | } | |
444 | #define side_field_vla(_name, _elem_type, _attr...) \ | |
445 | _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
446 | ||
447 | #define side_type_vla_visitor(_elem_type, _visitor, _attr...) \ | |
448 | { \ | |
449 | .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA_VISITOR), \ | |
450 | .u = { \ | |
451 | .side_vla_visitor = { \ | |
452 | .elem_type = SIDE_PTR_INIT(_elem_type), \ | |
453 | .visitor = SIDE_PTR_INIT(_visitor), \ | |
454 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
455 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
456 | }, \ | |
457 | }, \ | |
458 | } | |
459 | #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr...) \ | |
460 | _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
461 | ||
462 | /* Gather field and type definitions */ | |
463 | ||
464 | #define side_type_gather_byte(_offset, _access_mode, _attr...) \ | |
465 | { \ | |
466 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BYTE), \ | |
467 | .u = { \ | |
468 | .side_gather = { \ | |
469 | .u = { \ | |
470 | .side_byte = { \ | |
471 | .offset = _offset, \ | |
472 | .access_mode = _access_mode, \ | |
473 | .type = { \ | |
474 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
475 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
476 | }, \ | |
477 | }, \ | |
478 | }, \ | |
479 | }, \ | |
480 | }, \ | |
481 | } | |
482 | #define side_field_gather_byte(_name, _offset, _access_mode, _attr...) \ | |
483 | _side_field(_name, side_type_gather_byte(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
484 | ||
485 | #define _side_type_gather_bool(_byte_order, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
486 | { \ | |
487 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BOOL), \ | |
488 | .u = { \ | |
489 | .side_gather = { \ | |
490 | .u = { \ | |
491 | .side_bool = { \ | |
492 | .offset = _offset, \ | |
493 | .access_mode = _access_mode, \ | |
494 | .type = { \ | |
495 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
496 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
497 | .bool_size = _bool_size, \ | |
498 | .len_bits = _len_bits, \ | |
499 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ | |
500 | }, \ | |
501 | .offset_bits = _offset_bits, \ | |
502 | }, \ | |
503 | }, \ | |
504 | }, \ | |
505 | }, \ | |
506 | } | |
507 | #define side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
508 | _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_HOST, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
509 | #define side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
510 | _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_LE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
511 | #define side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
512 | _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_BE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
513 | ||
514 | #define side_field_gather_bool(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
515 | _side_field(_name, side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))) | |
516 | #define side_field_gather_bool_le(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
517 | _side_field(_name, side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))) | |
518 | #define side_field_gather_bool_be(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
519 | _side_field(_name, side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))) | |
520 | ||
521 | #define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \ | |
522 | _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
523 | { \ | |
524 | .type = SIDE_ENUM_INIT(_type), \ | |
525 | .u = { \ | |
526 | .side_gather = { \ | |
527 | .u = { \ | |
528 | .side_integer = { \ | |
529 | .offset = _offset, \ | |
530 | .access_mode = _access_mode, \ | |
531 | .type = { \ | |
532 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
533 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
534 | .integer_size = _integer_size, \ | |
535 | .len_bits = _len_bits, \ | |
536 | .signedness = _signedness, \ | |
537 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ | |
538 | }, \ | |
539 | .offset_bits = _offset_bits, \ | |
540 | }, \ | |
541 | }, \ | |
542 | }, \ | |
543 | }, \ | |
544 | } | |
545 | ||
546 | #define side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
547 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, \ | |
548 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
549 | #define side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
550 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, \ | |
551 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
552 | ||
553 | #define side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
554 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_LE, \ | |
555 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
556 | #define side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
557 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_LE, \ | |
558 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
559 | ||
560 | #define side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
561 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_BE, \ | |
562 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
563 | #define side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
564 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_BE, \ | |
565 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
566 | ||
567 | #define side_field_gather_unsigned_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
568 | _side_field(_name, side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
569 | #define side_field_gather_signed_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
570 | _side_field(_name, side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
571 | ||
572 | #define side_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
573 | _side_field(_name, side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
574 | #define side_field_gather_signed_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
575 | _side_field(_name, side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
576 | ||
577 | #define side_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
578 | _side_field(_name, side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
579 | #define side_field_gather_signed_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
580 | _side_field(_name, side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
581 | ||
582 | #define side_type_gather_pointer(_offset, _access_mode, _attr...) \ | |
583 | _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, \ | |
584 | _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
585 | #define side_field_gather_pointer(_name, _offset, _access_mode, _attr...) \ | |
586 | _side_field(_name, side_type_gather_pointer(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
587 | ||
588 | #define side_type_gather_pointer_le(_offset, _access_mode, _attr...) \ | |
589 | _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, \ | |
590 | _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
591 | #define side_field_gather_pointer_le(_name, _offset, _access_mode, _attr...) \ | |
592 | _side_field(_name, side_type_gather_pointer_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
593 | ||
594 | #define side_type_gather_pointer_be(_offset, _access_mode, _attr...) \ | |
595 | _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, \ | |
596 | _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
597 | #define side_field_gather_pointer_be(_name, _offset, _access_mode, _attr...) \ | |
598 | _side_field(_name, side_type_gather_pointer_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
599 | ||
600 | #define _side_type_gather_float(_byte_order, _offset, _float_size, _access_mode, _attr...) \ | |
601 | { \ | |
602 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_FLOAT), \ | |
603 | .u = { \ | |
604 | .side_gather = { \ | |
605 | .u = { \ | |
606 | .side_float = { \ | |
607 | .offset = _offset, \ | |
608 | .access_mode = _access_mode, \ | |
609 | .type = { \ | |
610 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
611 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
612 | .float_size = _float_size, \ | |
613 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ | |
614 | }, \ | |
615 | }, \ | |
616 | }, \ | |
617 | }, \ | |
618 | }, \ | |
619 | } | |
620 | ||
621 | #define side_type_gather_float(_offset, _float_size, _access_mode, _attr...) \ | |
622 | _side_type_gather_float(SIDE_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
623 | #define side_type_gather_float_le(_offset, _float_size, _access_mode, _attr...) \ | |
624 | _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_LE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
625 | #define side_type_gather_float_be(_offset, _float_size, _access_mode, _attr...) \ | |
626 | _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_BE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
627 | ||
628 | #define side_field_gather_float(_name, _offset, _float_size, _access_mode, _attr...) \ | |
629 | _side_field(_name, side_type_gather_float(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
630 | #define side_field_gather_float_le(_name, _offset, _float_size, _access_mode, _attr...) \ | |
631 | _side_field(_name, side_type_gather_float_le(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
632 | #define side_field_gather_float_be(_name, _offset, _float_size, _access_mode, _attr...) \ | |
633 | _side_field(_name, side_type_gather_float_be(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
634 | ||
635 | #define _side_type_gather_string(_offset, _byte_order, _unit_size, _access_mode, _attr...) \ | |
636 | { \ | |
637 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRING), \ | |
638 | .u = { \ | |
639 | .side_gather = { \ | |
640 | .u = { \ | |
641 | .side_string = { \ | |
642 | .offset = _offset, \ | |
643 | .access_mode = _access_mode, \ | |
644 | .type = { \ | |
645 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
646 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
647 | .unit_size = _unit_size, \ | |
648 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ | |
649 | }, \ | |
650 | }, \ | |
651 | }, \ | |
652 | }, \ | |
653 | }, \ | |
654 | } | |
655 | #define side_type_gather_string(_offset, _access_mode, _attr...) \ | |
656 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
657 | #define side_field_gather_string(_name, _offset, _access_mode, _attr...) \ | |
658 | _side_field(_name, side_type_gather_string(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
659 | ||
660 | #define side_type_gather_string16(_offset, _access_mode, _attr...) \ | |
661 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
662 | #define side_type_gather_string16_le(_offset, _access_mode, _attr...) \ | |
663 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
664 | #define side_type_gather_string16_be(_offset, _access_mode, _attr...) \ | |
665 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
666 | ||
667 | #define side_field_gather_string16(_name, _offset, _access_mode, _attr...) \ | |
668 | _side_field(_name, side_type_gather_string16(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
669 | #define side_field_gather_string16_le(_name, _offset, _access_mode, _attr...) \ | |
670 | _side_field(_name, side_type_gather_string16_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
671 | #define side_field_gather_string16_be(_name, _offset, _access_mode, _attr...) \ | |
672 | _side_field(_name, side_type_gather_string16_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
673 | ||
674 | #define side_type_gather_string32(_offset, _access_mode, _attr...) \ | |
675 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
676 | #define side_type_gather_string32_le(_offset, _access_mode, _attr...) \ | |
677 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
678 | #define side_type_gather_string32_be(_offset, _access_mode, _attr...) \ | |
679 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
680 | ||
681 | #define side_field_gather_string32(_name, _offset, _access_mode, _attr...) \ | |
682 | _side_field(_name, side_type_gather_string32(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
683 | #define side_field_gather_string32_le(_name, _offset, _access_mode, _attr...) \ | |
684 | _side_field(_name, side_type_gather_string32_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
685 | #define side_field_gather_string32_be(_name, _offset, _access_mode, _attr...) \ | |
686 | _side_field(_name, side_type_gather_string32_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
687 | ||
688 | #define side_type_gather_enum(_mappings, _elem_type) \ | |
689 | { \ | |
690 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ENUM), \ | |
691 | .u = { \ | |
692 | .side_enum = { \ | |
693 | .mappings = SIDE_PTR_INIT(_mappings), \ | |
694 | .elem_type = SIDE_PTR_INIT(_elem_type), \ | |
695 | }, \ | |
696 | }, \ | |
697 | } | |
698 | #define side_field_gather_enum(_name, _mappings, _elem_type) \ | |
699 | _side_field(_name, side_type_gather_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type))) | |
700 | ||
701 | #define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \ | |
702 | { \ | |
703 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRUCT), \ | |
704 | .u = { \ | |
705 | .side_gather = { \ | |
706 | .u = { \ | |
707 | .side_struct = { \ | |
708 | .offset = _offset, \ | |
709 | .access_mode = _access_mode, \ | |
710 | .type = SIDE_PTR_INIT(_struct_gather), \ | |
711 | .size = _size, \ | |
712 | }, \ | |
713 | }, \ | |
714 | }, \ | |
715 | }, \ | |
716 | } | |
717 | #define side_field_gather_struct(_name, _struct_gather, _offset, _size, _access_mode) \ | |
718 | _side_field(_name, side_type_gather_struct(SIDE_PARAM(_struct_gather), _offset, _size, _access_mode)) | |
719 | ||
720 | #define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr...) \ | |
721 | { \ | |
722 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ARRAY), \ | |
723 | .u = { \ | |
724 | .side_gather = { \ | |
725 | .u = { \ | |
726 | .side_array = { \ | |
727 | .offset = _offset, \ | |
728 | .access_mode = _access_mode, \ | |
729 | .type = { \ | |
730 | .elem_type = SIDE_PTR_INIT(_elem_type_gather), \ | |
731 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
732 | .length = _length, \ | |
733 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
734 | }, \ | |
735 | }, \ | |
736 | }, \ | |
737 | }, \ | |
738 | }, \ | |
739 | } | |
740 | #define side_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr...) \ | |
741 | _side_field(_name, side_type_gather_array(SIDE_PARAM(_elem_type), _length, _offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
742 | ||
743 | #define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \ | |
744 | { \ | |
745 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_VLA), \ | |
746 | .u = { \ | |
747 | .side_gather = { \ | |
748 | .u = { \ | |
749 | .side_vla = { \ | |
750 | .length_type = SIDE_PTR_INIT(_length_type_gather), \ | |
751 | .offset = _offset, \ | |
752 | .access_mode = _access_mode, \ | |
753 | .type = { \ | |
754 | .elem_type = SIDE_PTR_INIT(_elem_type_gather), \ | |
755 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
756 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
757 | }, \ | |
758 | }, \ | |
759 | }, \ | |
760 | }, \ | |
761 | }, \ | |
762 | } | |
763 | #define side_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \ | |
764 | _side_field(_name, side_type_gather_vla(SIDE_PARAM(_elem_type_gather), _offset, _access_mode, SIDE_PARAM(_length_type_gather), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
765 | ||
766 | #define side_elem(...) \ | |
767 | SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__) | |
768 | ||
769 | #define side_length(...) \ | |
770 | SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__) | |
771 | ||
772 | #define side_field_list(...) \ | |
773 | SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__) | |
774 | ||
775 | #define side_option_list(...) \ | |
776 | SIDE_COMPOUND_LITERAL(const struct side_variant_option, __VA_ARGS__) | |
777 | ||
778 | /* Stack-copy field arguments */ | |
779 | ||
66d7c96a MD |
780 | #define side_arg_null(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_NULL), .flags = 0, } |
781 | #define side_arg_bool(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_BOOL), .flags = 0, .u = { .side_static = { .bool_value = { .side_bool8 = !!(_val) } } } } | |
782 | #define side_arg_byte(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_BYTE), .flags = 0, .u = { .side_static = { .byte_value = (_val) } } } | |
783 | #define side_arg_string(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF8), .flags = 0, .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } } | |
784 | #define side_arg_string16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF16), .flags = 0, .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } } | |
785 | #define side_arg_string32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF32), .flags = 0, .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } } | |
786 | ||
787 | #define side_arg_u8(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U8), .flags = 0, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } } | |
788 | #define side_arg_u16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U16), .flags = 0, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } } | |
789 | #define side_arg_u32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U32), .flags = 0, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } } | |
790 | #define side_arg_u64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U64), .flags = 0, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } } | |
791 | #define side_arg_s8(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S8), .flags = 0, .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } } | |
792 | #define side_arg_s16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S16), .flags = 0, .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } } | |
793 | #define side_arg_s32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S32), .flags = 0, .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } } | |
794 | #define side_arg_s64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S64), .flags = 0, .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } } | |
795 | #define side_arg_pointer(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_POINTER), .flags = 0, .u = { .side_static = { .integer_value = { .side_uptr = (uintptr_t) (_val) } } } } | |
796 | #define side_arg_float_binary16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY16), .flags = 0, .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } } | |
797 | #define side_arg_float_binary32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY32), .flags = 0, .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } } | |
798 | #define side_arg_float_binary64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY64), .flags = 0, .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } } | |
799 | #define side_arg_float_binary128(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY128), .flags = 0, .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } } | |
800 | ||
801 | #define side_arg_struct(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRUCT), .flags = 0, .u = { .side_static = { .side_struct = SIDE_PTR_INIT(_side_type) } } } | |
57553dfd MD |
802 | |
803 | #define side_arg_define_variant(_identifier, _selector_val, _option) \ | |
e14987e0 | 804 | const struct side_arg_variant _identifier = { \ |
57553dfd MD |
805 | .selector = _selector_val, \ |
806 | .option = _option, \ | |
807 | } | |
808 | #define side_arg_variant(_side_variant) \ | |
809 | { \ | |
810 | .type = SIDE_ENUM_INIT(SIDE_TYPE_VARIANT), \ | |
66d7c96a | 811 | .flags = 0, \ |
57553dfd MD |
812 | .u = { \ |
813 | .side_static = { \ | |
814 | .side_variant = SIDE_PTR_INIT(_side_variant), \ | |
815 | }, \ | |
816 | }, \ | |
817 | } | |
818 | ||
66d7c96a MD |
819 | #define side_arg_array(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), .flags = 0, .u = { .side_static = { .side_array = SIDE_PTR_INIT(_side_type) } } } |
820 | #define side_arg_vla(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), .flags = 0, .u = { .side_static = { .side_vla = SIDE_PTR_INIT(_side_type) } } } | |
821 | #define side_arg_vla_visitor(_ctx) { .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA_VISITOR), .flags = 0, .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } } | |
57553dfd MD |
822 | |
823 | /* Gather field arguments */ | |
824 | ||
66d7c96a MD |
825 | #define side_arg_gather_bool(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BOOL), .flags = 0, .u = { .side_static = { .side_bool_gather_ptr = SIDE_PTR_INIT(_ptr) } } } |
826 | #define side_arg_gather_byte(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BYTE), .flags = 0, .u = { .side_static = { .side_byte_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
827 | #define side_arg_gather_pointer(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_POINTER), .flags = 0, .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
828 | #define side_arg_gather_integer(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_INTEGER), .flags = 0, .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
829 | #define side_arg_gather_float(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_FLOAT), .flags = 0, .u = { .side_static = { .side_float_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
830 | #define side_arg_gather_string(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRING), .flags = 0, .u = { .side_static = { .side_string_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
831 | #define side_arg_gather_struct(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRUCT), .flags = 0, .u = { .side_static = { .side_struct_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
832 | #define side_arg_gather_array(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ARRAY), .flags = 0, .u = { .side_static = { .side_array_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
833 | #define side_arg_gather_vla(_ptr, _length_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_VLA), .flags = 0, .u = { .side_static = { .side_vla_gather = { .ptr = SIDE_PTR_INIT(_ptr), .length_ptr = SIDE_PTR_INIT(_length_ptr) } } } } | |
57553dfd MD |
834 | |
835 | /* Dynamic field arguments */ | |
836 | ||
837 | #define side_arg_dynamic_null(_attr...) \ | |
838 | { \ | |
839 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_NULL), \ | |
66d7c96a | 840 | .flags = 0, \ |
57553dfd MD |
841 | .u = { \ |
842 | .side_dynamic = { \ | |
843 | .side_null = { \ | |
844 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
845 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
846 | }, \ | |
847 | }, \ | |
848 | }, \ | |
849 | } | |
850 | ||
851 | #define side_arg_dynamic_bool(_val, _attr...) \ | |
852 | { \ | |
853 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_BOOL), \ | |
66d7c96a | 854 | .flags = 0, \ |
57553dfd MD |
855 | .u = { \ |
856 | .side_dynamic = { \ | |
857 | .side_bool = { \ | |
858 | .type = { \ | |
859 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
860 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
861 | .bool_size = sizeof(uint8_t), \ | |
862 | .len_bits = 0, \ | |
863 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ | |
864 | }, \ | |
865 | .value = { \ | |
866 | .side_bool8 = !!(_val), \ | |
867 | }, \ | |
868 | }, \ | |
869 | }, \ | |
870 | }, \ | |
871 | } | |
872 | ||
873 | #define side_arg_dynamic_byte(_val, _attr...) \ | |
874 | { \ | |
875 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_BYTE), \ | |
66d7c96a | 876 | .flags = 0, \ |
57553dfd MD |
877 | .u = { \ |
878 | .side_dynamic = { \ | |
879 | .side_byte = { \ | |
880 | .type = { \ | |
881 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
882 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
883 | }, \ | |
884 | .value = (_val), \ | |
885 | }, \ | |
886 | }, \ | |
887 | }, \ | |
888 | } | |
889 | ||
890 | #define _side_arg_dynamic_string(_val, _byte_order, _unit_size, _attr...) \ | |
891 | { \ | |
892 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRING), \ | |
66d7c96a | 893 | .flags = 0, \ |
57553dfd MD |
894 | .u = { \ |
895 | .side_dynamic = { \ | |
896 | .side_string = { \ | |
897 | .type = { \ | |
898 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
899 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
900 | .unit_size = _unit_size, \ | |
901 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ | |
902 | }, \ | |
903 | .value = (uintptr_t) (_val), \ | |
904 | }, \ | |
905 | }, \ | |
906 | }, \ | |
907 | } | |
908 | #define side_arg_dynamic_string(_val, _attr...) \ | |
909 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
910 | #define side_arg_dynamic_string16(_val, _attr...) \ | |
911 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
912 | #define side_arg_dynamic_string16_le(_val, _attr...) \ | |
913 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
914 | #define side_arg_dynamic_string16_be(_val, _attr...) \ | |
915 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
916 | #define side_arg_dynamic_string32(_val, _attr...) \ | |
917 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
918 | #define side_arg_dynamic_string32_le(_val, _attr...) \ | |
919 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
920 | #define side_arg_dynamic_string32_be(_val, _attr...) \ | |
921 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
922 | ||
923 | #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size, _len_bits, _attr...) \ | |
924 | { \ | |
925 | .type = SIDE_ENUM_INIT(_type), \ | |
66d7c96a | 926 | .flags = 0, \ |
57553dfd MD |
927 | .u = { \ |
928 | .side_dynamic = { \ | |
929 | .side_integer = { \ | |
930 | .type = { \ | |
931 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
932 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
933 | .integer_size = _integer_size, \ | |
934 | .len_bits = _len_bits, \ | |
935 | .signedness = _signedness, \ | |
936 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ | |
937 | }, \ | |
938 | .value = { \ | |
939 | _field = (_val), \ | |
940 | }, \ | |
941 | }, \ | |
942 | }, \ | |
943 | }, \ | |
944 | } | |
945 | ||
946 | #define side_arg_dynamic_u8(_val, _attr...) \ | |
947 | _side_arg_dynamic_integer(.side_u8, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
948 | #define side_arg_dynamic_s8(_val, _attr...) \ | |
949 | _side_arg_dynamic_integer(.side_s8, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
950 | ||
951 | #define _side_arg_dynamic_u16(_val, _byte_order, _attr...) \ | |
952 | _side_arg_dynamic_integer(.side_u16, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
953 | #define _side_arg_dynamic_u32(_val, _byte_order, _attr...) \ | |
954 | _side_arg_dynamic_integer(.side_u32, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
955 | #define _side_arg_dynamic_u64(_val, _byte_order, _attr...) \ | |
956 | _side_arg_dynamic_integer(.side_u64, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
957 | ||
958 | #define _side_arg_dynamic_s16(_val, _byte_order, _attr...) \ | |
959 | _side_arg_dynamic_integer(.side_s16, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
960 | #define _side_arg_dynamic_s32(_val, _byte_order, _attr...) \ | |
961 | _side_arg_dynamic_integer(.side_s32, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
962 | #define _side_arg_dynamic_s64(_val, _byte_order, _attr...) \ | |
963 | _side_arg_dynamic_integer(.side_s64, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
964 | ||
965 | #define _side_arg_dynamic_pointer(_val, _byte_order, _attr...) \ | |
966 | _side_arg_dynamic_integer(.side_uptr, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER, false, _byte_order, \ | |
967 | sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
968 | ||
969 | #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size, _attr...) \ | |
970 | { \ | |
971 | .type = SIDE_ENUM_INIT(_type), \ | |
66d7c96a | 972 | .flags = 0, \ |
57553dfd MD |
973 | .u = { \ |
974 | .side_dynamic = { \ | |
975 | .side_float = { \ | |
976 | .type = { \ | |
977 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
978 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
979 | .float_size = _float_size, \ | |
980 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ | |
981 | }, \ | |
982 | .value = { \ | |
983 | _field = (_val), \ | |
984 | }, \ | |
985 | }, \ | |
986 | }, \ | |
987 | }, \ | |
988 | } | |
989 | ||
990 | #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr...) \ | |
991 | _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
992 | #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr...) \ | |
993 | _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
994 | #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr...) \ | |
995 | _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
996 | #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr...) \ | |
997 | _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
998 | ||
999 | /* Host endian */ | |
1000 | #define side_arg_dynamic_u16(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1001 | #define side_arg_dynamic_u32(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1002 | #define side_arg_dynamic_u64(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1003 | #define side_arg_dynamic_s16(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1004 | #define side_arg_dynamic_s32(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1005 | #define side_arg_dynamic_s64(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1006 | #define side_arg_dynamic_pointer(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1007 | #define side_arg_dynamic_float_binary16(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1008 | #define side_arg_dynamic_float_binary32(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1009 | #define side_arg_dynamic_float_binary64(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1010 | #define side_arg_dynamic_float_binary128(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1011 | ||
1012 | /* Little endian */ | |
1013 | #define side_arg_dynamic_u16_le(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1014 | #define side_arg_dynamic_u32_le(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1015 | #define side_arg_dynamic_u64_le(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1016 | #define side_arg_dynamic_s16_le(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1017 | #define side_arg_dynamic_s32_le(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1018 | #define side_arg_dynamic_s64_le(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1019 | #define side_arg_dynamic_pointer_le(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1020 | #define side_arg_dynamic_float_binary16_le(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1021 | #define side_arg_dynamic_float_binary32_le(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1022 | #define side_arg_dynamic_float_binary64_le(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1023 | #define side_arg_dynamic_float_binary128_le(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1024 | ||
1025 | /* Big endian */ | |
1026 | #define side_arg_dynamic_u16_be(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1027 | #define side_arg_dynamic_u32_be(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1028 | #define side_arg_dynamic_u64_be(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1029 | #define side_arg_dynamic_s16_be(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1030 | #define side_arg_dynamic_s32_be(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1031 | #define side_arg_dynamic_s64_be(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1032 | #define side_arg_dynamic_pointer_be(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1033 | #define side_arg_dynamic_float_binary16_be(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1034 | #define side_arg_dynamic_float_binary32_be(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1035 | #define side_arg_dynamic_float_binary64_be(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1036 | #define side_arg_dynamic_float_binary128_be(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1037 | ||
1038 | #define side_arg_dynamic_vla(_vla) \ | |
1039 | { \ | |
1040 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_VLA), \ | |
66d7c96a | 1041 | .flags = 0, \ |
57553dfd MD |
1042 | .u = { \ |
1043 | .side_dynamic = { \ | |
1044 | .side_dynamic_vla = SIDE_PTR_INIT(_vla), \ | |
1045 | }, \ | |
1046 | }, \ | |
1047 | } | |
1048 | ||
1049 | #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr...) \ | |
1050 | { \ | |
1051 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_VLA_VISITOR), \ | |
66d7c96a | 1052 | .flags = 0, \ |
57553dfd MD |
1053 | .u = { \ |
1054 | .side_dynamic = { \ | |
1055 | .side_dynamic_vla_visitor = { \ | |
1056 | .app_ctx = SIDE_PTR_INIT(_ctx), \ | |
1057 | .visitor = SIDE_PTR_INIT(_dynamic_vla_visitor), \ | |
1058 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
1059 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
1060 | }, \ | |
1061 | }, \ | |
1062 | }, \ | |
1063 | } | |
1064 | ||
1065 | #define side_arg_dynamic_struct(_struct) \ | |
1066 | { \ | |
1067 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRUCT), \ | |
66d7c96a | 1068 | .flags = 0, \ |
57553dfd MD |
1069 | .u = { \ |
1070 | .side_dynamic = { \ | |
1071 | .side_dynamic_struct = SIDE_PTR_INIT(_struct), \ | |
1072 | }, \ | |
1073 | }, \ | |
1074 | } | |
1075 | ||
1076 | #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr...) \ | |
1077 | { \ | |
1078 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRUCT_VISITOR), \ | |
66d7c96a | 1079 | .flags = 0, \ |
57553dfd MD |
1080 | .u = { \ |
1081 | .side_dynamic = { \ | |
1082 | .side_dynamic_struct_visitor = { \ | |
1083 | .app_ctx = SIDE_PTR_INIT(_ctx), \ | |
1084 | .visitor = SIDE_PTR_INIT(_dynamic_struct_visitor), \ | |
1085 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
1086 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
1087 | }, \ | |
1088 | }, \ | |
1089 | }, \ | |
1090 | } | |
1091 | ||
1092 | #define side_arg_dynamic_define_vec(_identifier, _sav, _attr...) \ | |
e14987e0 | 1093 | const struct side_arg _identifier##_vec[] = { _sav }; \ |
57553dfd MD |
1094 | const struct side_arg_dynamic_vla _identifier = { \ |
1095 | .sav = SIDE_PTR_INIT(_identifier##_vec), \ | |
1096 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
1097 | .len = SIDE_ARRAY_SIZE(_identifier##_vec), \ | |
1098 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
1099 | } | |
1100 | ||
1101 | #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr...) \ | |
e14987e0 | 1102 | const struct side_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \ |
57553dfd MD |
1103 | const struct side_arg_dynamic_struct _identifier = { \ |
1104 | .fields = SIDE_PTR_INIT(_identifier##_fields), \ | |
1105 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
1106 | .len = SIDE_ARRAY_SIZE(_identifier##_fields), \ | |
1107 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
1108 | } | |
1109 | ||
1110 | #define side_arg_define_vec(_identifier, _sav) \ | |
e14987e0 | 1111 | const struct side_arg _identifier##_vec[] = { _sav }; \ |
57553dfd MD |
1112 | const struct side_arg_vec _identifier = { \ |
1113 | .sav = SIDE_PTR_INIT(_identifier##_vec), \ | |
1114 | .len = SIDE_ARRAY_SIZE(_identifier##_vec), \ | |
1115 | } | |
1116 | ||
1117 | #define side_arg_dynamic_field(_name, _elem) \ | |
1118 | { \ | |
1119 | .field_name = SIDE_PTR_INIT(_name), \ | |
1120 | .elem = _elem, \ | |
1121 | } | |
1122 | ||
1123 | /* | |
1124 | * Event instrumentation description registration, runtime enabled state | |
1125 | * check, and instrumentation invocation. | |
1126 | */ | |
1127 | ||
1128 | #define side_arg_list(...) __VA_ARGS__ | |
1129 | ||
1130 | #define side_event_cond(_identifier) \ | |
1131 | if (side_unlikely(__atomic_load_n(&side_event_state__##_identifier.enabled, \ | |
1132 | __ATOMIC_RELAXED))) | |
1133 | ||
1134 | #define side_event_call(_identifier, _sav) \ | |
1135 | { \ | |
e14987e0 | 1136 | const struct side_arg side_sav[] = { _sav }; \ |
57553dfd MD |
1137 | const struct side_arg_vec side_arg_vec = { \ |
1138 | .sav = SIDE_PTR_INIT(side_sav), \ | |
1139 | .len = SIDE_ARRAY_SIZE(side_sav), \ | |
1140 | }; \ | |
49aea3ef | 1141 | side_call(&(side_event_state__##_identifier).parent, &side_arg_vec); \ |
57553dfd MD |
1142 | } |
1143 | ||
1144 | #define side_event(_identifier, _sav) \ | |
1145 | side_event_cond(_identifier) \ | |
1146 | side_event_call(_identifier, SIDE_PARAM(_sav)) | |
1147 | ||
1148 | #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr...) \ | |
1149 | { \ | |
e14987e0 | 1150 | const struct side_arg side_sav[] = { _sav }; \ |
57553dfd MD |
1151 | const struct side_arg_vec side_arg_vec = { \ |
1152 | .sav = SIDE_PTR_INIT(side_sav), \ | |
1153 | .len = SIDE_ARRAY_SIZE(side_sav), \ | |
1154 | }; \ | |
e14987e0 | 1155 | const struct side_arg_dynamic_field side_fields[] = { _var_fields }; \ |
57553dfd MD |
1156 | const struct side_arg_dynamic_struct var_struct = { \ |
1157 | .fields = SIDE_PTR_INIT(side_fields), \ | |
1158 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
1159 | .len = SIDE_ARRAY_SIZE(side_fields), \ | |
1160 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
1161 | }; \ | |
49aea3ef | 1162 | side_call_variadic(&(side_event_state__##_identifier.parent), &side_arg_vec, &var_struct); \ |
57553dfd MD |
1163 | } |
1164 | ||
1165 | #define side_event_variadic(_identifier, _sav, _var, _attr...) \ | |
1166 | side_event_cond(_identifier) \ | |
1167 | side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1168 | ||
1169 | #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _flags, _attr...) \ | |
1170 | _linkage struct side_event_description __attribute__((section("side_event_description"))) \ | |
1171 | _identifier; \ | |
1172 | _linkage struct side_event_state_0 __attribute__((section("side_event_state"))) \ | |
1173 | side_event_state__##_identifier = { \ | |
49aea3ef | 1174 | .parent = { \ |
57553dfd MD |
1175 | .version = SIDE_EVENT_STATE_ABI_VERSION, \ |
1176 | }, \ | |
3cac1780 | 1177 | .nr_callbacks = 0, \ |
57553dfd | 1178 | .enabled = 0, \ |
867b4725 | 1179 | .callbacks = (const struct side_callback *) &side_empty_callback[0], \ |
7269a8a3 | 1180 | .desc = &(_identifier), \ |
57553dfd MD |
1181 | }; \ |
1182 | _linkage struct side_event_description __attribute__((section("side_event_description"))) \ | |
1183 | _identifier = { \ | |
1184 | .struct_size = offsetof(struct side_event_description, end), \ | |
1185 | .version = SIDE_EVENT_DESCRIPTION_ABI_VERSION, \ | |
49aea3ef | 1186 | .state = SIDE_PTR_INIT(&(side_event_state__##_identifier.parent)), \ |
57553dfd MD |
1187 | .provider_name = SIDE_PTR_INIT(_provider), \ |
1188 | .event_name = SIDE_PTR_INIT(_event), \ | |
1189 | .fields = SIDE_PTR_INIT(_fields), \ | |
1190 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
1191 | .flags = (_flags), \ | |
1192 | .nr_side_type_label = _NR_SIDE_TYPE_LABEL, \ | |
1193 | .nr_side_attr_type = _NR_SIDE_ATTR_TYPE, \ | |
1194 | .loglevel = SIDE_ENUM_INIT(_loglevel), \ | |
1195 | .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ | |
1196 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ | |
57553dfd MD |
1197 | }; \ |
1198 | static const struct side_event_description *side_event_ptr__##_identifier \ | |
1199 | __attribute__((section("side_event_description_ptr"), used)) = &(_identifier); | |
1200 | ||
1201 | #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ | |
1202 | _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ | |
1203 | 0, ##_attr) | |
1204 | ||
1205 | #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ | |
1206 | _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ | |
1207 | SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1208 | ||
1209 | #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ | |
1210 | _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \ | |
1211 | _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1212 | ||
1213 | #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ | |
1214 | _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \ | |
1215 | _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1216 | ||
1217 | #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ | |
1218 | _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \ | |
1219 | _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1220 | ||
1221 | #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ | |
1222 | _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \ | |
1223 | _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1224 | ||
1225 | #define side_declare_event(_identifier) \ | |
1226 | extern struct side_event_state_0 side_event_state_##_identifier; \ | |
1227 | extern struct side_event_description _identifier | |
1228 | ||
1229 | #endif /* SIDE_INSTRUMENTATION_C_API_H */ |