source: trunk/processor/main.m4 @ 1440

Last change on this file since 1440 was 1440, checked in by moo, 14 months ago

adds ptrmove

  • Property svn:eol-style set to native
File size: 8.6 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')')')
29define(`SRCPTR_EX', `IFPTRMOVE(`(($1 *) (((char *) $2) + ptrmove->src))', `$2')')
30dnl }}}
31dnl {{{ SRCPTR(1:type, 2:elm)
32define(`DSTPTR', `DSTPTR_EX(`$1', `DST(`$2')')')
33define(`DSTPTR_EX', `SRCPTR_EX($@)')
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 }}}
130dnl {{{ EXPORT
131define(`EXPORT', `define(`EXPORT_$1')')
132dnl }}}
[1440]133dnl {{{ FIXPOINTER(1:type, 2:ele)
134define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `DST(`$2')', `SRCPTR(`$1', `$2')')')
[1]135dnl }}}
[1440]136dnl {{{ FIXPOINTER_EX(1:type, 2:dst, 3:src)
137define(`FIXPOINTER_EX', `
138    IFSTORE(`$2 = ($1 *) processor->shm->handlers->to_readonly(processor->shm, (void *)$2);')
139    IFPTRMOVE(`$2 = ($1 *) (((char *) $3) + ptrmove->ptrdiff);')
140')
141dnl }}}
[1439]142dnl {{{ IFNOTMEMCPY
143define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')')
144dnl }}}
[1]145dnl {{{ COPY
[1380]146define(`COPY', `IFNOTMEMCPY(`IFCOPY(`DST(`$1') = SRC(`$1');')')DONE(`$1')')
[1]147dnl }}}
[1440]148dnl {{{ COPY_N_EX(1:count, 2:type, 3:dst)
[662]149define(`COPY_N_EX', `
[1380]150    ALLOC(`DST(`$3')', `$2', `SRC(`$1')')
[662]151    IFCOPY(`
[1380]152        memcpy(DST(`$3'), SRC(`$3'), sizeof(DST(`$3[0]')) * SRC(`$1'));
[662]153        ')
154')
155dnl }}}
[311]156dnl {{{ COPYPOINTER
157define(`COPYPOINTER', `COPY(`$1')')
158dnl }}}
[1]159dnl {{{ SETNULL_EX
160define(`SETNULL_EX', `IFCOPY(`$1 = NULL;')')
[1380]161define(`SETNULL', `SETNULL_EX(`DST(`$1')')DONE(`$1')')
[1]162dnl }}}
[4]163dnl {{{ COPYNULL_EX(1:dst, 2:elm-name)
[1]164define(`COPYNULL_EX', `
[1313]165    IFDASM(`add_assoc_null_ex(dst, XCACHE_STRS("$2"));')
[1]166    IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')')
[837]167    assert(patsubst($1, dst, src) == NULL);
[1]168')
[4]169dnl }}}
170dnl {{{ COPYNULL(1:elm)
[1]171define(`COPYNULL', `
[1380]172    COPYNULL_EX(`DST(`$1')', `$1')DONE(`$1')
[1]173')
174dnl }}}
[844]175dnl {{{ COPYZERO_EX(1:dst, 2:elm-name)
176define(`COPYZERO_EX', `
[1313]177    IFDASM(`add_assoc_long_ex(dst, XCACHE_STRS("$2"), 0);')
[844]178    IFNOTMEMCPY(`IFCOPY(`$1 = 0;')')
179    assert(patsubst($1, dst, src) == 0);
180')
181dnl }}}
182dnl {{{ COPYZERO(1:elm)
183define(`COPYZERO', `
[1380]184    COPYZERO_EX(`DST(`$1')', `$1')DONE(`$1')
[844]185')
186dnl }}}
[4]187dnl {{{ LIST_DIFF(1:left-list, 2:right-list)
188define(`foreach',
189       `pushdef(`$1')_foreach(`$1', `$2', `$3')popdef(`$1')')
190define(`_arg1', `$1')
191define(`_foreach',                             
192       `ifelse(`$2', `()', ,                       
193       `define(`$1', _arg1$2)$3`'_foreach(`$1',
194                                                       (shift$2),
195                                                       `$3')')')
196define(`LIST_DIFF', `dnl
197foreach(`i', `($1)', `pushdef(`item_'defn(`i'))')dnl allocate variable for items in $1
198foreach(`i', `($2)', `pushdef(`item_'defn(`i'))undefine(`item_'defn(`i'))')dnl allocate variable for items in $2, and undefine it
199foreach(`i', `($1)', `ifdef(`item_'defn(`i'), `defn(`i') ')')dnl see what is still defined
[356]200foreach(`i', `($2)', `define(`item_'defn(`i'))popdef(`item_'defn(`i'))')dnl
[4]201foreach(`i', `($1)', `popdef(`item_'defn(`i'))')dnl
202')
203dnl }}}
[1]204dnl {{{ DONE_*
[877]205define(`DONE_SIZE', `IFAUTOCHECK(`dnl
[1201]206    xc_autocheck_done_size += (int) $1`';
[877]207    xc_autocheck_done_count ++;
[1]208')')
209define(`DONE', `
[719]210    define(`ELEMENTS_DONE', defn(`ELEMENTS_DONE')`,"$1"')
[877]211    IFAUTOCHECK(`dnl
212        if (zend_u_hash_exists(&xc_autocheck_done_names, IS_STRING, "$1", sizeof("$1"))) {
[719]213            fprintf(stderr
214                , "duplicate field at %s `#'%d FUNC_NAME`' : %s\n"
215                , __FILE__, __LINE__
216                , "$1"
217                );
218        }
219        else {
220            zend_uchar b = 1;
[877]221            zend_hash_add(&xc_autocheck_done_names, "$1", sizeof("$1"), (void*)&b, sizeof(b), NULL);
[719]222        }
223    ')
[843]224    DONE_SIZE(`sizeof(SRC(`$1'))')
[1]225')
226define(`DISABLECHECK', `
227    pushdef(`DONE_SIZE')
228    pushdef(`DONE')
229$1
230    popdef(`DONE_SIZE')
231    popdef(`DONE')
232')
233dnl }}}
234dnl {{{ IF**
[877]235define(`IFCALC', `ifelse(PROCESSOR_TYPE, `calc', `$1', `$2')')
236define(`IFSTORE', `ifelse(PROCESSOR_TYPE, `store', `$1', `$2')')
[198]237define(`IFCALCSTORE', `IFSTORE(`$1', `IFCALC(`$1', `$2')')')
[877]238define(`IFRESTORE', `ifelse(PROCESSOR_TYPE, `restore', `$1', `$2')')
[1440]239define(`IFPTRMOVE', `ifelse(PROCESSOR_TYPE, `ptrmove', `$1', `$2')')
[198]240define(`IFCOPY', `IFSTORE(`$1', `IFRESTORE(`$1', `$2')')')
241define(`IFCALCCOPY', `IFCALC(`$1', `IFCOPY(`$1', `$2')')')
[877]242define(`IFDPRINT', `ifelse(PROCESSOR_TYPE, `dprint', `$1', `$2')')
243define(`IFDASM', `ifelse(PROCESSOR_TYPE, `dasm', `$1', `$2')')
[1]244dnl }}}
[1439]245
[1]246EXPORT(`zend_op')
247EXPORT(`zend_op_array')
248EXPORT(`zend_function')
249EXPORT(`HashTable_zend_function')
250EXPORT(`zend_class_entry')
251EXPORT(`xc_classinfo_t')
252EXPORT(`xc_funcinfo_t')
[856]253EXPORT(`xc_entry_var_t')
[851]254EXPORT(`xc_entry_php_t')
[311]255EXPORT(`xc_entry_data_php_t')
[1]256EXPORT(`zval')
257
[4]258include(srcdir`/processor/hashtable.m4')
259include(srcdir`/processor/string.m4')
260include(srcdir`/processor/struct.m4')
[843]261include(srcdir`/processor/process.m4')
[4]262include(srcdir`/processor/head.m4')
[1]263
[877]264REDEF(`PROCESSOR_TYPE', `calc') include(srcdir`/processor/processor.m4')
265REDEF(`PROCESSOR_TYPE', `store') include(srcdir`/processor/processor.m4')
266REDEF(`PROCESSOR_TYPE', `restore') include(srcdir`/processor/processor.m4')
[1440]267REDEF(`PROCESSOR_TYPE', `ptrmove') include(srcdir`/processor/processor.m4')
[1]268
269#ifdef HAVE_XCACHE_DPRINT
[877]270REDEF(`PROCESSOR_TYPE', `dprint') include(srcdir`/processor/processor.m4')
[1]271#endif /* HAVE_XCACHE_DPRINT */
272#ifdef HAVE_XCACHE_DISASSEMBLER
[877]273REDEF(`PROCESSOR_TYPE', `dasm') include(srcdir`/processor/processor.m4')
[1]274#endif /* HAVE_XCACHE_DISASSEMBLER */
275
276ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)')
Note: See TracBrowser for help on using the repository browser.