Commit | Line | Data |
---|---|---|
57553dfd MD |
1 | // SPDX-License-Identifier: MIT |
2 | /* | |
3 | * Copyright 2022-2023 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
4 | */ | |
5 | ||
6 | #ifndef SIDE_TYPE_ARGUMENT_ABI_H | |
7 | #define SIDE_TYPE_ARGUMENT_ABI_H | |
8 | ||
9 | #include <stdint.h> | |
10 | #include <side/macros.h> | |
11 | #include <side/endian.h> | |
12 | ||
13 | #include <side/type-value-abi.h> | |
14 | #include <side/attribute-abi.h> | |
15 | #include <side/type-description-abi.h> | |
16 | #include <side/visitor-abi.h> | |
17 | ||
57553dfd MD |
18 | #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN) |
19 | # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE | |
20 | #else | |
21 | # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE | |
22 | #endif | |
23 | ||
24 | #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN) | |
25 | # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE | |
26 | #else | |
27 | # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE | |
28 | #endif | |
29 | ||
30 | union side_arg_static { | |
31 | /* Stack-copy basic types */ | |
32 | union side_bool_value bool_value; | |
33 | uint8_t byte_value; | |
34 | side_ptr_t(const void) string_value; /* const {uint8_t, uint16_t, uint32_t} * */ | |
35 | union side_integer_value integer_value; | |
36 | union side_float_value float_value; | |
37 | ||
38 | /* Stack-copy compound types */ | |
39 | side_ptr_t(const struct side_arg_vec) side_struct; | |
40 | side_ptr_t(const struct side_arg_variant) side_variant; | |
41 | side_ptr_t(const struct side_arg_vec) side_array; | |
42 | side_ptr_t(const struct side_arg_vec) side_vla; | |
43 | void *side_vla_app_visitor_ctx; | |
44 | ||
45 | /* Gather basic types */ | |
46 | side_ptr_t(const void) side_bool_gather_ptr; | |
47 | side_ptr_t(const void) side_byte_gather_ptr; | |
48 | side_ptr_t(const void) side_integer_gather_ptr; | |
49 | side_ptr_t(const void) side_float_gather_ptr; | |
50 | side_ptr_t(const void) side_string_gather_ptr; | |
51 | ||
52 | /* Gather compound types */ | |
53 | side_ptr_t(const void) side_array_gather_ptr; | |
54 | side_ptr_t(const void) side_struct_gather_ptr; | |
55 | struct { | |
56 | side_ptr_t(const void) ptr; | |
57 | side_ptr_t(const void) length_ptr; | |
58 | } SIDE_PACKED side_vla_gather; | |
59 | side_padding(32); | |
60 | } SIDE_PACKED; | |
61 | side_check_size(union side_arg_static, 32); | |
62 | ||
63 | struct side_arg_dynamic_vla { | |
64 | side_ptr_t(const struct side_arg) sav; | |
65 | side_ptr_t(const struct side_attr) attr; | |
66 | uint32_t len; | |
67 | uint32_t nr_attr; | |
68 | } SIDE_PACKED; | |
69 | side_check_size(struct side_arg_dynamic_vla, 40); | |
70 | ||
71 | struct side_arg_dynamic_struct { | |
72 | side_ptr_t(const struct side_arg_dynamic_field) fields; | |
73 | side_ptr_t(const struct side_attr) attr; | |
74 | uint32_t len; | |
75 | uint32_t nr_attr; | |
76 | } SIDE_PACKED; | |
77 | side_check_size(struct side_arg_dynamic_struct, 40); | |
78 | ||
79 | struct side_dynamic_struct_visitor { | |
80 | side_func_ptr_t(side_dynamic_struct_visitor_func) visitor; | |
81 | side_ptr_t(void) app_ctx; | |
82 | side_ptr_t(const struct side_attr) attr; | |
83 | uint32_t nr_attr; | |
84 | } SIDE_PACKED; | |
85 | side_check_size(struct side_dynamic_struct_visitor, 52); | |
86 | ||
87 | struct side_dynamic_vla_visitor { | |
88 | side_func_ptr_t(side_visitor_func) visitor; | |
89 | side_ptr_t(void) app_ctx; | |
90 | side_ptr_t(const struct side_attr) attr; | |
91 | uint32_t nr_attr; | |
92 | } SIDE_PACKED; | |
93 | side_check_size(struct side_dynamic_vla_visitor, 52); | |
94 | ||
95 | union side_arg_dynamic { | |
96 | /* Dynamic basic types */ | |
97 | struct side_type_null side_null; | |
98 | struct { | |
99 | struct side_type_bool type; | |
100 | union side_bool_value value; | |
101 | } SIDE_PACKED side_bool; | |
102 | struct { | |
103 | struct side_type_byte type; | |
104 | uint8_t value; | |
105 | } SIDE_PACKED side_byte; | |
106 | struct { | |
107 | struct side_type_string type; | |
108 | uint64_t value; /* const char * */ | |
109 | } SIDE_PACKED side_string; | |
110 | struct { | |
111 | struct side_type_integer type; | |
112 | union side_integer_value value; | |
113 | } SIDE_PACKED side_integer; | |
114 | struct { | |
115 | struct side_type_float type; | |
116 | union side_float_value value; | |
117 | } SIDE_PACKED side_float; | |
118 | ||
119 | /* Dynamic compound types */ | |
120 | side_ptr_t(const struct side_arg_dynamic_struct) side_dynamic_struct; | |
121 | side_ptr_t(const struct side_arg_dynamic_vla) side_dynamic_vla; | |
122 | ||
123 | struct side_dynamic_struct_visitor side_dynamic_struct_visitor; | |
124 | struct side_dynamic_vla_visitor side_dynamic_vla_visitor; | |
125 | ||
126 | side_padding(58); | |
127 | } SIDE_PACKED; | |
128 | side_check_size(union side_arg_dynamic, 58); | |
129 | ||
130 | struct side_arg { | |
131 | side_enum_t(enum side_type_label, uint16_t) type; | |
132 | union { | |
133 | union side_arg_static side_static; | |
134 | union side_arg_dynamic side_dynamic; | |
135 | side_padding(62); | |
136 | } SIDE_PACKED u; | |
137 | } SIDE_PACKED; | |
138 | side_check_size(struct side_arg, 64); | |
139 | ||
140 | struct side_arg_variant { | |
141 | struct side_arg selector; | |
142 | struct side_arg option; | |
143 | } SIDE_PACKED; | |
144 | side_check_size(struct side_arg_variant, 128); | |
145 | ||
146 | struct side_arg_vec { | |
147 | side_ptr_t(const struct side_arg) sav; | |
148 | uint32_t len; | |
149 | } SIDE_PACKED; | |
150 | side_check_size(struct side_arg_vec, 20); | |
151 | ||
152 | struct side_arg_dynamic_field { | |
153 | side_ptr_t(const char) field_name; | |
154 | const struct side_arg elem; | |
155 | } SIDE_PACKED; | |
156 | side_check_size(struct side_arg_dynamic_field, 16 + sizeof(const struct side_arg)); | |
157 | ||
158 | #endif /* SIDE_TYPE_ARGUMENT_ABI_H */ |