1/*
2   +----------------------------------------------------------------------+
3   | Zend Engine                                                          |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1998-2016 Zend Technologies Ltd. (http://www.zend.com) |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 2.00 of the Zend license,     |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.zend.com/license/2_00.txt.                                |
11   | If you did not receive a copy of the Zend license and are unable to  |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@zend.com so we can mail you a copy immediately.              |
14   +----------------------------------------------------------------------+
15   | Authors: Andi Gutmans <andi@zend.com>                                |
16   |          Zeev Suraski <zeev@zend.com>                                |
17   |          Dmitry Stogov <dmitry@zend.com>                             |
18   +----------------------------------------------------------------------+
19*/
20
21/* $Id$ */
22
23#include <stdio.h>
24
25#include "zend.h"
26#include "zend_alloc.h"
27#include "zend_compile.h"
28#include "zend_extensions.h"
29#include "zend_API.h"
30
31#include "zend_vm.h"
32
33static void zend_extension_op_array_ctor_handler(zend_extension *extension, zend_op_array *op_array)
34{
35	if (extension->op_array_ctor) {
36		extension->op_array_ctor(op_array);
37	}
38}
39
40static void zend_extension_op_array_dtor_handler(zend_extension *extension, zend_op_array *op_array)
41{
42	if (extension->op_array_dtor) {
43		extension->op_array_dtor(op_array);
44	}
45}
46
47static void op_array_alloc_ops(zend_op_array *op_array, uint32_t size)
48{
49	op_array->opcodes = erealloc(op_array->opcodes, size * sizeof(zend_op));
50}
51
52void init_op_array(zend_op_array *op_array, zend_uchar type, int initial_ops_size)
53{
54	op_array->type = type;
55	op_array->arg_flags[0] = 0;
56	op_array->arg_flags[1] = 0;
57	op_array->arg_flags[2] = 0;
58
59	op_array->refcount = (uint32_t *) emalloc(sizeof(uint32_t));
60	*op_array->refcount = 1;
61	op_array->last = 0;
62	op_array->opcodes = NULL;
63	op_array_alloc_ops(op_array, initial_ops_size);
64
65	op_array->last_var = 0;
66	op_array->vars = NULL;
67
68	op_array->T = 0;
69
70	op_array->function_name = NULL;
71	op_array->filename = zend_get_compiled_filename();
72	op_array->doc_comment = NULL;
73
74	op_array->arg_info = NULL;
75	op_array->num_args = 0;
76	op_array->required_num_args = 0;
77
78	op_array->scope = NULL;
79	op_array->prototype = NULL;
80
81	op_array->live_range = NULL;
82	op_array->try_catch_array = NULL;
83	op_array->last_live_range = 0;
84
85	op_array->static_variables = NULL;
86	op_array->last_try_catch = 0;
87
88	op_array->this_var = -1;
89
90	op_array->fn_flags = 0;
91
92	op_array->early_binding = -1;
93
94	op_array->last_literal = 0;
95	op_array->literals = NULL;
96
97	op_array->run_time_cache = NULL;
98	op_array->cache_size = 0;
99
100	memset(op_array->reserved, 0, ZEND_MAX_RESERVED_RESOURCES * sizeof(void*));
101
102	if (zend_extension_flags & ZEND_EXTENSIONS_HAVE_OP_ARRAY_CTOR) {
103		zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_ctor_handler, op_array);
104	}
105}
106
107ZEND_API void destroy_zend_function(zend_function *function)
108{
109	if (function->type == ZEND_USER_FUNCTION) {
110		destroy_op_array(&function->op_array);
111	} else {
112		ZEND_ASSERT(function->type == ZEND_INTERNAL_FUNCTION);
113		ZEND_ASSERT(function->common.function_name);
114		zend_string_release(function->common.function_name);
115	}
116}
117
118ZEND_API void zend_function_dtor(zval *zv)
119{
120	zend_function *function = Z_PTR_P(zv);
121
122	if (function->type == ZEND_USER_FUNCTION) {
123		ZEND_ASSERT(function->common.function_name);
124		destroy_op_array(&function->op_array);
125		/* op_arrays are allocated on arena, so we don't have to free them */
126	} else {
127		ZEND_ASSERT(function->type == ZEND_INTERNAL_FUNCTION);
128		ZEND_ASSERT(function->common.function_name);
129		zend_string_release(function->common.function_name);
130		if (!(function->common.fn_flags & ZEND_ACC_ARENA_ALLOCATED)) {
131			pefree(function, 1);
132		}
133	}
134}
135
136ZEND_API void zend_cleanup_op_array_data(zend_op_array *op_array)
137{
138	if (op_array->static_variables &&
139	    !(GC_FLAGS(op_array->static_variables) & IS_ARRAY_IMMUTABLE)) {
140		zend_hash_clean(op_array->static_variables);
141	}
142}
143
144ZEND_API void zend_cleanup_user_class_data(zend_class_entry *ce)
145{
146	/* Clean all parts that can contain run-time data */
147	/* Note that only run-time accessed data need to be cleaned up, pre-defined data can
148	   not contain objects and thus are not probelmatic */
149	if (ce->ce_flags & ZEND_HAS_STATIC_IN_METHODS) {
150		zend_function *func;
151
152		ZEND_HASH_FOREACH_PTR(&ce->function_table, func) {
153			if (func->type == ZEND_USER_FUNCTION) {
154				zend_cleanup_op_array_data((zend_op_array *) func);
155			}
156		} ZEND_HASH_FOREACH_END();
157	}
158	if (ce->static_members_table) {
159		zval *static_members = ce->static_members_table;
160		zval *p = static_members;
161		zval *end = p + ce->default_static_members_count;
162
163
164		ce->default_static_members_count = 0;
165		ce->default_static_members_table = ce->static_members_table = NULL;
166		while (p != end) {
167			i_zval_ptr_dtor(p ZEND_FILE_LINE_CC);
168			p++;
169		}
170		efree(static_members);
171	}
172}
173
174ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce)
175{
176	if (CE_STATIC_MEMBERS(ce)) {
177		zval *static_members = CE_STATIC_MEMBERS(ce);
178		zval *p = static_members;
179		zval *end = p + ce->default_static_members_count;
180
181#ifdef ZTS
182		CG(static_members_table)[(zend_intptr_t)(ce->static_members_table)] = NULL;
183#else
184		ce->static_members_table = NULL;
185#endif
186		ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
187		while (p != end) {
188			i_zval_ptr_dtor(p ZEND_FILE_LINE_CC);
189			p++;
190		}
191		efree(static_members);
192	}
193}
194
195void _destroy_zend_class_traits_info(zend_class_entry *ce)
196{
197	if (ce->num_traits > 0 && ce->traits) {
198		efree(ce->traits);
199	}
200
201	if (ce->trait_aliases) {
202		size_t i = 0;
203		while (ce->trait_aliases[i]) {
204			if (ce->trait_aliases[i]->trait_method) {
205				if (ce->trait_aliases[i]->trait_method->method_name) {
206	 				zend_string_release(ce->trait_aliases[i]->trait_method->method_name);
207				}
208				if (ce->trait_aliases[i]->trait_method->class_name) {
209	 				zend_string_release(ce->trait_aliases[i]->trait_method->class_name);
210				}
211				efree(ce->trait_aliases[i]->trait_method);
212			}
213
214			if (ce->trait_aliases[i]->alias) {
215				zend_string_release(ce->trait_aliases[i]->alias);
216			}
217
218			efree(ce->trait_aliases[i]);
219			i++;
220		}
221
222		efree(ce->trait_aliases);
223	}
224
225	if (ce->trait_precedences) {
226		size_t i = 0;
227
228		while (ce->trait_precedences[i]) {
229			zend_string_release(ce->trait_precedences[i]->trait_method->method_name);
230			zend_string_release(ce->trait_precedences[i]->trait_method->class_name);
231			efree(ce->trait_precedences[i]->trait_method);
232
233			if (ce->trait_precedences[i]->exclude_from_classes) {
234				size_t j = 0;
235				zend_trait_precedence *cur_precedence = ce->trait_precedences[i];
236				while (cur_precedence->exclude_from_classes[j].class_name) {
237					zend_string_release(cur_precedence->exclude_from_classes[j].class_name);
238					j++;
239				}
240				efree(ce->trait_precedences[i]->exclude_from_classes);
241			}
242			efree(ce->trait_precedences[i]);
243			i++;
244		}
245		efree(ce->trait_precedences);
246	}
247}
248
249ZEND_API void destroy_zend_class(zval *zv)
250{
251	zend_property_info *prop_info;
252	zend_class_entry *ce = Z_PTR_P(zv);
253
254	if (--ce->refcount > 0) {
255		return;
256	}
257	switch (ce->type) {
258		case ZEND_USER_CLASS:
259			if (ce->default_properties_table) {
260				zval *p = ce->default_properties_table;
261				zval *end = p + ce->default_properties_count;
262
263				while (p != end) {
264					i_zval_ptr_dtor(p ZEND_FILE_LINE_CC);
265					p++;
266				}
267				efree(ce->default_properties_table);
268			}
269			if (ce->default_static_members_table) {
270				zval *p = ce->default_static_members_table;
271				zval *end = p + ce->default_static_members_count;
272
273				while (p != end) {
274					i_zval_ptr_dtor(p ZEND_FILE_LINE_CC);
275					p++;
276				}
277				efree(ce->default_static_members_table);
278			}
279			ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) {
280				if (prop_info->ce == ce || (prop_info->flags & ZEND_ACC_SHADOW)) {
281					zend_string_release(prop_info->name);
282					if (prop_info->doc_comment) {
283						zend_string_release(prop_info->doc_comment);
284					}
285				}
286			} ZEND_HASH_FOREACH_END();
287			zend_hash_destroy(&ce->properties_info);
288			zend_string_release(ce->name);
289			zend_hash_destroy(&ce->function_table);
290			if (zend_hash_num_elements(&ce->constants_table)) {
291				zend_class_constant *c;
292
293				ZEND_HASH_FOREACH_PTR(&ce->constants_table, c) {
294					if (c->ce == ce) {
295						zval_ptr_dtor(&c->value);
296						if (c->doc_comment) {
297							zend_string_release(c->doc_comment);
298						}
299					}
300				} ZEND_HASH_FOREACH_END();
301				zend_hash_destroy(&ce->constants_table);
302			}
303			if (ce->num_interfaces > 0 && ce->interfaces) {
304				efree(ce->interfaces);
305			}
306			if (ce->info.user.doc_comment) {
307				zend_string_release(ce->info.user.doc_comment);
308			}
309
310			_destroy_zend_class_traits_info(ce);
311
312			break;
313		case ZEND_INTERNAL_CLASS:
314			if (ce->default_properties_table) {
315				zval *p = ce->default_properties_table;
316				zval *end = p + ce->default_properties_count;
317
318				while (p != end) {
319					zval_internal_ptr_dtor(p);
320					p++;
321				}
322				free(ce->default_properties_table);
323			}
324			if (ce->default_static_members_table) {
325				zval *p = ce->default_static_members_table;
326				zval *end = p + ce->default_static_members_count;
327
328				while (p != end) {
329					zval_internal_ptr_dtor(p);
330					p++;
331				}
332				free(ce->default_static_members_table);
333			}
334			zend_hash_destroy(&ce->properties_info);
335			zend_string_release(ce->name);
336			zend_hash_destroy(&ce->function_table);
337			if (zend_hash_num_elements(&ce->constants_table)) {
338				zend_class_constant *c;
339
340				ZEND_HASH_FOREACH_PTR(&ce->constants_table, c) {
341					zval_internal_ptr_dtor(&c->value);
342					if (c->doc_comment && c->ce == ce) {
343						zend_string_release(c->doc_comment);
344					}
345				} ZEND_HASH_FOREACH_END();
346				zend_hash_destroy(&ce->constants_table);
347			}
348			if (ce->num_interfaces > 0) {
349				free(ce->interfaces);
350			}
351			free(ce);
352			break;
353	}
354}
355
356void zend_class_add_ref(zval *zv)
357{
358	zend_class_entry *ce = Z_PTR_P(zv);
359
360	ce->refcount++;
361}
362
363ZEND_API void destroy_op_array(zend_op_array *op_array)
364{
365	zval *literal = op_array->literals;
366	zval *end;
367	uint32_t i;
368
369	if (op_array->static_variables &&
370	    !(GC_FLAGS(op_array->static_variables) & IS_ARRAY_IMMUTABLE)) {
371		if (--GC_REFCOUNT(op_array->static_variables) == 0) {
372			zend_array_destroy(op_array->static_variables);
373		}
374	}
375
376	if (op_array->run_time_cache && !op_array->function_name) {
377		efree(op_array->run_time_cache);
378		op_array->run_time_cache = NULL;
379	}
380
381	if (!op_array->refcount || --(*op_array->refcount) > 0) {
382		return;
383	}
384
385	efree_size(op_array->refcount, sizeof(*(op_array->refcount)));
386
387	if (op_array->vars) {
388		i = op_array->last_var;
389		while (i > 0) {
390			i--;
391			zend_string_release(op_array->vars[i]);
392		}
393		efree(op_array->vars);
394	}
395
396	if (literal) {
397	 	end = literal + op_array->last_literal;
398	 	while (literal < end) {
399			zval_ptr_dtor_nogc(literal);
400			literal++;
401		}
402		efree(op_array->literals);
403	}
404	efree(op_array->opcodes);
405
406	if (op_array->function_name) {
407		zend_string_release(op_array->function_name);
408	}
409	if (op_array->doc_comment) {
410		zend_string_release(op_array->doc_comment);
411	}
412	if (op_array->live_range) {
413		efree(op_array->live_range);
414	}
415	if (op_array->try_catch_array) {
416		efree(op_array->try_catch_array);
417	}
418	if (zend_extension_flags & ZEND_EXTENSIONS_HAVE_OP_ARRAY_DTOR) {
419		if (op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO) {
420			zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_dtor_handler, op_array);
421		}
422	}
423	if (op_array->arg_info) {
424		uint32_t num_args = op_array->num_args;
425		zend_arg_info *arg_info = op_array->arg_info;
426
427		if (op_array->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
428			arg_info--;
429			num_args++;
430		}
431		if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
432			num_args++;
433		}
434		for (i = 0 ; i < num_args; i++) {
435			if (arg_info[i].name) {
436				zend_string_release(arg_info[i].name);
437			}
438			if (arg_info[i].class_name) {
439				zend_string_release(arg_info[i].class_name);
440			}
441		}
442		efree(arg_info);
443	}
444}
445
446void init_op(zend_op *op)
447{
448	memset(op, 0, sizeof(zend_op));
449	op->lineno = CG(zend_lineno);
450	SET_UNUSED(op->result);
451}
452
453zend_op *get_next_op(zend_op_array *op_array)
454{
455	uint32_t next_op_num = op_array->last++;
456	zend_op *next_op;
457
458	if (next_op_num >= CG(context).opcodes_size) {
459		CG(context).opcodes_size *= 4;
460		op_array_alloc_ops(op_array, CG(context).opcodes_size);
461	}
462
463	next_op = &(op_array->opcodes[next_op_num]);
464
465	init_op(next_op);
466
467	return next_op;
468}
469
470int get_next_op_number(zend_op_array *op_array)
471{
472	return op_array->last;
473}
474
475zend_brk_cont_element *get_next_brk_cont_element(void)
476{
477	CG(context).last_brk_cont++;
478	CG(context).brk_cont_array = erealloc(CG(context).brk_cont_array, sizeof(zend_brk_cont_element) * CG(context).last_brk_cont);
479	return &CG(context).brk_cont_array[CG(context).last_brk_cont-1];
480}
481
482static void zend_update_extended_info(zend_op_array *op_array)
483{
484	zend_op *opline = op_array->opcodes, *end=opline+op_array->last;
485
486	while (opline<end) {
487		if (opline->opcode == ZEND_EXT_STMT) {
488			if (opline+1<end) {
489				if ((opline+1)->opcode == ZEND_EXT_STMT) {
490					opline->opcode = ZEND_NOP;
491					opline++;
492					continue;
493				}
494				if (opline+1<end) {
495					opline->lineno = (opline+1)->lineno;
496				}
497			} else {
498				opline->opcode = ZEND_NOP;
499			}
500		}
501		opline++;
502	}
503}
504
505static void zend_extension_op_array_handler(zend_extension *extension, zend_op_array *op_array)
506{
507	if (extension->op_array_handler) {
508		extension->op_array_handler(op_array);
509	}
510}
511
512static void zend_check_finally_breakout(zend_op_array *op_array, uint32_t op_num, uint32_t dst_num)
513{
514	int i;
515
516	for (i = 0; i < op_array->last_try_catch; i++) {
517		if ((op_num < op_array->try_catch_array[i].finally_op ||
518					op_num >= op_array->try_catch_array[i].finally_end)
519				&& (dst_num >= op_array->try_catch_array[i].finally_op &&
520					 dst_num <= op_array->try_catch_array[i].finally_end)) {
521			CG(in_compilation) = 1;
522			CG(active_op_array) = op_array;
523			CG(zend_lineno) = op_array->opcodes[op_num].lineno;
524			zend_error_noreturn(E_COMPILE_ERROR, "jump into a finally block is disallowed");
525		} else if ((op_num >= op_array->try_catch_array[i].finally_op
526					&& op_num <= op_array->try_catch_array[i].finally_end)
527				&& (dst_num > op_array->try_catch_array[i].finally_end
528					|| dst_num < op_array->try_catch_array[i].finally_op)) {
529			CG(in_compilation) = 1;
530			CG(active_op_array) = op_array;
531			CG(zend_lineno) = op_array->opcodes[op_num].lineno;
532			zend_error_noreturn(E_COMPILE_ERROR, "jump out of a finally block is disallowed");
533		}
534	}
535}
536
537static uint32_t zend_get_brk_cont_target(const zend_op_array *op_array, const zend_op *opline) {
538	int nest_levels = opline->op2.num;
539	int array_offset = opline->op1.num;
540	zend_brk_cont_element *jmp_to;
541	do {
542		jmp_to = &CG(context).brk_cont_array[array_offset];
543		if (nest_levels > 1) {
544			array_offset = jmp_to->parent;
545		}
546	} while (--nest_levels > 0);
547
548	return opline->opcode == ZEND_BRK ? jmp_to->brk : jmp_to->cont;
549}
550
551ZEND_API int pass_two(zend_op_array *op_array)
552{
553	zend_op *opline, *end;
554
555	if (!ZEND_USER_CODE(op_array->type)) {
556		return 0;
557	}
558	if (CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) {
559		zend_update_extended_info(op_array);
560	}
561	if (CG(compiler_options) & ZEND_COMPILE_HANDLE_OP_ARRAY) {
562		if (zend_extension_flags & ZEND_EXTENSIONS_HAVE_OP_ARRAY_HANDLER) {
563			zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_handler, op_array);
564		}
565	}
566
567	if (CG(context).vars_size != op_array->last_var) {
568		op_array->vars = (zend_string**) erealloc(op_array->vars, sizeof(zend_string*)*op_array->last_var);
569		CG(context).vars_size = op_array->last_var;
570	}
571	if (CG(context).opcodes_size != op_array->last) {
572		op_array->opcodes = (zend_op *) erealloc(op_array->opcodes, sizeof(zend_op)*op_array->last);
573		CG(context).opcodes_size = op_array->last;
574	}
575	if (CG(context).literals_size != op_array->last_literal) {
576		op_array->literals = (zval*)erealloc(op_array->literals, sizeof(zval) * op_array->last_literal);
577		CG(context).literals_size = op_array->last_literal;
578	}
579	opline = op_array->opcodes;
580	end = opline + op_array->last;
581	while (opline < end) {
582		switch (opline->opcode) {
583			case ZEND_FAST_CALL:
584				opline->op1.opline_num = op_array->try_catch_array[opline->op1.num].finally_op;
585				ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, opline->op1);
586				break;
587			case ZEND_BRK:
588			case ZEND_CONT:
589				{
590					uint32_t jmp_target = zend_get_brk_cont_target(op_array, opline);
591
592					if (op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK) {
593						zend_check_finally_breakout(op_array, opline - op_array->opcodes, jmp_target);
594					}
595					opline->opcode = ZEND_JMP;
596					opline->op1.opline_num = jmp_target;
597					opline->op2.num = 0;
598					ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, opline->op1);
599				}
600				break;
601			case ZEND_GOTO:
602				zend_resolve_goto_label(op_array, opline);
603				if (op_array->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK) {
604					zend_check_finally_breakout(op_array, opline - op_array->opcodes, opline->op1.opline_num);
605				}
606				/* break omitted intentionally */
607			case ZEND_JMP:
608				ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, opline->op1);
609				break;
610			case ZEND_JMPZNZ:
611				/* absolute index to relative offset */
612				opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, opline->extended_value);
613				/* break omitted intentionally */
614			case ZEND_JMPZ:
615			case ZEND_JMPNZ:
616			case ZEND_JMPZ_EX:
617			case ZEND_JMPNZ_EX:
618			case ZEND_JMP_SET:
619			case ZEND_COALESCE:
620			case ZEND_FE_RESET_R:
621			case ZEND_FE_RESET_RW:
622				ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, opline->op2);
623				break;
624			case ZEND_ASSERT_CHECK:
625			{
626				/* If result of assert is unused, result of check is unused as well */
627				zend_op *call = &op_array->opcodes[opline->op2.opline_num - 1];
628				if (call->opcode == ZEND_EXT_FCALL_END) {
629					call--;
630				}
631				if (call->result_type == IS_UNUSED) {
632					opline->result_type = IS_UNUSED;
633				}
634				ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, opline->op2);
635				break;
636			}
637			case ZEND_DECLARE_ANON_CLASS:
638			case ZEND_DECLARE_ANON_INHERITED_CLASS:
639			case ZEND_CATCH:
640			case ZEND_FE_FETCH_R:
641			case ZEND_FE_FETCH_RW:
642				/* absolute index to relative offset */
643				opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, opline->extended_value);
644				break;
645			case ZEND_VERIFY_RETURN_TYPE:
646				if (op_array->fn_flags & ZEND_ACC_GENERATOR) {
647					if (opline->op1_type != IS_UNUSED) {
648						zend_op *ret = opline;
649						do ret++; while (ret->opcode != ZEND_RETURN);
650
651						ret->op1 = opline->op1;
652						ret->op1_type = opline->op1_type;
653					}
654
655					MAKE_NOP(opline);
656				}
657				break;
658			case ZEND_RETURN:
659			case ZEND_RETURN_BY_REF:
660				if (op_array->fn_flags & ZEND_ACC_GENERATOR) {
661					opline->opcode = ZEND_GENERATOR_RETURN;
662				}
663				break;
664		}
665		if (opline->op1_type == IS_CONST) {
666			ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline->op1);
667		} else if (opline->op1_type & (IS_VAR|IS_TMP_VAR)) {
668			opline->op1.var = (uint32_t)(zend_intptr_t)ZEND_CALL_VAR_NUM(NULL, op_array->last_var + opline->op1.var);
669		}
670		if (opline->op2_type == IS_CONST) {
671			ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline->op2);
672		} else if (opline->op2_type & (IS_VAR|IS_TMP_VAR)) {
673			opline->op2.var = (uint32_t)(zend_intptr_t)ZEND_CALL_VAR_NUM(NULL, op_array->last_var + opline->op2.var);
674		}
675		if (opline->result_type & (IS_VAR|IS_TMP_VAR)) {
676			opline->result.var = (uint32_t)(zend_intptr_t)ZEND_CALL_VAR_NUM(NULL, op_array->last_var + opline->result.var);
677		}
678		ZEND_VM_SET_OPCODE_HANDLER(opline);
679		opline++;
680	}
681
682	if (op_array->live_range) {
683		int i;
684
685		for (i = 0; i < op_array->last_live_range; i++) {
686			op_array->live_range[i].var =
687				(uint32_t)(zend_intptr_t)ZEND_CALL_VAR_NUM(NULL, op_array->last_var + (op_array->live_range[i].var / sizeof(zval))) |
688				(op_array->live_range[i].var & ZEND_LIVE_MASK);
689		}
690	}
691
692	op_array->fn_flags |= ZEND_ACC_DONE_PASS_TWO;
693	return 0;
694}
695
696ZEND_API unary_op_type get_unary_op(int opcode)
697{
698	switch (opcode) {
699		case ZEND_BW_NOT:
700			return (unary_op_type) bitwise_not_function;
701		case ZEND_BOOL_NOT:
702			return (unary_op_type) boolean_not_function;
703		default:
704			return (unary_op_type) NULL;
705	}
706}
707
708ZEND_API binary_op_type get_binary_op(int opcode)
709{
710	switch (opcode) {
711		case ZEND_ADD:
712		case ZEND_ASSIGN_ADD:
713			return (binary_op_type) add_function;
714		case ZEND_SUB:
715		case ZEND_ASSIGN_SUB:
716			return (binary_op_type) sub_function;
717		case ZEND_MUL:
718		case ZEND_ASSIGN_MUL:
719			return (binary_op_type) mul_function;
720		case ZEND_POW:
721			return (binary_op_type) pow_function;
722		case ZEND_DIV:
723		case ZEND_ASSIGN_DIV:
724			return (binary_op_type) div_function;
725		case ZEND_MOD:
726		case ZEND_ASSIGN_MOD:
727			return (binary_op_type) mod_function;
728		case ZEND_SL:
729		case ZEND_ASSIGN_SL:
730			return (binary_op_type) shift_left_function;
731		case ZEND_SR:
732		case ZEND_ASSIGN_SR:
733			return (binary_op_type) shift_right_function;
734		case ZEND_FAST_CONCAT:
735		case ZEND_CONCAT:
736		case ZEND_ASSIGN_CONCAT:
737			return (binary_op_type) concat_function;
738		case ZEND_IS_IDENTICAL:
739			return (binary_op_type) is_identical_function;
740		case ZEND_IS_NOT_IDENTICAL:
741			return (binary_op_type) is_not_identical_function;
742		case ZEND_IS_EQUAL:
743			return (binary_op_type) is_equal_function;
744		case ZEND_IS_NOT_EQUAL:
745			return (binary_op_type) is_not_equal_function;
746		case ZEND_IS_SMALLER:
747			return (binary_op_type) is_smaller_function;
748		case ZEND_IS_SMALLER_OR_EQUAL:
749			return (binary_op_type) is_smaller_or_equal_function;
750		case ZEND_SPACESHIP:
751			return (binary_op_type) compare_function;
752		case ZEND_BW_OR:
753		case ZEND_ASSIGN_BW_OR:
754			return (binary_op_type) bitwise_or_function;
755		case ZEND_BW_AND:
756		case ZEND_ASSIGN_BW_AND:
757			return (binary_op_type) bitwise_and_function;
758		case ZEND_BW_XOR:
759		case ZEND_ASSIGN_BW_XOR:
760			return (binary_op_type) bitwise_xor_function;
761		case ZEND_BOOL_XOR:
762			return (binary_op_type) boolean_xor_function;
763		default:
764			return (binary_op_type) NULL;
765	}
766}
767
768/*
769 * Local variables:
770 * tab-width: 4
771 * c-basic-offset: 4
772 * indent-tabs-mode: t
773 * End:
774 */
775