source: trunk/processor/main.m4 @ 1471

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

relocate: rename marcos to relocate

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