source: trunk/processor/main.m4 @ 1468

Last change on this file since 1468 was 1468, checked in by moo, 5 months ago

clean up shm handlers

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