source: trunk/processor/main.m4 @ 1488

Last change on this file since 1488 was 1488, checked in by moo, 7 months ago

Decompiler PHP_5_6: updated support for zend_ast

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