SIDE_TYPE_FLOAT_BINARY128,
SIDE_TYPE_STRING,
- /* Enumeration types */
- SIDE_TYPE_ENUM_U8,
- SIDE_TYPE_ENUM_U16,
- SIDE_TYPE_ENUM_U32,
- SIDE_TYPE_ENUM_U64,
- SIDE_TYPE_ENUM_S8,
- SIDE_TYPE_ENUM_S16,
- SIDE_TYPE_ENUM_S32,
- SIDE_TYPE_ENUM_S64,
-
- SIDE_TYPE_ENUM_BITMAP8,
- SIDE_TYPE_ENUM_BITMAP16,
- SIDE_TYPE_ENUM_BITMAP32,
- SIDE_TYPE_ENUM_BITMAP64,
-
/* Compound types */
SIDE_TYPE_STRUCT,
SIDE_TYPE_ARRAY,
SIDE_TYPE_VLA_S64,
SIDE_TYPE_VLA_BLOB,
+ /* Enumeration types */
+ SIDE_TYPE_ENUM_U8,
+ SIDE_TYPE_ENUM_U16,
+ SIDE_TYPE_ENUM_U32,
+ SIDE_TYPE_ENUM_U64,
+ SIDE_TYPE_ENUM_S8,
+ SIDE_TYPE_ENUM_S16,
+ SIDE_TYPE_ENUM_S32,
+ SIDE_TYPE_ENUM_S64,
+
+ SIDE_TYPE_ENUM_BITMAP8,
+ SIDE_TYPE_ENUM_BITMAP16,
+ SIDE_TYPE_ENUM_BITMAP32,
+ SIDE_TYPE_ENUM_BITMAP64,
+
+ SIDE_TYPE_ENUM_BITMAP_ARRAY,
+ SIDE_TYPE_ENUM_BITMAP_VLA,
+
/* Dynamic type */
SIDE_TYPE_DYNAMIC,
};
uint32_t nr_attr;
} side_basic;
- /* Enumeration types */
- const struct side_enum_mappings *side_enum_mappings;
- const struct side_enum_bitmap_mappings *side_enum_bitmap_mappings;
-
/* Compound types */
struct {
const struct side_type_description *elem_type;
uint32_t nr_attr;
} side_vla_visitor;
const struct side_type_struct *side_struct;
+
+ /* Enumeration types */
+ const struct side_enum_mappings *side_enum_mappings;
+ const struct side_enum_bitmap_mappings *side_enum_bitmap_mappings;
+ struct {
+ const struct side_type_description *elem_type;
+ const struct side_enum_bitmap_mappings *mappings;
+ uint32_t length;
+ } side_enum_bitmap_array;
+ struct {
+ const struct side_type_description *elem_type;
+ const struct side_enum_bitmap_mappings *mappings;
+ } side_enum_bitmap_vla;
} u;
};
.side_enum_bitmap_mappings = _mappings, \
}, \
}
-#define _side_field_enum_bitmap(_name, _type, _mappings) \
- _side_field(_name, side_type_enum_bitmap(_type, SIDE_PARAM(_mappings)))
+#define side_type_enum_bitmap8(_mappings) \
+ side_type_enum_bitmap(SIDE_TYPE_ENUM_BITMAP8, SIDE_PARAM(_mappings))
+#define side_type_enum_bitmap16(_mappings) \
+ side_type_enum_bitmap(SIDE_TYPE_ENUM_BITMAP16, SIDE_PARAM(_mappings))
+#define side_type_enum_bitmap32(_mappings) \
+ side_type_enum_bitmap(SIDE_TYPE_ENUM_BITMAP32, SIDE_PARAM(_mappings))
+#define side_type_enum_bitmap64(_mappings) \
+ side_type_enum_bitmap(SIDE_TYPE_ENUM_BITMAP64, SIDE_PARAM(_mappings))
+
+#define _side_field_enum_bitmap(_name, _type) _side_field(_name, SIDE_PARAM(_type))
#define side_field_enum_bitmap8(_name, _mappings) \
- _side_field_enum_bitmap(_name, SIDE_TYPE_ENUM_BITMAP8, SIDE_PARAM(_mappings))
+ _side_field_enum_bitmap(_name, side_type_enum_bitmap8(SIDE_PARAM(_mappings)))
#define side_field_enum_bitmap16(_name, _mappings) \
- _side_field_enum_bitmap(_name, SIDE_TYPE_ENUM_BITMAP16, SIDE_PARAM(_mappings))
+ _side_field_enum_bitmap(_name, side_type_enum_bitmap16(SIDE_PARAM(_mappings)))
#define side_field_enum_bitmap32(_name, _mappings) \
- _side_field_enum_bitmap(_name, SIDE_TYPE_ENUM_BITMAP32, SIDE_PARAM(_mappings))
+ _side_field_enum_bitmap(_name, side_type_enum_bitmap32(SIDE_PARAM(_mappings)))
#define side_field_enum_bitmap64(_name, _mappings) \
- _side_field_enum_bitmap(_name, SIDE_TYPE_ENUM_BITMAP64, SIDE_PARAM(_mappings))
+ _side_field_enum_bitmap(_name, side_type_enum_bitmap64(SIDE_PARAM(_mappings)))
+
+#define side_type_enum_bitmap_array(_mappings, _elem_type, _length) \
+ { \
+ .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, \
+ .u = { \
+ .side_enum_bitmap_array = { \
+ .elem_type = _elem_type, \
+ .mappings = _mappings, \
+ .length = _length, \
+ }, \
+ }, \
+ }
+#define side_field_enum_bitmap_array(_name, _mappings, _elem_type, _length) \
+ _side_field(_name, side_type_enum_bitmap_array(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type), _length))
+
+#define side_type_enum_bitmap_vla(_mappings, _elem_type) \
+ { \
+ .type = SIDE_TYPE_ENUM_BITMAP_VLA, \
+ .u = { \
+ .side_enum_bitmap_vla = { \
+ .elem_type = _elem_type, \
+ .mappings = _mappings, \
+ }, \
+ }, \
+ }
+#define side_field_enum_bitmap_vla(_name, _mappings, _elem_type) \
+ _side_field(_name, side_type_enum_bitmap_vla(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
#define side_type_struct(_struct) \
{ \
#define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
#define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
#define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
+#define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
+#define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
#define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
#define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
#define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
side_enum_bitmap_mapping_value("3", 3),
side_enum_bitmap_mapping_value("30", 30),
side_enum_bitmap_mapping_value("63", 63),
+ side_enum_bitmap_mapping_range("158-160", 158, 160),
+ side_enum_bitmap_mapping_value("159", 159),
+ side_enum_bitmap_mapping_range("500-700", 500, 700),
),
side_attr_list()
);
side_field_enum_bitmap32("bit_31", &myenum_bitmap),
side_field_enum_bitmap64("bit_63", &myenum_bitmap),
side_field_enum_bitmap64("bits_1+63", &myenum_bitmap),
+ side_field_enum_bitmap_array("bit_159", &myenum_bitmap,
+ side_elem(side_type_u32(side_attr_list())), 5),
+ side_field_enum_bitmap_vla("bit_159", &myenum_bitmap,
+ side_elem(side_type_u32(side_attr_list()))),
),
side_attr_list()
);
void test_enum_bitmap(void)
{
my_provider_event_enum_bitmap_enabled = 1;
- side_event(my_provider_event_enum_bitmap,
- side_arg_list(
- side_arg_enum_bitmap32(1 << 0),
- side_arg_enum_bitmap32(1 << 1),
- side_arg_enum_bitmap8(1 << 2),
- side_arg_enum_bitmap8(1 << 3),
- side_arg_enum_bitmap32(1 << 30),
- side_arg_enum_bitmap32(1 << 31),
- side_arg_enum_bitmap64(1ULL << 63),
- side_arg_enum_bitmap64((1ULL << 1) | (1ULL << 63)),
- )
- );
+ side_event_cond(my_provider_event_enum_bitmap) {
+ side_arg_define_vec(myarray,
+ side_arg_list(
+ side_arg_u32(0),
+ side_arg_u32(0),
+ side_arg_u32(0),
+ side_arg_u32(0),
+ side_arg_u32(0x80000000), /* bit 159 */
+ )
+ );
+ side_event_call(my_provider_event_enum_bitmap,
+ side_arg_list(
+ side_arg_enum_bitmap32(1 << 0),
+ side_arg_enum_bitmap32(1 << 1),
+ side_arg_enum_bitmap8(1 << 2),
+ side_arg_enum_bitmap8(1 << 3),
+ side_arg_enum_bitmap32(1 << 30),
+ side_arg_enum_bitmap32(1 << 31),
+ side_arg_enum_bitmap64(1ULL << 63),
+ side_arg_enum_bitmap64((1ULL << 1) | (1ULL << 63)),
+ side_arg_enum_bitmap_array(&myarray),
+ side_arg_enum_bitmap_vla(&myarray),
+ )
+ );
+ }
}
static uint8_t blob_fixint[] = { 0x55, 0x44, 0x33, 0x22, 0x11 };
}
static
-void print_enum_bitmap(const struct side_enum_bitmap_mappings *side_enum_mappings, uint64_t value)
+uint32_t enum_type_to_stride(const struct side_type_description *type_desc)
{
+ uint32_t stride_bit;
+
+ switch (type_desc->type) {
+ case SIDE_TYPE_ENUM_BITMAP8:
+ case SIDE_TYPE_U8:
+ case SIDE_TYPE_S8:
+ stride_bit = 8;
+ break;
+ case SIDE_TYPE_ENUM_BITMAP16:
+ case SIDE_TYPE_U16:
+ case SIDE_TYPE_S16:
+ stride_bit = 16;
+ break;
+ case SIDE_TYPE_ENUM_BITMAP32:
+ case SIDE_TYPE_U32:
+ case SIDE_TYPE_S32:
+ stride_bit = 32;
+ break;
+ case SIDE_TYPE_ENUM_BITMAP64:
+ case SIDE_TYPE_U64:
+ case SIDE_TYPE_S64:
+ stride_bit = 64;
+ break;
+ case SIDE_TYPE_ENUM_BITMAP_ARRAY:
+ stride_bit = enum_type_to_stride(type_desc->u.side_enum_bitmap_array.elem_type);
+ break;
+ case SIDE_TYPE_ENUM_BITMAP_VLA:
+ stride_bit = enum_type_to_stride(type_desc->u.side_enum_bitmap_vla.elem_type);
+ break;
+ default:
+ abort();
+ }
+ return stride_bit;
+}
+
+static
+void print_enum_bitmap(const struct side_type_description *type_desc,
+ const struct side_arg_vec *item)
+{
+ const struct side_enum_bitmap_mappings *side_enum_mappings;
int i, print_count = 0;
+ uint32_t stride_bit, nr_items;
+ const struct side_arg_vec *array_item;
+
+ stride_bit = enum_type_to_stride(type_desc);
+
+ switch (type_desc->type) {
+ case SIDE_TYPE_ENUM_BITMAP8: /* Fall-through */
+ case SIDE_TYPE_ENUM_BITMAP16: /* Fall-through */
+ case SIDE_TYPE_ENUM_BITMAP32: /* Fall-through */
+ case SIDE_TYPE_ENUM_BITMAP64:
+ array_item = item;
+ nr_items = 1;
+ side_enum_mappings = type_desc->u.side_enum_bitmap_mappings;
+ break;
+ case SIDE_TYPE_ENUM_BITMAP_ARRAY:
+ nr_items = type_desc->u.side_enum_bitmap_array.length;
+ array_item = item->u.side_array->sav;
+ side_enum_mappings = type_desc->u.side_enum_bitmap_array.mappings;
+ break;
+ case SIDE_TYPE_ENUM_BITMAP_VLA:
+ nr_items = item->u.side_vla->len;
+ array_item = item->u.side_vla->sav;
+ side_enum_mappings = type_desc->u.side_enum_bitmap_vla.mappings;
+ break;
+ default:
+ abort();
+ }
print_attributes("attr: ", side_enum_mappings->attr, side_enum_mappings->nr_attr);
printf("%s", side_enum_mappings->nr_attr ? ", " : "");
- printf("value: 0x%" PRIx64 ", labels: [ ", value);
+ printf("labels: [ ");
for (i = 0; i < side_enum_mappings->nr_mappings; i++) {
const struct side_enum_bitmap_mapping *mapping = &side_enum_mappings->mappings[i];
bool match = false;
int64_t bit;
- if (mapping->range_begin < 0 || mapping->range_end > 63
- || mapping->range_end < mapping->range_begin) {
+ if (mapping->range_begin < 0 || mapping->range_end < mapping->range_begin) {
printf("ERROR: Unexpected enum bitmap range: %" PRIu64 "-%" PRIu64 "\n",
mapping->range_begin, mapping->range_end);
abort();
}
for (bit = mapping->range_begin; bit <= mapping->range_end; bit++) {
- if (value & (1ULL << bit)) {
- match = true;
+ if (bit > (nr_items * stride_bit) - 1)
+ break;
+ switch (stride_bit) {
+ case 8:
+ {
+ uint8_t v = array_item[bit / 8].u.side_u8;
+ if (v & (1ULL << (bit % 8))) {
+ match = true;
+ goto match;
+ }
+ break;
+ }
+ case 16:
+ {
+ uint16_t v = array_item[bit / 16].u.side_u16;
+ if (v & (1ULL << (bit % 16))) {
+ match = true;
+ goto match;
+ }
+ break;
+ }
+ case 32:
+ {
+ uint32_t v = array_item[bit / 32].u.side_u32;
+ if (v & (1ULL << (bit % 32))) {
+ match = true;
+ goto match;
+ }
break;
}
+ case 64:
+ {
+ uint64_t v = array_item[bit / 64].u.side_u64;
+ if (v & (1ULL << (bit % 64))) {
+ match = true;
+ goto match;
+ }
+ break;
+ }
+ default:
+ abort();
+ }
}
+match:
if (match) {
printf("%s", print_count++ ? ", " : "");
printf("\"%s\"", mapping->label);
item->u.side_s64);
break;
- case SIDE_TYPE_ENUM_BITMAP8:
- print_enum_bitmap(type_desc->u.side_enum_bitmap_mappings,
- (uint64_t) item->u.side_u8);
- break;
- case SIDE_TYPE_ENUM_BITMAP16:
- print_enum_bitmap(type_desc->u.side_enum_bitmap_mappings,
- (uint64_t) item->u.side_u16);
- break;
- case SIDE_TYPE_ENUM_BITMAP32:
- print_enum_bitmap(type_desc->u.side_enum_bitmap_mappings,
- (uint64_t) item->u.side_u32);
- break;
+ case SIDE_TYPE_ENUM_BITMAP8: /* Fall-through */
+ case SIDE_TYPE_ENUM_BITMAP16: /* Fall-through */
+ case SIDE_TYPE_ENUM_BITMAP32: /* Fall-through */
case SIDE_TYPE_ENUM_BITMAP64:
- print_enum_bitmap(type_desc->u.side_enum_bitmap_mappings,
- item->u.side_u64);
+ case SIDE_TYPE_ENUM_BITMAP_ARRAY:
+ case SIDE_TYPE_ENUM_BITMAP_VLA:
+ print_enum_bitmap(type_desc, item);
break;
case SIDE_TYPE_FLOAT_BINARY16: