source: trunk/processor/main.m4 @ 233

Last change on this file since 233 was 233, checked in by moo, 8 years ago

processor: apply reference handling on opcode caching. reverted [196] [199] [220] and refix for #36

File size: 7.6 KB
RevLine 
[1]1divert(-1)
2dnl ================ start ======================
[12]3dnl define(`XCACHE_ENABLE_TEST')
[1]4define(`USEMEMCPY')
5
6dnl ================ main
7
8dnl {{{ basic
9define(`REDEF', `undefine(`$1') define(`$1', `$2')')
10define(`ONCE', `ifdef(`ONCE $1', `', `define(`ONCE $1')$1')')
11define(`m4_errprint', `ONCE(`errprint(`$1
12')')')
[233]13define(`ZEND_STRS', `($1), (sizeof($1))')
14define(`ZEND_STRL', `($1), (sizeof($1) - 1)')
[1]15dnl ============
16define(`INDENT', `xc_dprint_indent(indent);')
17dnl }}}
18dnl {{{ ALLOC(1:dst, 2:type, 3:count=1, 4:clean=false, 5:forcetype=$2)
19define(`ALLOC', `
20    pushdef(`COUNT', `ifelse(`$3', `', `1', `$3')')
21    pushdef(`SIZE', `sizeof($2)ifelse(`$3', `', `', ` * $3')')
22    pushdef(`FORCETYPE', `ifelse(`$5', , `$2', `$5')')
23    /* allocate */
24    IFCALC(`
25        IFASSERT(`
[193]26            xc_stack_push(&processor->allocsizes, (void *) (long) (SIZE));
27            xc_stack_push(&processor->allocsizes, (void *) (long) (__LINE__));
[1]28        ')
29        processor->size = (size_t) ALIGN(processor->size);
30        processor->size += SIZE;
31    ')
32    IFSTORE(`
33        IFASSERT(`{
34            if (!xc_stack_size(&processor->allocsizes)) {
35                fprintf(stderr, "mismatch `$@' at line %d\n", __LINE__);
36            }
37            else {
[193]38                unsigned long expect = (unsigned long) xc_stack_pop(&processor->allocsizes);
39                unsigned long atline = (unsigned long) xc_stack_pop(&processor->allocsizes);
40                unsigned long real = SIZE;
[1]41                if (expect != real) {
[197]42                    fprintf(stderr, "mismatch `$@' at line %d(was %d): real %lu - expect %lu = %l\n", __LINE__, atline, real, expect, real - expect);
[1]43                }
44            }
45        }')
46        $1 = (FORCETYPE *) (processor->p = (char *) ALIGN(processor->p));
47        ifelse(`$4', `', `
48                IFASSERT(`memset($1, -1, SIZE);')
49            ', `
50                memset($1, 0, SIZE);
51        ')
52        processor->p += SIZE;
53    ')
54    IFRESTORE(`ifelse(`$4', `', `
55            ifelse(
56                FORCETYPE*COUNT, `zval*1', `ALLOC_ZVAL($1);',
57                FORCETYPE*COUNT, `HashTable*1', `ALLOC_HASHTABLE($1);',
58                `', `', `$1 = (FORCETYPE *) emalloc(SIZE);')
59            IFASSERT(`memset($1, -1, SIZE);')
60        ', `
61            $1 = (FORCETYPE *) ecalloc(COUNT, sizeof($2));
62        ')
63    ')
64    popdef(`COUNT')
65    popdef(`SIZE')
66')
67dnl CALLOC(1:dst, 2:type [, 3:count=1 ])
68define(`CALLOC', `ALLOC(`$1', `$2', `$3', `1')')
69dnl }}}
70dnl {{{ PROC_INT(1:elm, 2:format=%d, 3:type=, 4:spec=)
71define(`PROC_INT', `
72    IFNOTMEMCPY(`IFCOPY(`dst->$1 = src->$1;')')
73    IFDPRINT(`
74        INDENT()
75        ifelse(
76            `$3 $1', `zval_data_type type', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_data_type(src->$1));'
77        , `$3 $1', `int op_type', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_op_type(src->$1));'
78        , `$3 $1', `zend_uchar opcode', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_opcode(src->$1));'
79        , `', `', `fprintf(stderr, "$3:$1:\t%ifelse(`$2',`',`d',`$2')\n", src->$1);')
80    ')
81    IFDASM(`
82        ifelse(
83            `$3', `zend_bool', `add_assoc_bool_ex(dst, ZEND_STRS("$1"), src->$1 ? 1 : 0);'
84        , `', `', `add_assoc_long_ex(dst, ZEND_STRS("$1"), src->$1);'
85        )
86    ')
87    DONE(`$1')
88')
89dnl }}}
[4]90dnl {{{ PROC_CLASS_ENTRY_P(1:elm)
91define(`PROC_CLASS_ENTRY_P', `PROC_CLASS_ENTRY_P_EX(`dst->$1', `src->$1', `$1')`'DONE(`$1')')
92dnl PROC_CLASS_ENTRY_P_EX(1:dst, 2:src, 3:elm-name)
[1]93define(`PROC_CLASS_ENTRY_P_EX', `
94    if ($2) {
95        IFSTORE(`$1 = (zend_class_entry *) xc_get_class_num(processor, $2);')
[90]96        IFRESTORE(`$1 = xc_get_class(processor, (zend_ulong) $2);')
[4]97        IFDASM(`add_assoc_stringl_ex(dst, ZEND_STRS("$3"), $2->name, strlen($2->name), 1);')
[1]98    }
99    else {
[4]100        COPYNULL_EX(`$1', `$3')
[1]101    }
102')
103dnl }}}
104dnl {{{ IFASSERT
105define(`IFASSERT', `ifdef(`XCACHE_ENABLE_TEST', `
106#ifndef NDEBUG
107        $1
108#endif
109')')
110dnl }}}
111dnl {{{ DBG
112define(`DBG', `ifdef(`XCACHE_ENABLE_TEST', `
113    /* `$1' */
114')')
115dnl }}}
116dnl {{{ EXPORT
117define(`EXPORT', `define(`EXPORT_$1')')
118dnl }}}
119dnl {{{ FIXPOINTER
120define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `dst->$2')')
121define(`FIXPOINTER_EX', `IFSTORE(`
[148]122    $2 = ($1 *) processor->xce_src->cache->shm->handlers->to_readonly(processor->xce_src->cache->shm, (char *)$2);
[1]123')')
124define(`UNFIXPOINTER', `UNFIXPOINTER_EX(`$1', `dst->$2')')
125define(`UNFIXPOINTER_EX', `IFSTORE(`
[148]126    $2 = ($1 *) processor->xce_src->cache->shm->handlers->to_readwrite(processor->xce_src->cache->shm, (char *)$2);
[1]127')')
128dnl }}}
129dnl {{{ COPY
130define(`COPY', `IFNOTMEMCPY(`IFCOPY(`dst->$1 = src->$1;')')DONE(`$1')')
131dnl }}}
132dnl {{{ SETNULL_EX
133define(`SETNULL_EX', `IFCOPY(`$1 = NULL;')')
134define(`SETNULL', `SETNULL_EX(`dst->$1')DONE(`$1')')
135dnl }}}
[4]136dnl {{{ COPYNULL_EX(1:dst, 2:elm-name)
[1]137define(`COPYNULL_EX', `
[4]138    IFDASM(`add_assoc_null_ex(dst, ZEND_STRS("$2"));')
[1]139    IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')')
140')
[4]141dnl }}}
142dnl {{{ COPYNULL(1:elm)
143# foreach(VAR, (LIST), STMT)
144m4_define([foreach],
145       [m4_pushdef([$1])_foreach([$1], [$2], [$3])m4_popdef([$1])])
146m4_define([_arg1], [$1])
147m4_define([_foreach],
148       [ifelse([$2], [()], ,
149       [m4_define([$1], _arg1$2)$3[]_foreach([$1],
150                                                       (shift$2),
151                                                       [$3])])])
[1]152define(`COPYNULL', `
[4]153    COPYNULL_EX(`dst->$1', `$2')DONE(`$1')
[1]154')
155dnl }}}
[4]156dnl {{{ LIST_DIFF(1:left-list, 2:right-list)
157define(`foreach',
158       `pushdef(`$1')_foreach(`$1', `$2', `$3')popdef(`$1')')
159define(`_arg1', `$1')
160define(`_foreach',                             
161       `ifelse(`$2', `()', ,                       
162       `define(`$1', _arg1$2)$3`'_foreach(`$1',
163                                                       (shift$2),
164                                                       `$3')')')
165define(`LIST_DIFF', `dnl
166foreach(`i', `($1)', `pushdef(`item_'defn(`i'))')dnl allocate variable for items in $1
167foreach(`i', `($2)', `pushdef(`item_'defn(`i'))undefine(`item_'defn(`i'))')dnl allocate variable for items in $2, and undefine it
168foreach(`i', `($1)', `ifdef(`item_'defn(`i'), `defn(`i') ')')dnl see what is still defined
169foreach(`i', `($2)', `popdef(`item_'defn(`i'))')dnl
170foreach(`i', `($1)', `popdef(`item_'defn(`i'))')dnl
171')
172dnl }}}
[1]173dnl {{{ DONE_*
174define(`DONE_SIZE', `IFASSERT(`
175    done_size += $1`';
176    done_count ++;
177')')
178define(`DONE', `
[4]179    define(`ELEMENTS_DONE', defn(`ELEMENTS_DONE')`,$1')
[1]180    DONE_SIZE(`sizeof(src->$1)')
181')
182define(`DISABLECHECK', `
183    pushdef(`DONE_SIZE')
184    pushdef(`DONE')
185$1
186    popdef(`DONE_SIZE')
187    popdef(`DONE')
188')
189dnl }}}
190dnl {{{ IF**
191define(`IFCALC', `ifelse(KIND, `calc', `$1', `$2')')
192define(`IFSTORE', `ifelse(KIND, `store', `$1', `$2')')
[198]193define(`IFCALCSTORE', `IFSTORE(`$1', `IFCALC(`$1', `$2')')')
[1]194define(`IFRESTORE', `ifelse(KIND, `restore', `$1', `$2')')
[198]195define(`IFCOPY', `IFSTORE(`$1', `IFRESTORE(`$1', `$2')')')
196define(`IFCALCCOPY', `IFCALC(`$1', `IFCOPY(`$1', `$2')')')
[1]197define(`IFDPRINT', `ifelse(KIND, `dprint', `$1', `$2')')
198define(`IFASM', `ifelse(KIND, `asm', `$1', `$2')')
199define(`IFDASM', `ifelse(KIND, `dasm', `$1', `$2')')
200dnl }}}
201EXPORT(`zend_op')
202EXPORT(`zend_op_array')
203EXPORT(`zend_function')
204EXPORT(`HashTable_zend_function')
205EXPORT(`zend_class_entry')
206EXPORT(`xc_classinfo_t')
207EXPORT(`xc_funcinfo_t')
208EXPORT(`xc_entry_t')
209EXPORT(`zval')
210
[4]211include(srcdir`/processor/hashtable.m4')
212include(srcdir`/processor/string.m4')
213include(srcdir`/processor/struct.m4')
214include(srcdir`/processor/dispatch.m4')
215include(srcdir`/processor/head.m4')
[1]216
217define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')')
[4]218REDEF(`KIND', `calc') include(srcdir`/processor/processor.m4')
219REDEF(`KIND', `store') include(srcdir`/processor/processor.m4')
220REDEF(`KIND', `restore') include(srcdir`/processor/processor.m4')
[1]221
222REDEF(`IFNOTMEMCPY', `$1')
223#ifdef HAVE_XCACHE_DPRINT
[4]224REDEF(`KIND', `dprint') include(srcdir`/processor/processor.m4')
[1]225#endif /* HAVE_XCACHE_DPRINT */
226#ifdef HAVE_XCACHE_DISASSEMBLER
[4]227REDEF(`KIND', `dasm') include(srcdir`/processor/processor.m4')
[1]228#endif /* HAVE_XCACHE_DISASSEMBLER */
229#ifdef HAVE_XCACHE_ASSEMBLER
[4]230REDEF(`KIND', `asm') include(srcdir`/processor/processor.m4')
[1]231#endif /* HAVE_XCACHE_ASSEMBLER */
232
233ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)')
Note: See TracBrowser for help on using the repository browser.