From 728c42e921aeb34620b06fea23db97609cbafee0 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 30 Jan 2022 10:47:37 +0900 Subject: [PATCH] [gamecode] Use pr_type_names for debug views I abandoned the reason for doing it (adding a pile of vector types), but I liked the cleanup. All the implementations are hand-written still, but at least the boilerplate stuff is automated. --- include/QF/progs.h | 19 +---- include/QF/progs/pr_comp.h | 14 +++- include/QF/progs/pr_type_names.h | 2 +- libs/gamecode/pr_debug.c | 118 +++++-------------------------- 4 files changed, 34 insertions(+), 119 deletions(-) diff --git a/include/QF/progs.h b/include/QF/progs.h index f8ef4abfd..769fdb533 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -1794,28 +1794,13 @@ typedef void (*type_view_func) (struct qfot_type_s *type, pr_type_t *value, the entire contents of the data. */ typedef struct type_view_s { - type_view_func void_view; - type_view_func string_view; - type_view_func float_view; - type_view_func vector_view; - type_view_func entity_view; - type_view_func field_view; - type_view_func func_view; - type_view_func pointer_view; - type_view_func quat_view; - type_view_func int_view; - type_view_func uint_view; - type_view_func short_view; - type_view_func double_view; - type_view_func long_view; - type_view_func ulong_view; - type_view_func ushort_view; - type_view_func struct_view; type_view_func union_view; type_view_func enum_view; type_view_func array_view; type_view_func class_view; +#define EV_TYPE(type) type_view_func type##_view; +#include "QF/progs/pr_type_names.h" } type_view_t; void PR_Debug_Init (progs_t *pr); diff --git a/include/QF/progs/pr_comp.h b/include/QF/progs/pr_comp.h index d201bff87..1012f320d 100644 --- a/include/QF/progs/pr_comp.h +++ b/include/QF/progs/pr_comp.h @@ -43,18 +43,30 @@ typedef uint16_t pr_ushort_t __attribute__((aligned(2)));; typedef t n __attribute__ ((vector_size (s*sizeof (t)))) PR_VEC_TYPE (pr_int_t, pr_ivec2_t, 2); +typedef pr_int_t pr_ivec3_t[3]; PR_VEC_TYPE (pr_int_t, pr_ivec4_t, 4); + PR_VEC_TYPE (pr_uint_t, pr_uivec2_t, 2); +typedef pr_uint_t pr_uivec3_t[3]; PR_VEC_TYPE (pr_uint_t, pr_uivec4_t, 4); + PR_VEC_TYPE (float, pr_vec2_t, 2); +typedef pr_float_t pr_vec3_t[3]; PR_VEC_TYPE (float, pr_vec4_t, 4); + PR_VEC_TYPE (pr_long_t, pr_lvec2_t, 2); +typedef pr_long_t pr_lvec3_t[3]; PR_VEC_TYPE (pr_long_t, pr_lvec4_t, 4); + PR_VEC_TYPE (pr_ulong_t, pr_ulvec2_t, 2); +typedef pr_ulong_t pr_ulvec3_t[3]; PR_VEC_TYPE (pr_ulong_t, pr_ulvec4_t, 4); + PR_VEC_TYPE (double, pr_dvec2_t, 2); +typedef pr_double_t pr_dvec3_t[3]; PR_VEC_TYPE (double, pr_dvec4_t, 4); + #define EV_TYPE(type) ev_##type, typedef enum { #include "QF/progs/pr_type_names.h" @@ -62,7 +74,7 @@ typedef enum { ev_type_count // not a type, gives number of types } etype_t; -#define PR_SIZEOF(type) (sizeof (pr_##type##_t) / sizeof (pr_int_t)) +#define PR_SIZEOF(type) (sizeof (pr_##type##_t) / (sizeof (pr_int_t))) #define PR_ALIGNOF(type) (__alignof__ (pr_##type##_t) / __alignof__ (pr_int_t)) extern const pr_ushort_t pr_type_size[ev_type_count]; diff --git a/include/QF/progs/pr_type_names.h b/include/QF/progs/pr_type_names.h index 5e9904b2a..3e0daf10a 100644 --- a/include/QF/progs/pr_type_names.h +++ b/include/QF/progs/pr_type_names.h @@ -45,6 +45,6 @@ EV_TYPE(short) // value is embedded in the opcode EV_TYPE(double) EV_TYPE(long) EV_TYPE(ulong) -EV_TYPE(ushort) +EV_TYPE(ushort) // value is embedded in the opcode #undef EV_TYPE diff --git a/libs/gamecode/pr_debug.c b/libs/gamecode/pr_debug.c index b9c3862c5..041963233 100644 --- a/libs/gamecode/pr_debug.c +++ b/libs/gamecode/pr_debug.c @@ -59,6 +59,7 @@ #include "QF/progs/pr_debug.h" #include "QF/progs/pr_type.h" +#include "QF/simd/types.h" #include "compat.h" @@ -121,38 +122,6 @@ cvar_t *pr_source_path; static char *source_path_string; static char **source_paths; -static void pr_debug_void_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_string_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_float_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_vector_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_entity_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_field_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_func_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_pointer_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_quat_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_int_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_uint_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_short_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_double_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_long_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_ulong_view (qfot_type_t *type, pr_type_t *value, - void *_data); -static void pr_debug_ushort_view (qfot_type_t *type, pr_type_t *value, - void *_data); static void pr_debug_struct_view (qfot_type_t *type, pr_type_t *value, void *_data); static void pr_debug_union_view (qfot_type_t *type, pr_type_t *value, @@ -163,29 +132,20 @@ static void pr_debug_array_view (qfot_type_t *type, pr_type_t *value, void *_data); static void pr_debug_class_view (qfot_type_t *type, pr_type_t *value, void *_data); +#define EV_TYPE(t) \ + static void pr_debug_##t##_view (qfot_type_t *type, pr_type_t *value, \ + void *_data); +#include "QF/progs/pr_type_names.h" static type_view_t raw_type_view = { - pr_debug_void_view, - pr_debug_string_view, - pr_debug_float_view, - pr_debug_vector_view, - pr_debug_entity_view, - pr_debug_field_view, - pr_debug_func_view, - pr_debug_pointer_view, - pr_debug_quat_view, - pr_debug_int_view, - pr_debug_uint_view, - pr_debug_short_view, - pr_debug_double_view, - pr_debug_long_view, - pr_debug_ulong_view, - pr_debug_ushort_view, pr_debug_struct_view, pr_debug_union_view, pr_debug_enum_view, pr_debug_array_view, pr_debug_class_view, +#define EV_TYPE(t) \ + pr_debug_##t##_view, +#include "QF/progs/pr_type_names.h" }; static const char * @@ -1040,60 +1000,18 @@ PR_DumpState (progs_t *pr) #define ISDENORM(x) ((x) && !((x) & 0x7f800000)) -static const char * +static void value_string (pr_debug_data_t *data, qfot_type_t *type, pr_type_t *value) { switch (type->meta) { case ty_basic: switch (type->type) { - case ev_void: - raw_type_view.void_view (type, value, data); - break; - case ev_string: - raw_type_view.string_view (type, value, data); - break; - case ev_float: - raw_type_view.float_view (type, value, data); - break; - case ev_vector: - raw_type_view.vector_view (type, value, data); - break; - case ev_entity: - raw_type_view.entity_view (type, value, data); - break; - case ev_field: - raw_type_view.field_view (type, value, data); - break; - case ev_func: - raw_type_view.func_view (type, value, data); - break; - case ev_ptr: - raw_type_view.pointer_view (type, value, data); - break; - case ev_quaternion: - raw_type_view.quat_view (type, value, data); - break; - case ev_int: - raw_type_view.int_view (type, value, data); - break; - case ev_uint: - raw_type_view.uint_view (type, value, data); - break; - case ev_short: - raw_type_view.short_view (type, value, data); - break; - case ev_double: - raw_type_view.double_view (type, value, data); - break; - case ev_long: - raw_type_view.long_view (type, value, data); - break; - case ev_ulong: - raw_type_view.ulong_view (type, value, data); - break; - case ev_ushort: - raw_type_view.ushort_view (type, value, data); +#define EV_TYPE(t) \ + case ev_##t: \ + raw_type_view.t##_view (type, value, data); \ break; +#include "QF/progs/pr_type_names.h" + case ev_invalid: case ev_type_count: dstring_appendstr (data->dstr, ""); @@ -1116,9 +1034,9 @@ value_string (pr_debug_data_t *data, qfot_type_t *type, pr_type_t *value) break; case ty_alias://XXX type = &G_STRUCT (data->pr, qfot_type_t, type->alias.aux_type); - return value_string (data, type, value); + value_string (data, type, value); + break; } - return data->dstr->str; } static pr_def_t * @@ -1331,7 +1249,7 @@ pr_debug_func_view (qfot_type_t *type, pr_type_t *value, void *_data) } static void -pr_debug_pointer_view (qfot_type_t *type, pr_type_t *value, void *_data) +pr_debug_ptr_view (qfot_type_t *type, pr_type_t *value, void *_data) { __auto_type data = (pr_debug_data_t *) _data; progs_t *pr = data->pr; @@ -1353,7 +1271,7 @@ pr_debug_pointer_view (qfot_type_t *type, pr_type_t *value, void *_data) } static void -pr_debug_quat_view (qfot_type_t *type, pr_type_t *value, void *_data) +pr_debug_quaternion_view (qfot_type_t *type, pr_type_t *value, void *_data) { __auto_type data = (pr_debug_data_t *) _data; dstring_t *dstr = data->dstr;