source: trunk/processor/main.m4 @ 860

Last change on this file since 860 was 860, checked in by moo, 3 years ago

kill warnings

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