source: trunk/processor/main.m4 @ 302

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

c comments fix

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