source: trunk/processor/main.m4 @ 1443

Last change on this file since 1443 was 1443, checked in by moo, 11 months ago

simplify export code

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