source: trunk/processor/main.m4 @ 1

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

initial import to online

File size: 6.0 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 }}}
89dnl {{{ PROC_CLASS_ENTRY_P
90define(`PROC_CLASS_ENTRY_P', `PROC_CLASS_ENTRY_P_EX(`dst->$1', `src->$1')`'DONE(`$1')')
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_uint) $2);')
95        IFDASM(`add_assoc_stringl_ex(dst, ZEND_STRS("patsubst(`$1', `dst->')"), $2->name, strlen($2->name), 1);')
96    }
97    else {
98        COPYNULL_EX($1)
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 *) xc_shm_to_readonly(processor->xce_src->cache->shm, (char *)$2);
121')')
122define(`UNFIXPOINTER', `UNFIXPOINTER_EX(`$1', `dst->$2')')
123define(`UNFIXPOINTER_EX', `IFSTORE(`
124    $2 = ($1 *) xc_shm_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
135define(`COPYNULL_EX', `
136    IFDASM(`add_assoc_null_ex(dst, ZEND_STRS("patsubst(`$1', `dst->')"));')
137    IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')')
138')
139define(`COPYNULL', `
140    COPYNULL_EX(`dst->$1')DONE(`$1')
141')
142dnl }}}
143dnl {{{ DONE_*
144define(`DONE_SIZE', `IFASSERT(`
145    done_size += $1`';
146    done_count ++;
147')')
148define(`DONE', `
149    dnl ifelse(regexp(defn(`ELEMENTS'), ` $1'), -1, m4_errprint(`Unknown $1') m4exit(1))
150    define(`ELEMENTS', patsubst(defn(`ELEMENTS'), ` $1\>'))
151    DONE_SIZE(`sizeof(src->$1)')
152')
153define(`DISABLECHECK', `
154    pushdef(`DONE_SIZE')
155    pushdef(`DONE')
156$1
157    popdef(`DONE_SIZE')
158    popdef(`DONE')
159')
160dnl }}}
161dnl {{{ IF**
162define(`IFCALC', `ifelse(KIND, `calc', `$1', `$2')')
163define(`IFSTORE', `ifelse(KIND, `store', `$1', `$2')')
164define(`IFCALCSTORE', `IFSTORE(`$1', `
165    IFCALC(`$1', `$2')
166')')
167define(`IFRESTORE', `ifelse(KIND, `restore', `$1', `$2')')
168define(`IFCOPY', `IFSTORE(`$1', `
169    IFRESTORE(`$1', `$2')
170')')
171define(`IFCALCCOPY', `IFCALC(`$1', `
172    IFCOPY(`$1', `$2')
173')')
174define(`IFDPRINT', `ifelse(KIND, `dprint', `$1', `$2')')
175define(`IFASM', `ifelse(KIND, `asm', `$1', `$2')')
176define(`IFDASM', `ifelse(KIND, `dasm', `$1', `$2')')
177dnl }}}
178EXPORT(`zend_op')
179EXPORT(`zend_op_array')
180EXPORT(`zend_function')
181EXPORT(`HashTable_zend_function')
182EXPORT(`zend_class_entry')
183EXPORT(`xc_classinfo_t')
184EXPORT(`xc_funcinfo_t')
185EXPORT(`xc_entry_t')
186EXPORT(`zval')
187
188include(hashtable.m4)
189include(string.m4)
190include(struct.m4)
191include(dispatch.m4)
192include(head.m4)
193
194define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')')
195REDEF(`KIND', `calc') include(processor.m4)
196REDEF(`KIND', `store') include(processor.m4)
197REDEF(`KIND', `restore') include(processor.m4)
198
199REDEF(`IFNOTMEMCPY', `$1')
200#ifdef HAVE_XCACHE_DPRINT
201REDEF(`KIND', `dprint') include(processor.m4)
202#endif /* HAVE_XCACHE_DPRINT */
203#ifdef HAVE_XCACHE_DISASSEMBLER
204REDEF(`KIND', `dasm') include(processor.m4)
205#endif /* HAVE_XCACHE_DISASSEMBLER */
206#ifdef HAVE_XCACHE_ASSEMBLER
207REDEF(`KIND', `asm') include(processor.m4)
208#endif /* HAVE_XCACHE_ASSEMBLER */
209
210ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)')
Note: See TracBrowser for help on using the repository browser.