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
Line 
1divert(-1)
2dnl ================ start ======================
3dnl #define HAVE_XCACHE_TEST
4dnl define(`DEBUG_SIZE')
5define(`USEMEMCPY')
6
7dnl ================ main
8
9dnl {{{ basic
10define(`REDEF', `ifdef(`$1', `undefine(`$1')') define(`$1', `$2')')
11define(`MAKE_MACRONAME', `translit(`$1', ` ():
12', `_____')')
13define(`ONCE', `ifdef(MAKE_MACRONAME(`ONCE $1'), `', `define(MAKE_MACRONAME(`ONCE $1'))$1')')
14define(`m4_errprint', `ONCE(`errprint(`$1
15')')')
16ifdef(`len', `
17define(`m4_len', defn(`len'))
18undefine(`len')
19')
20define(`dirof', `patsubst(`$1', `[/\\][^/\\]*$', `')')
21ifdef(`__dir__', `', `
22define(`__dir__', `dirof(__file__)')
23')
24define(`XCACHE_STRS', `($1), (sizeof($1))')
25define(`XCACHE_STRL', `($1), (sizeof($1) - 1)')
26define(`SRC', `ifelse(`$1', `', `src', `src->$1')')
27define(`DST', `ifelse(`$1', `', `dst', `dst->$1')')
28dnl ============
29define(`INDENT', `xc_dprint_indent(indent);')
30dnl }}}
31dnl {{{ PTR_FROM_VIRTUAL_EX(1:type, 2:elm)
32define(`PTR_FROM_VIRTUAL_EX', `$2')
33dnl }}}
34dnl {{{ ALLOC(1:dst, 2:type, 3:count=1, 4:clean=false, 5:realtype=$2)
35define(`ALLOC', `
36    pushdef(`COUNT', `ifelse(`$3', `', `1', `$3')')
37    ifdef(`ALLOC_SIZE_HELPER', `
38        pushdef(`SIZE', `ALLOC_SIZE_HELPER()')
39    ', `
40        pushdef(`SIZE', `sizeof($2)ifelse(`$3', `', `', ` * $3')')
41    ')
42    pushdef(`REALTYPE', `ifelse(`$5', , `$2', `$5')')
43    /* allocate */
44    IFCALC(`
45        IFAUTOCHECK(`
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            }
51        ')
52        processor->size = (size_t) ALIGN(processor->size);
53        processor->size += SIZE;
54    ')
55    IFSTORE(`
56        IFAUTOCHECK(`{
57            if (!xc_vector_size(&processor->allocsizes)) {
58                fprintf(stderr, "mismatch `$@' at line %d\n", __LINE__);
59            }
60            else {
61                unsigned long expect = xc_vector_pop_back(unsigned long, &processor->allocsizes);
62                unsigned long atline = xc_vector_pop_back(unsigned long, &processor->allocsizes);
63                unsigned long real = SIZE;
64                if (expect != real) {
65                    fprintf(stderr, "mismatch `$@' at line %d(was %lu): real %lu - expect %lu = %lu\n", __LINE__, atline, real, expect, real - expect);
66                }
67            }
68        }')
69        ifdef(`DEBUG_SIZE', ` {
70            void *oldp = processor->p;
71        ')
72        $1 = (REALTYPE *) (processor->p = (char *) ALIGN(processor->p));
73        ifelse(`$4', `', `
74                IFAUTOCHECK(`xc_memsetptr($1, (void *) (unsigned long) __LINE__, SIZE);')
75            ', `
76                memset($1, 0, SIZE);
77        ')
78        processor->p += SIZE;
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);
83        }
84        ')
85    ')
86    IFRESTORE(`ifelse(`$4', `', `
87            ifelse(
88                REALTYPE*COUNT, `zval*1', `ALLOC_ZVAL($1);',
89                REALTYPE*COUNT, `HashTable*1', `ALLOC_HASHTABLE($1);',
90                `', `', `$1 = (REALTYPE *) emalloc(SIZE);')
91            IFAUTOCHECK(`xc_memsetptr($1, (void *) __LINE__, SIZE);')
92        ', `
93            $1 = (REALTYPE *) ecalloc(COUNT, sizeof($2));
94        ')
95    ')
96    popdef(`REALTYPE')
97    popdef(`COUNT')
98    popdef(`SIZE')
99')
100dnl CALLOC(1:dst, 2:type [, 3:count=1, 4:realtype=$2 ])
101define(`CALLOC', `ALLOC(`$1', `$2', `$3', `1', `$4')')
102dnl }}}
103dnl {{{ PROC_CLASS_ENTRY_P(1:elm)
104define(`PROC_CLASS_ENTRY_P', `PROC_CLASS_ENTRY_P_EX(`DST(`$1')', `SRC(`$1')', `$1')`'DONE(`$1')')
105dnl PROC_CLASS_ENTRY_P_EX(1:dst, 2:src, 3:elm-name)
106define(`PROC_CLASS_ENTRY_P_EX', `
107    if ($2) {
108        IFSTORE(`$1 = (zend_class_entry *) xc_get_class_num(processor, $2);')
109        IFRESTORE(`$1 = xc_get_class(processor, (zend_ulong) $2);')
110#ifdef IS_UNICODE
111        IFDASM(`add_assoc_unicodel_ex(DST(), XCACHE_STRS("$3"), ZSTR_U($2->name), $2->name_length, 1);')
112#else
113        IFDASM(`add_assoc_stringl_ex(DST(), XCACHE_STRS("$3"), (char *) $2->name, $2->name_length, 1);')
114#endif
115    }
116    else {
117        COPYNULL_EX(`$1', `$3')
118    }
119')
120dnl }}}
121dnl {{{ IFAUTOCHECK
122define(`IFAUTOCHECK', `
123#ifdef HAVE_XCACHE_TEST
124    $1
125ifelse(`$2', `', `
126#else
127    $2
128')
129#endif
130')
131dnl }}}
132dnl {{{ DBG
133define(`DBG', `/* `$1' */
134')
135dnl }}}
136dnl {{{ EXPORT(1:code)
137define(`EXPORT', `/* export: $1 :export */')
138define(`EXPORTED', `EXPORT(`$1')
139$1')
140define(`EXPORTED_FUNCTION', `EXPORT(`$1;')
141$1')
142dnl }}}
143dnl {{{ EXPORT_PROCESSOR(1:type, 2:processor)
144define(`EXPORT_PROCESSOR', `define(`EXPORT_$1_$2', 1)')
145dnl }}}
146dnl {{{ RELOCATE(1:type, 2:ele)
147define(`RELOCATE', `RELOCATE_EX(`$1', `DST(`$2')')')
148dnl }}}
149dnl {{{ RELOCATE_EX(1:type, 2:dst)
150define(`RELOCATE_EX', `')
151dnl }}}
152dnl {{{ IFNOTMEMCPY
153define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')')
154dnl }}}
155dnl {{{ COPY
156define(`COPY', `IFNOTMEMCPY(`IFCOPY(`DST(`$1') = SRC(`$1');')')DONE(`$1')')
157dnl }}}
158dnl {{{ COPY_N_EX(1:count, 2:type, 3:dst)
159define(`COPY_N_EX', `
160    ALLOC(`DST(`$3')', `$2', `SRC(`$1')')
161    IFCOPY(`
162        memcpy(DST(`$3'), SRC(`$3'), sizeof(DST(`$3[0]')) * SRC(`$1'));
163        ')
164')
165dnl }}}
166dnl {{{ COPYPOINTER
167define(`COPYPOINTER', `COPY(`$1')')
168dnl }}}
169dnl {{{ SETNULL_EX
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')
180define(`SETNULL', `SETNULL_EX(`DST(`$1')')DONE(`$1')')
181dnl }}}
182dnl {{{ COPYNULL_EX(1:dst, 2:elm-name)
183define(`COPYNULL_EX', `
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    ')
191    IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')')
192    assert(patsubst($1, DST(), SRC()) == NULL);
193')
194dnl }}}
195dnl {{{ COPYNULL(1:elm)
196define(`COPYNULL', `
197    COPYNULL_EX(`DST(`$1')', `$1')DONE(`$1')
198')
199dnl }}}
200dnl {{{ COPYZERO_EX(1:dst, 2:elm-name)
201define(`COPYZERO_EX', `
202    IFDASM(`add_assoc_long_ex(DST(), XCACHE_STRS("$2"), 0);')
203    IFNOTMEMCPY(`IFCOPY(`$1 = 0;')')
204    assert(patsubst($1, DST(), SRC()) == 0);
205')
206dnl }}}
207dnl {{{ COPYZERO(1:elm)
208define(`COPYZERO', `
209    COPYZERO_EX(`DST(`$1')', `$1')DONE(`$1')
210')
211dnl }}}
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
225foreach(`i', `($2)', `define(`item_'defn(`i'))popdef(`item_'defn(`i'))')dnl
226foreach(`i', `($1)', `popdef(`item_'defn(`i'))')dnl
227')
228dnl }}}
229dnl {{{ DONE_*
230define(`DONE_SIZE', `IFAUTOCHECK(`dnl
231    xc_autocheck_done_size += (int) $1`';
232    xc_autocheck_done_count ++;
233')')
234define(`DONE', `
235    define(`ELEMENTS_DONE', defn(`ELEMENTS_DONE')`,"$1"')
236    IFAUTOCHECK(`dnl
237        if (zend_u_hash_exists(&xc_autocheck_done_names, IS_STRING, "$1", sizeof("$1"))) {
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;
246            zend_hash_add(&xc_autocheck_done_names, "$1", sizeof("$1"), (void*)&b, sizeof(b), NULL);
247        }
248    ')
249    DONE_SIZE(`sizeof(SRC(`$1'))')
250')
251define(`DISABLECHECK', `
252    pushdef(`DONE_SIZE')
253    pushdef(`DONE')
254$1
255    popdef(`DONE_SIZE')
256    popdef(`DONE')
257')
258dnl }}}
259dnl {{{ IF**
260define(`IFCALC', `ifelse(PROCESSOR_TYPE, `calc', `$1', `$2')')
261define(`IFSTORE', `ifelse(PROCESSOR_TYPE, `store', `$1', `$2')')
262define(`IFCALCSTORE', `IFSTORE(`$1', `IFCALC(`$1', `$2')')')
263define(`IFRESTORE', `ifelse(PROCESSOR_TYPE, `restore', `$1', `$2')')
264define(`IFCOPY', `IFSTORE(`$1', `IFRESTORE(`$1', `$2')')')
265define(`IFCALCCOPY', `IFCALC(`$1', `IFCOPY(`$1', `$2')')')
266define(`PROCRELOCATE', `ifelse(PROCESSOR_TYPE, `relocate', `$1', `$2')')
267define(`IFRELOCATE', `ifelse(defn(`RELOCATE_EX'), `', `$2', `$1')')
268define(`IFDPRINT', `ifelse(PROCESSOR_TYPE, `dprint', `$1', `$2')')
269define(`IFDASM', `ifelse(PROCESSOR_TYPE, `dasm', `$1', `$2')')
270dnl }}}
271
272EXPORT_PROCESSOR(`dasm',   `zend_op_array')
273EXPORT_PROCESSOR(`dasm',   `zend_function')
274EXPORT_PROCESSOR(`dasm',   `zend_class_entry')
275EXPORT_PROCESSOR(`dasm',   `zend_ast')
276EXPORT_PROCESSOR(`dprint', `zval')
277
278include(__dir__`/hashtable.m4')
279include(__dir__`/string.m4')
280include(__dir__`/struct.m4')
281include(__dir__`/process.m4')
282include(__dir__`/head.m4')
283
284dnl ==== calc ====
285REDEF(`PROCESSOR_TYPE', `calc')
286include(__dir__`/processor.m4')
287
288dnl ==== store ====
289pushdef(`RELOCATE_EX', `$2 = ptradd($1 *, notnullable($2), processor->relocatediff);')
290REDEF(`PROCESSOR_TYPE', `store')
291include(__dir__`/processor.m4')
292popdef(`RELOCATE_EX')
293
294dnl ==== restore ====
295REDEF(`PROCESSOR_TYPE', `restore')
296include(__dir__`/processor.m4')
297
298dnl ==== relocate ====
299pushdef(`PTR_FROM_VIRTUAL_EX', `ptradd($1 *, notnullable($2), ptrdiff)')
300pushdef(`RELOCATE_EX', `$2 = ptradd($1 *, notnullable($2), relocatediff);')
301pushdef(`SRC', defn(`DST'))
302REDEF(`PROCESSOR_TYPE', `relocate')
303include(__dir__`/processor.m4')
304popdef(`SRC')
305popdef(`RELOCATE_EX')
306popdef(`PTR_FROM_VIRTUAL_EX')
307
308dnl ==== dprint ====
309#ifdef HAVE_XCACHE_DPRINT
310REDEF(`PROCESSOR_TYPE', `dprint') include(__dir__`/processor.m4')
311#endif /* HAVE_XCACHE_DPRINT */
312
313dnl ==== dasm ====
314#ifdef HAVE_XCACHE_DISASSEMBLER
315REDEF(`PROCESSOR_TYPE', `dasm') include(__dir__`/processor.m4')
316#endif /* HAVE_XCACHE_DISASSEMBLER */
317
318undefine(`PROCESSOR_TYPE')
319
320include(__dir__`/foot.m4')
321
322ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)')
Note: See TracBrowser for help on using the repository browser.