source: trunk/processor/main.m4 @ 1444

Last change on this file since 1444 was 1444, checked in by moo, 9 months ago

relocate WIP

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