1 /*
2    +----------------------------------------------------------------------+
3    | Zend OPcache                                                         |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1998-2016 The PHP Group                                |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP 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.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Andi Gutmans <andi@zend.com>                                |
16    |          Zeev Suraski <zeev@zend.com>                                |
17    |          Stanislav Malyshev <stas@zend.com>                          |
18    |          Dmitry Stogov <dmitry@zend.com>                             |
19    +----------------------------------------------------------------------+
20 */
21 
22 #ifndef ZEND_OPTIMIZER_INTERNAL_H
23 #define ZEND_OPTIMIZER_INTERNAL_H
24 
25 #include "ZendAccelerator.h"
26 
27 #if ZEND_EXTENSION_API_NO > PHP_5_4_X_API_NO
28 # define VAR_NUM(v) ((zend_uint)(EX_TMP_VAR_NUM(0, 0) - EX_TMP_VAR(0, v)))
29 # define NUM_VAR(v) ((zend_uint)(zend_uintptr_t)EX_TMP_VAR_NUM(0, v))
30 #elif ZEND_EXTENSION_API_NO > PHP_5_2_X_API_NO
31 # define VAR_NUM(v) ((v)/ZEND_MM_ALIGNED_SIZE(sizeof(temp_variable)))
32 # define NUM_VAR(v) ((v)*ZEND_MM_ALIGNED_SIZE(sizeof(temp_variable)))
33 #else
34 # define VAR_NUM(v) ((v)/(sizeof(temp_variable)))
35 # define NUM_VAR(v) ((v)*(sizeof(temp_variable)))
36 #endif
37 
38 #define INV_COND(op)       ((op) == ZEND_JMPZ    ? ZEND_JMPNZ    : ZEND_JMPZ)
39 #define INV_EX_COND(op)    ((op) == ZEND_JMPZ_EX ? ZEND_JMPNZ    : ZEND_JMPZ)
40 #define INV_COND_EX(op)    ((op) == ZEND_JMPZ    ? ZEND_JMPNZ_EX : ZEND_JMPZ_EX)
41 #define INV_EX_COND_EX(op) ((op) == ZEND_JMPZ_EX ? ZEND_JMPNZ_EX : ZEND_JMPZ_EX)
42 
43 #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
44 # define MAKE_NOP(opline)	{ opline->opcode = ZEND_NOP;  memset(&opline->result,0,sizeof(opline->result)); memset(&opline->op1,0,sizeof(opline->op1)); memset(&opline->op2,0,sizeof(opline->op2)); opline->result_type=opline->op1_type=opline->op2_type=IS_UNUSED; opline->handler = zend_opcode_handlers[ZEND_NOP]; }
45 # define RESULT_USED(op)	(((op->result_type & IS_VAR) && !(op->result_type & EXT_TYPE_UNUSED)) || op->result_type == IS_TMP_VAR)
46 # define RESULT_UNUSED(op)	((op->result_type & EXT_TYPE_UNUSED) != 0)
47 # define SAME_VAR(op1, op2) ((((op1 ## _type & IS_VAR) && (op2 ## _type & IS_VAR)) || (op1 ## _type == IS_TMP_VAR && op2 ## _type == IS_TMP_VAR)) && op1.var == op2.var)
48 #else
49 # define MAKE_NOP(opline)	{ opline->opcode = ZEND_NOP;  memset(&opline->result,0,sizeof(znode)); memset(&opline->op1,0,sizeof(znode)); memset(&opline->op2,0,sizeof(znode)); opline->result.op_type=opline->op1.op_type=opline->op2.op_type=IS_UNUSED; opline->handler = zend_opcode_handlers[ZEND_NOP]; }
50 # define RESULT_USED(op)	((op->result.op_type == IS_VAR && (op->result.u.EA.type & EXT_TYPE_UNUSED) == 0) || (op->result.op_type == IS_TMP_VAR))
51 # define RESULT_UNUSED(op)	((op->result.op_type == IS_VAR) && (op->result.u.EA.type == EXT_TYPE_UNUSED))
52 # define SAME_VAR(op1, op2) 	(((op1.op_type == IS_VAR && op2.op_type == IS_VAR) || (op1.op_type == IS_TMP_VAR && op2.op_type == IS_TMP_VAR)) && op1.u.var == op2.u.var)
53 #endif
54 
55 typedef struct _zend_code_block zend_code_block;
56 typedef struct _zend_block_source zend_block_source;
57 
58 struct _zend_code_block {
59 	int                 access;
60 	zend_op            *start_opline;
61 	int                 start_opline_no;
62 	int                 len;
63 	zend_code_block    *op1_to;
64 	zend_code_block    *op2_to;
65 	zend_code_block    *ext_to;
66 	zend_code_block    *follow_to;
67 	zend_code_block    *next;
68 	zend_block_source  *sources;
69 	zend_bool           protected; /* don't merge this block with others */
70 };
71 
72 typedef struct _zend_cfg {
73 	zend_code_block    *blocks;
74 	zend_code_block   **try;
75 	zend_code_block   **catch;
76 	zend_code_block   **loop_start;
77 	zend_code_block   **loop_cont;
78 	zend_code_block   **loop_brk;
79 } zend_cfg;
80 
81 struct _zend_block_source {
82 	zend_code_block    *from;
83 	zend_block_source  *next;
84 };
85 
86 #endif
87