source: trunk/processor/main.m4 @ 4

Last change on this file since 4 was 4, checked in by moo, 9 years ago

compatibility fix: remove the using of gnu m4 extension

File size: 7.4 KB
RevLine 
[1]1divert(-1)
2dnl ================ start ======================
3define(`XCACHE_ENABLE_TEST')
4define(`USEMEMCPY')
5
6dnl ================ main
7
8dnl {{{ basic
9define(`REDEF', `undefine(`$1') define(`$1', `$2')')
10define(`ONCE', `ifdef(`ONCE $1', `', `define(`ONCE $1')$1')')
11define(`m4_errprint', `ONCE(`errprint(`$1
12')')')
13dnl ============
14define(`INDENT', `xc_dprint_indent(indent);')
15dnl }}}
16dnl {{{ ALLOC(1:dst, 2:type, 3:count=1, 4:clean=false, 5:forcetype=$2)
17dnl don't use typeof(dst) as we need the compiler warning
18define(`ALLOC', `
19    pushdef(`COUNT', `ifelse(`$3', `', `1', `$3')')
20    pushdef(`SIZE', `sizeof($2)ifelse(`$3', `', `', ` * $3')')
21    pushdef(`FORCETYPE', `ifelse(`$5', , `$2', `$5')')
22    /* allocate */
23    IFCALC(`
24        IFASSERT(`
25            xc_stack_push(&processor->allocsizes, (void*)(SIZE));
26            xc_stack_push(&processor->allocsizes, (void*)(__LINE__));
27        ')
28        processor->size = (size_t) ALIGN(processor->size);
29        processor->size += SIZE;
30    ')
31    IFSTORE(`
32        IFASSERT(`{
33            if (!xc_stack_size(&processor->allocsizes)) {
34                fprintf(stderr, "mismatch `$@' at line %d\n", __LINE__);
35            }
36            else {
37                int expect = (int)xc_stack_pop(&processor->allocsizes);
38                int atline = (int)xc_stack_pop(&processor->allocsizes);
39                int real = SIZE;
40                if (expect != real) {
41                    fprintf(stderr, "mismatch `$@' at line %d(was %d): real %d - expect %d = %d\n", __LINE__, atline, real, expect, real - expect);
42                }
43            }
44        }')
45        $1 = (FORCETYPE *) (processor->p = (char *) ALIGN(processor->p));
46        ifelse(`$4', `', `
47                IFASSERT(`memset($1, -1, SIZE);')
48            ', `
49                memset($1, 0, SIZE);
50        ')
51        processor->p += SIZE;
52    ')
53    IFRESTORE(`ifelse(`$4', `', `
54            ifelse(
55                FORCETYPE*COUNT, `zval*1', `ALLOC_ZVAL($1);',
56                FORCETYPE*COUNT, `HashTable*1', `ALLOC_HASHTABLE($1);',
57                `', `', `$1 = (FORCETYPE *) emalloc(SIZE);')
58            IFASSERT(`memset($1, -1, SIZE);')
59        ', `
60            $1 = (FORCETYPE *) ecalloc(COUNT, sizeof($2));
61        ')
62    ')
63    popdef(`COUNT')
64    popdef(`SIZE')
65')
66dnl CALLOC(1:dst, 2:type [, 3:count=1 ])
67define(`CALLOC', `ALLOC(`$1', `$2', `$3', `1')')
68dnl }}}
69dnl {{{ PROC_INT(1:elm, 2:format=%d, 3:type=, 4:spec=)
70define(`PROC_INT', `
71    IFNOTMEMCPY(`IFCOPY(`dst->$1 = src->$1;')')
72    IFDPRINT(`
73        INDENT()
74        ifelse(
75            `$3 $1', `zval_data_type type', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_data_type(src->$1));'
76        , `$3 $1', `int op_type', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_op_type(src->$1));'
77        , `$3 $1', `zend_uchar opcode', `fprintf(stderr, "$3:$1:\t%d %s\n", src->$1, xc_get_opcode(src->$1));'
78        , `', `', `fprintf(stderr, "$3:$1:\t%ifelse(`$2',`',`d',`$2')\n", src->$1);')
79    ')
80    IFDASM(`
81        ifelse(
82            `$3', `zend_bool', `add_assoc_bool_ex(dst, ZEND_STRS("$1"), src->$1 ? 1 : 0);'
83        , `', `', `add_assoc_long_ex(dst, ZEND_STRS("$1"), src->$1);'
84        )
85    ')
86    DONE(`$1')
87')
88dnl }}}
[4]89dnl {{{ PROC_CLASS_ENTRY_P(1:elm)
90define(`PROC_CLASS_ENTRY_P', `PROC_CLASS_ENTRY_P_EX(`dst->$1', `src->$1', `$1')`'DONE(`$1')')
91dnl PROC_CLASS_ENTRY_P_EX(1:dst, 2:src, 3:elm-name)
[1]92define(`PROC_CLASS_ENTRY_P_EX', `
93    if ($2) {
94        IFSTORE(`$1 = (zend_class_entry *) xc_get_class_num(processor, $2);')
95        IFRESTORE(`$1 = xc_get_class(processor, (zend_uint) $2);')
[4]96        IFDASM(`add_assoc_stringl_ex(dst, ZEND_STRS("$3"), $2->name, strlen($2->name), 1);')
[1]97    }
98    else {
[4]99        COPYNULL_EX(`$1', `$3')
[1]100    }
101')
102dnl }}}
103dnl {{{ IFASSERT
104define(`IFASSERT', `ifdef(`XCACHE_ENABLE_TEST', `
105#ifndef NDEBUG
106        $1
107#endif
108')')
109dnl }}}
110dnl {{{ DBG
111define(`DBG', `ifdef(`XCACHE_ENABLE_TEST', `
112    /* `$1' */
113')')
114dnl }}}
115dnl {{{ EXPORT
116define(`EXPORT', `define(`EXPORT_$1')')
117dnl }}}
118dnl {{{ FIXPOINTER
119define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `dst->$2')')
120define(`FIXPOINTER_EX', `IFSTORE(`
121    $2 = ($1 *) xc_shm_to_readonly(processor->xce_src->cache->shm, (char *)$2);
122')')
123define(`UNFIXPOINTER', `UNFIXPOINTER_EX(`$1', `dst->$2')')
124define(`UNFIXPOINTER_EX', `IFSTORE(`
125    $2 = ($1 *) xc_shm_to_readwrite(processor->xce_src->cache->shm, (char *)$2);
126')')
127dnl }}}
128dnl {{{ COPY
129define(`COPY', `IFNOTMEMCPY(`IFCOPY(`dst->$1 = src->$1;')')DONE(`$1')')
130dnl }}}
131dnl {{{ SETNULL_EX
132define(`SETNULL_EX', `IFCOPY(`$1 = NULL;')')
133define(`SETNULL', `SETNULL_EX(`dst->$1')DONE(`$1')')
134dnl }}}
[4]135dnl {{{ COPYNULL_EX(1:dst, 2:elm-name)
[1]136define(`COPYNULL_EX', `
[4]137    IFDASM(`add_assoc_null_ex(dst, ZEND_STRS("$2"));')
[1]138    IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')')
139')
[4]140dnl }}}
141dnl {{{ COPYNULL(1:elm)
142# foreach(VAR, (LIST), STMT)
143m4_define([foreach],
144       [m4_pushdef([$1])_foreach([$1], [$2], [$3])m4_popdef([$1])])
145m4_define([_arg1], [$1])
146m4_define([_foreach],
147       [ifelse([$2], [()], ,
148       [m4_define([$1], _arg1$2)$3[]_foreach([$1],
149                                                       (shift$2),
150                                                       [$3])])])
[1]151define(`COPYNULL', `
[4]152    COPYNULL_EX(`dst->$1', `$2')DONE(`$1')
[1]153')
154dnl }}}
[4]155dnl {{{ LIST_DIFF(1:left-list, 2:right-list)
156define(`foreach',
157       `pushdef(`$1')_foreach(`$1', `$2', `$3')popdef(`$1')')
158define(`_arg1', `$1')
159define(`_foreach',                             
160       `ifelse(`$2', `()', ,                       
161       `define(`$1', _arg1$2)$3`'_foreach(`$1',
162                                                       (shift$2),
163                                                       `$3')')')
164define(`LIST_DIFF', `dnl
165foreach(`i', `($1)', `pushdef(`item_'defn(`i'))')dnl allocate variable for items in $1
166foreach(`i', `($2)', `pushdef(`item_'defn(`i'))undefine(`item_'defn(`i'))')dnl allocate variable for items in $2, and undefine it
167foreach(`i', `($1)', `ifdef(`item_'defn(`i'), `defn(`i') ')')dnl see what is still defined
168foreach(`i', `($2)', `popdef(`item_'defn(`i'))')dnl
169foreach(`i', `($1)', `popdef(`item_'defn(`i'))')dnl
170')
171dnl }}}
[1]172dnl {{{ DONE_*
173define(`DONE_SIZE', `IFASSERT(`
174    done_size += $1`';
175    done_count ++;
176')')
177define(`DONE', `
[4]178    define(`ELEMENTS_DONE', defn(`ELEMENTS_DONE')`,$1')
[1]179    DONE_SIZE(`sizeof(src->$1)')
180')
181define(`DISABLECHECK', `
182    pushdef(`DONE_SIZE')
183    pushdef(`DONE')
184$1
185    popdef(`DONE_SIZE')
186    popdef(`DONE')
187')
188dnl }}}
189dnl {{{ IF**
190define(`IFCALC', `ifelse(KIND, `calc', `$1', `$2')')
191define(`IFSTORE', `ifelse(KIND, `store', `$1', `$2')')
192define(`IFCALCSTORE', `IFSTORE(`$1', `
193    IFCALC(`$1', `$2')
194')')
195define(`IFRESTORE', `ifelse(KIND, `restore', `$1', `$2')')
196define(`IFCOPY', `IFSTORE(`$1', `
197    IFRESTORE(`$1', `$2')
198')')
199define(`IFCALCCOPY', `IFCALC(`$1', `
200    IFCOPY(`$1', `$2')
201')')
202define(`IFDPRINT', `ifelse(KIND, `dprint', `$1', `$2')')
203define(`IFASM', `ifelse(KIND, `asm', `$1', `$2')')
204define(`IFDASM', `ifelse(KIND, `dasm', `$1', `$2')')
205dnl }}}
206EXPORT(`zend_op')
207EXPORT(`zend_op_array')
208EXPORT(`zend_function')
209EXPORT(`HashTable_zend_function')
210EXPORT(`zend_class_entry')
211EXPORT(`xc_classinfo_t')
212EXPORT(`xc_funcinfo_t')
213EXPORT(`xc_entry_t')
214EXPORT(`zval')
215
[4]216include(srcdir`/processor/hashtable.m4')
217include(srcdir`/processor/string.m4')
218include(srcdir`/processor/struct.m4')
219include(srcdir`/processor/dispatch.m4')
220include(srcdir`/processor/head.m4')
[1]221
222define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')')
[4]223REDEF(`KIND', `calc') include(srcdir`/processor/processor.m4')
224REDEF(`KIND', `store') include(srcdir`/processor/processor.m4')
225REDEF(`KIND', `restore') include(srcdir`/processor/processor.m4')
[1]226
227REDEF(`IFNOTMEMCPY', `$1')
228#ifdef HAVE_XCACHE_DPRINT
[4]229REDEF(`KIND', `dprint') include(srcdir`/processor/processor.m4')
[1]230#endif /* HAVE_XCACHE_DPRINT */
231#ifdef HAVE_XCACHE_DISASSEMBLER
[4]232REDEF(`KIND', `dasm') include(srcdir`/processor/processor.m4')
[1]233#endif /* HAVE_XCACHE_DISASSEMBLER */
234#ifdef HAVE_XCACHE_ASSEMBLER
[4]235REDEF(`KIND', `asm') include(srcdir`/processor/processor.m4')
[1]236#endif /* HAVE_XCACHE_ASSEMBLER */
237
238ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)')
Note: See TracBrowser for help on using the repository browser.