SIDE_TYPE_S16,
SIDE_TYPE_S32,
SIDE_TYPE_S64,
+
SIDE_TYPE_STRING,
SIDE_TYPE_DYNAMIC,
SIDE_TYPE_STRUCT,
SIDE_TYPE_ARRAY,
SIDE_TYPE_VLA,
SIDE_TYPE_VLA_VISITOR,
+
+ SIDE_TYPE_ARRAY_U8,
+ SIDE_TYPE_ARRAY_U16,
+ SIDE_TYPE_ARRAY_U32,
+ SIDE_TYPE_ARRAY_U64,
+ SIDE_TYPE_ARRAY_S8,
+ SIDE_TYPE_ARRAY_S16,
+ SIDE_TYPE_ARRAY_S32,
+ SIDE_TYPE_ARRAY_S64,
+
//TODO:
- //specialized array and vla for fixed-size integers (optimization)
+ //specialized vla for fixed-size integers (optimization)
//variants (discriminated unions)
};
int16_t side_s16;
int32_t side_s32;
int64_t side_s64;
+
const char *string;
const struct side_arg_vec_description *side_struct;
const struct side_arg_vec_description *side_array;
const struct side_arg_vec_description *side_vla;
void *side_vla_visitor_ctx;
+
+ void *side_array_fixint;
} u;
};
#define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
#define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_visitor_ctx = (_ctx) } }
+#define side_arg_array_u8(ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (ptr) } }
+#define side_arg_array_u16(ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (ptr) } }
+#define side_arg_array_u32(ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (ptr) } }
+#define side_arg_array_u64(ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (ptr) } }
+#define side_arg_array_s8(ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (ptr) } }
+#define side_arg_array_s16(ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (ptr) } }
+#define side_arg_array_s32(ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (ptr) } }
+#define side_arg_array_s64(ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (ptr) } }
+
#define side_arg_define_vec(_identifier, _sav) \
const struct side_arg_vec _identifier##_vec[] = { _sav }; \
const struct side_arg_vec_description _identifier = { \
void tracer_print_vla(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc);
static
void tracer_print_vla_visitor(const struct side_type_description *type_desc, void *ctx);
+static
+void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item);
static
void tracer_print_type(const struct side_type_description *type_desc, const struct side_arg_vec *item)
{
- if (type_desc->type != SIDE_TYPE_DYNAMIC && type_desc->type != item->type) {
- printf("ERROR: type mismatch between description and arguments\n");
- abort();
+ switch (item->type) {
+ case SIDE_TYPE_ARRAY_U8:
+ case SIDE_TYPE_ARRAY_U16:
+ case SIDE_TYPE_ARRAY_U32:
+ case SIDE_TYPE_ARRAY_U64:
+ case SIDE_TYPE_ARRAY_S8:
+ case SIDE_TYPE_ARRAY_S16:
+ case SIDE_TYPE_ARRAY_S32:
+ case SIDE_TYPE_ARRAY_S64:
+ if (type_desc->type != SIDE_TYPE_ARRAY) {
+ printf("ERROR: type mismatch between description and arguments\n");
+ abort();
+ }
+ break;
+ default:
+ if (type_desc->type != SIDE_TYPE_DYNAMIC && type_desc->type != item->type) {
+ printf("ERROR: type mismatch between description and arguments\n");
+ abort();
+ }
+ break;
}
-
switch (item->type) {
case SIDE_TYPE_U8:
printf("%" PRIu8, item->u.side_u8);
case SIDE_TYPE_VLA_VISITOR:
tracer_print_vla_visitor(type_desc, item->u.side_vla_visitor_ctx);
break;
+ case SIDE_TYPE_ARRAY_U8:
+ case SIDE_TYPE_ARRAY_U16:
+ case SIDE_TYPE_ARRAY_U32:
+ case SIDE_TYPE_ARRAY_U64:
+ case SIDE_TYPE_ARRAY_S8:
+ case SIDE_TYPE_ARRAY_S16:
+ case SIDE_TYPE_ARRAY_S32:
+ case SIDE_TYPE_ARRAY_S64:
+ tracer_print_array_fixint(type_desc, item);
+ break;
default:
printf("<UNKNOWN TYPE>");
abort();
}
}
+void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item)
+{
+ const struct side_type_description *elem_type = type_desc->u.side_array.elem_type;
+ uint32_t side_sav_len = type_desc->u.side_array.length;
+ void *p = item->u.side_array_fixint;
+ enum side_type side_type;
+ int i;
+
+ if (elem_type->type != SIDE_TYPE_DYNAMIC) {
+ switch (item->type) {
+ case SIDE_TYPE_ARRAY_U8:
+ if (elem_type->type != SIDE_TYPE_U8)
+ goto type_error;
+ break;
+ case SIDE_TYPE_ARRAY_U16:
+ if (elem_type->type != SIDE_TYPE_U16)
+ goto type_error;
+ break;
+ case SIDE_TYPE_ARRAY_U32:
+ if (elem_type->type != SIDE_TYPE_U32)
+ goto type_error;
+ break;
+ case SIDE_TYPE_ARRAY_U64:
+ if (elem_type->type != SIDE_TYPE_U64)
+ goto type_error;
+ break;
+ case SIDE_TYPE_ARRAY_S8:
+ if (elem_type->type != SIDE_TYPE_S8)
+ goto type_error;
+ break;
+ case SIDE_TYPE_ARRAY_S16:
+ if (elem_type->type != SIDE_TYPE_S16)
+ goto type_error;
+ break;
+ case SIDE_TYPE_ARRAY_S32:
+ if (elem_type->type != SIDE_TYPE_S32)
+ goto type_error;
+ break;
+ case SIDE_TYPE_ARRAY_S64:
+ if (elem_type->type != SIDE_TYPE_S64)
+ goto type_error;
+ break;
+ }
+ side_type = elem_type->type;
+ } else {
+ switch (item->type) {
+ case SIDE_TYPE_ARRAY_U8:
+ side_type = SIDE_TYPE_U8;
+ break;
+ case SIDE_TYPE_ARRAY_U16:
+ side_type = SIDE_TYPE_U16;
+ break;
+ case SIDE_TYPE_ARRAY_U32:
+ side_type = SIDE_TYPE_U32;
+ break;
+ case SIDE_TYPE_ARRAY_U64:
+ side_type = SIDE_TYPE_U64;
+ break;
+ case SIDE_TYPE_ARRAY_S8:
+ side_type = SIDE_TYPE_S8;
+ break;
+ case SIDE_TYPE_ARRAY_S16:
+ side_type = SIDE_TYPE_S16;
+ break;
+ case SIDE_TYPE_ARRAY_S32:
+ side_type = SIDE_TYPE_S32;
+ break;
+ case SIDE_TYPE_ARRAY_S64:
+ side_type = SIDE_TYPE_S64;
+ break;
+ }
+ }
+
+ printf("[ ");
+ for (i = 0; i < side_sav_len; i++) {
+ struct side_arg_vec sav_elem = {
+ .type = side_type,
+ };
+
+ switch (side_type) {
+ case SIDE_TYPE_U8:
+ sav_elem.u.side_u8 = ((const uint8_t *) p)[i];
+ break;
+ case SIDE_TYPE_S8:
+ sav_elem.u.side_s8 = ((const int8_t *) p)[i];
+ break;
+ case SIDE_TYPE_U16:
+ sav_elem.u.side_u16 = ((const uint16_t *) p)[i];
+ break;
+ case SIDE_TYPE_S16:
+ sav_elem.u.side_s16 = ((const int16_t *) p)[i];
+ break;
+ case SIDE_TYPE_U32:
+ sav_elem.u.side_u32 = ((const uint32_t *) p)[i];
+ break;
+ case SIDE_TYPE_S32:
+ sav_elem.u.side_s32 = ((const int32_t *) p)[i];
+ break;
+ case SIDE_TYPE_U64:
+ sav_elem.u.side_u64 = ((const uint64_t *) p)[i];
+ break;
+ case SIDE_TYPE_S64:
+ sav_elem.u.side_s64 = ((const int64_t *) p)[i];
+ break;
+
+ default:
+ printf("ERROR: Unexpected type\n");
+ abort();
+ }
+
+ printf("%s", i ? ", " : "");
+ tracer_print_type(elem_type, &sav_elem);
+ }
+ printf(" ]");
+ return;
+
+type_error:
+ printf("ERROR: type mismatch\n");
+ abort();
+}
+
void tracer_call(const struct side_event_description *desc, const struct side_arg_vec_description *sav_desc)
{
const struct side_arg_vec *sav = sav_desc->sav;