[gamecode] Create macros for progs sizeof and alignof

I wound up needing the idioms in too many places.
This commit is contained in:
Bill Currie 2022-01-23 14:27:36 +09:00
parent 3c86660d4a
commit e746e39738
3 changed files with 6 additions and 3 deletions

View file

@ -62,6 +62,9 @@ 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_ALIGNOF(type) (__alignof__ (pr_##type##_t) / __alignof__ (pr_int_t))
extern const pr_ushort_t pr_type_size[ev_type_count];
extern const pr_ushort_t pr_type_alignment[ev_type_count];
extern const char * const pr_type_name[ev_type_count];

View file

@ -33,13 +33,13 @@
#include "QF/progs.h"
#define EV_TYPE(type) (sizeof (pr_##type##_t) / sizeof (pr_int_t)),
#define EV_TYPE(type) PR_SIZEOF(type),
VISIBLE const pr_ushort_t pr_type_size[ev_type_count] = {
#include "QF/progs/pr_type_names.h"
0, // ev_invalid not a valid/simple type
};
#define EV_TYPE(type) (__alignof__ (pr_##type##_t) / __alignof__ (pr_int_t)),
#define EV_TYPE(type) PR_ALIGNOF(type),
VISIBLE const pr_ushort_t pr_type_alignment[ev_type_count] = {
#include "QF/progs/pr_type_names.h"
0, // ev_invalid not a valid/simple type

View file

@ -64,7 +64,7 @@
type_t type_##t = { \
.type = ev_##t, \
.name = #t, \
.alignment = __alignof__(pr_##t##_t) / __alignof__ (pr_int_t), \
.alignment = PR_ALIGNOF(t), \
.meta = ty_basic, \
{{ __builtin_choose_expr (ev_##t == ev_field \
|| ev_##t == ev_func \