summaryrefslogtreecommitdiff
path: root/rt_struct.h
blob: b1ccd5f56c3bba509f76473ee3553130c5db481f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef RT_STRUCT_H
#define RT_STRUCT_H

#include <stddef.h>
#include <stdint.h>
#include <time.h>

typedef enum rts_type_tag rts_type_tag;
typedef struct rts_type rts_type;
typedef struct rts_member rts_member;

enum rts_type_tag {
	TAG_UINT,
	TAG_SINT,
	TAG_INT = TAG_SINT,
	TAG_UCHAR,
	TAG_SCHAR,
	TAG_CHAR,
	TAG_USHORT,
	TAG_SSHORT,
	TAG_SHORT = TAG_SSHORT,
	TAG_ULONG,
	TAG_SLONG,
	TAG_LONG = TAG_SLONG,
	TAG_ULONGLONG,
	TAG_SLONGLONG,
	TAG_LONGLONG = TAG_SLONGLONG,
	TAG_FLOAT,
	TAG_DOUBLE,
	TAG_LONGDOUBLE,
	TAG_TIME,
	TAG_SIZE,
	TAG_UINT8,
	TAG_INT8,
	TAG_UINT16,
	TAG_INT16,
	TAG_UINT32,
	TAG_INT32,
	TAG_UINT64,
	TAG_INT64,
	TAG_POINTER,
	TAG_STRUCT,
	TAG_UNION,
	NUM_TAG
};

struct rts_type {
	rts_type_tag tag;	/* Type Tag. */
	char *name;		/* Name of type. */
	int is_packed;		/* Packed type flag. */
	size_t alignment;	/* Alignment of type. */
	size_t size;		/* Size of type. */
	rts_member **members;	/* Member(s) of type. */
	size_t *offsets;	/* Offset(s) of type. */
};

struct rts_member {
	char *name;		/* Name of member. */
	int ptr_count;		/* Pointer count of member. */
	int arr_count;		/* Array dimension count of member. */
	rts_type *type;		/* Type of member. */
};

#define TYPEDEF_RTS(name, type)					\
	struct _align_##name {					\
		char c;						\
		type x;						\
	};							\
	static const rts_type RTS_TYPE_##name = {		\
		TAG_##name,					\
		NULL,						\
		0,						\
		offsetof(struct _align_##name, x),		\
		sizeof(type),					\
		NULL, NULL					\
	}							\

TYPEDEF_RTS(UINT, unsigned int);
TYPEDEF_RTS(SINT, signed int);
TYPEDEF_RTS(INT, int);

TYPEDEF_RTS(UCHAR, unsigned char);
TYPEDEF_RTS(SCHAR, signed char);
TYPEDEF_RTS(CHAR, char);

TYPEDEF_RTS(USHORT, unsigned short);
TYPEDEF_RTS(SSHORT, signed short);
TYPEDEF_RTS(SHORT, short);

TYPEDEF_RTS(ULONG, unsigned long);
TYPEDEF_RTS(SLONG, signed long);
TYPEDEF_RTS(LONG, long);

TYPEDEF_RTS(ULONGLONG, unsigned long long);
TYPEDEF_RTS(SLONGLONG, signed long long);
TYPEDEF_RTS(LONGLONG, long long);

TYPEDEF_RTS(FLOAT, float);
TYPEDEF_RTS(DOUBLE, double);
TYPEDEF_RTS(LONGDOUBLE, long double);

TYPEDEF_RTS(TIME, time_t);
TYPEDEF_RTS(SIZE, size_t);

TYPEDEF_RTS(UINT8, uint8_t);
TYPEDEF_RTS(INT8, int8_t);

TYPEDEF_RTS(UINT16, uint16_t);
TYPEDEF_RTS(INT16, int16_t);

TYPEDEF_RTS(UINT32, uint32_t);
TYPEDEF_RTS(INT32, int32_t);

TYPEDEF_RTS(UINT64, uint64_t);
TYPEDEF_RTS(INT64, int64_t);

TYPEDEF_RTS(POINTER, void *);

#undef TYPEDEF_RTS

extern int create_rts(rts_type *type);

#endif