1 | define(`pushdefFUNC_NAME', ` |
---|
2 | pushdef(`FUNC_NAME', `xc_`'PROCESSOR_TYPE`'_`'ifelse(`$2', `', `$1', `$2')') |
---|
3 | ') |
---|
4 | dnl {{{ DECL_STRUCT_P_FUNC(1:type, 2:name, 3:comma=;) |
---|
5 | define(`DECL_STRUCT_P_FUNC', `translit( |
---|
6 | pushdefFUNC_NAME(`$1', `$2') |
---|
7 | define(`DEFINED_'ifelse(`$2', `', `$1', `$2'), `') |
---|
8 | ifdef(`EXPORT_'ifelse(`$2', `', `$1', `$2'), `void', `static void inline') |
---|
9 | FUNC_NAME`'( |
---|
10 | IFDPRINT( `const $1 * const src, int indent') |
---|
11 | IFCALC( `xc_processor_t *processor, const $1 * const src') |
---|
12 | IFSTORE( `xc_processor_t *processor, $1 *dst, const $1 * const src') |
---|
13 | IFRESTORE(`xc_processor_t *processor, $1 *dst, const $1 * const src') |
---|
14 | IFDASM( `xc_dasm_t *dasm, zval *dst, const $1 * const src') |
---|
15 | IFASM( `$1 *dst, const $1 * const src') |
---|
16 | TSRMLS_DC |
---|
17 | )ifelse(`$3', `', `;') |
---|
18 | popdef(`FUNC_NAME')dnl |
---|
19 | , ` |
---|
20 | ', ` ')') |
---|
21 | dnl }}} |
---|
22 | dnl {{{ DEF_STRUCT_P_FUNC(1:type, 2:name, 3:body) |
---|
23 | define(`DEF_STRUCT_P_FUNC', ` |
---|
24 | pushdefFUNC_NAME(`$1', `$2') |
---|
25 | /* {`{'{ FUNC_NAME */ |
---|
26 | ifdef(`EXPORT_'ifelse(`$2', `', `$1', `$2'), ` |
---|
27 | /* export: DECL_STRUCT_P_FUNC(`$1', `$2') :export */ |
---|
28 | ') |
---|
29 | DECL_STRUCT_P_FUNC(`$1', `$2', 1) |
---|
30 | { |
---|
31 | pushdef(`ELEMENTS_DONE') |
---|
32 | IFAUTOCHECK(` |
---|
33 | /* {{{ init assert */ |
---|
34 | ifdef(`SIZEOF_$1', , `m4_errprint(`Warning: missing SIZEOF_$1, safe to ignore')') |
---|
35 | ifdef(`COUNTOF_$1', , `m4_errprint(`Warning: missing COUNTOF_$1, safe to ignore')') |
---|
36 | dnl SIZEOF_x COUNTOF_x can be both defined or both not |
---|
37 | ifdef(`SIZEOF_$1', ` |
---|
38 | ifdef(`COUNTOF_$1', , `m4_errprint(`AUTOCHECK WARN: missing COUNTOF_$1')') |
---|
39 | ', ` |
---|
40 | define(`SIZEOF_$1', 0) |
---|
41 | ') |
---|
42 | ifdef(`COUNTOF_$1', ` |
---|
43 | ifdef(`SIZEOF_$1', , `m4_errprint(`AUTOCHECK WARN: missing SIZEOF_$1')') |
---|
44 | ', ` |
---|
45 | define(`COUNTOF_$1', 0) |
---|
46 | ') |
---|
47 | int xc_autocheck_assert_size = SIZEOF_$1, assert_count = COUNTOF_$1; |
---|
48 | int xc_autocheck_done_size = 0, xc_autocheck_done_count = 0; |
---|
49 | ifdef(`ELEMENTSOF_$1', ` |
---|
50 | const char *xc_autocheck_assert_names[] = { ELEMENTSOF_$1 }; |
---|
51 | size_t xc_autocheck_assert_names_count = sizeof(xc_autocheck_assert_names) / sizeof(xc_autocheck_assert_names[0]); |
---|
52 | ', ` |
---|
53 | const char **xc_autocheck_assert_names = NULL; |
---|
54 | size_t xc_autocheck_assert_names_count = 0; |
---|
55 | ') |
---|
56 | zend_bool xc_autocheck_skip = 0; |
---|
57 | HashTable xc_autocheck_done_names; |
---|
58 | zend_hash_init(&xc_autocheck_done_names, 0, NULL, NULL, 0); |
---|
59 | /* }}} */ |
---|
60 | IFRESTORE(`assert(xc_is_shm(src));') |
---|
61 | IFCALCSTORE(`assert(!xc_is_shm(src));') |
---|
62 | do { |
---|
63 | ') |
---|
64 | ifdef(`SIZEOF_$1', , `m4_errprint(`AUTOCHECK WARN: $1: missing structinfo, dont panic')') |
---|
65 | |
---|
66 | ifdef(`USEMEMCPY', `IFCOPY(` |
---|
67 | memcpy(dst, src, sizeof($1)); |
---|
68 | do { |
---|
69 | ')') |
---|
70 | |
---|
71 | IFDPRINT(` |
---|
72 | fprintf(stderr, "%s", "{\n"); |
---|
73 | indent ++; |
---|
74 | ') |
---|
75 | $3`' |
---|
76 | IFDPRINT(` |
---|
77 | indent --; |
---|
78 | INDENT()fprintf(stderr, "}\n"); |
---|
79 | ') |
---|
80 | IFAUTOCHECK(` |
---|
81 | /* {{{ autocheck */ |
---|
82 | if (!xc_autocheck_skip) { |
---|
83 | int name_check_errors = xc_check_names(__FILE__, __LINE__, "FUNC_NAME", xc_autocheck_assert_names, xc_autocheck_assert_names_count, &xc_autocheck_done_names); |
---|
84 | |
---|
85 | if (xc_autocheck_done_count != assert_count) { |
---|
86 | fprintf(stderr |
---|
87 | , "count assertion failed at %s `#'%d FUNC_NAME`' : unexpected:%d - expecting:%d = %d != 0\n" |
---|
88 | , __FILE__, __LINE__ |
---|
89 | , xc_autocheck_done_count, assert_count, xc_autocheck_done_count - assert_count |
---|
90 | ); |
---|
91 | } |
---|
92 | if (xc_autocheck_done_size != xc_autocheck_assert_size) { |
---|
93 | fprintf(stderr |
---|
94 | , "size assertion failed at %s `#'%d FUNC_NAME`' : unexpected:%d - expecting:%d = %d != 0\n" |
---|
95 | , __FILE__, __LINE__ |
---|
96 | , xc_autocheck_done_size, xc_autocheck_assert_size, xc_autocheck_done_size - xc_autocheck_assert_size |
---|
97 | ); |
---|
98 | } |
---|
99 | if (name_check_errors || xc_autocheck_done_count != assert_count || xc_autocheck_done_size != xc_autocheck_assert_size) { |
---|
100 | assert(0); |
---|
101 | } |
---|
102 | } |
---|
103 | zend_hash_destroy(&xc_autocheck_done_names); |
---|
104 | /* }}} */ |
---|
105 | ') |
---|
106 | ifdef(`ELEMENTSOF_$1', ` |
---|
107 | pushdef(`ELEMENTS_UNDONE', LIST_DIFF(defn(`ELEMENTSOF_$1'), defn(`ELEMENTS_DONE'))) |
---|
108 | ifelse(defn(`ELEMENTS_UNDONE'), , `m4_errprint(`AUTOCHECK INFO: $1: processor looks good')', ` |
---|
109 | m4_errprint(`AUTOCHECK ERROR: ====' PROCESSOR_TYPE `$1 =================') |
---|
110 | m4_errprint(`AUTOCHECK expected:' defn(`ELEMENTSOF_$1')) |
---|
111 | m4_errprint(`AUTOCHECK missing :' defn(`ELEMENTS_UNDONE')) |
---|
112 | define(`EXIT_PENDING', 1) |
---|
113 | ') |
---|
114 | popdef(`ELEMENTS_UNDONE') |
---|
115 | ') |
---|
116 | ifdef(`USEMEMCPY', `IFCOPY(` |
---|
117 | } while (0); |
---|
118 | ')') |
---|
119 | IFAUTOCHECK(` |
---|
120 | } while (0); |
---|
121 | ') |
---|
122 | popdef(`ELEMENTS_DONE') |
---|
123 | } |
---|
124 | /* }`}'} */ |
---|
125 | popdef(`FUNC_NAME') |
---|
126 | ') |
---|
127 | dnl }}} |
---|
128 | dnl {{{ STRUCT_P_EX(1:type, 2:dst, 3:src, 4:elm-name, 5:name=type, 6:&) |
---|
129 | define(`STRUCT_P_EX', ` |
---|
130 | DBG(`$0($*)') |
---|
131 | pushdefFUNC_NAME(`$1', `$5') |
---|
132 | ifdef(`DEFINED_'ifelse(`$5', `', `$1', `$5'), `', `m4_errprint(`AUTOCHECK ERROR: Unknown struct "'ifelse(`$5', `', `$1', `$5')`"')define(`EXIT_PENDING', 1)') |
---|
133 | assert(sizeof($1) == sizeof(($6 $3)[0])); |
---|
134 | ifelse(`$6', `', `ALLOC(`$2', `$1')') |
---|
135 | IFDASM(`do { |
---|
136 | zval *zv; |
---|
137 | ALLOC_INIT_ZVAL(zv); |
---|
138 | array_init(zv); |
---|
139 | ') |
---|
140 | FUNC_NAME`'( |
---|
141 | IFDPRINT( ` $6 $3, indent') |
---|
142 | IFCALC( `processor, $6 $3') |
---|
143 | IFSTORE( `processor, $6 $2, $6 $3') |
---|
144 | IFRESTORE(`processor, $6 $2, $6 $3') |
---|
145 | IFDASM( `dasm, zv, $6 $3') |
---|
146 | IFASM( `$6 $2, $6 $3') |
---|
147 | TSRMLS_CC |
---|
148 | ); |
---|
149 | IFDASM(` |
---|
150 | add_assoc_zval_ex(dst, ZEND_STRS("$4"), zv); |
---|
151 | } while (0); |
---|
152 | ') |
---|
153 | popdef(`FUNC_NAME') |
---|
154 | ifelse(`$6', , `FIXPOINTER_EX(`$1', `$2')') |
---|
155 | ') |
---|
156 | dnl }}} |
---|
157 | dnl {{{ STRUCT_P(1:type, 2:elm, 3:name=type) |
---|
158 | define(`STRUCT_P', ` |
---|
159 | DBG(`$0($*)') |
---|
160 | if (SRC(`$2')) { |
---|
161 | IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2 ");') |
---|
162 | STRUCT_P_EX(`$1', `dst->$2', `SRC(`$2')', `$2', `$3') |
---|
163 | } |
---|
164 | else { |
---|
165 | IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2:\tNULL\n");') |
---|
166 | COPYNULL_EX(`dst->$2', `$2') |
---|
167 | } |
---|
168 | DONE(`$2') |
---|
169 | ') |
---|
170 | dnl }}} |
---|
171 | dnl {{{ STRUCT(1:type, 2:elm, 3:name=type) |
---|
172 | define(`STRUCT', ` |
---|
173 | DBG(`$0($*)') |
---|
174 | assert(sizeof($1) == sizeof(SRC(`$2'))); |
---|
175 | IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2 ");') |
---|
176 | STRUCT_P_EX(`$1', `dst->$2', `SRC(`$2')', `$2', `$3', `&') |
---|
177 | DONE(`$2') |
---|
178 | ') |
---|
179 | dnl }}} |
---|
180 | dnl {{{ STRUCT_ARRAY(1:count_type, 2:count, 3:type, 4:elm, 5:name=type, 6:loopcounter) |
---|
181 | define(`STRUCT_ARRAY', ` |
---|
182 | if (SRC(`$4')) { |
---|
183 | ifelse( |
---|
184 | `$6', `', `ifelse(`$1', `', `size_t', `$1') i; pushdef(`LOOPCOUNTER', `i')', |
---|
185 | `', `', `pushdef(`LOOPCOUNTER', `$6')') |
---|
186 | pushdefFUNC_NAME(`$3', `$5') |
---|
187 | IFDASM(` |
---|
188 | zval *arr; |
---|
189 | ALLOC_INIT_ZVAL(arr); |
---|
190 | array_init(arr); |
---|
191 | |
---|
192 | for (LOOPCOUNTER = 0; |
---|
193 | ifelse(`$2', `', `SRC(`$4[LOOPCOUNTER]')', |
---|
194 | `', `', `LOOPCOUNTER < SRC(`$2')'); |
---|
195 | ++LOOPCOUNTER) { |
---|
196 | zval *zv; |
---|
197 | |
---|
198 | ALLOC_INIT_ZVAL(zv); |
---|
199 | array_init(zv); |
---|
200 | FUNC_NAME (dasm, zv, &(SRC(`$4[LOOPCOUNTER]')) TSRMLS_CC); |
---|
201 | add_next_index_zval(arr, zv); |
---|
202 | } |
---|
203 | add_assoc_zval_ex(dst, ZEND_STRS("$4"), arr); |
---|
204 | ', ` |
---|
205 | dnl find count with NULL |
---|
206 | ifelse(`$2', `', ` |
---|
207 | size_t count = 0; |
---|
208 | while (SRC(`$4[count]')) { |
---|
209 | ++count; |
---|
210 | } |
---|
211 | ++count; |
---|
212 | pushdef(`ARRAY_ELEMENT_COUNT', `count') |
---|
213 | ', |
---|
214 | `', `', `pushdef(`ARRAY_ELEMENT_COUNT', `SRC(`$2')')') |
---|
215 | ALLOC(`dst->$4', `$3', `ARRAY_ELEMENT_COUNT') |
---|
216 | popdef(`ARRAY_ELEMENT_COUNT') |
---|
217 | |
---|
218 | for (LOOPCOUNTER = 0; |
---|
219 | ifelse(`$2', `', `SRC(`$4[LOOPCOUNTER]')', |
---|
220 | `', `', `LOOPCOUNTER < SRC(`$2')'); |
---|
221 | ++LOOPCOUNTER) { |
---|
222 | DISABLECHECK(` |
---|
223 | STRUCT(`$3', `$4[LOOPCOUNTER]', `$5') |
---|
224 | ') |
---|
225 | } |
---|
226 | dnl the end marker |
---|
227 | ifelse(`$2', `', `IFCOPY(`DST(`$4[LOOPCOUNTER]') = NULL;')') |
---|
228 | ')dnl IFDASM |
---|
229 | DONE(`$4') |
---|
230 | popdef(`FUNC_NAME') |
---|
231 | popdef(`LOOPCOUNTER') |
---|
232 | } |
---|
233 | else { |
---|
234 | COPYNULL(`$4') |
---|
235 | } |
---|
236 | ') |
---|
237 | dnl }}} |
---|