mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Add extra VM operand specialization
For now RETVAL and OP_DATA= are supported
This commit is contained in:
parent
af66ad2857
commit
00a2c30c59
5 changed files with 12317 additions and 5065 deletions
|
@ -1098,164 +1098,6 @@ static ZEND_COLD int zend_verify_missing_return_type(zend_function *zf, void **c
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static zend_always_inline void zend_assign_to_object(zval *retval, zval *object, uint32_t object_op_type, zval *property_name, uint32_t property_op_type, int value_type, znode_op value_op, const zend_execute_data *execute_data, void **cache_slot)
|
|
||||||
{
|
|
||||||
zend_free_op free_value;
|
|
||||||
zval *value = get_zval_ptr_r(value_type, value_op, execute_data, &free_value);
|
|
||||||
zval tmp;
|
|
||||||
|
|
||||||
if (object_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(object) != IS_OBJECT)) {
|
|
||||||
do {
|
|
||||||
if (object_op_type == IS_VAR && UNEXPECTED(Z_ISERROR_P(object))) {
|
|
||||||
if (retval) {
|
|
||||||
ZVAL_NULL(retval);
|
|
||||||
}
|
|
||||||
FREE_OP(free_value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Z_ISREF_P(object)) {
|
|
||||||
object = Z_REFVAL_P(object);
|
|
||||||
if (EXPECTED(Z_TYPE_P(object) == IS_OBJECT)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (EXPECTED(Z_TYPE_P(object) <= IS_FALSE ||
|
|
||||||
(Z_TYPE_P(object) == IS_STRING && Z_STRLEN_P(object) == 0))) {
|
|
||||||
zend_object *obj;
|
|
||||||
|
|
||||||
zval_ptr_dtor(object);
|
|
||||||
object_init(object);
|
|
||||||
Z_ADDREF_P(object);
|
|
||||||
obj = Z_OBJ_P(object);
|
|
||||||
zend_error(E_WARNING, "Creating default object from empty value");
|
|
||||||
if (GC_REFCOUNT(obj) == 1) {
|
|
||||||
/* the enclosing container was deleted, obj is unreferenced */
|
|
||||||
if (retval) {
|
|
||||||
ZVAL_NULL(retval);
|
|
||||||
}
|
|
||||||
FREE_OP(free_value);
|
|
||||||
OBJ_RELEASE(obj);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Z_DELREF_P(object);
|
|
||||||
} else {
|
|
||||||
zend_error(E_WARNING, "Attempt to assign property of non-object");
|
|
||||||
if (retval) {
|
|
||||||
ZVAL_NULL(retval);
|
|
||||||
}
|
|
||||||
FREE_OP(free_value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property_op_type == IS_CONST &&
|
|
||||||
EXPECTED(Z_OBJCE_P(object) == CACHED_PTR_EX(cache_slot))) {
|
|
||||||
uint32_t prop_offset = (uint32_t)(intptr_t)CACHED_PTR_EX(cache_slot + 1);
|
|
||||||
zend_object *zobj = Z_OBJ_P(object);
|
|
||||||
zval *property;
|
|
||||||
|
|
||||||
if (EXPECTED(prop_offset != (uint32_t)ZEND_DYNAMIC_PROPERTY_OFFSET)) {
|
|
||||||
property = OBJ_PROP(zobj, prop_offset);
|
|
||||||
if (Z_TYPE_P(property) != IS_UNDEF) {
|
|
||||||
fast_assign:
|
|
||||||
value = zend_assign_to_variable(property, value, value_type);
|
|
||||||
if (retval && EXPECTED(!EG(exception))) {
|
|
||||||
ZVAL_COPY(retval, value);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (EXPECTED(zobj->properties != NULL)) {
|
|
||||||
if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {
|
|
||||||
if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
|
|
||||||
GC_REFCOUNT(zobj->properties)--;
|
|
||||||
}
|
|
||||||
zobj->properties = zend_array_dup(zobj->properties);
|
|
||||||
}
|
|
||||||
property = zend_hash_find(zobj->properties, Z_STR_P(property_name));
|
|
||||||
if (property) {
|
|
||||||
goto fast_assign;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!zobj->ce->__set) {
|
|
||||||
|
|
||||||
if (EXPECTED(zobj->properties == NULL)) {
|
|
||||||
rebuild_object_properties(zobj);
|
|
||||||
}
|
|
||||||
/* separate our value if necessary */
|
|
||||||
if (value_type == IS_CONST) {
|
|
||||||
if (UNEXPECTED(Z_OPT_COPYABLE_P(value))) {
|
|
||||||
ZVAL_COPY_VALUE(&tmp, value);
|
|
||||||
zval_copy_ctor_func(&tmp);
|
|
||||||
value = &tmp;
|
|
||||||
}
|
|
||||||
} else if (value_type != IS_TMP_VAR) {
|
|
||||||
if (Z_ISREF_P(value)) {
|
|
||||||
if (value_type == IS_VAR) {
|
|
||||||
zend_reference *ref = Z_REF_P(value);
|
|
||||||
if (--(GC_REFCOUNT(ref)) == 0) {
|
|
||||||
ZVAL_COPY_VALUE(&tmp, Z_REFVAL_P(value));
|
|
||||||
efree_size(ref, sizeof(zend_reference));
|
|
||||||
value = &tmp;
|
|
||||||
} else {
|
|
||||||
value = Z_REFVAL_P(value);
|
|
||||||
if (Z_REFCOUNTED_P(value)) {
|
|
||||||
Z_ADDREF_P(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
value = Z_REFVAL_P(value);
|
|
||||||
if (Z_REFCOUNTED_P(value)) {
|
|
||||||
Z_ADDREF_P(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (value_type == IS_CV && Z_REFCOUNTED_P(value)) {
|
|
||||||
Z_ADDREF_P(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
zend_hash_add_new(zobj->properties, Z_STR_P(property_name), value);
|
|
||||||
if (retval) {
|
|
||||||
ZVAL_COPY(retval, value);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Z_OBJ_HT_P(object)->write_property) {
|
|
||||||
zend_error(E_WARNING, "Attempt to assign property of non-object");
|
|
||||||
if (retval) {
|
|
||||||
ZVAL_NULL(retval);
|
|
||||||
}
|
|
||||||
FREE_OP(free_value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* separate our value if necessary */
|
|
||||||
if (value_type == IS_CONST) {
|
|
||||||
if (UNEXPECTED(Z_OPT_COPYABLE_P(value))) {
|
|
||||||
ZVAL_COPY_VALUE(&tmp, value);
|
|
||||||
zval_copy_ctor_func(&tmp);
|
|
||||||
value = &tmp;
|
|
||||||
}
|
|
||||||
} else if (value_type != IS_TMP_VAR) {
|
|
||||||
ZVAL_DEREF(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Z_OBJ_HT_P(object)->write_property(object, property_name, value, cache_slot);
|
|
||||||
|
|
||||||
if (retval && EXPECTED(!EG(exception))) {
|
|
||||||
ZVAL_COPY(retval, value);
|
|
||||||
}
|
|
||||||
if (value_type == IS_CONST) {
|
|
||||||
zval_ptr_dtor_nogc(value);
|
|
||||||
} else {
|
|
||||||
FREE_OP(free_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static zend_never_inline void zend_assign_to_object_dim(zval *retval, zval *object, zval *property_name, int value_type, znode_op value_op, const zend_execute_data *execute_data)
|
static zend_never_inline void zend_assign_to_object_dim(zval *retval, zval *object, zval *property_name, int value_type, znode_op value_op, const zend_execute_data *execute_data)
|
||||||
{
|
{
|
||||||
zend_free_op free_value;
|
zend_free_op free_value;
|
||||||
|
|
|
@ -1231,7 +1231,7 @@ ZEND_VM_HANDLER(135, ZEND_POST_DEC_OBJ, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV)
|
||||||
ZEND_VM_DISPATCH_TO_HELPER(zend_post_incdec_property_helper, inc, 0);
|
ZEND_VM_DISPATCH_TO_HELPER(zend_post_incdec_property_helper, inc, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEND_VM_HANDLER(34, ZEND_PRE_INC, VAR|CV, ANY)
|
ZEND_VM_HANDLER(34, ZEND_PRE_INC, VAR|CV, ANY, SPEC(RETVAL))
|
||||||
{
|
{
|
||||||
USE_OPLINE
|
USE_OPLINE
|
||||||
zend_free_op free_op1;
|
zend_free_op free_op1;
|
||||||
|
@ -1271,7 +1271,7 @@ ZEND_VM_HANDLER(34, ZEND_PRE_INC, VAR|CV, ANY)
|
||||||
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
|
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEND_VM_HANDLER(35, ZEND_PRE_DEC, VAR|CV, ANY)
|
ZEND_VM_HANDLER(35, ZEND_PRE_DEC, VAR|CV, ANY, SPEC(RETVAL))
|
||||||
{
|
{
|
||||||
USE_OPLINE
|
USE_OPLINE
|
||||||
zend_free_op free_op1;
|
zend_free_op free_op1;
|
||||||
|
@ -2094,12 +2094,11 @@ ZEND_VM_C_LABEL(try_fetch_list):
|
||||||
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
|
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEND_VM_HANDLER(136, ZEND_ASSIGN_OBJ, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV)
|
ZEND_VM_HANDLER(136, ZEND_ASSIGN_OBJ, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV, SPEC(OP_DATA=CONST|TMP|VAR|CV))
|
||||||
{
|
{
|
||||||
USE_OPLINE
|
USE_OPLINE
|
||||||
zend_free_op free_op1, free_op2;
|
zend_free_op free_op1, free_op2, free_op_data;
|
||||||
zval *object;
|
zval *object, *property_name, *value, tmp;
|
||||||
zval *property_name;
|
|
||||||
|
|
||||||
SAVE_OPLINE();
|
SAVE_OPLINE();
|
||||||
object = GET_OP1_OBJ_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);
|
object = GET_OP1_OBJ_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);
|
||||||
|
@ -2111,20 +2110,171 @@ ZEND_VM_HANDLER(136, ZEND_ASSIGN_OBJ, VAR|UNUSED|THIS|CV, CONST|TMPVAR|CV)
|
||||||
}
|
}
|
||||||
|
|
||||||
property_name = GET_OP2_ZVAL_PTR(BP_VAR_R);
|
property_name = GET_OP2_ZVAL_PTR(BP_VAR_R);
|
||||||
|
value = GET_OP_DATA_ZVAL_PTR(BP_VAR_R);
|
||||||
|
|
||||||
zend_assign_to_object(UNEXPECTED(RETURN_VALUE_USED(opline)) ? EX_VAR(opline->result.var) : NULL, object, OP1_TYPE, property_name, OP2_TYPE, (opline+1)->op1_type, (opline+1)->op1, execute_data, ((OP2_TYPE == IS_CONST) ? CACHE_ADDR(Z_CACHE_SLOT_P(property_name)) : NULL));
|
if (OP1_TYPE != IS_UNUSED && UNEXPECTED(Z_TYPE_P(object) != IS_OBJECT)) {
|
||||||
|
do {
|
||||||
|
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_ISERROR_P(object))) {
|
||||||
|
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||||
|
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||||
|
}
|
||||||
|
FREE_OP_DATA();
|
||||||
|
ZEND_VM_C_GOTO(exit_assign_obj);
|
||||||
|
}
|
||||||
|
if (Z_ISREF_P(object)) {
|
||||||
|
object = Z_REFVAL_P(object);
|
||||||
|
if (EXPECTED(Z_TYPE_P(object) == IS_OBJECT)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (EXPECTED(Z_TYPE_P(object) <= IS_FALSE ||
|
||||||
|
(Z_TYPE_P(object) == IS_STRING && Z_STRLEN_P(object) == 0))) {
|
||||||
|
zend_object *obj;
|
||||||
|
|
||||||
|
zval_ptr_dtor(object);
|
||||||
|
object_init(object);
|
||||||
|
Z_ADDREF_P(object);
|
||||||
|
obj = Z_OBJ_P(object);
|
||||||
|
zend_error(E_WARNING, "Creating default object from empty value");
|
||||||
|
if (GC_REFCOUNT(obj) == 1) {
|
||||||
|
/* the enclosing container was deleted, obj is unreferenced */
|
||||||
|
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||||
|
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||||
|
}
|
||||||
|
FREE_OP_DATA();
|
||||||
|
OBJ_RELEASE(obj);
|
||||||
|
ZEND_VM_C_GOTO(exit_assign_obj);
|
||||||
|
}
|
||||||
|
Z_DELREF_P(object);
|
||||||
|
} else {
|
||||||
|
zend_error(E_WARNING, "Attempt to assign property of non-object");
|
||||||
|
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||||
|
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||||
|
}
|
||||||
|
FREE_OP_DATA();
|
||||||
|
ZEND_VM_C_GOTO(exit_assign_obj);
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OP2_TYPE == IS_CONST &&
|
||||||
|
EXPECTED(Z_OBJCE_P(object) == CACHED_PTR(Z_CACHE_SLOT_P(property_name)))) {
|
||||||
|
uint32_t prop_offset = (uint32_t)(intptr_t)CACHED_PTR(Z_CACHE_SLOT_P(property_name) + sizeof(void*));
|
||||||
|
zend_object *zobj = Z_OBJ_P(object);
|
||||||
|
zval *property;
|
||||||
|
|
||||||
|
if (EXPECTED(prop_offset != (uint32_t)ZEND_DYNAMIC_PROPERTY_OFFSET)) {
|
||||||
|
property = OBJ_PROP(zobj, prop_offset);
|
||||||
|
if (Z_TYPE_P(property) != IS_UNDEF) {
|
||||||
|
ZEND_VM_C_LABEL(fast_assign_obj):
|
||||||
|
value = zend_assign_to_variable(property, value, OP_DATA_TYPE);
|
||||||
|
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||||
|
ZVAL_COPY(EX_VAR(opline->result.var), value);
|
||||||
|
}
|
||||||
|
ZEND_VM_C_GOTO(exit_assign_obj);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (EXPECTED(zobj->properties != NULL)) {
|
||||||
|
if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {
|
||||||
|
if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
|
||||||
|
GC_REFCOUNT(zobj->properties)--;
|
||||||
|
}
|
||||||
|
zobj->properties = zend_array_dup(zobj->properties);
|
||||||
|
}
|
||||||
|
property = zend_hash_find(zobj->properties, Z_STR_P(property_name));
|
||||||
|
if (property) {
|
||||||
|
ZEND_VM_C_GOTO(fast_assign_obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!zobj->ce->__set) {
|
||||||
|
|
||||||
|
if (EXPECTED(zobj->properties == NULL)) {
|
||||||
|
rebuild_object_properties(zobj);
|
||||||
|
}
|
||||||
|
/* separate our value if necessary */
|
||||||
|
if (OP_DATA_TYPE == IS_CONST) {
|
||||||
|
if (UNEXPECTED(Z_OPT_COPYABLE_P(value))) {
|
||||||
|
ZVAL_COPY_VALUE(&tmp, value);
|
||||||
|
zval_copy_ctor_func(&tmp);
|
||||||
|
value = &tmp;
|
||||||
|
}
|
||||||
|
} else if (OP_DATA_TYPE != IS_TMP_VAR) {
|
||||||
|
if (Z_ISREF_P(value)) {
|
||||||
|
if (OP_DATA_TYPE == IS_VAR) {
|
||||||
|
zend_reference *ref = Z_REF_P(value);
|
||||||
|
if (--GC_REFCOUNT(ref) == 0) {
|
||||||
|
ZVAL_COPY_VALUE(&tmp, Z_REFVAL_P(value));
|
||||||
|
efree_size(ref, sizeof(zend_reference));
|
||||||
|
value = &tmp;
|
||||||
|
} else {
|
||||||
|
value = Z_REFVAL_P(value);
|
||||||
|
if (Z_REFCOUNTED_P(value)) {
|
||||||
|
Z_ADDREF_P(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = Z_REFVAL_P(value);
|
||||||
|
if (Z_REFCOUNTED_P(value)) {
|
||||||
|
Z_ADDREF_P(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (OP_DATA_TYPE == IS_CV && Z_REFCOUNTED_P(value)) {
|
||||||
|
Z_ADDREF_P(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zend_hash_add_new(zobj->properties, Z_STR_P(property_name), value);
|
||||||
|
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||||
|
ZVAL_COPY(EX_VAR(opline->result.var), value);
|
||||||
|
}
|
||||||
|
ZEND_VM_C_GOTO(exit_assign_obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Z_OBJ_HT_P(object)->write_property) {
|
||||||
|
zend_error(E_WARNING, "Attempt to assign property of non-object");
|
||||||
|
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||||
|
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||||
|
}
|
||||||
|
FREE_OP_DATA();
|
||||||
|
ZEND_VM_C_GOTO(exit_assign_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* separate our value if necessary */
|
||||||
|
if (OP_DATA_TYPE == IS_CONST) {
|
||||||
|
if (UNEXPECTED(Z_OPT_COPYABLE_P(value))) {
|
||||||
|
ZVAL_COPY_VALUE(&tmp, value);
|
||||||
|
zval_copy_ctor_func(&tmp);
|
||||||
|
value = &tmp;
|
||||||
|
}
|
||||||
|
} else if (OP_DATA_TYPE != IS_TMP_VAR) {
|
||||||
|
ZVAL_DEREF(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Z_OBJ_HT_P(object)->write_property(object, property_name, value, (OP2_TYPE == IS_CONST) ? CACHE_ADDR(Z_CACHE_SLOT_P(property_name)) : NULL);
|
||||||
|
|
||||||
|
if (UNEXPECTED(RETURN_VALUE_USED(opline)) && EXPECTED(!EG(exception))) {
|
||||||
|
ZVAL_COPY(EX_VAR(opline->result.var), value);
|
||||||
|
}
|
||||||
|
if (OP_DATA_TYPE == IS_CONST) {
|
||||||
|
zval_ptr_dtor_nogc(value);
|
||||||
|
} else {
|
||||||
|
FREE_OP_DATA();
|
||||||
|
}
|
||||||
|
ZEND_VM_C_LABEL(exit_assign_obj):
|
||||||
FREE_OP2();
|
FREE_OP2();
|
||||||
FREE_OP1_VAR_PTR();
|
FREE_OP1_VAR_PTR();
|
||||||
/* assign_obj has two opcodes! */
|
/* assign_obj has two opcodes! */
|
||||||
ZEND_VM_NEXT_OPCODE_EX(1, 2);
|
ZEND_VM_NEXT_OPCODE_EX(1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEND_VM_HANDLER(147, ZEND_ASSIGN_DIM, VAR|CV, CONST|TMPVAR|UNUSED|NEXT|CV)
|
ZEND_VM_HANDLER(147, ZEND_ASSIGN_DIM, VAR|CV, CONST|TMPVAR|UNUSED|NEXT|CV, SPEC(OP_DATA=CONST|TMP|VAR|CV))
|
||||||
{
|
{
|
||||||
USE_OPLINE
|
USE_OPLINE
|
||||||
zend_free_op free_op1;
|
zend_free_op free_op1;
|
||||||
zval *object_ptr;
|
zval *object_ptr;
|
||||||
zend_free_op free_op2, free_op_data1;
|
zend_free_op free_op2, free_op_data;
|
||||||
zval *value;
|
zval *value;
|
||||||
zval *variable_ptr;
|
zval *variable_ptr;
|
||||||
zval *dim;
|
zval *dim;
|
||||||
|
@ -2147,14 +2297,14 @@ ZEND_VM_C_LABEL(try_assign_dim_array):
|
||||||
variable_ptr = zend_fetch_dimension_address_inner(Z_ARRVAL_P(object_ptr), dim, OP2_TYPE, BP_VAR_W);
|
variable_ptr = zend_fetch_dimension_address_inner(Z_ARRVAL_P(object_ptr), dim, OP2_TYPE, BP_VAR_W);
|
||||||
FREE_OP2();
|
FREE_OP2();
|
||||||
}
|
}
|
||||||
value = get_zval_ptr_r((opline+1)->op1_type, (opline+1)->op1, execute_data, &free_op_data1);
|
|
||||||
if (UNEXPECTED(variable_ptr == NULL)) {
|
if (UNEXPECTED(variable_ptr == NULL)) {
|
||||||
FREE_OP(free_op_data1);
|
FREE_UNFETCHED_OP_DATA();
|
||||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||||
ZVAL_NULL(EX_VAR(opline->result.var));
|
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = zend_assign_to_variable(variable_ptr, value, (opline+1)->op1_type);
|
value = GET_OP_DATA_ZVAL_PTR(BP_VAR_R);
|
||||||
|
value = zend_assign_to_variable(variable_ptr, value, OP_DATA_TYPE);
|
||||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||||
ZVAL_COPY(EX_VAR(opline->result.var), value);
|
ZVAL_COPY(EX_VAR(opline->result.var), value);
|
||||||
}
|
}
|
||||||
|
@ -2170,13 +2320,13 @@ ZEND_VM_C_LABEL(try_assign_dim_array):
|
||||||
zend_free_op free_op2;
|
zend_free_op free_op2;
|
||||||
zval *property_name = GET_OP2_ZVAL_PTR(BP_VAR_R);
|
zval *property_name = GET_OP2_ZVAL_PTR(BP_VAR_R);
|
||||||
|
|
||||||
zend_assign_to_object_dim(UNEXPECTED(RETURN_VALUE_USED(opline)) ? EX_VAR(opline->result.var) : NULL, object_ptr, property_name, (opline+1)->op1_type, (opline+1)->op1, execute_data);
|
zend_assign_to_object_dim(UNEXPECTED(RETURN_VALUE_USED(opline)) ? EX_VAR(opline->result.var) : NULL, object_ptr, property_name, OP_DATA_TYPE, (opline+1)->op1, execute_data);
|
||||||
FREE_OP2();
|
FREE_OP2();
|
||||||
} else if (EXPECTED(Z_TYPE_P(object_ptr) == IS_STRING)) {
|
} else if (EXPECTED(Z_TYPE_P(object_ptr) == IS_STRING)) {
|
||||||
if (EXPECTED(Z_STRLEN_P(object_ptr) != 0)) {
|
if (EXPECTED(Z_STRLEN_P(object_ptr) != 0)) {
|
||||||
if (OP2_TYPE == IS_UNUSED) {
|
if (OP2_TYPE == IS_UNUSED) {
|
||||||
zend_throw_error(NULL, "[] operator not supported for strings");
|
zend_throw_error(NULL, "[] operator not supported for strings");
|
||||||
FREE_UNFETCHED_OP((opline+1)->op1_type, (opline+1)->op1.var);
|
FREE_UNFETCHED_OP_DATA();
|
||||||
FREE_OP1_VAR_PTR();
|
FREE_OP1_VAR_PTR();
|
||||||
HANDLE_EXCEPTION();
|
HANDLE_EXCEPTION();
|
||||||
} else {
|
} else {
|
||||||
|
@ -2185,9 +2335,9 @@ ZEND_VM_C_LABEL(try_assign_dim_array):
|
||||||
dim = GET_OP2_ZVAL_PTR(BP_VAR_R);
|
dim = GET_OP2_ZVAL_PTR(BP_VAR_R);
|
||||||
offset = zend_fetch_string_offset(object_ptr, dim, BP_VAR_W);
|
offset = zend_fetch_string_offset(object_ptr, dim, BP_VAR_W);
|
||||||
FREE_OP2();
|
FREE_OP2();
|
||||||
value = get_zval_ptr_r_deref((opline+1)->op1_type, (opline+1)->op1, execute_data, &free_op_data1);
|
value = GET_OP_DATA_ZVAL_PTR_DEREF(BP_VAR_R);
|
||||||
zend_assign_to_string_offset(object_ptr, offset, value, (UNEXPECTED(RETURN_VALUE_USED(opline)) ? EX_VAR(opline->result.var) : NULL));
|
zend_assign_to_string_offset(object_ptr, offset, value, (UNEXPECTED(RETURN_VALUE_USED(opline)) ? EX_VAR(opline->result.var) : NULL));
|
||||||
FREE_OP(free_op_data1);
|
FREE_OP_DATA();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
zval_ptr_dtor_nogc(object_ptr);
|
zval_ptr_dtor_nogc(object_ptr);
|
||||||
|
@ -2203,10 +2353,8 @@ ZEND_VM_C_LABEL(assign_dim_convert_to_array):
|
||||||
} else {
|
} else {
|
||||||
zend_error(E_WARNING, "Cannot use a scalar value as an array");
|
zend_error(E_WARNING, "Cannot use a scalar value as an array");
|
||||||
ZEND_VM_C_LABEL(assign_dim_clean):
|
ZEND_VM_C_LABEL(assign_dim_clean):
|
||||||
dim = GET_OP2_ZVAL_PTR(BP_VAR_R);
|
FREE_UNFETCHED_OP2();
|
||||||
FREE_OP2();
|
FREE_UNFETCHED_OP_DATA();
|
||||||
value = get_zval_ptr_r((opline+1)->op1_type, (opline+1)->op1, execute_data, &free_op_data1);
|
|
||||||
FREE_OP(free_op_data1);
|
|
||||||
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
|
||||||
ZVAL_NULL(EX_VAR(opline->result.var));
|
ZVAL_NULL(EX_VAR(opline->result.var));
|
||||||
}
|
}
|
||||||
|
|
11157
Zend/zend_vm_execute.h
11157
Zend/zend_vm_execute.h
File diff suppressed because it is too large
Load diff
|
@ -494,6 +494,56 @@ $op2_free_unfetched = array(
|
||||||
"TMPVAR" => "zval_ptr_dtor_nogc(EX_VAR(opline->op2.var))",
|
"TMPVAR" => "zval_ptr_dtor_nogc(EX_VAR(opline->op2.var))",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$op_data_type = array(
|
||||||
|
"ANY" => "(opline+1)->op1_type",
|
||||||
|
"TMP" => "IS_TMP_VAR",
|
||||||
|
"VAR" => "IS_VAR",
|
||||||
|
"CONST" => "IS_CONST",
|
||||||
|
"UNUSED" => "IS_UNUSED",
|
||||||
|
"CV" => "IS_CV",
|
||||||
|
"TMPVAR" => "(IS_TMP_VAR|IS_VAR)",
|
||||||
|
);
|
||||||
|
|
||||||
|
$op_data_get_zval_ptr = array(
|
||||||
|
"ANY" => "get_zval_ptr((opline+1)->op1_type, (opline+1)->op1, execute_data, &free_op_data, \\1)",
|
||||||
|
"TMP" => "_get_zval_ptr_tmp((opline+1)->op1.var, execute_data, &free_op_data)",
|
||||||
|
"VAR" => "_get_zval_ptr_var((opline+1)->op1.var, execute_data, &free_op_data)",
|
||||||
|
"CONST" => "EX_CONSTANT((opline+1)->op1)",
|
||||||
|
"UNUSED" => "NULL",
|
||||||
|
"CV" => "_get_zval_ptr_cv_\\1(execute_data, (opline+1)->op1.var)",
|
||||||
|
"TMPVAR" => "_get_zval_ptr_var((opline+1)->op1.var, execute_data, &free_op_data)",
|
||||||
|
);
|
||||||
|
|
||||||
|
$op_data_get_zval_ptr_deref = array(
|
||||||
|
"ANY" => "get_zval_ptr((opline+1)->op1_type, (opline+1)->op1, execute_data, &free_op_data, \\1)",
|
||||||
|
"TMP" => "_get_zval_ptr_tmp((opline+1)->op1.var, execute_data, &free_op_data)",
|
||||||
|
"VAR" => "_get_zval_ptr_var_deref((opline+1)->op1.var, execute_data, &free_op_data)",
|
||||||
|
"CONST" => "EX_CONSTANT((opline+1)->op1)",
|
||||||
|
"UNUSED" => "NULL",
|
||||||
|
"CV" => "_get_zval_ptr_cv_deref_\\1(execute_data, (opline+1)->op1.var)",
|
||||||
|
"TMPVAR" => "???",
|
||||||
|
);
|
||||||
|
|
||||||
|
$op_data_free_op = array(
|
||||||
|
"ANY" => "FREE_OP(free_op_data)",
|
||||||
|
"TMP" => "zval_ptr_dtor_nogc(free_op_data)",
|
||||||
|
"VAR" => "zval_ptr_dtor_nogc(free_op_data)",
|
||||||
|
"CONST" => "",
|
||||||
|
"UNUSED" => "",
|
||||||
|
"CV" => "",
|
||||||
|
"TMPVAR" => "zval_ptr_dtor_nogc(free_op_data)",
|
||||||
|
);
|
||||||
|
|
||||||
|
$op_data_free_unfetched = array(
|
||||||
|
"ANY" => "FREE_UNFETCHED_OP((opline+1)->op1_type, (opline+1)->op1.var)",
|
||||||
|
"TMP" => "zval_ptr_dtor_nogc(EX_VAR((opline+1)->op1.var))",
|
||||||
|
"VAR" => "zval_ptr_dtor_nogc(EX_VAR((opline+1)->op1.var))",
|
||||||
|
"CONST" => "",
|
||||||
|
"UNUSED" => "",
|
||||||
|
"CV" => "",
|
||||||
|
"TMPVAR" => "zval_ptr_dtor_nogc(EX_VAR((opline+1)->op1.var))",
|
||||||
|
);
|
||||||
|
|
||||||
$list = array(); // list of opcode handlers and helpers in original order
|
$list = array(); // list of opcode handlers and helpers in original order
|
||||||
$opcodes = array(); // opcode handlers by code
|
$opcodes = array(); // opcode handlers by code
|
||||||
$helpers = array(); // opcode helpers by name
|
$helpers = array(); // opcode helpers by name
|
||||||
|
@ -556,7 +606,7 @@ function opcode_name($name, $spec, $op1, $op2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates code for opcode handler or helper
|
// Generates code for opcode handler or helper
|
||||||
function gen_code($f, $spec, $kind, $export, $code, $op1, $op2, $name) {
|
function gen_code($f, $spec, $kind, $export, $code, $op1, $op2, $name, $extra_spec=null) {
|
||||||
global $op1_type, $op2_type, $op1_get_zval_ptr, $op2_get_zval_ptr,
|
global $op1_type, $op2_type, $op1_get_zval_ptr, $op2_get_zval_ptr,
|
||||||
$op1_get_zval_ptr_deref, $op2_get_zval_ptr_deref,
|
$op1_get_zval_ptr_deref, $op2_get_zval_ptr_deref,
|
||||||
$op1_get_zval_ptr_undef, $op2_get_zval_ptr_undef,
|
$op1_get_zval_ptr_undef, $op2_get_zval_ptr_undef,
|
||||||
|
@ -569,7 +619,9 @@ function gen_code($f, $spec, $kind, $export, $code, $op1, $op2, $name) {
|
||||||
$op1_get_obj_zval_ptr_ptr_undef, $op2_get_obj_zval_ptr_ptr_undef,
|
$op1_get_obj_zval_ptr_ptr_undef, $op2_get_obj_zval_ptr_ptr_undef,
|
||||||
$op1_free, $op2_free, $op1_free_unfetched, $op2_free_unfetched,
|
$op1_free, $op2_free, $op1_free_unfetched, $op2_free_unfetched,
|
||||||
$op1_free_op, $op2_free_op, $op1_free_op_if_var, $op2_free_op_if_var,
|
$op1_free_op, $op2_free_op, $op1_free_op_if_var, $op2_free_op_if_var,
|
||||||
$op1_free_op_var_ptr, $op2_free_op_var_ptr, $prefix;
|
$op1_free_op_var_ptr, $op2_free_op_var_ptr, $prefix,
|
||||||
|
$op_data_type, $op_data_get_zval_ptr, $op_data_get_zval_ptr_deref,
|
||||||
|
$op_data_free_op, $op_data_free_unfetched;
|
||||||
|
|
||||||
// Specializing
|
// Specializing
|
||||||
$code = preg_replace(
|
$code = preg_replace(
|
||||||
|
@ -615,7 +667,13 @@ function gen_code($f, $spec, $kind, $export, $code, $op1, $op2, $name) {
|
||||||
"/^#(\s*)if\s+1\s*\\|\\|.*[^\\\\]$/m",
|
"/^#(\s*)if\s+1\s*\\|\\|.*[^\\\\]$/m",
|
||||||
"/^#(\s*)if\s+0\s*&&.*[^\\\\]$/m",
|
"/^#(\s*)if\s+0\s*&&.*[^\\\\]$/m",
|
||||||
"/^#(\s*)ifdef\s+ZEND_VM_EXPORT\s*\n/m",
|
"/^#(\s*)ifdef\s+ZEND_VM_EXPORT\s*\n/m",
|
||||||
"/^#(\s*)ifndef\s+ZEND_VM_EXPORT\s*\n/m"
|
"/^#(\s*)ifndef\s+ZEND_VM_EXPORT\s*\n/m",
|
||||||
|
"/OP_DATA_TYPE/",
|
||||||
|
"/GET_OP_DATA_ZVAL_PTR\(([^)]*)\)/",
|
||||||
|
"/GET_OP_DATA_ZVAL_PTR_DEREF\(([^)]*)\)/",
|
||||||
|
"/FREE_OP_DATA\(\)/",
|
||||||
|
"/FREE_UNFETCHED_OP_DATA\(\)/",
|
||||||
|
"/RETURN_VALUE_USED\(opline\)/"
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
$op1_type[$op1],
|
$op1_type[$op1],
|
||||||
|
@ -654,12 +712,18 @@ function gen_code($f, $spec, $kind, $export, $code, $op1, $op2, $name) {
|
||||||
($op1!="ANY"||$op2!="ANY")?"#\\1if 0\n":"#\\1if 1\n",
|
($op1!="ANY"||$op2!="ANY")?"#\\1if 0\n":"#\\1if 1\n",
|
||||||
($op1!="ANY"||$op2!="ANY")?"0":"1",
|
($op1!="ANY"||$op2!="ANY")?"0":"1",
|
||||||
($op1!="ANY"||$op2!="ANY")?"1":"0",
|
($op1!="ANY"||$op2!="ANY")?"1":"0",
|
||||||
"\\1".(($spec && $kind != ZEND_VM_KIND_CALL)?("_SPEC".$prefix[$op1].$prefix[$op2]):""),
|
"\\1".(($spec && $kind != ZEND_VM_KIND_CALL)?("_SPEC".$prefix[$op1].$prefix[$op2].extra_spec_name($extra_spec)):""),
|
||||||
"goto \\1".(($spec && $kind != ZEND_VM_KIND_CALL)?("_SPEC".$prefix[$op1].$prefix[$op2]):""),
|
"goto \\1".(($spec && $kind != ZEND_VM_KIND_CALL)?("_SPEC".$prefix[$op1].$prefix[$op2].extra_spec_name($extra_spec)):""),
|
||||||
"#\\1if 1",
|
"#\\1if 1",
|
||||||
"#\\1if 0",
|
"#\\1if 0",
|
||||||
$export?"#\\1if 1\n":"#\\1if 0\n",
|
$export?"#\\1if 1\n":"#\\1if 0\n",
|
||||||
$export?"#\\1if 0\n":"#\\1if 1\n"
|
$export?"#\\1if 0\n":"#\\1if 1\n",
|
||||||
|
$op_data_type[isset($extra_spec['op_data']) ? $extra_spec['op_data'] : "ANY"],
|
||||||
|
$op_data_get_zval_ptr[isset($extra_spec['op_data']) ? $extra_spec['op_data'] : "ANY"],
|
||||||
|
$op_data_get_zval_ptr_deref[isset($extra_spec['op_data']) ? $extra_spec['op_data'] : "ANY"],
|
||||||
|
$op_data_free_op[isset($extra_spec['op_data']) ? $extra_spec['op_data'] : "ANY"],
|
||||||
|
$op_data_free_unfetched[isset($extra_spec['op_data']) ? $extra_spec['op_data'] : "ANY"],
|
||||||
|
isset($extra_spec['retval']) ? $extra_spec['retval'] : "RETURN_VALUE_USED(opline)",
|
||||||
),
|
),
|
||||||
$code);
|
$code);
|
||||||
|
|
||||||
|
@ -751,6 +815,7 @@ function gen_code($f, $spec, $kind, $export, $code, $op1, $op2, $name) {
|
||||||
}
|
}
|
||||||
$del_free_op1 = (strpos($code, "free_op1") === false);
|
$del_free_op1 = (strpos($code, "free_op1") === false);
|
||||||
$del_free_op2 = (strpos($code, "free_op2") === false);
|
$del_free_op2 = (strpos($code, "free_op2") === false);
|
||||||
|
$del_free_op_data = (strpos($code, "free_op_data") === false);
|
||||||
$n = 0;
|
$n = 0;
|
||||||
foreach ($matches as $match) {
|
foreach ($matches as $match) {
|
||||||
$dcl = $match[0];
|
$dcl = $match[0];
|
||||||
|
@ -765,6 +830,11 @@ function gen_code($f, $spec, $kind, $export, $code, $op1, $op2, $name) {
|
||||||
$dcl = preg_replace("/free_op2\s*;/", ";", $dcl);
|
$dcl = preg_replace("/free_op2\s*;/", ";", $dcl);
|
||||||
$changed = 1;
|
$changed = 1;
|
||||||
}
|
}
|
||||||
|
if ($del_free_op_data && strpos($dcl, "free_op_data") !== false) {
|
||||||
|
$dcl = preg_replace("/free_op_data\s*,\s*/", "", $dcl);
|
||||||
|
$dcl = preg_replace("/free_op_data\s*;/", ";", $dcl);
|
||||||
|
$changed = 1;
|
||||||
|
}
|
||||||
if ($changed) {
|
if ($changed) {
|
||||||
$dcl = preg_replace("/,\s*;/", ";", $dcl);
|
$dcl = preg_replace("/,\s*;/", ";", $dcl);
|
||||||
$dcl = preg_replace("/zend_free_op\s*;/", "", $dcl);
|
$dcl = preg_replace("/zend_free_op\s*;/", "", $dcl);
|
||||||
|
@ -784,7 +854,7 @@ function gen_code($f, $spec, $kind, $export, $code, $op1, $op2, $name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates opcode handler
|
// Generates opcode handler
|
||||||
function gen_handler($f, $spec, $kind, $name, $op1, $op2, $use, $code, $lineno) {
|
function gen_handler($f, $spec, $kind, $name, $op1, $op2, $use, $code, $lineno, $extra_spec = null, &$switch_labels = []) {
|
||||||
global $definition_file, $prefix, $typecode, $opnames;
|
global $definition_file, $prefix, $typecode, $opnames;
|
||||||
|
|
||||||
if (ZEND_VM_LINES) {
|
if (ZEND_VM_LINES) {
|
||||||
|
@ -792,30 +862,33 @@ function gen_handler($f, $spec, $kind, $name, $op1, $op2, $use, $code, $lineno)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate opcode handler's entry point according to selected threading model
|
// Generate opcode handler's entry point according to selected threading model
|
||||||
|
$spec_name = $name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2].($spec?extra_spec_name($extra_spec):"");
|
||||||
switch($kind) {
|
switch($kind) {
|
||||||
case ZEND_VM_KIND_CALL:
|
case ZEND_VM_KIND_CALL:
|
||||||
out($f,"static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ".$name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2]."_HANDLER(ZEND_OPCODE_HANDLER_ARGS)\n");
|
out($f,"static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL {$spec_name}_HANDLER(ZEND_OPCODE_HANDLER_ARGS)\n");
|
||||||
break;
|
break;
|
||||||
case ZEND_VM_KIND_SWITCH:
|
case ZEND_VM_KIND_SWITCH:
|
||||||
if ($spec) {
|
if ($spec) {
|
||||||
out($f,"case ".((string)($opnames[$name]*25+($typecode[$op1=="TMPVAR"?"TMP":$op1]*5)+$typecode[$op2=="TMPVAR"?"TMP":$op2])).": /*".$name."_SPEC".$prefix[$op1].$prefix[$op2]."_HANDLER*/");
|
$cur = $switch_labels ? end($switch_labels) + 1 : 0;
|
||||||
|
out($f,"case $cur: /* $spec_name */");
|
||||||
|
$switch_labels[$spec_name] = $cur;
|
||||||
} else {
|
} else {
|
||||||
out($f,"case ".$name.":");
|
out($f,"case ".$name.":");
|
||||||
}
|
}
|
||||||
if ($use) {
|
if ($use) {
|
||||||
// This handler is used by other handlers. We will add label to call it.
|
// This handler is used by other handlers. We will add label to call it.
|
||||||
out($f," ".$name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2]."_LABEL:\n");
|
out($f," {$spec_name}_LABEL:\n");
|
||||||
} else {
|
} else {
|
||||||
out($f,"\n");
|
out($f,"\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ZEND_VM_KIND_GOTO:
|
case ZEND_VM_KIND_GOTO:
|
||||||
out($f,$name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2]."_HANDLER: ZEND_VM_GUARD(".$name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2].");\n");
|
out($f,"{$spec_name}_HANDLER: ZEND_VM_GUARD($spec_name);\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate opcode handler's code
|
// Generate opcode handler's code
|
||||||
gen_code($f, $spec, $kind, 0, $code, $op1, $op2, $name);
|
gen_code($f, $spec, $kind, 0, $code, $op1, $op2, $name, $extra_spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates helper
|
// Generates helper
|
||||||
|
@ -857,48 +930,39 @@ function gen_helper($f, $spec, $kind, $name, $op1, $op2, $param, $code, $lineno,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates array of opcode handlers (specialized or unspecialized)
|
// Generates array of opcode handlers (specialized or unspecialized)
|
||||||
function gen_labels($f, $spec, $kind, $prolog) {
|
function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = []) {
|
||||||
global $opcodes, $op_types, $prefix, $typecode;
|
global $opcodes, $op_types, $prefix;
|
||||||
|
|
||||||
$next = 0;
|
$next = 0;
|
||||||
|
$label = 0;
|
||||||
if ($spec) {
|
if ($spec) {
|
||||||
// Emit labels for specialized executor
|
// Emit labels for specialized executor
|
||||||
|
|
||||||
// For each opcode in opcode number order
|
// For each opcode in opcode number order
|
||||||
foreach($opcodes as $num => $dsc) {
|
foreach($opcodes as $num => $dsc) {
|
||||||
while ($next != $num) {
|
$specs[$num] = "$label";
|
||||||
// If some opcode numbers are not used then fill hole with pointers
|
$spec_op1 = $spec_op2 = $spec_extra = false;
|
||||||
// to handler of undefined opcode
|
|
||||||
$op1t = $op_types;
|
|
||||||
// For each op1.op_type except ANY
|
|
||||||
foreach($op1t as $op1) {
|
|
||||||
if ($op1 != "ANY") {
|
|
||||||
$op2t = $op_types;
|
|
||||||
// For each op2.op_type except ANY
|
|
||||||
foreach($op2t as $op2) {
|
|
||||||
if ($op2 != "ANY") {
|
|
||||||
// Emit pointer to handler of undefined opcode
|
|
||||||
switch ($kind) {
|
|
||||||
case ZEND_VM_KIND_CALL:
|
|
||||||
out($f,$prolog."ZEND_NULL_HANDLER,\n");
|
|
||||||
break;
|
|
||||||
case ZEND_VM_KIND_SWITCH:
|
|
||||||
out($f,$prolog."(void*)(uintptr_t)-1,\n");
|
|
||||||
break;
|
|
||||||
case ZEND_VM_KIND_GOTO:
|
|
||||||
out($f,$prolog."(void*)&&ZEND_NULL_HANDLER,\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$next++;
|
|
||||||
}
|
|
||||||
$next = $num + 1;
|
$next = $num + 1;
|
||||||
$op1t = $op_types;
|
$diff = array_diff_key(array_flip($op_types), isset($dsc["op1"]) ? $dsc["op1"] : []);
|
||||||
|
if ((count($diff) == count($op_types) - 1 ? isset($diff["ANY"]) : count($diff) != count($op_types)) || isset($dsc["op1"]["TMPVAR"])) {
|
||||||
|
$spec_op1 = true;
|
||||||
|
$specs[$num] .= " | SPEC_RULE_OP1";
|
||||||
|
}
|
||||||
|
$diff = array_diff_key(array_flip($op_types), isset($dsc["op2"]) ? $dsc["op2"] : []);
|
||||||
|
if ((count($diff) == count($op_types) - 1 ? isset($diff["ANY"]) : count($diff) != count($op_types)) || isset($dsc["op2"]["TMPVAR"])) {
|
||||||
|
$spec_op2 = true;
|
||||||
|
$specs[$num] .= " | SPEC_RULE_OP2";
|
||||||
|
}
|
||||||
|
$spec_extra = call_user_func_array("array_merge", extra_spec_handler($dsc) ?: [[]]);
|
||||||
|
$flags = extra_spec_flags($spec_extra);
|
||||||
|
if ($flags) {
|
||||||
|
$specs[$num] .= " | ".implode("|", $flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
$foreach_op1 = function($do) use ($dsc, $op_types) {
|
||||||
|
return function() use ($do, $dsc, $op_types) {
|
||||||
// For each op1.op_type except ANY
|
// For each op1.op_type except ANY
|
||||||
foreach($op1t as $op1) {
|
foreach($op_types as $op1) {
|
||||||
if ($op1 != "ANY") {
|
if ($op1 != "ANY") {
|
||||||
if (!isset($dsc["op1"][$op1])) {
|
if (!isset($dsc["op1"][$op1])) {
|
||||||
if (($op1 == "TMP" || $op1 == "VAR") && isset($dsc["op1"]["TMPVAR"])) {
|
if (($op1 == "TMP" || $op1 == "VAR") && isset($dsc["op1"]["TMPVAR"])) {
|
||||||
|
@ -908,9 +972,15 @@ function gen_labels($f, $spec, $kind, $prolog) {
|
||||||
$op1 = "ANY";
|
$op1 = "ANY";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$op2t = $op_types;
|
$do($op1, "ANY");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
$foreach_op2 = function($do) use ($dsc, $op_types) {
|
||||||
|
return function($op1) use ($do, $dsc, $op_types) {
|
||||||
// For each op2.op_type except ANY
|
// For each op2.op_type except ANY
|
||||||
foreach($op2t as $op2) {
|
foreach($op_types as $op2) {
|
||||||
if ($op2 != "ANY") {
|
if ($op2 != "ANY") {
|
||||||
if (!isset($dsc["op2"][$op2])) {
|
if (!isset($dsc["op2"][$op2])) {
|
||||||
if (($op2 == "TMP" || $op2 == "VAR") && isset($dsc["op2"]["TMPVAR"])) {
|
if (($op2 == "TMP" || $op2 == "VAR") && isset($dsc["op2"]["TMPVAR"])) {
|
||||||
|
@ -920,39 +990,97 @@ function gen_labels($f, $spec, $kind, $prolog) {
|
||||||
$op2 = "ANY";
|
$op2 = "ANY";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$do($op1, $op2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
$foreach_op_data = function($do) use ($dsc, $op_types) {
|
||||||
|
return function($op1, $op2, $extra_spec = []) use ($do, $dsc, $op_types) {
|
||||||
|
// For each op_data.op_type except ANY
|
||||||
|
foreach($op_types as $op_data) {
|
||||||
|
if ($op_data != "ANY") {
|
||||||
|
if (!isset($dsc["spec"]["op_data"][$op_data])) {
|
||||||
|
if (($op_data == "TMP" || $op_data == "VAR") && isset($dsc["spec"]["op_data"]["TMPVAR"])) {
|
||||||
|
$op_data = "TMPVAR";
|
||||||
|
} else {
|
||||||
|
// Try to use unspecialized handler
|
||||||
|
$op_data = "ANY";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$do($op1, $op2, ["op_data" => $op_data] + $extra_spec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
$foreach_extra_spec = function($do, $spec) use ($dsc) {
|
||||||
|
return function($op1, $op2, $extra_spec = []) use ($do, $spec, $dsc) {
|
||||||
|
foreach ($dsc["spec"][$spec] as $val) {
|
||||||
|
$do($op1, $op2, [$spec => $val] + $extra_spec);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
$generate = function ($op1, $op2, $extra_spec = []) use ($f, $kind, $dsc, $prefix, $prolog, $num, $switch_labels, &$label) {
|
||||||
|
global $typecode;
|
||||||
|
|
||||||
// Check if specialized handler is defined
|
// Check if specialized handler is defined
|
||||||
|
/* TODO: figure out better way to signal "specialized and not defined" than an extra lookup */
|
||||||
if (isset($dsc["op1"][$op1]) &&
|
if (isset($dsc["op1"][$op1]) &&
|
||||||
isset($dsc["op2"][$op2])) {
|
isset($dsc["op2"][$op2]) &&
|
||||||
|
(!isset($extra_spec["op_data"]) || isset($dsc["spec"]["op_data"][$extra_spec["op_data"]]))) {
|
||||||
// Emit pointer to specialized handler
|
// Emit pointer to specialized handler
|
||||||
|
$spec_name = $dsc["op"]."_SPEC".$prefix[$op1].$prefix[$op2].extra_spec_name($extra_spec);
|
||||||
switch ($kind) {
|
switch ($kind) {
|
||||||
case ZEND_VM_KIND_CALL:
|
case ZEND_VM_KIND_CALL:
|
||||||
out($f,$prolog.$dsc["op"]."_SPEC".$prefix[$op1].$prefix[$op2]."_HANDLER,\n");
|
out($f,"$prolog{$spec_name}_HANDLER,\n");
|
||||||
|
$label++;
|
||||||
break;
|
break;
|
||||||
case ZEND_VM_KIND_SWITCH:
|
case ZEND_VM_KIND_SWITCH:
|
||||||
out($f,$prolog."(void*)(uintptr_t)".((string)($num*25+$typecode[$op1=="TMPVAR"?"TMP":$op1]*5+$typecode[$op2=="TMPVAR"?"TMP":$op2])).",\n");
|
out($f,$prolog."(void*)(uintptr_t)$switch_labels[$spec_name],\n");
|
||||||
|
$label++;
|
||||||
break;
|
break;
|
||||||
case ZEND_VM_KIND_GOTO:
|
case ZEND_VM_KIND_GOTO:
|
||||||
out($f,$prolog."(void*)&&".$dsc["op"]."_SPEC".$prefix[$op1].$prefix[$op2]."_HANDLER,\n");
|
out($f,$prolog."(void*)&&{$spec_name}_HANDLER,\n");
|
||||||
|
$label++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Emit pinter to handler of undefined opcode
|
// Emit pointer to handler of undefined opcode
|
||||||
switch ($kind) {
|
switch ($kind) {
|
||||||
case ZEND_VM_KIND_CALL:
|
case ZEND_VM_KIND_CALL:
|
||||||
out($f,$prolog."ZEND_NULL_HANDLER,\n");
|
out($f,$prolog."ZEND_NULL_HANDLER,\n");
|
||||||
|
$label++;
|
||||||
break;
|
break;
|
||||||
case ZEND_VM_KIND_SWITCH:
|
case ZEND_VM_KIND_SWITCH:
|
||||||
out($f,$prolog."(void*)(uintptr_t)-1,\n");
|
out($f,$prolog."(void*)(uintptr_t)-1,\n");
|
||||||
|
$label++;
|
||||||
break;
|
break;
|
||||||
case ZEND_VM_KIND_GOTO:
|
case ZEND_VM_KIND_GOTO:
|
||||||
out($f,$prolog."(void*)&&ZEND_NULL_HANDLER,\n");
|
out($f,$prolog."(void*)&&ZEND_NULL_HANDLER,\n");
|
||||||
|
$label++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$do = $generate;
|
||||||
|
if ($spec_extra) {
|
||||||
|
foreach ($spec_extra as $extra => $devnull) {
|
||||||
|
if ($extra == "op_data") {
|
||||||
|
$do = $foreach_op_data($do);
|
||||||
|
} else {
|
||||||
|
$do = $foreach_extra_spec($do, $extra);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($spec_op2) {
|
||||||
|
$do = $foreach_op2($do);
|
||||||
}
|
}
|
||||||
|
if ($spec_op1) {
|
||||||
|
$do = $foreach_op1($do);
|
||||||
|
}
|
||||||
|
|
||||||
|
$do("ANY", "ANY");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Emit labels for unspecialized executor
|
// Emit labels for unspecialized executor
|
||||||
|
@ -1019,6 +1147,21 @@ function gen_labels($f, $spec, $kind, $prolog) {
|
||||||
out($f,$prolog."(void*)&&ZEND_NULL_HANDLER\n");
|
out($f,$prolog."(void*)&&ZEND_NULL_HANDLER\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
$specs[$num + 1] = "$label";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generates specialized offsets
|
||||||
|
function gen_specs($f, $spec, $kind, $prolog, $specs) {
|
||||||
|
$lastdef = array_pop($specs);
|
||||||
|
$last = 0;
|
||||||
|
foreach ($specs as $num => $def) {
|
||||||
|
while (++$last < $num) {
|
||||||
|
out($f, "$prolog$lastdef,\n");
|
||||||
|
}
|
||||||
|
$last = $num;
|
||||||
|
out($f, "$prolog$def,\n");
|
||||||
|
}
|
||||||
|
out($f, "$prolog$lastdef\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates handler for undefined opcodes (CALL threading model)
|
// Generates handler for undefined opcodes (CALL threading model)
|
||||||
|
@ -1039,8 +1182,69 @@ function gen_null_handler($f) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extra_spec_name($extra_spec) {
|
||||||
|
global $prefix;
|
||||||
|
|
||||||
|
$s = "";
|
||||||
|
if (isset($extra_spec["op_data"])) {
|
||||||
|
$s .= "_OP_DATA" . $prefix[$extra_spec["op_data"]];
|
||||||
|
}
|
||||||
|
if (isset($extra_spec["retval"])) {
|
||||||
|
$s .= "_RETVAL_".($extra_spec["retval"] ? "USED" : "UNUSED");
|
||||||
|
}
|
||||||
|
return $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function extra_spec_flags($extra_spec) {
|
||||||
|
$s = [];
|
||||||
|
if (isset($extra_spec["op_data"])) {
|
||||||
|
$s[] = "SPEC_RULE_OP_DATA";
|
||||||
|
}
|
||||||
|
if (isset($extra_spec["retval"])) {
|
||||||
|
$s[] = "SPEC_RULE_RETVAL";
|
||||||
|
}
|
||||||
|
return $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function extra_spec_handler($dsc) {
|
||||||
|
global $op_types_ex;
|
||||||
|
|
||||||
|
if (!isset($dsc["spec"])) {
|
||||||
|
return array(array());
|
||||||
|
}
|
||||||
|
$specs = $dsc["spec"];
|
||||||
|
|
||||||
|
if (isset($specs["op_data"])) {
|
||||||
|
$op_data_specs = $specs["op_data"];
|
||||||
|
$specs["op_data"] = [];
|
||||||
|
foreach($op_types_ex as $op_data) {
|
||||||
|
if (isset($dsc["spec"]["op_data"][$op_data])) {
|
||||||
|
$specs["op_data"][] = $op_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$f = function($specs) use (&$f) {
|
||||||
|
$spec = key($specs);
|
||||||
|
$top = array_shift($specs);
|
||||||
|
if ($specs) {
|
||||||
|
$next = $f($specs);
|
||||||
|
} else {
|
||||||
|
$next = [[]];
|
||||||
|
}
|
||||||
|
$ret = [];
|
||||||
|
foreach ($next as $existing) {
|
||||||
|
foreach ($top as $mode) {
|
||||||
|
$ret[] = [$spec => $mode] + $existing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
|
};
|
||||||
|
return $f($specs);
|
||||||
|
}
|
||||||
|
|
||||||
// Generates all opcode handlers and helpers (specialized or unspecilaized)
|
// Generates all opcode handlers and helpers (specialized or unspecilaized)
|
||||||
function gen_executor_code($f, $spec, $kind, $prolog) {
|
function gen_executor_code($f, $spec, $kind, $prolog, &$switch_labels = []) {
|
||||||
global $list, $opcodes, $helpers, $op_types_ex;
|
global $list, $opcodes, $helpers, $op_types_ex;
|
||||||
|
|
||||||
if ($spec) {
|
if ($spec) {
|
||||||
|
@ -1055,11 +1259,13 @@ function gen_executor_code($f, $spec, $kind, $prolog) {
|
||||||
foreach ($list as $lineno => $dsc) {
|
foreach ($list as $lineno => $dsc) {
|
||||||
if (isset($dsc["handler"])) {
|
if (isset($dsc["handler"])) {
|
||||||
$num = $dsc["handler"];
|
$num = $dsc["handler"];
|
||||||
|
foreach (extra_spec_handler($opcodes[$num]) as $extra_spec) {
|
||||||
// Check if handler accepts such types of operands (op1 and op2)
|
// Check if handler accepts such types of operands (op1 and op2)
|
||||||
if (isset($opcodes[$num]["op1"][$op1]) &&
|
if (isset($opcodes[$num]["op1"][$op1]) &&
|
||||||
isset($opcodes[$num]["op2"][$op2])) {
|
isset($opcodes[$num]["op2"][$op2])) {
|
||||||
// Generate handler code
|
// Generate handler code
|
||||||
gen_handler($f, 1, $kind, $opcodes[$num]["op"], $op1, $op2, isset($opcodes[$num]["use"]), $opcodes[$num]["code"], $lineno);
|
gen_handler($f, 1, $kind, $opcodes[$num]["op"], $op1, $op2, isset($opcodes[$num]["use"]), $opcodes[$num]["code"], $lineno, $extra_spec, $switch_labels);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (isset($dsc["helper"])) {
|
} else if (isset($dsc["helper"])) {
|
||||||
$num = $dsc["helper"];
|
$num = $dsc["helper"];
|
||||||
|
@ -1129,6 +1335,7 @@ function skip_blanks($f, $prolog, $epilog) {
|
||||||
function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name) {
|
function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name) {
|
||||||
global $params, $skeleton_file, $line_no;
|
global $params, $skeleton_file, $line_no;
|
||||||
|
|
||||||
|
$switch_labels = [];
|
||||||
$lineno = 0;
|
$lineno = 0;
|
||||||
foreach ($skl as $line) {
|
foreach ($skl as $line) {
|
||||||
// Skeleton file contains special markers in form %NAME% those are
|
// Skeleton file contains special markers in form %NAME% those are
|
||||||
|
@ -1136,6 +1343,13 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name)
|
||||||
if (preg_match("/(.*)[{][%]([A-Z_]*)[%][}](.*)/", $line, $m)) {
|
if (preg_match("/(.*)[{][%]([A-Z_]*)[%][}](.*)/", $line, $m)) {
|
||||||
switch ($m[2]) {
|
switch ($m[2]) {
|
||||||
case "DEFINES":
|
case "DEFINES":
|
||||||
|
out($f,"#define SPEC_START_MASK 0x0000ffff\n");
|
||||||
|
out($f,"#define SPEC_RULE_OP1 0x00010000\n");
|
||||||
|
out($f,"#define SPEC_RULE_OP2 0x00020000\n");
|
||||||
|
out($f,"#define SPEC_RULE_OP_DATA 0x00040000\n");
|
||||||
|
out($f,"#define SPEC_RULE_RETVAL 0x00080000\n");
|
||||||
|
out($f,"\n");
|
||||||
|
out($f,"static const uint32_t *zend_spec_handlers;\n");
|
||||||
out($f,"static const void **zend_opcode_handlers;\n");
|
out($f,"static const void **zend_opcode_handlers;\n");
|
||||||
out($f,"static const void *zend_vm_get_opcode_handler(zend_uchar opcode, const zend_op* op);\n\n");
|
out($f,"static const void *zend_vm_get_opcode_handler(zend_uchar opcode, const zend_op* op);\n\n");
|
||||||
switch ($kind) {
|
switch ($kind) {
|
||||||
|
@ -1321,9 +1535,13 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name)
|
||||||
$prolog = $m[1];
|
$prolog = $m[1];
|
||||||
out($f,$prolog."if (UNEXPECTED(execute_data == NULL)) {\n");
|
out($f,$prolog."if (UNEXPECTED(execute_data == NULL)) {\n");
|
||||||
out($f,$prolog."\tstatic const void* labels[] = {\n");
|
out($f,$prolog."\tstatic const void* labels[] = {\n");
|
||||||
gen_labels($f, $spec, $kind, $prolog."\t\t");
|
gen_labels($f, $spec, $kind, $prolog."\t\t", $specs);
|
||||||
out($f,$prolog."\t};\n");
|
out($f,$prolog."\t};\n");
|
||||||
|
out($f,$prolog."static const uint32_t specs[] = {\n");
|
||||||
|
gen_specs($f, $spec, $kind, $prolog."\t", $specs);
|
||||||
|
out($f,$prolog."};\n");
|
||||||
out($f,$prolog."\tzend_opcode_handlers = (const void **) labels;\n");
|
out($f,$prolog."\tzend_opcode_handlers = (const void **) labels;\n");
|
||||||
|
out($f,$prolog."\tzend_spec_handlers = (const uint32_t *) specs;\n");
|
||||||
out($f,$prolog."\treturn;\n");
|
out($f,$prolog."\treturn;\n");
|
||||||
out($f,$prolog."}\n");
|
out($f,$prolog."}\n");
|
||||||
} else {
|
} else {
|
||||||
|
@ -1384,7 +1602,7 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name)
|
||||||
"#endif\n");
|
"#endif\n");
|
||||||
} else {
|
} else {
|
||||||
// Emit executor code
|
// Emit executor code
|
||||||
gen_executor_code($f, $spec, $kind, $m[1]);
|
gen_executor_code($f, $spec, $kind, $m[1], $switch_labels);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "EXTERNAL_EXECUTOR":
|
case "EXTERNAL_EXECUTOR":
|
||||||
|
@ -1405,9 +1623,13 @@ function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name)
|
||||||
out($f,$prolog.$executor_name."_ex(NULL);\n");
|
out($f,$prolog.$executor_name."_ex(NULL);\n");
|
||||||
} else {
|
} else {
|
||||||
out($f,$prolog."static const void *labels[] = {\n");
|
out($f,$prolog."static const void *labels[] = {\n");
|
||||||
gen_labels($f, $spec, $kind, $prolog."\t");
|
gen_labels($f, $spec, $kind, $prolog."\t", $specs, $switch_labels);
|
||||||
|
out($f,$prolog."};\n");
|
||||||
|
out($f,$prolog."static const uint32_t specs[] = {\n");
|
||||||
|
gen_specs($f, $spec, $kind, $prolog."\t", $specs);
|
||||||
out($f,$prolog."};\n");
|
out($f,$prolog."};\n");
|
||||||
out($f,$prolog."zend_opcode_handlers = labels;\n");
|
out($f,$prolog."zend_opcode_handlers = labels;\n");
|
||||||
|
out($f,$prolog."zend_spec_handlers = specs;\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1456,6 +1678,34 @@ function parse_ext_spec($def, $lineno, $str) {
|
||||||
return $flags;
|
return $flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parse_spec_rules($def, $lineno, $str) {
|
||||||
|
$ret = array();
|
||||||
|
$a = explode(",", $str);
|
||||||
|
foreach($a as $rule) {
|
||||||
|
$n = strpos($rule, "=");
|
||||||
|
if ($n !== false) {
|
||||||
|
$id = trim(substr($rule, 0, $n));
|
||||||
|
$val = trim(substr($rule, $n+1));
|
||||||
|
switch ($id) {
|
||||||
|
case "OP_DATA":
|
||||||
|
$ret["op_data"] = parse_operand_spec($def, $lineno, $val, $devnull);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
die("ERROR ($def:$lineno): Wrong specialization rules '$str'\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch ($rule) {
|
||||||
|
case "RETVAL":
|
||||||
|
$ret["retval"] = [0, 1];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
die("ERROR ($def:$lineno): Wrong specialization rules '$str'\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
function gen_vm($def, $skel) {
|
function gen_vm($def, $skel) {
|
||||||
global $definition_file, $skeleton_file, $executor_file,
|
global $definition_file, $skeleton_file, $executor_file,
|
||||||
$op_types, $list, $opcodes, $helpers, $params, $opnames,
|
$op_types, $list, $opcodes, $helpers, $params, $opnames,
|
||||||
|
@ -1489,7 +1739,7 @@ function gen_vm($def, $skel) {
|
||||||
if (strpos($line,"ZEND_VM_HANDLER(") === 0) {
|
if (strpos($line,"ZEND_VM_HANDLER(") === 0) {
|
||||||
// Parsing opcode handler's definition
|
// Parsing opcode handler's definition
|
||||||
if (preg_match(
|
if (preg_match(
|
||||||
"/^ZEND_VM_HANDLER\(\s*([0-9]+)\s*,\s*([A-Z_]+)\s*,\s*([A-Z_|]+)\s*,\s*([A-Z_|]+)\s*(,\s*([A-Z_|]+)\s*)?\)/",
|
"/^ZEND_VM_HANDLER\(\s*([0-9]+)\s*,\s*([A-Z_]+)\s*,\s*([A-Z_|]+)\s*,\s*([A-Z_|]+)\s*(,\s*([A-Z_|]+)\s*)?(,\s*SPEC\(([A-Z_|=,]+)\)\s*)?\)/",
|
||||||
$line,
|
$line,
|
||||||
$m) == 0) {
|
$m) == 0) {
|
||||||
die("ERROR ($def:$lineno): Invalid ZEND_VM_HANDLER definition.\n");
|
die("ERROR ($def:$lineno): Invalid ZEND_VM_HANDLER definition.\n");
|
||||||
|
@ -1500,7 +1750,7 @@ function gen_vm($def, $skel) {
|
||||||
$op1 = parse_operand_spec($def, $lineno, $m[3], $flags1);
|
$op1 = parse_operand_spec($def, $lineno, $m[3], $flags1);
|
||||||
$op2 = parse_operand_spec($def, $lineno, $m[4], $flags2);
|
$op2 = parse_operand_spec($def, $lineno, $m[4], $flags2);
|
||||||
$flags = $flags1 | ($flags2 << 8);
|
$flags = $flags1 | ($flags2 << 8);
|
||||||
if (isset($m[6])) {
|
if (!empty($m[6])) {
|
||||||
$flags |= parse_ext_spec($def, $lineno, $m[6]);
|
$flags |= parse_ext_spec($def, $lineno, $m[6]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1517,6 +1767,9 @@ function gen_vm($def, $skel) {
|
||||||
die("ERROR ($def:$lineno): Opcode with name '$op' is already defined.\n");
|
die("ERROR ($def:$lineno): Opcode with name '$op' is already defined.\n");
|
||||||
}
|
}
|
||||||
$opcodes[$code] = array("op"=>$op,"op1"=>$op1,"op2"=>$op2,"code"=>"","flags"=>$flags);
|
$opcodes[$code] = array("op"=>$op,"op1"=>$op1,"op2"=>$op2,"code"=>"","flags"=>$flags);
|
||||||
|
if (isset($m[8])) {
|
||||||
|
$opcodes[$code]["spec"] = parse_spec_rules($def, $lineno, $m[8]);
|
||||||
|
}
|
||||||
$opnames[$op] = $code;
|
$opnames[$op] = $code;
|
||||||
$handler = $code;
|
$handler = $code;
|
||||||
$helper = null;
|
$helper = null;
|
||||||
|
@ -1740,26 +1993,32 @@ function gen_vm($def, $skel) {
|
||||||
if (!ZEND_VM_SPEC) {
|
if (!ZEND_VM_SPEC) {
|
||||||
out($f, "\treturn zend_opcode_handlers[opcode];\n");
|
out($f, "\treturn zend_opcode_handlers[opcode];\n");
|
||||||
} else {
|
} else {
|
||||||
out($f, "\t\tstatic const int zend_vm_decode[] = {\n");
|
out($f, "\tstatic const int zend_vm_decode[] = {\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 0 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 0 */\n");
|
||||||
out($f, "\t\t\t_CONST_CODE, /* 1 = IS_CONST */\n");
|
out($f, "\t\t_CONST_CODE, /* 1 = IS_CONST */\n");
|
||||||
out($f, "\t\t\t_TMP_CODE, /* 2 = IS_TMP_VAR */\n");
|
out($f, "\t\t_TMP_CODE, /* 2 = IS_TMP_VAR */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 3 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 3 */\n");
|
||||||
out($f, "\t\t\t_VAR_CODE, /* 4 = IS_VAR */\n");
|
out($f, "\t\t_VAR_CODE, /* 4 = IS_VAR */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 5 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 5 */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 6 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 6 */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 7 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 7 */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 8 = IS_UNUSED */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 8 = IS_UNUSED */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 9 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 9 */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 10 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 10 */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 11 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 11 */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 12 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 12 */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 13 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 13 */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 14 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 14 */\n");
|
||||||
out($f, "\t\t\t_UNUSED_CODE, /* 15 */\n");
|
out($f, "\t\t_UNUSED_CODE, /* 15 */\n");
|
||||||
out($f, "\t\t\t_CV_CODE /* 16 = IS_CV */\n");
|
out($f, "\t\t_CV_CODE /* 16 = IS_CV */\n");
|
||||||
out($f, "\t\t};\n");
|
out($f, "\t};\n");
|
||||||
out($f, "\t\treturn zend_opcode_handlers[opcode * 25 + zend_vm_decode[op->op1_type] * 5 + zend_vm_decode[op->op2_type]];\n");
|
out($f, "\tuint32_t spec = zend_spec_handlers[opcode];\n");
|
||||||
|
out($f, "\tuint32_t offset = 0;\n");
|
||||||
|
out($f, "\tif (spec & SPEC_RULE_OP1) offset = offset * 5 + zend_vm_decode[op->op1_type];\n");
|
||||||
|
out($f, "\tif (spec & SPEC_RULE_OP2) offset = offset * 5 + zend_vm_decode[op->op2_type];\n");
|
||||||
|
out($f, "\tif (spec & SPEC_RULE_OP_DATA) offset = offset * 5 + zend_vm_decode[(op + 1)->op1_type];\n");
|
||||||
|
out($f, "\tif (spec & SPEC_RULE_RETVAL) offset = offset * 2 + ((op->result_type & EXT_TYPE_UNUSED) == 0);\n");
|
||||||
|
out($f, "\treturn zend_opcode_handlers[(spec & SPEC_START_MASK) + offset];\n");
|
||||||
}
|
}
|
||||||
out($f, "}\n\n");
|
out($f, "}\n\n");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue