2006-05-09 10:58:38 +00:00
|
|
|
define(`pushdefFUNC_NAME', `
|
2012-04-01 03:39:31 +00:00
|
|
|
pushdef(`FUNC_NAME', `xc_`'PROCESSOR_TYPE`'_`'ifelse(`$2', `', `$1', `$2')')
|
2006-05-09 10:58:38 +00:00
|
|
|
')
|
|
|
|
dnl {{{ DECL_STRUCT_P_FUNC(1:type, 2:name, 3:comma=;)
|
2006-05-13 01:54:55 +00:00
|
|
|
define(`DECL_STRUCT_P_FUNC', `translit(
|
2006-05-09 10:58:38 +00:00
|
|
|
pushdefFUNC_NAME(`$1', `$2')
|
|
|
|
define(`DEFINED_'ifelse(`$2', `', `$1', `$2'), `')
|
|
|
|
ifdef(`EXPORT_'ifelse(`$2', `', `$1', `$2'), `void', `static void inline')
|
|
|
|
FUNC_NAME`'(
|
|
|
|
IFDPRINT( `const $1 * const src, int indent')
|
2006-09-18 00:27:17 +00:00
|
|
|
IFCALC( `xc_processor_t *processor, const $1 * const src')
|
|
|
|
IFSTORE( `xc_processor_t *processor, $1 *dst, const $1 * const src')
|
|
|
|
IFRESTORE(`xc_processor_t *processor, $1 *dst, const $1 * const src')
|
2012-06-26 13:53:44 +00:00
|
|
|
IFDASM( `xc_dasm_t *dasm, zval *dst, const $1 * const src')
|
2006-05-09 10:58:38 +00:00
|
|
|
IFASM( `$1 *dst, const $1 * const src')
|
|
|
|
TSRMLS_DC
|
|
|
|
)ifelse(`$3', `', `;')
|
|
|
|
popdef(`FUNC_NAME')dnl
|
2006-05-13 01:54:55 +00:00
|
|
|
, `
|
|
|
|
', ` ')')
|
2006-05-09 10:58:38 +00:00
|
|
|
dnl }}}
|
|
|
|
dnl {{{ DEF_STRUCT_P_FUNC(1:type, 2:name, 3:body)
|
|
|
|
define(`DEF_STRUCT_P_FUNC', `
|
|
|
|
pushdefFUNC_NAME(`$1', `$2')
|
|
|
|
/* {`{'{ FUNC_NAME */
|
|
|
|
ifdef(`EXPORT_'ifelse(`$2', `', `$1', `$2'), `
|
|
|
|
/* export: DECL_STRUCT_P_FUNC(`$1', `$2') :export */
|
|
|
|
')
|
|
|
|
DECL_STRUCT_P_FUNC(`$1', `$2', 1)
|
|
|
|
{
|
2006-05-26 02:31:45 +00:00
|
|
|
pushdef(`ELEMENTS_DONE')
|
2012-04-01 03:39:31 +00:00
|
|
|
IFAUTOCHECK(`
|
2006-05-09 10:58:38 +00:00
|
|
|
/* {{{ init assert */
|
2012-07-26 03:43:51 +00:00
|
|
|
ifdef(`SIZEOF_$1', , `m4_errprint(`Warning: missing SIZEOF_$1, safe to ignore')')
|
|
|
|
ifdef(`COUNTOF_$1', , `m4_errprint(`Warning: missing COUNTOF_$1, safe to ignore')')
|
2006-05-26 02:31:45 +00:00
|
|
|
dnl SIZEOF_x COUNTOF_x can be both defined or both not
|
|
|
|
ifdef(`SIZEOF_$1', `
|
|
|
|
ifdef(`COUNTOF_$1', , `m4_errprint(`AUTOCHECK WARN: missing COUNTOF_$1')')
|
|
|
|
', `
|
|
|
|
define(`SIZEOF_$1', 0)
|
|
|
|
')
|
|
|
|
ifdef(`COUNTOF_$1', `
|
|
|
|
ifdef(`SIZEOF_$1', , `m4_errprint(`AUTOCHECK WARN: missing SIZEOF_$1')')
|
|
|
|
', `
|
|
|
|
define(`COUNTOF_$1', 0)
|
|
|
|
')
|
2012-04-01 03:39:31 +00:00
|
|
|
int xc_autocheck_assert_size = SIZEOF_$1, assert_count = COUNTOF_$1;
|
|
|
|
int xc_autocheck_done_size = 0, xc_autocheck_done_count = 0;
|
|
|
|
const char *xc_autocheck_assert_names[] = { ifdef(`ELEMENTSOF_$1', `ELEMENTSOF_$1') };
|
|
|
|
zend_bool xc_autocheck_skip = 0;
|
|
|
|
HashTable xc_autocheck_done_names;
|
|
|
|
zend_hash_init(&xc_autocheck_done_names, 0, NULL, NULL, 0);
|
2006-05-09 10:58:38 +00:00
|
|
|
/* }}} */
|
|
|
|
IFRESTORE(`assert(xc_is_shm(src));')
|
|
|
|
IFCALCSTORE(`assert(!xc_is_shm(src));')
|
2006-05-24 07:52:48 +00:00
|
|
|
do {
|
2006-05-09 10:58:38 +00:00
|
|
|
')
|
2011-04-09 10:22:14 +00:00
|
|
|
ifdef(`SIZEOF_$1', , `m4_errprint(`AUTOCHECK WARN: $1: missing structinfo, dont panic')')
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
ifdef(`USEMEMCPY', `IFCOPY(`
|
|
|
|
memcpy(dst, src, sizeof($1));
|
2006-05-24 07:52:48 +00:00
|
|
|
do {
|
2006-05-09 10:58:38 +00:00
|
|
|
')')
|
|
|
|
|
|
|
|
IFDPRINT(`
|
2008-02-29 08:58:29 +00:00
|
|
|
fprintf(stderr, "%s", "{\n");
|
2006-05-09 10:58:38 +00:00
|
|
|
indent ++;
|
|
|
|
')
|
|
|
|
$3`'
|
|
|
|
IFDPRINT(`
|
|
|
|
indent --;
|
|
|
|
INDENT()fprintf(stderr, "}\n");
|
|
|
|
')
|
2012-04-01 03:39:31 +00:00
|
|
|
IFAUTOCHECK(`
|
2012-04-01 06:20:16 +00:00
|
|
|
/* {{{ autocheck */
|
|
|
|
if (!xc_autocheck_skip) {
|
2012-04-01 03:39:31 +00:00
|
|
|
int name_check_errors = xc_check_names(__FILE__, __LINE__, "FUNC_NAME", xc_autocheck_assert_names, sizeof(xc_autocheck_assert_names) / sizeof(xc_autocheck_assert_names[0]), &xc_autocheck_done_names);
|
2011-04-09 10:22:14 +00:00
|
|
|
|
2012-04-01 03:39:31 +00:00
|
|
|
if (xc_autocheck_done_count != assert_count) {
|
|
|
|
fprintf(stderr
|
|
|
|
, "count assertion failed at %s `#'%d FUNC_NAME`' : unexpected:%d - expecting:%d = %d != 0\n"
|
|
|
|
, __FILE__, __LINE__
|
|
|
|
, xc_autocheck_done_count, assert_count, xc_autocheck_done_count - assert_count
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (xc_autocheck_done_size != xc_autocheck_assert_size) {
|
|
|
|
fprintf(stderr
|
|
|
|
, "size assertion failed at %s `#'%d FUNC_NAME`' : unexpected:%d - expecting:%d = %d != 0\n"
|
|
|
|
, __FILE__, __LINE__
|
|
|
|
, xc_autocheck_done_size, xc_autocheck_assert_size, xc_autocheck_done_size - xc_autocheck_assert_size
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (name_check_errors || xc_autocheck_done_count != assert_count || xc_autocheck_done_size != xc_autocheck_assert_size) {
|
|
|
|
assert(0);
|
|
|
|
}
|
2012-04-01 06:20:16 +00:00
|
|
|
}
|
|
|
|
zend_hash_destroy(&xc_autocheck_done_names);
|
|
|
|
/* }}} */
|
2012-04-01 03:39:31 +00:00
|
|
|
')
|
|
|
|
ifdef(`ELEMENTSOF_$1', `
|
|
|
|
pushdef(`ELEMENTS_UNDONE', LIST_DIFF(defn(`ELEMENTSOF_$1'), defn(`ELEMENTS_DONE')))
|
|
|
|
ifelse(defn(`ELEMENTS_UNDONE'), , `m4_errprint(`AUTOCHECK INFO: $1: processor looks good')', `
|
|
|
|
m4_errprint(`AUTOCHECK ERROR: ====' PROCESSOR_TYPE `$1 =================')
|
|
|
|
m4_errprint(`AUTOCHECK expected:' defn(`ELEMENTSOF_$1'))
|
|
|
|
m4_errprint(`AUTOCHECK missing :' defn(`ELEMENTS_UNDONE'))
|
|
|
|
define(`EXIT_PENDING', 1)
|
2006-05-26 02:31:45 +00:00
|
|
|
')
|
2012-04-01 03:39:31 +00:00
|
|
|
popdef(`ELEMENTS_UNDONE')
|
2006-05-26 02:31:45 +00:00
|
|
|
')
|
2006-05-24 07:52:48 +00:00
|
|
|
ifdef(`USEMEMCPY', `IFCOPY(`
|
|
|
|
} while (0);
|
|
|
|
')')
|
2012-04-01 03:39:31 +00:00
|
|
|
IFAUTOCHECK(`
|
2006-05-24 07:52:48 +00:00
|
|
|
} while (0);
|
2006-05-13 01:54:55 +00:00
|
|
|
')
|
2006-05-26 02:31:45 +00:00
|
|
|
popdef(`ELEMENTS_DONE')
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
/* }`}'} */
|
|
|
|
popdef(`FUNC_NAME')
|
|
|
|
')
|
|
|
|
dnl }}}
|
2006-05-13 01:54:55 +00:00
|
|
|
dnl {{{ STRUCT_P_EX(1:type, 2:dst, 3:src, 4:elm-name, 5:name=type, 6:&)
|
2006-05-09 10:58:38 +00:00
|
|
|
define(`STRUCT_P_EX', `
|
|
|
|
DBG(`$0($*)')
|
2006-05-13 01:54:55 +00:00
|
|
|
pushdefFUNC_NAME(`$1', `$5')
|
2012-03-25 07:01:16 +00:00
|
|
|
ifdef(`DEFINED_'ifelse(`$5', `', `$1', `$5'), `', `m4_errprint(`AUTOCHECK ERROR: Unknown struct "'ifelse(`$5', `', `$1', `$5')`"')define(`EXIT_PENDING', 1)')
|
2006-05-13 01:54:55 +00:00
|
|
|
assert(sizeof($1) == sizeof(($6 $3)[0]));
|
|
|
|
ifelse(`$6', `', `ALLOC(`$2', `$1')')
|
2006-05-09 10:58:38 +00:00
|
|
|
IFDASM(`do {
|
|
|
|
zval *zv;
|
|
|
|
ALLOC_INIT_ZVAL(zv);
|
|
|
|
array_init(zv);
|
|
|
|
')
|
|
|
|
FUNC_NAME`'(
|
2006-05-13 01:54:55 +00:00
|
|
|
IFDPRINT( ` $6 $3, indent')
|
|
|
|
IFCALC( `processor, $6 $3')
|
|
|
|
IFSTORE( `processor, $6 $2, $6 $3')
|
|
|
|
IFRESTORE(`processor, $6 $2, $6 $3')
|
2012-06-26 13:53:44 +00:00
|
|
|
IFDASM( `dasm, zv, $6 $3')
|
2006-05-13 01:54:55 +00:00
|
|
|
IFASM( `$6 $2, $6 $3')
|
2006-05-09 10:58:38 +00:00
|
|
|
TSRMLS_CC
|
|
|
|
);
|
|
|
|
IFDASM(`
|
2006-05-13 01:54:55 +00:00
|
|
|
add_assoc_zval_ex(dst, ZEND_STRS("$4"), zv);
|
2006-05-09 10:58:38 +00:00
|
|
|
} while (0);
|
|
|
|
')
|
|
|
|
popdef(`FUNC_NAME')
|
2006-05-13 01:54:55 +00:00
|
|
|
ifelse(`$6', , `FIXPOINTER_EX(`$1', `$2')')
|
2006-05-09 10:58:38 +00:00
|
|
|
')
|
|
|
|
dnl }}}
|
|
|
|
dnl {{{ STRUCT_P(1:type, 2:elm, 3:name=type)
|
|
|
|
define(`STRUCT_P', `
|
|
|
|
DBG(`$0($*)')
|
2012-03-25 07:01:16 +00:00
|
|
|
if (SRC(`$2')) {
|
2008-02-29 08:58:29 +00:00
|
|
|
IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2 ");')
|
2012-03-25 07:01:16 +00:00
|
|
|
STRUCT_P_EX(`$1', `dst->$2', `SRC(`$2')', `$2', `$3')
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2:\tNULL\n");')
|
2006-10-10 00:31:50 +00:00
|
|
|
COPYNULL_EX(`dst->$2', `$2')
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
DONE(`$2')
|
|
|
|
')
|
|
|
|
dnl }}}
|
|
|
|
dnl {{{ STRUCT(1:type, 2:elm, 3:name=type)
|
|
|
|
define(`STRUCT', `
|
|
|
|
DBG(`$0($*)')
|
2012-03-25 07:01:16 +00:00
|
|
|
assert(sizeof($1) == sizeof(SRC(`$2')));
|
2008-02-29 08:58:29 +00:00
|
|
|
IFDPRINT(`INDENT()`'fprintf(stderr, "$1:$2 ");')
|
2012-03-25 07:01:16 +00:00
|
|
|
STRUCT_P_EX(`$1', `dst->$2', `SRC(`$2')', `$2', `$3', `&')
|
2006-05-09 10:58:38 +00:00
|
|
|
DONE(`$2')
|
|
|
|
')
|
|
|
|
dnl }}}
|
2012-06-23 04:49:59 +00:00
|
|
|
dnl {{{ STRUCT_ARRAY(1:count_type, 2:count, 3:type, 4:elm, 5:name=type, 6:loopcounter)
|
2006-05-09 10:58:38 +00:00
|
|
|
define(`STRUCT_ARRAY', `
|
2012-06-23 04:49:59 +00:00
|
|
|
if (SRC(`$4')) {
|
2009-08-03 08:15:53 +00:00
|
|
|
ifelse(
|
2012-06-23 04:49:59 +00:00
|
|
|
`$6', `', `ifelse(`$1', `', `size_t', `$1') i; pushdef(`LOOPCOUNTER', `i')',
|
|
|
|
`', `', `pushdef(`LOOPCOUNTER', `$6')')
|
|
|
|
pushdefFUNC_NAME(`$3', `$5')
|
2006-05-09 10:58:38 +00:00
|
|
|
IFDASM(`
|
|
|
|
zval *arr;
|
|
|
|
ALLOC_INIT_ZVAL(arr);
|
|
|
|
array_init(arr);
|
2012-03-25 01:58:22 +00:00
|
|
|
|
2012-03-25 07:01:16 +00:00
|
|
|
for (LOOPCOUNTER = 0;
|
2012-06-23 04:49:59 +00:00
|
|
|
ifelse(`$2', `', `SRC(`$4[LOOPCOUNTER]')',
|
|
|
|
`', `', `LOOPCOUNTER < SRC(`$2')');
|
2012-03-25 07:01:16 +00:00
|
|
|
++LOOPCOUNTER) {
|
2006-05-09 10:58:38 +00:00
|
|
|
zval *zv;
|
|
|
|
|
|
|
|
ALLOC_INIT_ZVAL(zv);
|
|
|
|
array_init(zv);
|
2012-06-26 13:53:44 +00:00
|
|
|
FUNC_NAME (dasm, zv, &(SRC(`$4[LOOPCOUNTER]')) TSRMLS_CC);
|
2006-05-09 10:58:38 +00:00
|
|
|
add_next_index_zval(arr, zv);
|
|
|
|
}
|
2012-06-23 04:49:59 +00:00
|
|
|
add_assoc_zval_ex(dst, ZEND_STRS("$4"), arr);
|
2006-05-09 10:58:38 +00:00
|
|
|
', `
|
2012-03-25 01:58:22 +00:00
|
|
|
dnl find count with NULL
|
2012-06-23 04:49:59 +00:00
|
|
|
ifelse(`$2', `', `
|
2012-03-25 07:01:16 +00:00
|
|
|
size_t count = 0;
|
2012-06-23 04:49:59 +00:00
|
|
|
while (SRC(`$4[count]')) {
|
2012-03-25 07:01:16 +00:00
|
|
|
++count;
|
2012-03-25 01:58:22 +00:00
|
|
|
}
|
|
|
|
++count;
|
2012-03-25 07:01:16 +00:00
|
|
|
pushdef(`ARRAY_ELEMENT_COUNT', `count')
|
2012-03-25 01:58:22 +00:00
|
|
|
',
|
2012-06-23 04:49:59 +00:00
|
|
|
`', `', `pushdef(`ARRAY_ELEMENT_COUNT', `SRC(`$2')')')
|
|
|
|
ALLOC(`dst->$4', `$3', `ARRAY_ELEMENT_COUNT')
|
2012-03-25 07:01:16 +00:00
|
|
|
popdef(`ARRAY_ELEMENT_COUNT')
|
|
|
|
|
|
|
|
for (LOOPCOUNTER = 0;
|
2012-06-23 04:49:59 +00:00
|
|
|
ifelse(`$2', `', `SRC(`$4[LOOPCOUNTER]')',
|
|
|
|
`', `', `LOOPCOUNTER < SRC(`$2')');
|
2012-03-25 07:01:16 +00:00
|
|
|
++LOOPCOUNTER) {
|
2006-05-09 10:58:38 +00:00
|
|
|
DISABLECHECK(`
|
2012-06-23 04:49:59 +00:00
|
|
|
STRUCT(`$3', `$4[LOOPCOUNTER]', `$5')
|
2006-05-09 10:58:38 +00:00
|
|
|
')
|
|
|
|
}
|
2012-03-25 07:01:16 +00:00
|
|
|
dnl the end marker
|
2012-06-23 04:49:59 +00:00
|
|
|
ifelse(`$2', `', `IFCOPY(`DST(`$4[LOOPCOUNTER]') = NULL;')')
|
2006-05-09 10:58:38 +00:00
|
|
|
')dnl IFDASM
|
2012-06-23 04:49:59 +00:00
|
|
|
DONE(`$4')
|
2006-05-09 10:58:38 +00:00
|
|
|
popdef(`FUNC_NAME')
|
2009-08-03 08:15:53 +00:00
|
|
|
popdef(`LOOPCOUNTER')
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-23 04:49:59 +00:00
|
|
|
COPYNULL(`$4')
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
')
|
|
|
|
dnl }}}
|