source: trunk/processor/main.m4 @ 295

Last change on this file since 295 was 295, checked in by moo, 7 years ago

remove warnings

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