source: trunk/processor/main.m4 @ 148

Last change on this file since 148 was 148, checked in by moo, 8 years ago

reconstruct shm/allocator

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