source: trunk/processor/main.m4

Last change on this file was 1555, checked in by moo, 7 weeks ago

separate plain c code to .h files

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