[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.
This commit is contained in:
Bill Currie 2022-01-30 10:47:37 +09:00
parent 5ba6bf02e8
commit 728c42e921
4 changed files with 34 additions and 119 deletions

View file

@ -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);

View file

@ -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];

View file

@ -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

View file

@ -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;