source: trunk/processor/main.m4 @ 1440

Last change on this file since 1440 was 1440, checked in by moo, 10 months ago

adds ptrmove

  • 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 {{{ SRCPTR(1:type, 2:elm)
28define(`SRCPTR', `SRCPTR_EX(`$1', `SRC(`$2')')')
29define(`SRCPTR_EX', `IFPTRMOVE(`(($1 *) (((char *) $2) + ptrmove->src))', `$2')')
30dnl }}}
31dnl {{{ SRCPTR(1:type, 2:elm)
32define(`DSTPTR', `DSTPTR_EX(`$1', `DST(`$2')')')
33define(`DSTPTR_EX', `SRCPTR_EX($@)')
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
131define(`EXPORT', `define(`EXPORT_$1')')
132dnl }}}
133dnl {{{ FIXPOINTER(1:type, 2:ele)
134define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `DST(`$2')', `SRCPTR(`$1', `$2')')')
135dnl }}}
136dnl {{{ FIXPOINTER_EX(1:type, 2:dst, 3:src)
137define(`FIXPOINTER_EX', `
138    IFSTORE(`$2 = ($1 *) processor->shm->handlers->to_readonly(processor->shm, (void *)$2);')
139    IFPTRMOVE(`$2 = ($1 *) (((char *) $3) + ptrmove->ptrdiff);')
140')
141dnl }}}
142dnl {{{ IFNOTMEMCPY
143define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')')
144dnl }}}
145dnl {{{ COPY
146define(`COPY', `IFNOTMEMCPY(`IFCOPY(`DST(`$1') = SRC(`$1');')')DONE(`$1')')
147dnl }}}
148dnl {{{ COPY_N_EX(1:count, 2:type, 3:dst)
149define(`COPY_N_EX', `
150    ALLOC(`DST(`$3')', `$2', `SRC(`$1')')
151    IFCOPY(`
152        memcpy(DST(`$3'), SRC(`$3'), sizeof(DST(`$3[0]')) * SRC(`$1'));
153        ')
154')
155dnl }}}
156dnl {{{ COPYPOINTER
157define(`COPYPOINTER', `COPY(`$1')')
158dnl }}}
159dnl {{{ SETNULL_EX
160define(`SETNULL_EX', `IFCOPY(`$1 = NULL;')')
161define(`SETNULL', `SETNULL_EX(`DST(`$1')')DONE(`$1')')
162dnl }}}
163dnl {{{ COPYNULL_EX(1:dst, 2:elm-name)
164define(`COPYNULL_EX', `
165    IFDASM(`add_assoc_null_ex(dst, XCACHE_STRS("$2"));')
166    IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')')
167    assert(patsubst($1, dst, src) == NULL);
168')
169dnl }}}
170dnl {{{ COPYNULL(1:elm)
171define(`COPYNULL', `
172    COPYNULL_EX(`DST(`$1')', `$1')DONE(`$1')
173')
174dnl }}}
175dnl {{{ COPYZERO_EX(1:dst, 2:elm-name)
176define(`COPYZERO_EX', `
177    IFDASM(`add_assoc_long_ex(dst, XCACHE_STRS("$2"), 0);')
178    IFNOTMEMCPY(`IFCOPY(`$1 = 0;')')
179    assert(patsubst($1, dst, src) == 0);
180')
181dnl }}}
182dnl {{{ COPYZERO(1:elm)
183define(`COPYZERO', `
184    COPYZERO_EX(`DST(`$1')', `$1')DONE(`$1')
185')
186dnl }}}
187dnl {{{ LIST_DIFF(1:left-list, 2:right-list)
188define(`foreach',
189       `pushdef(`$1')_foreach(`$1', `$2', `$3')popdef(`$1')')
190define(`_arg1', `$1')
191define(`_foreach',                             
192       `ifelse(`$2', `()', ,                       
193       `define(`$1', _arg1$2)$3`'_foreach(`$1',
194                                                       (shift$2),
195                                                       `$3')')')
196define(`LIST_DIFF', `dnl
197foreach(`i', `($1)', `pushdef(`item_'defn(`i'))')dnl allocate variable for items in $1
198foreach(`i', `($2)', `pushdef(`item_'defn(`i'))undefine(`item_'defn(`i'))')dnl allocate variable for items in $2, and undefine it
199foreach(`i', `($1)', `ifdef(`item_'defn(`i'), `defn(`i') ')')dnl see what is still defined
200foreach(`i', `($2)', `define(`item_'defn(`i'))popdef(`item_'defn(`i'))')dnl
201foreach(`i', `($1)', `popdef(`item_'defn(`i'))')dnl
202')
203dnl }}}
204dnl {{{ DONE_*
205define(`DONE_SIZE', `IFAUTOCHECK(`dnl
206    xc_autocheck_done_size += (int) $1`';
207    xc_autocheck_done_count ++;
208')')
209define(`DONE', `
210    define(`ELEMENTS_DONE', defn(`ELEMENTS_DONE')`,"$1"')
211    IFAUTOCHECK(`dnl
212        if (zend_u_hash_exists(&xc_autocheck_done_names, IS_STRING, "$1", sizeof("$1"))) {
213            fprintf(stderr
214                , "duplicate field at %s `#'%d FUNC_NAME`' : %s\n"
215                , __FILE__, __LINE__
216                , "$1"
217                );
218        }
219        else {
220            zend_uchar b = 1;
221            zend_hash_add(&xc_autocheck_done_names, "$1", sizeof("$1"), (void*)&b, sizeof(b), NULL);
222        }
223    ')
224    DONE_SIZE(`sizeof(SRC(`$1'))')
225')
226define(`DISABLECHECK', `
227    pushdef(`DONE_SIZE')
228    pushdef(`DONE')
229$1
230    popdef(`DONE_SIZE')
231    popdef(`DONE')
232')
233dnl }}}
234dnl {{{ IF**
235define(`IFCALC', `ifelse(PROCESSOR_TYPE, `calc', `$1', `$2')')
236define(`IFSTORE', `ifelse(PROCESSOR_TYPE, `store', `$1', `$2')')
237define(`IFCALCSTORE', `IFSTORE(`$1', `IFCALC(`$1', `$2')')')
238define(`IFRESTORE', `ifelse(PROCESSOR_TYPE, `restore', `$1', `$2')')
239define(`IFPTRMOVE', `ifelse(PROCESSOR_TYPE, `ptrmove', `$1', `$2')')
240define(`IFCOPY', `IFSTORE(`$1', `IFRESTORE(`$1', `$2')')')
241define(`IFCALCCOPY', `IFCALC(`$1', `IFCOPY(`$1', `$2')')')
242define(`IFDPRINT', `ifelse(PROCESSOR_TYPE, `dprint', `$1', `$2')')
243define(`IFDASM', `ifelse(PROCESSOR_TYPE, `dasm', `$1', `$2')')
244dnl }}}
245
246EXPORT(`zend_op')
247EXPORT(`zend_op_array')
248EXPORT(`zend_function')
249EXPORT(`HashTable_zend_function')
250EXPORT(`zend_class_entry')
251EXPORT(`xc_classinfo_t')
252EXPORT(`xc_funcinfo_t')
253EXPORT(`xc_entry_var_t')
254EXPORT(`xc_entry_php_t')
255EXPORT(`xc_entry_data_php_t')
256EXPORT(`zval')
257
258include(srcdir`/processor/hashtable.m4')
259include(srcdir`/processor/string.m4')
260include(srcdir`/processor/struct.m4')
261include(srcdir`/processor/process.m4')
262include(srcdir`/processor/head.m4')
263
264REDEF(`PROCESSOR_TYPE', `calc') include(srcdir`/processor/processor.m4')
265REDEF(`PROCESSOR_TYPE', `store') include(srcdir`/processor/processor.m4')
266REDEF(`PROCESSOR_TYPE', `restore') include(srcdir`/processor/processor.m4')
267REDEF(`PROCESSOR_TYPE', `ptrmove') include(srcdir`/processor/processor.m4')
268
269#ifdef HAVE_XCACHE_DPRINT
270REDEF(`PROCESSOR_TYPE', `dprint') include(srcdir`/processor/processor.m4')
271#endif /* HAVE_XCACHE_DPRINT */
272#ifdef HAVE_XCACHE_DISASSEMBLER
273REDEF(`PROCESSOR_TYPE', `dasm') include(srcdir`/processor/processor.m4')
274#endif /* HAVE_XCACHE_DISASSEMBLER */
275
276ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)')
Note: See TracBrowser for help on using the repository browser.