source: trunk/processor/main.m4 @ 1473

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

processor: avoid using srcdir dstdir marco for m4

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