1 | divert(-1) |
---|
2 | dnl ================ start ====================== |
---|
3 | dnl define(`XCACHE_ENABLE_TEST') |
---|
4 | define(`USEMEMCPY') |
---|
5 | |
---|
6 | dnl ================ main |
---|
7 | |
---|
8 | dnl {{{ basic |
---|
9 | define(`REDEF', `undefine(`$1') define(`$1', `$2')') |
---|
10 | define(`ONCE', `ifdef(`ONCE $1', `', `define(`ONCE $1')$1')') |
---|
11 | define(`m4_errprint', `ONCE(`errprint(`$1 |
---|
12 | ')')') |
---|
13 | define(`ZEND_STRS', `($1), (sizeof($1))') |
---|
14 | define(`ZEND_STRL', `($1), (sizeof($1) - 1)') |
---|
15 | dnl ============ |
---|
16 | define(`INDENT', `xc_dprint_indent(indent);') |
---|
17 | dnl }}} |
---|
18 | dnl {{{ ALLOC(1:dst, 2:type, 3:count=1, 4:clean=false, 5:forcetype=$2) |
---|
19 | define(`ALLOC', ` |
---|
20 | pushdef(`COUNT', `ifelse(`$3', `', `1', `$3')') |
---|
21 | pushdef(`SIZE', `sizeof($2)ifelse(`$3', `', `', ` * $3')') |
---|
22 | pushdef(`FORCETYPE', `ifelse(`$5', , `$2', `$5')') |
---|
23 | /* allocate */ |
---|
24 | IFCALC(` |
---|
25 | IFASSERT(` |
---|
26 | xc_stack_push(&processor->allocsizes, (void *) (long) (SIZE)); |
---|
27 | xc_stack_push(&processor->allocsizes, (void *) (long) (__LINE__)); |
---|
28 | ') |
---|
29 | processor->size = (size_t) ALIGN(processor->size); |
---|
30 | processor->size += SIZE; |
---|
31 | ') |
---|
32 | IFSTORE(` |
---|
33 | IFASSERT(`{ |
---|
34 | if (!xc_stack_size(&processor->allocsizes)) { |
---|
35 | fprintf(stderr, "mismatch `$@' at line %d\n", __LINE__); |
---|
36 | } |
---|
37 | else { |
---|
38 | unsigned long expect = (unsigned long) xc_stack_pop(&processor->allocsizes); |
---|
39 | unsigned long atline = (unsigned long) xc_stack_pop(&processor->allocsizes); |
---|
40 | unsigned long real = SIZE; |
---|
41 | if (expect != real) { |
---|
42 | fprintf(stderr, "mismatch `$@' at line %d(was %d): real %lu - expect %lu = %l\n", __LINE__, atline, real, expect, real - expect); |
---|
43 | } |
---|
44 | } |
---|
45 | }') |
---|
46 | $1 = (FORCETYPE *) (processor->p = (char *) ALIGN(processor->p)); |
---|
47 | ifelse(`$4', `', ` |
---|
48 | IFASSERT(`memset($1, -1, SIZE);') |
---|
49 | ', ` |
---|
50 | memset($1, 0, SIZE); |
---|
51 | ') |
---|
52 | processor->p += SIZE; |
---|
53 | ') |
---|
54 | IFRESTORE(`ifelse(`$4', `', ` |
---|
55 | ifelse( |
---|
56 | FORCETYPE*COUNT, `zval*1', `ALLOC_ZVAL($1);', |
---|
57 | FORCETYPE*COUNT, `HashTable*1', `ALLOC_HASHTABLE($1);', |
---|
58 | `', `', `$1 = (FORCETYPE *) emalloc(SIZE);') |
---|
59 | IFASSERT(`memset($1, -1, SIZE);') |
---|
60 | ', ` |
---|
61 | $1 = (FORCETYPE *) ecalloc(COUNT, sizeof($2)); |
---|
62 | ') |
---|
63 | ') |
---|
64 | popdef(`COUNT') |
---|
65 | popdef(`SIZE') |
---|
66 | ') |
---|
67 | dnl CALLOC(1:dst, 2:type [, 3:count=1 ]) |
---|
68 | define(`CALLOC', `ALLOC(`$1', `$2', `$3', `1')') |
---|
69 | dnl }}} |
---|
70 | dnl {{{ PROC_INT(1:elm, 2:format=%d, 3:type=, 4:spec=) |
---|
71 | define(`PROC_INT', ` |
---|
72 | IFNOTMEMCPY(`IFCOPY(`dst->$1 = src->$1;')') |
---|
73 | IFDPRINT(` |
---|
74 | INDENT() |
---|
75 | ifelse( |
---|
76 | `$3 $1', `zval_data_type type', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_data_type(src->$1));' |
---|
77 | , `$3 $1', `int op_type', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_op_type(src->$1));' |
---|
78 | , `$3 $1', `zend_uchar opcode', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_opcode(src->$1));' |
---|
79 | , `', `', `fprintf(stderr, "$3:$1:\t%ifelse(`$2',`',`d',`$2')\n", src->$1);') |
---|
80 | ') |
---|
81 | IFDASM(` |
---|
82 | ifelse( |
---|
83 | `$3', `zend_bool', `add_assoc_bool_ex(dst, ZEND_STRS("$1"), src->$1 ? 1 : 0);' |
---|
84 | , `', `', `add_assoc_long_ex(dst, ZEND_STRS("$1"), src->$1);' |
---|
85 | ) |
---|
86 | ') |
---|
87 | DONE(`$1') |
---|
88 | ') |
---|
89 | dnl }}} |
---|
90 | dnl {{{ PROC_CLASS_ENTRY_P(1:elm) |
---|
91 | define(`PROC_CLASS_ENTRY_P', `PROC_CLASS_ENTRY_P_EX(`dst->$1', `src->$1', `$1')`'DONE(`$1')') |
---|
92 | dnl PROC_CLASS_ENTRY_P_EX(1:dst, 2:src, 3:elm-name) |
---|
93 | define(`PROC_CLASS_ENTRY_P_EX', ` |
---|
94 | if ($2) { |
---|
95 | IFSTORE(`$1 = (zend_class_entry *) xc_get_class_num(processor, $2);') |
---|
96 | IFRESTORE(`$1 = xc_get_class(processor, (zend_ulong) $2);') |
---|
97 | IFDASM(`add_assoc_stringl_ex(dst, ZEND_STRS("$3"), $2->name, strlen($2->name), 1);') |
---|
98 | } |
---|
99 | else { |
---|
100 | COPYNULL_EX(`$1', `$3') |
---|
101 | } |
---|
102 | ') |
---|
103 | dnl }}} |
---|
104 | dnl {{{ IFASSERT |
---|
105 | define(`IFASSERT', `ifdef(`XCACHE_ENABLE_TEST', ` |
---|
106 | #ifndef NDEBUG |
---|
107 | $1 |
---|
108 | #endif |
---|
109 | ')') |
---|
110 | dnl }}} |
---|
111 | dnl {{{ DBG |
---|
112 | define(`DBG', `ifdef(`XCACHE_ENABLE_TEST', ` |
---|
113 | /* `$1' */ |
---|
114 | ')') |
---|
115 | dnl }}} |
---|
116 | dnl {{{ EXPORT |
---|
117 | define(`EXPORT', `define(`EXPORT_$1')') |
---|
118 | dnl }}} |
---|
119 | dnl {{{ FIXPOINTER |
---|
120 | define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `dst->$2')') |
---|
121 | define(`FIXPOINTER_EX', `IFSTORE(` |
---|
122 | $2 = ($1 *) processor->xce_src->cache->shm->handlers->to_readonly(processor->xce_src->cache->shm, (char *)$2); |
---|
123 | ')') |
---|
124 | define(`UNFIXPOINTER', `UNFIXPOINTER_EX(`$1', `dst->$2')') |
---|
125 | define(`UNFIXPOINTER_EX', `IFSTORE(` |
---|
126 | $2 = ($1 *) processor->xce_src->cache->shm->handlers->to_readwrite(processor->xce_src->cache->shm, (char *)$2); |
---|
127 | ')') |
---|
128 | dnl }}} |
---|
129 | dnl {{{ COPY |
---|
130 | define(`COPY', `IFNOTMEMCPY(`IFCOPY(`dst->$1 = src->$1;')')DONE(`$1')') |
---|
131 | dnl }}} |
---|
132 | dnl {{{ SETNULL_EX |
---|
133 | define(`SETNULL_EX', `IFCOPY(`$1 = NULL;')') |
---|
134 | define(`SETNULL', `SETNULL_EX(`dst->$1')DONE(`$1')') |
---|
135 | dnl }}} |
---|
136 | dnl {{{ COPYNULL_EX(1:dst, 2:elm-name) |
---|
137 | define(`COPYNULL_EX', ` |
---|
138 | IFDASM(`add_assoc_null_ex(dst, ZEND_STRS("$2"));') |
---|
139 | IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')') |
---|
140 | ') |
---|
141 | dnl }}} |
---|
142 | dnl {{{ COPYNULL(1:elm) |
---|
143 | # foreach(VAR, (LIST), STMT) |
---|
144 | m4_define([foreach], |
---|
145 | [m4_pushdef([$1])_foreach([$1], [$2], [$3])m4_popdef([$1])]) |
---|
146 | m4_define([_arg1], [$1]) |
---|
147 | m4_define([_foreach], |
---|
148 | [ifelse([$2], [()], , |
---|
149 | [m4_define([$1], _arg1$2)$3[]_foreach([$1], |
---|
150 | (shift$2), |
---|
151 | [$3])])]) |
---|
152 | define(`COPYNULL', ` |
---|
153 | COPYNULL_EX(`dst->$1', `$2')DONE(`$1') |
---|
154 | ') |
---|
155 | dnl }}} |
---|
156 | dnl {{{ LIST_DIFF(1:left-list, 2:right-list) |
---|
157 | define(`foreach', |
---|
158 | `pushdef(`$1')_foreach(`$1', `$2', `$3')popdef(`$1')') |
---|
159 | define(`_arg1', `$1') |
---|
160 | define(`_foreach', |
---|
161 | `ifelse(`$2', `()', , |
---|
162 | `define(`$1', _arg1$2)$3`'_foreach(`$1', |
---|
163 | (shift$2), |
---|
164 | `$3')')') |
---|
165 | define(`LIST_DIFF', `dnl |
---|
166 | foreach(`i', `($1)', `pushdef(`item_'defn(`i'))')dnl allocate variable for items in $1 |
---|
167 | foreach(`i', `($2)', `pushdef(`item_'defn(`i'))undefine(`item_'defn(`i'))')dnl allocate variable for items in $2, and undefine it |
---|
168 | foreach(`i', `($1)', `ifdef(`item_'defn(`i'), `defn(`i') ')')dnl see what is still defined |
---|
169 | foreach(`i', `($2)', `popdef(`item_'defn(`i'))')dnl |
---|
170 | foreach(`i', `($1)', `popdef(`item_'defn(`i'))')dnl |
---|
171 | ') |
---|
172 | dnl }}} |
---|
173 | dnl {{{ DONE_* |
---|
174 | define(`DONE_SIZE', `IFASSERT(` |
---|
175 | done_size += $1`'; |
---|
176 | done_count ++; |
---|
177 | ')') |
---|
178 | define(`DONE', ` |
---|
179 | define(`ELEMENTS_DONE', defn(`ELEMENTS_DONE')`,$1') |
---|
180 | DONE_SIZE(`sizeof(src->$1)') |
---|
181 | ') |
---|
182 | define(`DISABLECHECK', ` |
---|
183 | pushdef(`DONE_SIZE') |
---|
184 | pushdef(`DONE') |
---|
185 | $1 |
---|
186 | popdef(`DONE_SIZE') |
---|
187 | popdef(`DONE') |
---|
188 | ') |
---|
189 | dnl }}} |
---|
190 | dnl {{{ IF** |
---|
191 | define(`IFCALC', `ifelse(KIND, `calc', `$1', `$2')') |
---|
192 | define(`IFSTORE', `ifelse(KIND, `store', `$1', `$2')') |
---|
193 | define(`IFCALCSTORE', `IFSTORE(`$1', `IFCALC(`$1', `$2')')') |
---|
194 | define(`IFRESTORE', `ifelse(KIND, `restore', `$1', `$2')') |
---|
195 | define(`IFCOPY', `IFSTORE(`$1', `IFRESTORE(`$1', `$2')')') |
---|
196 | define(`IFCALCCOPY', `IFCALC(`$1', `IFCOPY(`$1', `$2')')') |
---|
197 | define(`IFDPRINT', `ifelse(KIND, `dprint', `$1', `$2')') |
---|
198 | define(`IFASM', `ifelse(KIND, `asm', `$1', `$2')') |
---|
199 | define(`IFDASM', `ifelse(KIND, `dasm', `$1', `$2')') |
---|
200 | dnl }}} |
---|
201 | EXPORT(`zend_op') |
---|
202 | EXPORT(`zend_op_array') |
---|
203 | EXPORT(`zend_function') |
---|
204 | EXPORT(`HashTable_zend_function') |
---|
205 | EXPORT(`zend_class_entry') |
---|
206 | EXPORT(`xc_classinfo_t') |
---|
207 | EXPORT(`xc_funcinfo_t') |
---|
208 | EXPORT(`xc_entry_t') |
---|
209 | EXPORT(`zval') |
---|
210 | |
---|
211 | include(srcdir`/processor/hashtable.m4') |
---|
212 | include(srcdir`/processor/string.m4') |
---|
213 | include(srcdir`/processor/struct.m4') |
---|
214 | include(srcdir`/processor/dispatch.m4') |
---|
215 | include(srcdir`/processor/head.m4') |
---|
216 | |
---|
217 | define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')') |
---|
218 | REDEF(`KIND', `calc') include(srcdir`/processor/processor.m4') |
---|
219 | REDEF(`KIND', `store') include(srcdir`/processor/processor.m4') |
---|
220 | REDEF(`KIND', `restore') include(srcdir`/processor/processor.m4') |
---|
221 | |
---|
222 | REDEF(`IFNOTMEMCPY', `$1') |
---|
223 | #ifdef HAVE_XCACHE_DPRINT |
---|
224 | REDEF(`KIND', `dprint') include(srcdir`/processor/processor.m4') |
---|
225 | #endif /* HAVE_XCACHE_DPRINT */ |
---|
226 | #ifdef HAVE_XCACHE_DISASSEMBLER |
---|
227 | REDEF(`KIND', `dasm') include(srcdir`/processor/processor.m4') |
---|
228 | #endif /* HAVE_XCACHE_DISASSEMBLER */ |
---|
229 | #ifdef HAVE_XCACHE_ASSEMBLER |
---|
230 | REDEF(`KIND', `asm') include(srcdir`/processor/processor.m4') |
---|
231 | #endif /* HAVE_XCACHE_ASSEMBLER */ |
---|
232 | |
---|
233 | ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)') |
---|