//fixed forever, or think of a scheme that would allow their binary
//representation to be extended if need be.
-//TODO: enum bitmap
-
struct side_arg_vec;
struct side_arg_vec_description;
struct side_arg_dynamic_vec;
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_FLOAT_BINARY16,
SIDE_TYPE_FLOAT_BINARY32,
SIDE_TYPE_FLOAT_BINARY64,
#define side_arg_enum_s16(val) { .type = SIDE_TYPE_ENUM_S16, .u = { .side_s16 = (val) } }
#define side_arg_enum_s32(val) { .type = SIDE_TYPE_ENUM_S32, .u = { .side_s32 = (val) } }
#define side_arg_enum_s64(val) { .type = SIDE_TYPE_ENUM_S64, .u = { .side_s64 = (val) } }
+#define side_arg_enum_bitmap8(val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (val) } }
+#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_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) } }
);
}
+/* A bitmap enum maps bits to labels. */
+static side_define_enum(myenum_bitmap,
+ side_mapping_list(
+ side_enum_mapping_value("0", 0),
+ side_enum_mapping_range("1-2", 1, 2),
+ side_enum_mapping_range("2-4", 2, 4),
+ side_enum_mapping_value("3", 3),
+ side_enum_mapping_value("30", 30),
+ side_enum_mapping_value("63", 63),
+ )
+);
+
+static side_define_event(my_provider_event_enum_bitmap, "myprovider", "myeventenumbitmap", SIDE_LOGLEVEL_DEBUG,
+ side_field_list(
+ side_field_enum("bit_0", SIDE_TYPE_ENUM_BITMAP32, &myenum_bitmap, side_attr_list()),
+ side_field_enum("bit_1", SIDE_TYPE_ENUM_BITMAP32, &myenum_bitmap, side_attr_list()),
+ side_field_enum("bit_2", SIDE_TYPE_ENUM_BITMAP8, &myenum_bitmap, side_attr_list()),
+ side_field_enum("bit_3", SIDE_TYPE_ENUM_BITMAP8, &myenum_bitmap, side_attr_list()),
+ side_field_enum("bit_30", SIDE_TYPE_ENUM_BITMAP32, &myenum_bitmap, side_attr_list()),
+ side_field_enum("bit_31", SIDE_TYPE_ENUM_BITMAP32, &myenum_bitmap, side_attr_list()),
+ side_field_enum("bit_63", SIDE_TYPE_ENUM_BITMAP64, &myenum_bitmap, side_attr_list()),
+ side_field_enum("bits_1+63", SIDE_TYPE_ENUM_BITMAP64, &myenum_bitmap, side_attr_list()),
+ ),
+ side_attr_list()
+);
+
+static
+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)),
+ )
+ );
+}
+
+
int main()
{
test_fields();
test_float();
test_variadic_float();
test_enum();
+ test_enum_bitmap();
return 0;
}
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
+#include <stdbool.h>
#include <side/trace.h>
for (i = 0; i < side_enum_mappings->nr_mappings; i++) {
const struct side_enum_mapping *mapping = &side_enum_mappings->mappings[i];
+ if (mapping->range_end < mapping->range_begin) {
+ printf("ERROR: Unexpected enum range: %" PRIu64 "-%" PRIu64 "\n",
+ mapping->range_begin, mapping->range_end);
+ abort();
+ }
if (value >= mapping->range_begin && value <= mapping->range_end) {
printf("%s", print_count++ ? ", " : "");
printf("\"%s\"", mapping->label);
printf(" ]");
}
+static
+void print_enum_bitmap(const struct side_enum_mappings *side_enum_mappings, uint64_t value)
+{
+ int i, print_count = 0;
+
+ printf("0x%" PRIx64 ", labels: [ ", value);
+ for (i = 0; i < side_enum_mappings->nr_mappings; i++) {
+ const struct side_enum_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) {
+ 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;
+ break;
+ }
+ }
+ if (match) {
+ printf("%s", print_count++ ? ", " : "");
+ printf("\"%s\"", mapping->label);
+ }
+ }
+ if (!print_count)
+ printf("<NO LABEL>");
+ printf(" ]");
+}
+
static
void tracer_print_type(const struct side_type_description *type_desc, const struct side_arg_vec *item)
{
item->u.side_s64);
break;
+ case SIDE_TYPE_ENUM_BITMAP8:
+ print_enum_bitmap(type_desc->u.side_enum_mappings,
+ (uint64_t) item->u.side_u8);
+ break;
+ case SIDE_TYPE_ENUM_BITMAP16:
+ print_enum_bitmap(type_desc->u.side_enum_mappings,
+ (uint64_t) item->u.side_u16);
+ break;
+ case SIDE_TYPE_ENUM_BITMAP32:
+ print_enum_bitmap(type_desc->u.side_enum_mappings,
+ (uint64_t) item->u.side_u32);
+ break;
+ case SIDE_TYPE_ENUM_BITMAP64:
+ print_enum_bitmap(type_desc->u.side_enum_mappings,
+ item->u.side_u64);
+ break;
+
case SIDE_TYPE_FLOAT_BINARY16:
#if __HAVE_FLOAT16
printf("%g", (double) item->u.side_float_binary16);