source: trunk/processor/main.m4 @ 1439

Last change on this file since 1439 was 1439, checked in by moo, 14 months ago

code cleanup

  • Property svn:eol-style set to native
File size: 8.6 KB
Line 
1divert(-1)
2dnl ================ start ======================
3dnl define(`XCACHE_ENABLE_TEST')
4dnl define(`DEBUG_SIZE')
5define(`USEMEMCPY')
6
7dnl ================ main
8
9dnl {{{ basic
10define(`REDEF', `ifdef(`$1', `undefine(`$1')') define(`$1', `$2')')
11define(`MAKE_MACRONAME', `translit(`$1', ` ():
12', `_____')')
13define(`ONCE', `ifdef(MAKE_MACRONAME(`ONCE $1'), `', `define(MAKE_MACRONAME(`ONCE $1'))$1')')
14define(`m4_errprint', `ONCE(`errprint(`$1
15')')')
16ifdef(`len', `
17define(`m4_len', defn(`len'))
18undefine(`len')
19')
20define(`XCACHE_STRS', `($1), (sizeof($1))')
21define(`XCACHE_STRL', `($1), (sizeof($1) - 1)')
22define(`DST', `dst->$1')
23define(`SRC', `src->$1')
24dnl ============
25define(`INDENT', `xc_dprint_indent(indent);')
26dnl }}}
27dnl {{{ ALLOC(1:dst, 2:type, 3:count=1, 4:clean=false, 5:realtype=$2)
28define(`ALLOC', `
29    pushdef(`COUNT', `ifelse(`$3', `', `1', `$3')')
30    pushdef(`SIZE', `sizeof($2)ifelse(`$3', `', `', ` * $3')')
31    pushdef(`REALTYPE', `ifelse(`$5', , `$2', `$5')')
32    /* allocate */
33    IFCALC(`
34        IFAUTOCHECK(`
35            xc_stack_push(&processor->allocsizes, (void *) (long) (SIZE));
36            xc_stack_push(&processor->allocsizes, (void *) (long) (__LINE__));
37        ')
38        processor->size = (size_t) ALIGN(processor->size);
39        processor->size += SIZE;
40    ')
41    IFSTORE(`
42        IFAUTOCHECK(`{
43            if (!xc_stack_count(&processor->allocsizes)) {
44                fprintf(stderr, "mismatch `$@' at line %d\n", __LINE__);
45            }
46            else {
47                unsigned long expect = (unsigned long) xc_stack_pop(&processor->allocsizes);
48                unsigned long atline = (unsigned long) xc_stack_pop(&processor->allocsizes);
49                unsigned long real = SIZE;
50                if (expect != real) {
51                    fprintf(stderr, "mismatch `$@' at line %d(was %lu): real %lu - expect %lu = %lu\n", __LINE__, atline, real, expect, real - expect);
52                }
53            }
54        }')
55        ifdef(`DEBUG_SIZE', ` {
56            void *oldp = processor->p;
57        ')
58        $1 = (REALTYPE *) (processor->p = (char *) ALIGN(processor->p));
59        ifelse(`$4', `', `
60                IFAUTOCHECK(`memsetptr($1, (void *) (unsigned long) __LINE__, SIZE);')
61            ', `
62                memset($1, 0, SIZE);
63        ')
64        processor->p += SIZE;
65
66        ifdef(`DEBUG_SIZE', `
67            xc_totalsize += (char *) processor->p - (char *) oldp;
68            fprintf(stderr, "%d\t%d\t`'SIZE()\n", (char *) processor->p - (char *) oldp, xc_totalsize);
69        }
70        ')
71    ')
72    IFRESTORE(`ifelse(`$4', `', `
73            ifelse(
74                REALTYPE*COUNT, `zval*1', `ALLOC_ZVAL($1);',
75                REALTYPE*COUNT, `HashTable*1', `ALLOC_HASHTABLE($1);',
76                `', `', `$1 = (REALTYPE *) emalloc(SIZE);')
77            IFAUTOCHECK(`memsetptr($1, (void *) __LINE__, SIZE);')
78        ', `
79            $1 = (REALTYPE *) ecalloc(COUNT, sizeof($2));
80        ')
81    ')
82    popdef(`REALTYPE')
83    popdef(`COUNT')
84    popdef(`SIZE')
85')
86dnl CALLOC(1:dst, 2:type [, 3:count=1, 4:realtype=$2 ])
87define(`CALLOC', `ALLOC(`$1', `$2', `$3', `1', `$4')')
88dnl }}}
89dnl {{{ PROC_CLASS_ENTRY_P(1:elm)
90define(`PROC_CLASS_ENTRY_P', `PROC_CLASS_ENTRY_P_EX(`DST(`$1')', `SRC(`$1')', `$1')`'DONE(`$1')')
91dnl PROC_CLASS_ENTRY_P_EX(1:dst, 2:src, 3:elm-name)
92define(`PROC_CLASS_ENTRY_P_EX', `
93    if ($2) {
94        IFSTORE(`$1 = (zend_class_entry *) xc_get_class_num(processor, $2);')
95        IFRESTORE(`$1 = xc_get_class(processor, (zend_ulong) $2);')
96#ifdef IS_UNICODE
97        IFDASM(`add_assoc_unicodel_ex(dst, XCACHE_STRS("$3"), ZSTR_U($2->name), $2->name_length, 1);')
98#else
99        IFDASM(`add_assoc_stringl_ex(dst, XCACHE_STRS("$3"), (char *) $2->name, $2->name_length, 1);')
100#endif
101    }
102    else {
103        COPYNULL_EX(`$1', `$3')
104    }
105')
106dnl }}}
107dnl {{{ IFAUTOCHECKEX
108define(`IFAUTOCHECKEX', `ifdef(`XCACHE_ENABLE_TEST', `$1', `$2')')
109dnl }}}
110dnl {{{ IFAUTOCHECK
111define(`IFAUTOCHECK', `IFAUTOCHECKEX(`
112#ifndef NDEBUG
113        $1
114#endif
115')')
116dnl }}}
117dnl {{{ DBG
118define(`DBG', `ifdef(`XCACHE_ENABLE_TEST', `
119    /* `$1' */
120')')
121dnl }}}
122dnl {{{ EXPORT
123define(`EXPORT', `define(`EXPORT_$1')')
124dnl }}}
125dnl {{{ FIXPOINTER
126define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `DST(`$2')')')
127define(`FIXPOINTER_EX', `IFSTORE(`
128    $2 = ($1 *) processor->shm->handlers->to_readonly(processor->shm, (void *)$2);
129')')
130define(`UNFIXPOINTER', `UNFIXPOINTER_EX(`$1', `DST(`$2')')')
131define(`UNFIXPOINTER_EX', `IFSTORE(`
132    $2 = ($1 *) processor->shm->handlers->to_readwrite(processor->shm, (void *)$2);
133')')
134dnl }}}
135dnl {{{ IFNOTMEMCPY
136define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')')
137dnl }}}
138dnl {{{ COPY
139define(`COPY', `IFNOTMEMCPY(`IFCOPY(`DST(`$1') = SRC(`$1');')')DONE(`$1')')
140dnl }}}
141dnl {{{ COPY_N_EX
142define(`COPY_N_EX', `
143    ALLOC(`DST(`$3')', `$2', `SRC(`$1')')
144    IFCOPY(`
145        memcpy(DST(`$3'), SRC(`$3'), sizeof(DST(`$3[0]')) * SRC(`$1'));
146        ')
147')
148dnl }}}
149dnl {{{ COPY_N
150define(`COPY_N', `COPY_N_EX(`$1',`$2')DONE(`$1')')
151dnl }}}
152dnl {{{ COPYPOINTER
153define(`COPYPOINTER', `COPY(`$1')')
154dnl }}}
155dnl {{{ COPYARRAY_EX
156define(`COPYARRAY_EX', `IFNOTMEMCPY(`IFCOPY(`memcpy(DST(`$1'), SRC(`$1'), sizeof(DST(`$1')));')')')
157dnl }}}
158dnl {{{ COPYARRAY
159define(`COPYARRAY', `COPYARRAY_EX(`$1',`$2')DONE(`$1')')
160dnl }}}
161dnl {{{ SETNULL_EX
162define(`SETNULL_EX', `IFCOPY(`$1 = NULL;')')
163define(`SETNULL', `SETNULL_EX(`DST(`$1')')DONE(`$1')')
164dnl }}}
165dnl {{{ SETZERO_EX
166define(`SETZERO_EX', `IFCOPY(`$1 = 0;')')
167define(`SETZERO', `SETZERO_EX(`DST(`$1')')DONE(`$1')')
168dnl }}}
169dnl {{{ COPYNULL_EX(1:dst, 2:elm-name)
170define(`COPYNULL_EX', `
171    IFDASM(`add_assoc_null_ex(dst, XCACHE_STRS("$2"));')
172    IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')')
173    assert(patsubst($1, dst, src) == NULL);
174')
175dnl }}}
176dnl {{{ COPYNULL(1:elm)
177define(`COPYNULL', `
178    COPYNULL_EX(`DST(`$1')', `$1')DONE(`$1')
179')
180dnl }}}
181dnl {{{ COPYZERO_EX(1:dst, 2:elm-name)
182define(`COPYZERO_EX', `
183    IFDASM(`add_assoc_long_ex(dst, XCACHE_STRS("$2"), 0);')
184    IFNOTMEMCPY(`IFCOPY(`$1 = 0;')')
185    assert(patsubst($1, dst, src) == 0);
186')
187dnl }}}
188dnl {{{ COPYZERO(1:elm)
189define(`COPYZERO', `
190    COPYZERO_EX(`DST(`$1')', `$1')DONE(`$1')
191')
192dnl }}}
193dnl {{{ LIST_DIFF(1:left-list, 2:right-list)
194define(`foreach',
195       `pushdef(`$1')_foreach(`$1', `$2', `$3')popdef(`$1')')
196define(`_arg1', `$1')
197define(`_foreach',                             
198       `ifelse(`$2', `()', ,                       
199       `define(`$1', _arg1$2)$3`'_foreach(`$1',
200                                                       (shift$2),
201                                                       `$3')')')
202define(`LIST_DIFF', `dnl
203foreach(`i', `($1)', `pushdef(`item_'defn(`i'))')dnl allocate variable for items in $1
204foreach(`i', `($2)', `pushdef(`item_'defn(`i'))undefine(`item_'defn(`i'))')dnl allocate variable for items in $2, and undefine it
205foreach(`i', `($1)', `ifdef(`item_'defn(`i'), `defn(`i') ')')dnl see what is still defined
206foreach(`i', `($2)', `define(`item_'defn(`i'))popdef(`item_'defn(`i'))')dnl
207foreach(`i', `($1)', `popdef(`item_'defn(`i'))')dnl
208')
209dnl }}}
210dnl {{{ DONE_*
211define(`DONE_SIZE', `IFAUTOCHECK(`dnl
212    xc_autocheck_done_size += (int) $1`';
213    xc_autocheck_done_count ++;
214')')
215define(`DONE', `
216    define(`ELEMENTS_DONE', defn(`ELEMENTS_DONE')`,"$1"')
217    IFAUTOCHECK(`dnl
218        if (zend_u_hash_exists(&xc_autocheck_done_names, IS_STRING, "$1", sizeof("$1"))) {
219            fprintf(stderr
220                , "duplicate field at %s `#'%d FUNC_NAME`' : %s\n"
221                , __FILE__, __LINE__
222                , "$1"
223                );
224        }
225        else {
226            zend_uchar b = 1;
227            zend_hash_add(&xc_autocheck_done_names, "$1", sizeof("$1"), (void*)&b, sizeof(b), NULL);
228        }
229    ')
230    DONE_SIZE(`sizeof(SRC(`$1'))')
231')
232define(`DISABLECHECK', `
233    pushdef(`DONE_SIZE')
234    pushdef(`DONE')
235$1
236    popdef(`DONE_SIZE')
237    popdef(`DONE')
238')
239dnl }}}
240dnl {{{ IF**
241define(`IFCALC', `ifelse(PROCESSOR_TYPE, `calc', `$1', `$2')')
242define(`IFSTORE', `ifelse(PROCESSOR_TYPE, `store', `$1', `$2')')
243define(`IFCALCSTORE', `IFSTORE(`$1', `IFCALC(`$1', `$2')')')
244define(`IFRESTORE', `ifelse(PROCESSOR_TYPE, `restore', `$1', `$2')')
245define(`IFCOPY', `IFSTORE(`$1', `IFRESTORE(`$1', `$2')')')
246define(`IFCALCCOPY', `IFCALC(`$1', `IFCOPY(`$1', `$2')')')
247define(`IFDPRINT', `ifelse(PROCESSOR_TYPE, `dprint', `$1', `$2')')
248define(`IFDASM', `ifelse(PROCESSOR_TYPE, `dasm', `$1', `$2')')
249dnl }}}
250
251EXPORT(`zend_op')
252EXPORT(`zend_op_array')
253EXPORT(`zend_function')
254EXPORT(`HashTable_zend_function')
255EXPORT(`zend_class_entry')
256EXPORT(`xc_classinfo_t')
257EXPORT(`xc_funcinfo_t')
258EXPORT(`xc_entry_var_t')
259EXPORT(`xc_entry_php_t')
260EXPORT(`xc_entry_data_php_t')
261EXPORT(`zval')
262
263include(srcdir`/processor/hashtable.m4')
264include(srcdir`/processor/string.m4')
265include(srcdir`/processor/struct.m4')
266include(srcdir`/processor/process.m4')
267include(srcdir`/processor/head.m4')
268
269REDEF(`PROCESSOR_TYPE', `calc') include(srcdir`/processor/processor.m4')
270REDEF(`PROCESSOR_TYPE', `store') include(srcdir`/processor/processor.m4')
271REDEF(`PROCESSOR_TYPE', `restore') include(srcdir`/processor/processor.m4')
272
273#ifdef HAVE_XCACHE_DPRINT
274REDEF(`PROCESSOR_TYPE', `dprint') include(srcdir`/processor/processor.m4')
275#endif /* HAVE_XCACHE_DPRINT */
276#ifdef HAVE_XCACHE_DISASSEMBLER
277REDEF(`PROCESSOR_TYPE', `dasm') include(srcdir`/processor/processor.m4')
278#endif /* HAVE_XCACHE_DISASSEMBLER */
279
280ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)')
Note: See TracBrowser for help on using the repository browser.