source: trunk/processor/main.m4 @ 1443

Last change on this file since 1443 was 1443, checked in by moo, 13 months ago

simplify export code

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