summaryrefslogtreecommitdiff
path: root/processor/process.m4
blob: d59a1b3dfd91a9df52664460741104ecf0fe84df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
define(`PROCESS_SCALAR', `dnl {{{ (1:elm, 2:format=%d, 3:type=)
	IFNOTMEMCPY(`IFCOPY(`DST(`$1') = SRC(`$1');')')
	IFDPRINT(`
		INDENT()
		fprintf(stderr, "$3:$1:\t%ifelse(`$2',`',`d',`$2')\n", SRC(`$1'));
	')
	IFDASM(`
		ifelse(
			`$3', `zend_bool', `add_assoc_bool_ex(dst, XCACHE_STRS("$1"), SRC(`$1') ? 1 : 0);'
		, `$3', `double', `add_assoc_double_ex(dst, XCACHE_STRS("$1"), SRC(`$1'));'
		, `', `', `add_assoc_long_ex(dst, XCACHE_STRS("$1"), SRC(`$1'));'
		)
	')
	DONE(`$1')
')
dnl }}}
dnl {{{ PROCESS_CTEXTPOINTER
define(`PROCESS_CTEXTPOINTER', `COPY(`$1')')
dnl }}}
define(`PROCESS_xc_ztstring', `dnl {{{ (1:elm)
	pushdef(`REALPTRTYPE', `zend_class_entry')
	PROC_STRING(`$1')
	popdef(`REALPTRTYPE')
')
dnl }}}
define(`PROCESS_xc_zval_type_t', `dnl {{{ (1:elm)
	IFDPRINT(`
		INDENT()
		fprintf(stderr, ":$1:\t%d %s\n", SRC(`$1'), xc_get_data_type(SRC(`$1')));
		DONE(`$1')
	', `PROCESS_SCALAR(`$1')')
')
dnl }}}
define(`PROCESS_xc_op_type', `dnl {{{ (1:elm)
	IFDPRINT(`
		INDENT()
		fprintf(stderr, ":$1:\t%d %s\n", SRC(`$1'), xc_get_op_type(SRC(`$1')));
		DONE(`$1')
	', `PROCESS_SCALAR(`$1')')
')
dnl }}}
define(`PROCESS_xc_opcode', `dnl {{{ (1:elm)
	IFDPRINT(`
		INDENT()
		fprintf(stderr, ":$1:\t%u %s\n", SRC(`$1'), xc_get_opcode(SRC(`$1')));
		DONE(`$1')
	', `PROCESS_SCALAR(`$1')')
')
dnl }}}
define(`PROCESS', `dnl PROCESS(1:type, 2:elm)
	DBG(`$0($*)')
	assert(sizeof($1) == sizeof(SRC(`$2')));
	ifelse(
		`$1', `zend_bool',        `PROCESS_SCALAR(`$2', `u',  `$1')'
	, `$1', `zend_uchar',       `PROCESS_SCALAR(`$2', `u',  `$1')'
	, `$1', `char',             `PROCESS_SCALAR(`$2', `d',  `$1')'
	, `$1', `int32_t',          `PROCESS_SCALAR(`$2', `d',  `$1')'
	, `$1', `unsigned char',    `PROCESS_SCALAR(`$2', `u',  `$1')'
	, `$1', `zend_uint',        `PROCESS_SCALAR(`$2', `u',  `$1')'
	, `$1', `uint',             `PROCESS_SCALAR(`$2', `u',  `$1')'
	, `$1', `unsigned int',     `PROCESS_SCALAR(`$2', `u',  `$1')'
	, `$1', `zend_ulong',       `PROCESS_SCALAR(`$2', `lu', `$1')'
	, `$1', `ulong',            `PROCESS_SCALAR(`$2', `lu', `$1')'
	, `$1', `size_t',           `PROCESS_SCALAR(`$2', `lu', `$1')'
	, `$1', `long',             `PROCESS_SCALAR(`$2', `ld', `$1')'
	, `$1', `time_t',           `PROCESS_SCALAR(`$2', `ld', `$1')'
	, `$1', `zend_ushort',      `PROCESS_SCALAR(`$2', `hu', `$1')'
	, `$1', `int',              `PROCESS_SCALAR(`$2', `d',  `$1')'
	, `$1', `double',           `PROCESS_SCALAR(`$2', `f',  `$1')'
	, `$1', `xc_entry_type_t',  `PROCESS_SCALAR(`$2', `d',  `$1')'
	, `$1', `xc_hash_value_t',  `PROCESS_SCALAR(`$2', `lu', `$1')'
	, `$1', `last_brk_cont_t',  `PROCESS_SCALAR(`$2', `d', `$1')'
	, `$1', `zend_object_handle',`PROCESS_SCALAR(`$2', `d', `$1')'

	, `$1', `xc_ztstring',       `PROCESS_xc_ztstring(`$2')'
	, `$1', `xc_zval_type_t',    `PROCESS_xc_zval_type_t(`$2')'
	, `$1', `xc_op_type',        `PROCESS_xc_op_type(`$2')'
	, `$1', `xc_opcode',         `PROCESS_xc_opcode(`$2')'
	, `$1', `opcode_handler_t',  `/* is copying enough? */PROCESS_CTEXTPOINTER(`$2')'
	, `$1', `xc_md5sum_t',       `COPY(`$2')'
	, `', `', `m4_errprint(`AUTOCHECK ERROR: Unknown type "$1"')define(`EXIT_PENDING', 1)'
	)
')
define(`PROCESS_ARRAY', `dnl {{{ (1:count, 2:type, 3:elm, [4:real_type])
	if (SRC(`$3')) {
		int LOOPCOUNTER;
		IFDASM(`
			zval *arr;
			ALLOC_INIT_ZVAL(arr);
			array_init(arr);

			for (LOOPCOUNTER = 0;
					ifelse(`$1', `', `SRC(`$3[LOOPCOUNTER]')',
					`', `', `LOOPCOUNTER < SRC(`$1')');
					++LOOPCOUNTER) {
				pushdef(`dst', `arr')
				pushdef(`SRC', `ifelse(`$4', `', `', `($2)')' defn(`SRC') `[LOOPCOUNTER]')
				pushdef(`add_assoc_bool_ex', `add_next_index_bool($1, $3)')
				pushdef(`add_assoc_string_ex', `add_next_index_string($1, $3)')
				pushdef(`add_assoc_long_ex', `add_next_index_long($1, $3)')
				pushdef(`add_assoc_zval_ex', `add_next_index_zval($1, $3)')
				DISABLECHECK(`
					PROCESS(`$2', `$3')
				')
				popdef(`add_assoc_zval_ex')
				popdef(`add_assoc_long_ex')
				popdef(`add_assoc_string_ex')
				popdef(`add_assoc_bool_ex')
				popdef(`SRC')
				popdef(`dst')
			}
			add_assoc_zval_ex(dst, XCACHE_STRS("$3"), arr);
		', `
			dnl find count with NULL
			ifelse(`$1', `', `
				size_t count = 0;
				while (SRC(`$3[count]')) {
					++count;
				}
				++count;
				pushdef(`STRUCT_COUNT', `count')
			',
			`', `', `pushdef(`STRUCT_COUNT', `SRC(`$1')')')
			ALLOC(`DST(`$3')', `$2', `STRUCT_COUNT', , `$4')
			popdef(`STRUCT_COUNT')

			for (LOOPCOUNTER = 0;
					ifelse(`$1', `', `SRC(`$3[LOOPCOUNTER]')',
					`', `', `LOOPCOUNTER < SRC(`$1')');
					++LOOPCOUNTER) {
				DISABLECHECK(`
					pushdef(`DST', defn(`DST') `[LOOPCOUNTER]')
					pushdef(`SRC', `ifelse(`$4', `', `', `', `', `($2)')' defn(`SRC') `[LOOPCOUNTER]')
					PROCESS(`$2', `$3')
					popdef(`SRC')
					popdef(`DST')
				')
			}
			dnl the end marker
			ifelse(`$1', `', `IFCOPY(`DST(`$3[LOOPCOUNTER]') = NULL;')')
		')dnl IFDASM
		DONE(`$3')
	}
	else {
		COPYNULL(`$3')
	}
')
dnl }}}