source: trunk/processor/main.m4 @ 291

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

typo of last fix

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