| 1 | divert(-1) |
|---|
| 2 | dnl ================ start ====================== |
|---|
| 3 | define(`XCACHE_ENABLE_TEST') |
|---|
| 4 | define(`USEMEMCPY') |
|---|
| 5 | |
|---|
| 6 | dnl ================ main |
|---|
| 7 | |
|---|
| 8 | dnl {{{ basic |
|---|
| 9 | define(`REDEF', `undefine(`$1') define(`$1', `$2')') |
|---|
| 10 | define(`ONCE', `ifdef(`ONCE $1', `', `define(`ONCE $1')$1')') |
|---|
| 11 | define(`m4_errprint', `ONCE(`errprint(`$1 |
|---|
| 12 | ')')') |
|---|
| 13 | dnl ============ |
|---|
| 14 | define(`INDENT', `xc_dprint_indent(indent);') |
|---|
| 15 | dnl }}} |
|---|
| 16 | dnl {{{ ALLOC(1:dst, 2:type, 3:count=1, 4:clean=false, 5:forcetype=$2) |
|---|
| 17 | dnl don't use typeof(dst) as we need the compiler warning |
|---|
| 18 | define(`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 | ') |
|---|
| 66 | dnl CALLOC(1:dst, 2:type [, 3:count=1 ]) |
|---|
| 67 | define(`CALLOC', `ALLOC(`$1', `$2', `$3', `1')') |
|---|
| 68 | dnl }}} |
|---|
| 69 | dnl {{{ PROC_INT(1:elm, 2:format=%d, 3:type=, 4:spec=) |
|---|
| 70 | define(`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 | ') |
|---|
| 88 | dnl }}} |
|---|
| 89 | dnl {{{ PROC_CLASS_ENTRY_P |
|---|
| 90 | define(`PROC_CLASS_ENTRY_P', `PROC_CLASS_ENTRY_P_EX(`dst->$1', `src->$1')`'DONE(`$1')') |
|---|
| 91 | define(`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 | ') |
|---|
| 101 | dnl }}} |
|---|
| 102 | dnl {{{ IFASSERT |
|---|
| 103 | define(`IFASSERT', `ifdef(`XCACHE_ENABLE_TEST', ` |
|---|
| 104 | #ifndef NDEBUG |
|---|
| 105 | $1 |
|---|
| 106 | #endif |
|---|
| 107 | ')') |
|---|
| 108 | dnl }}} |
|---|
| 109 | dnl {{{ DBG |
|---|
| 110 | define(`DBG', `ifdef(`XCACHE_ENABLE_TEST', ` |
|---|
| 111 | /* `$1' */ |
|---|
| 112 | ')') |
|---|
| 113 | dnl }}} |
|---|
| 114 | dnl {{{ EXPORT |
|---|
| 115 | define(`EXPORT', `define(`EXPORT_$1')') |
|---|
| 116 | dnl }}} |
|---|
| 117 | dnl {{{ FIXPOINTER |
|---|
| 118 | define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `dst->$2')') |
|---|
| 119 | define(`FIXPOINTER_EX', `IFSTORE(` |
|---|
| 120 | $2 = ($1 *) xc_shm_to_readonly(processor->xce_src->cache->shm, (char *)$2); |
|---|
| 121 | ')') |
|---|
| 122 | define(`UNFIXPOINTER', `UNFIXPOINTER_EX(`$1', `dst->$2')') |
|---|
| 123 | define(`UNFIXPOINTER_EX', `IFSTORE(` |
|---|
| 124 | $2 = ($1 *) xc_shm_to_readwrite(processor->xce_src->cache->shm, (char *)$2); |
|---|
| 125 | ')') |
|---|
| 126 | dnl }}} |
|---|
| 127 | dnl {{{ COPY |
|---|
| 128 | define(`COPY', `IFNOTMEMCPY(`IFCOPY(`dst->$1 = src->$1;')')DONE(`$1')') |
|---|
| 129 | dnl }}} |
|---|
| 130 | dnl {{{ SETNULL_EX |
|---|
| 131 | define(`SETNULL_EX', `IFCOPY(`$1 = NULL;')') |
|---|
| 132 | define(`SETNULL', `SETNULL_EX(`dst->$1')DONE(`$1')') |
|---|
| 133 | dnl }}} |
|---|
| 134 | dnl {{{ COPYNULL_EX |
|---|
| 135 | define(`COPYNULL_EX', ` |
|---|
| 136 | IFDASM(`add_assoc_null_ex(dst, ZEND_STRS("patsubst(`$1', `dst->')"));') |
|---|
| 137 | IFNOTMEMCPY(`IFCOPY(`$1 = NULL;')') |
|---|
| 138 | ') |
|---|
| 139 | define(`COPYNULL', ` |
|---|
| 140 | COPYNULL_EX(`dst->$1')DONE(`$1') |
|---|
| 141 | ') |
|---|
| 142 | dnl }}} |
|---|
| 143 | dnl {{{ DONE_* |
|---|
| 144 | define(`DONE_SIZE', `IFASSERT(` |
|---|
| 145 | done_size += $1`'; |
|---|
| 146 | done_count ++; |
|---|
| 147 | ')') |
|---|
| 148 | define(`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 | ') |
|---|
| 153 | define(`DISABLECHECK', ` |
|---|
| 154 | pushdef(`DONE_SIZE') |
|---|
| 155 | pushdef(`DONE') |
|---|
| 156 | $1 |
|---|
| 157 | popdef(`DONE_SIZE') |
|---|
| 158 | popdef(`DONE') |
|---|
| 159 | ') |
|---|
| 160 | dnl }}} |
|---|
| 161 | dnl {{{ IF** |
|---|
| 162 | define(`IFCALC', `ifelse(KIND, `calc', `$1', `$2')') |
|---|
| 163 | define(`IFSTORE', `ifelse(KIND, `store', `$1', `$2')') |
|---|
| 164 | define(`IFCALCSTORE', `IFSTORE(`$1', ` |
|---|
| 165 | IFCALC(`$1', `$2') |
|---|
| 166 | ')') |
|---|
| 167 | define(`IFRESTORE', `ifelse(KIND, `restore', `$1', `$2')') |
|---|
| 168 | define(`IFCOPY', `IFSTORE(`$1', ` |
|---|
| 169 | IFRESTORE(`$1', `$2') |
|---|
| 170 | ')') |
|---|
| 171 | define(`IFCALCCOPY', `IFCALC(`$1', ` |
|---|
| 172 | IFCOPY(`$1', `$2') |
|---|
| 173 | ')') |
|---|
| 174 | define(`IFDPRINT', `ifelse(KIND, `dprint', `$1', `$2')') |
|---|
| 175 | define(`IFASM', `ifelse(KIND, `asm', `$1', `$2')') |
|---|
| 176 | define(`IFDASM', `ifelse(KIND, `dasm', `$1', `$2')') |
|---|
| 177 | dnl }}} |
|---|
| 178 | EXPORT(`zend_op') |
|---|
| 179 | EXPORT(`zend_op_array') |
|---|
| 180 | EXPORT(`zend_function') |
|---|
| 181 | EXPORT(`HashTable_zend_function') |
|---|
| 182 | EXPORT(`zend_class_entry') |
|---|
| 183 | EXPORT(`xc_classinfo_t') |
|---|
| 184 | EXPORT(`xc_funcinfo_t') |
|---|
| 185 | EXPORT(`xc_entry_t') |
|---|
| 186 | EXPORT(`zval') |
|---|
| 187 | |
|---|
| 188 | include(hashtable.m4) |
|---|
| 189 | include(string.m4) |
|---|
| 190 | include(struct.m4) |
|---|
| 191 | include(dispatch.m4) |
|---|
| 192 | include(head.m4) |
|---|
| 193 | |
|---|
| 194 | define(`IFNOTMEMCPY', `ifdef(`USEMEMCPY', `', `$1')') |
|---|
| 195 | REDEF(`KIND', `calc') include(processor.m4) |
|---|
| 196 | REDEF(`KIND', `store') include(processor.m4) |
|---|
| 197 | REDEF(`KIND', `restore') include(processor.m4) |
|---|
| 198 | |
|---|
| 199 | REDEF(`IFNOTMEMCPY', `$1') |
|---|
| 200 | #ifdef HAVE_XCACHE_DPRINT |
|---|
| 201 | REDEF(`KIND', `dprint') include(processor.m4) |
|---|
| 202 | #endif /* HAVE_XCACHE_DPRINT */ |
|---|
| 203 | #ifdef HAVE_XCACHE_DISASSEMBLER |
|---|
| 204 | REDEF(`KIND', `dasm') include(processor.m4) |
|---|
| 205 | #endif /* HAVE_XCACHE_DISASSEMBLER */ |
|---|
| 206 | #ifdef HAVE_XCACHE_ASSEMBLER |
|---|
| 207 | REDEF(`KIND', `asm') include(processor.m4) |
|---|
| 208 | #endif /* HAVE_XCACHE_ASSEMBLER */ |
|---|
| 209 | |
|---|
| 210 | ifdef(`EXIT_PENDING', `m4exit(EXIT_PENDING)') |
|---|