source: trunk/processor/main.m4

Last change on this file was 1492, checked in by moo, 8 weeks ago

disassembler: fix support for assoc/next

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