Browse files

- Commit new VM

- Old one is tagged as PRE_NEW_VM_GEN_PATCH
- Still doing work so more commits to come. Don't complain (yet) :)
  • Loading branch information...
1 parent b20d2ba commit e50a6fde116a76e1f4d0b8d62873d885eb36851e @andigutmans andigutmans committed Oct 22, 2004
Showing with 4,545 additions and 628 deletions.
  1. +1 −1 Zend/Makefile.frag
  2. +47 −262 Zend/zend_execute.c
  3. +1 −365 Zend/zend_vm.h
  4. +3,423 −0 Zend/zend_vm_def.h
  5. +72 −0 Zend/zend_vm_execute.skl
  6. +1,001 −0 Zend/zend_vm_gen.php
View
2 Zend/Makefile.frag
@@ -1 +1 @@
-Zend/zend_execute.lo: $(srcdir)/zend_vm_spec.h $(srcdir)/zend_vm_handlers.h
+Zend/zend_execute.lo: $(srcdir)/zend_vm_execute.h
View
309 Zend/zend_execute.c
@@ -36,6 +36,21 @@
#include "zend_exceptions.h"
#include "zend_vm.h"
+#define _CONST_CODE 0
+#define _TMP_CODE 1
+#define _VAR_CODE 2
+#define _UNUSED_CODE 3
+#define _CV_CODE 4
+
+#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(ZEND_VM_OLD_EXECUTOR)
+# define ZEND_VM_ALWAYS_INLINE __attribute__ ((always_inline))
+void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((alias("zend_error"),noreturn));
+/*extern void zend_error_noreturn(int type, const char *format, ...) __asm__("zend_error") __attribute__ ((noreturn));*/
+#else
+# define ZEND_VM_ALWAYS_INLINE
+# define zend_error_noreturn zend_error
+#endif
+
typedef int (*incdec_t)(zval *);
#define get_zval_ptr(node, Ts, should_free, type) _get_zval_ptr(node, Ts, should_free, type TSRMLS_CC)
@@ -260,8 +275,6 @@ static inline zval **_get_zval_ptr_ptr(znode *node, temp_variable *Ts, zend_free
}
}
-#ifdef ZEND_VM_SPEC
-
static inline zval *_get_zval_ptr_const(znode *node, temp_variable *Ts, zend_free_op *should_free TSRMLS_DC)
{
return &node->u.constant;
@@ -453,7 +466,6 @@ static inline zval **_get_obj_zval_ptr_ptr_unused(znode *op, temp_variable *Ts,
return NULL;
}
}
-#endif
static inline void zend_switch_free(zend_op *opline, temp_variable *Ts TSRMLS_DC)
{
@@ -1427,265 +1439,38 @@ ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, int return_v
((zend_internal_function *) execute_data_ptr->function_state.function)->handler(execute_data_ptr->opline->extended_value, (*(temp_variable *)((char *) execute_data_ptr->Ts + execute_data_ptr->opline->result.u.var)).var.ptr, execute_data_ptr->object, return_value_used TSRMLS_CC);
}
-ZEND_API void execute(zend_op_array *op_array TSRMLS_DC)
-{
- zend_execute_data execute_data;
- ZEND_VM_HELPER_VAR(int (*binary_op)(zval *result, zval *op1, zval *op2 TSRMLS_DC))
- ZEND_VM_HELPER_VAR(incdec_t incdec_op)
- ZEND_VM_HELPER_VAR(int prop_dim)
- ZEND_VM_HELPER_VAR(int type)
-
-#if ZEND_VM_KIND == ZEND_VM_KIND_GOTO
- if (op_array == NULL) {
- goto init_labels;
- }
-#endif
-
- /* Initialize execute_data */
- EX(fbc) = NULL;
- EX(object) = NULL;
- if (op_array->T < TEMP_VAR_STACK_LIMIT) {
- EX(Ts) = (temp_variable *) do_alloca(sizeof(temp_variable) * op_array->T);
- } else {
- EX(Ts) = (temp_variable *) safe_emalloc(sizeof(temp_variable), op_array->T, 0);
- }
- EX(CVs) = (zval***)do_alloca(sizeof(zval**) * op_array->last_var);
- memset(EX(CVs), 0, sizeof(zval**) * op_array->last_var);
- EX(op_array) = op_array;
- EX(original_in_execution) = EG(in_execution);
- EX(symbol_table) = EG(active_symbol_table);
- EX(prev_execute_data) = EG(current_execute_data);
- EG(current_execute_data) = &execute_data;
-
- EG(in_execution) = 1;
- if (op_array->start_op) {
- ZEND_VM_SET_OPCODE(op_array->start_op);
- } else {
- ZEND_VM_SET_OPCODE(op_array->opcodes);
- }
-
- if (op_array->uses_this && EG(This)) {
- EG(This)->refcount++; /* For $this pointer */
- if (zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), NULL)==FAILURE) {
- EG(This)->refcount--;
- }
- }
-
- EG(opline_ptr) = &EX(opline);
-
- EX(function_state).function = (zend_function *) op_array;
- EG(function_state_ptr) = &EX(function_state);
-#if ZEND_DEBUG
- /* function_state.function_symbol_table is saved as-is to a stack,
- * which is an intentional UMR. Shut it up if we're in DEBUG.
- */
- EX(function_state).function_symbol_table = NULL;
-#endif
-
- while (1) {
-ZEND_VM_CONTINUE_LABEL
-#ifdef ZEND_WIN32
- if (EG(timed_out)) {
- zend_timeout(0);
- }
-#endif
-
- ZEND_VM_DISPATCH() {
-#if ZEND_VM_KIND == ZEND_VM_KIND_CALL
- return;
-#else
-# include "zend_vm_spec.h"
-#endif
- }
-
- }
- zend_error_noreturn(E_ERROR, "Arrived at end of main loop which shouldn't happen");
-#if ZEND_VM_KIND == ZEND_VM_KIND_GOTO
- {
- static const opcode_handler_t labels[] = {ZEND_VM_LABELS};
-
- init_labels:
- zend_opcode_handlers = (opcode_handler_t*)labels;
- return;
- }
-#endif
-}
-
-#if ZEND_VM_KIND == ZEND_VM_KIND_CALL
-# undef EX
-# define EX(element) execute_data->element
-# include"zend_vm_spec.h"
-#endif
-
-void zend_init_opcodes_handlers()
-{
-#if ZEND_VM_KIND == ZEND_VM_KIND_GOTO
- TSRMLS_FETCH();
- zend_execute(NULL TSRMLS_CC);
-#else
- static const opcode_handler_t labels[] = {ZEND_VM_LABELS};
-
- zend_opcode_handlers = (opcode_handler_t*)labels;
-#endif
-}
-
-#ifdef ZEND_VM_HAVE_OLD_EXECUTOR
-/* Old Style Executor */
-/* TODO: remove it */
-
-# undef EX
-# define EX(element) execute_data.element
-
-/* Hack */
-# define ZEND_VM_OLD_EXECUTOR
-# undef ZEND_VM_H
-# undef ZEND_VM_KIND
-# define ZEND_VM_KIND ZEND_VM_KIND_CALL
-# undef ZEND_VM_SPEC
-# undef ZEND_VM_ALWAYS_INLINE
-# undef zend_error_noreturn
-# undef ZEND_VM_CODE
-# undef ZEND_VM_SPEC_OPCODE
-# undef ZEND_VM_SET_OPCODE_HANDLER
-# undef EXECUTE_DATA
-# undef ZEND_VM_HELPER_VAR
-# undef ZEND_VM_DISPATCH
-# undef ZEND_VM_HANDLER
-# undef ZEND_VM_HANDLER_EX
-# undef ZEND_VM_HELPER
-# undef ZEND_VM_HELPER_EX
-# undef ZEND_VM_SPEC_HANDLER
-# undef ZEND_VM_SPEC_HANDLER_EX
-# undef ZEND_VM_SPEC_HELPER
-# undef ZEND_VM_SPEC_HELPER_EX
-# undef ZEND_VM_NULL_HANDLER
-# undef ZEND_VM_DISPATCH_TO_HANDLER
-# undef ZEND_VM_DISPATCH_TO_HELPER
-# undef ZEND_VM_DISPATCH_TO_HELPER_EX
-# undef ZEND_VM_SPEC_DISPATCH_TO_HANDLER
-# undef ZEND_VM_SPEC_DISPATCH_TO_HELPER
-# undef ZEND_VM_SPEC_DISPATCH_TO_HELPER_EX
-# undef ZEND_VM_CONTINUE
-# undef ZEND_VM_NEXT_OPCODE
-# undef ZEND_VM_RETURN_FROM_EXECUTE_LOOP
-# undef ZEND_VM_LABEL
-# undef ZEND_VM_NULL_LABEL
-# undef ZEND_VM_SPEC_LABEL
-# undef ZEND_VM_SPEC_NULL_LABEL
-# undef ZEND_VM_CONTINUE_LABEL
-
-# include "zend_vm.h"
-
-static void old_execute(zend_op_array *op_array TSRMLS_DC)
-{
- zend_execute_data execute_data;
-
- /* Initialize execute_data */
- EX(fbc) = NULL;
- EX(object) = NULL;
- if (op_array->T < TEMP_VAR_STACK_LIMIT) {
- EX(Ts) = (temp_variable *) do_alloca(sizeof(temp_variable) * op_array->T);
- } else {
- EX(Ts) = (temp_variable *) safe_emalloc(sizeof(temp_variable), op_array->T, 0);
- }
- EX(CVs) = (zval***)do_alloca(sizeof(zval**) * op_array->last_var);
- memset(EX(CVs), 0, sizeof(zval**) * op_array->last_var);
- EX(op_array) = op_array;
- EX(original_in_execution) = EG(in_execution);
- EX(symbol_table) = EG(active_symbol_table);
- EX(prev_execute_data) = EG(current_execute_data);
- EG(current_execute_data) = &execute_data;
-
- EG(in_execution) = 1;
- if (op_array->start_op) {
- ZEND_VM_SET_OPCODE(op_array->start_op);
- } else {
- ZEND_VM_SET_OPCODE(op_array->opcodes);
- }
-
- if (op_array->uses_this && EG(This)) {
- EG(This)->refcount++; /* For $this pointer */
- if (zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), NULL)==FAILURE) {
- EG(This)->refcount--;
- }
- }
-
- EG(opline_ptr) = &EX(opline);
-
- EX(function_state).function = (zend_function *) op_array;
- EG(function_state_ptr) = &EX(function_state);
-#if ZEND_DEBUG
- /* function_state.function_symbol_table is saved as-is to a stack,
- * which is an intentional UMR. Shut it up if we're in DEBUG.
- */
- EX(function_state).function_symbol_table = NULL;
-#endif
-
- while (1) {
-#ifdef ZEND_WIN32
- if (EG(timed_out)) {
- zend_timeout(0);
- }
-#endif
-
- ZEND_VM_DISPATCH() {
- return;
- }
-
- }
- zend_error_noreturn(E_ERROR, "Arrived at end of main loop which shouldn't happen");
-}
-# undef EX
-# define EX(element) execute_data->element
-
-/* Hack */
-# undef OP1_OP2_MASK
-# undef HAVE_OP
-# undef ZEND_VM_C_GOTO
-# undef ZEND_VM_C_LABEL
-
-# include"zend_vm_spec.h"
-
-ZEND_API int zend_vm_old_executor = 0;
-
-void zend_vm_set_opcode_handler(zend_op* op)
-{
- if (zend_vm_old_executor) {
- op->handler = zend_opcode_handlers[op->opcode];
- } else {
- static const int zend_vm_decode[] = {
- _UNUSED_CODE, /* 0 */
- _CONST_CODE, /* 1 = IS_CONST */
- _TMP_CODE, /* 2 = IS_TMP_VAR */
- _UNUSED_CODE, /* 3 */
- _VAR_CODE, /* 4 = IS_VAR */
- _UNUSED_CODE, /* 5 */
- _UNUSED_CODE, /* 6 */
- _UNUSED_CODE, /* 7 */
- _UNUSED_CODE, /* 8 = IS_UNUSED */
- _UNUSED_CODE, /* 9 */
- _UNUSED_CODE, /* 10 */
- _UNUSED_CODE, /* 11 */
- _UNUSED_CODE, /* 12 */
- _UNUSED_CODE, /* 13 */
- _UNUSED_CODE, /* 14 */
- _UNUSED_CODE, /* 15 */
- _CV_CODE /* 16 = IS_CV */
- };
- op->handler = zend_opcode_handlers[op->opcode * 25 + zend_vm_decode[op->op1.op_type] * 5 + zend_vm_decode[op->op2.op_type]];
- }
-}
-
-
-ZEND_API void zend_vm_use_old_executor()
-{
- static opcode_handler_t labels[512] = {ZEND_VM_LABELS};
-
- zend_vm_old_executor = 1;
- zend_opcode_handlers = (opcode_handler_t*)labels;
- zend_execute = old_execute;
-}
-#endif
+#define ZEND_VM_NEXT_OPCODE() \
+ CHECK_SYMBOL_TABLES() \
+ EX(opline)++; \
+ ZEND_VM_CONTINUE()
+
+#define ZEND_VM_SET_OPCODE(new_op) \
+ CHECK_SYMBOL_TABLES() \
+ EX(opline) = new_op
+
+#define ZEND_VM_INC_OPCODE() \
+ if (!EG(exception)) { \
+ CHECK_SYMBOL_TABLES() \
+ EX(opline)++; \
+ }
+
+#define ZEND_VM_RETURN_FROM_EXECUTE_LOOP() \
+ free_alloca(EX(CVs)); \
+ if (EX(op_array)->T < TEMP_VAR_STACK_LIMIT) { \
+ free_alloca(EX(Ts)); \
+ } else { \
+ efree(EX(Ts)); \
+ } \
+ EG(in_execution) = EX(original_in_execution); \
+ EG(current_execute_data) = EX(prev_execute_data); \
+ ZEND_VM_RETURN()
+
+#define ZEND_VM_CONTINUE_JMP() \
+ ZEND_VM_CONTINUE()
+
+static int zend_vm_old_executor = 0;
+
+#include "zend_vm_execute.h"
/*
* Local variables:
View
366 Zend/zend_vm.h
@@ -21,373 +21,9 @@
#ifndef ZEND_VM_H
#define ZEND_VM_H
-#define ZEND_VM_HAVE_OLD_EXECUTOR
-
-#define ZEND_VM_KIND_CALL 1
-#define ZEND_VM_KIND_SWITCH 2
-#define ZEND_VM_KIND_GOTO 3
-
-#ifndef ZEND_VM_OLD_EXECUTOR
-/*# define ZEND_VM_KIND ZEND_VM_KIND_CALL */
-# define ZEND_VM_SPEC
-#endif
-
-/* don't edit the rest of the file */
-
-#ifdef ZEND_VM_HAVE_OLD_EXECUTOR
ZEND_API void zend_vm_use_old_executor();
void zend_vm_set_opcode_handler(zend_op* opcode);
-#endif
-
-#define _CONST_CODE 0
-#define _TMP_CODE 1
-#define _VAR_CODE 2
-#define _UNUSED_CODE 3
-#define _CV_CODE 4
-
-#ifndef ZEND_VM_KIND
-# ifdef __GNUC__
-# define ZEND_VM_KIND ZEND_VM_KIND_GOTO
-# else
-# define ZEND_VM_KIND ZEND_VM_KIND_CALL
-# endif
-#endif
-
-#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(ZEND_VM_OLD_EXECUTOR)
-# define ZEND_VM_ALWAYS_INLINE __attribute__ ((always_inline))
-void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((alias("zend_error"),noreturn));
-/*extern void zend_error_noreturn(int type, const char *format, ...) __asm__("zend_error") __attribute__ ((noreturn));*/
-#else
-# define ZEND_VM_ALWAYS_INLINE
-# define zend_error_noreturn zend_error
-#endif
-
-#ifndef ZEND_VM_SPEC
-# define ZEND_VM_CODE(opcode, op1, op2) opcode
-# define ZEND_VM_SPEC_OPCODE(opcode, op1, op2) opcode
-# ifdef ZEND_VM_HAVE_OLD_EXECUTOR
-# define ZEND_VM_SET_OPCODE_HANDLER(opline) \
- zend_vm_set_opcode_handler(opline)
-# else
-# define ZEND_VM_SET_OPCODE_HANDLER(opline) \
- opline->handler = zend_opcode_handlers[opline->opcode]
-# endif
-#else
-static const int zend_vm_decode[] = {
- _UNUSED_CODE, /* 0 */
- _CONST_CODE, /* 1 = IS_CONST */
- _TMP_CODE, /* 2 = IS_TMP_VAR */
- _UNUSED_CODE, /* 3 */
- _VAR_CODE, /* 4 = IS_VAR */
- _UNUSED_CODE, /* 5 */
- _UNUSED_CODE, /* 6 */
- _UNUSED_CODE, /* 7 */
- _UNUSED_CODE, /* 8 = IS_UNUSED */
- _UNUSED_CODE, /* 9 */
- _UNUSED_CODE, /* 10 */
- _UNUSED_CODE, /* 11 */
- _UNUSED_CODE, /* 12 */
- _UNUSED_CODE, /* 13 */
- _UNUSED_CODE, /* 14 */
- _UNUSED_CODE, /* 15 */
- _CV_CODE /* 16 = IS_CV */
-};
-
-# define ZEND_VM_CODE(opcode, op1, op2) \
- opcode * 25 + op1 * 5 + op2
-# define ZEND_VM_SPEC_OPCODE(opcode, op1, op2) \
- ZEND_VM_CODE(opcode, zend_vm_decode[op1], zend_vm_decode[op2])
-# ifdef ZEND_VM_HAVE_OLD_EXECUTOR
-# define ZEND_VM_SET_OPCODE_HANDLER(opline) \
- zend_vm_set_opcode_handler(opline)
-# else
-# define ZEND_VM_SET_OPCODE_HANDLER(opline) \
- opline->handler = zend_opcode_handlers[ZEND_VM_SPEC_OPCODE(opline->opcode, opline->op1.op_type, opline->op2.op_type)]
-# endif
-#endif
-
-
-#if ZEND_VM_KIND == ZEND_VM_KIND_CALL
-
-# define EXECUTE_DATA execute_data
-
-# define ZEND_VM_HELPER_VAR(X)
-
-# define ZEND_VM_DISPATCH() \
- if (EX(opline)->handler(&execute_data TSRMLS_CC) > 0)
-
-# define ZEND_VM_CONTINUE_LABEL
-
-# define ZEND_VM_HANDLER(OP) \
- static int OP##_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
-
-# define ZEND_VM_HANDLER_EX(OP) \
- static int OP##_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
-
-# define ZEND_VM_HELPER(NAME) \
- static int NAME(ZEND_OPCODE_HANDLER_ARGS)
-
-# define ZEND_VM_HELPER_EX(NAME,PARAM) \
- static int NAME(PARAM, ZEND_OPCODE_HANDLER_ARGS)
-
-# define ZEND_VM_SPEC_HANDLER(OP, CODE) \
- static int OP##_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
-
-# define ZEND_VM_SPEC_HANDLER_EX(OP, CODE) \
- static int OP##_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
-
-# define ZEND_VM_SPEC_HELPER(NAME) \
- static int NAME(ZEND_OPCODE_HANDLER_ARGS)
-
-# define ZEND_VM_SPEC_HELPER_EX(NAME,PARAM) \
- static int NAME(PARAM, ZEND_OPCODE_HANDLER_ARGS)
-
-# define ZEND_VM_NULL_HANDLER() \
- int ZEND_VM_NULL(ZEND_OPCODE_HANDLER_ARGS)
-
-# define ZEND_VM_DISPATCH_TO_HANDLER(OP) \
- return OP##_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
-
-# define ZEND_VM_DISPATCH_TO_HELPER(NAME) \
- return NAME(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
-
-# define ZEND_VM_DISPATCH_TO_HELPER_EX(NAME,VAR,VAL) \
- return NAME(VAL, ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
-
-# define ZEND_VM_SPEC_DISPATCH_TO_HANDLER(OP) \
- return OP##_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
-
-# define ZEND_VM_SPEC_DISPATCH_TO_HELPER(NAME) \
- return NAME(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
-
-# define ZEND_VM_SPEC_DISPATCH_TO_HELPER_EX(NAME,VAR,VAL) \
- return NAME(VAL, ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
-
-# define ZEND_VM_CONTINUE() \
- return 0
-
-# define ZEND_VM_NEXT_OPCODE() \
- CHECK_SYMBOL_TABLES() \
- EX(opline)++; \
- return 0
-
-# define ZEND_VM_SET_OPCODE(new_op) \
- CHECK_SYMBOL_TABLES() \
- EX(opline) = new_op
-
-# define ZEND_VM_INC_OPCODE() \
- if (!EG(exception)) { \
- CHECK_SYMBOL_TABLES() \
- EX(opline)++; \
- }
-
-# define ZEND_VM_RETURN_FROM_EXECUTE_LOOP() \
- free_alloca(EX(CVs)); \
- if (EX(op_array)->T < TEMP_VAR_STACK_LIMIT) { \
- free_alloca(EX(Ts)); \
- } else { \
- efree(EX(Ts)); \
- } \
- EG(in_execution) = EX(original_in_execution); \
- EG(current_execute_data) = EX(prev_execute_data); \
- return 1;
-
-# define ZEND_VM_LABEL(OP) OP##_HANDLER
-# define ZEND_VM_NULL_LABEL ZEND_VM_NULL
-# define ZEND_VM_SPEC_LABEL(OP,CODE) OP##_HANDLER
-# define ZEND_VM_SPEC_NULL_LABEL ZEND_VM_NULL
-
-#elif ZEND_VM_KIND == ZEND_VM_KIND_SWITCH
-
-# define EXECUTE_DATA &execute_data
-
-# define ZEND_VM_HELPER_VAR(X) X;
-
-# define ZEND_VM_DISPATCH() \
- switch ((int)EX(opline)->handler)
-
-# define ZEND_VM_CONTINUE_LABEL \
- zend_vm_continue:
-
-# define ZEND_VM_HANDLER(OP) \
- case OP:
-
-# define ZEND_VM_HANDLER_EX(OP) \
- case OP: \
- OP##_LABEL:
-
-# define ZEND_VM_HELPER(NAME) \
- NAME:
-
-# define ZEND_VM_HELPER_EX(NAME,PARAM) \
- NAME:
-
-# define ZEND_VM_SPEC_HANDLER(OP, CODE) \
- case CODE:
-
-# define ZEND_VM_SPEC_HANDLER_EX(OP, CODE) \
- case CODE: \
- OP##_LABEL:
-
-# define ZEND_VM_SPEC_HELPER(NAME) \
- NAME:
-
-# define ZEND_VM_SPEC_HELPER_EX(NAME,PARAM) \
- NAME:
-
-# define ZEND_VM_NULL_HANDLER() \
- default:
-
-# define ZEND_VM_DISPATCH_TO_HANDLER(OP) \
- goto OP##_LABEL
-
-# define ZEND_VM_DISPATCH_TO_HELPER(NAME) \
- goto NAME
-
-# define ZEND_VM_DISPATCH_TO_HELPER_EX(NAME,VAR,VAL) \
- VAR = VAL; \
- goto NAME
-
-# define ZEND_VM_SPEC_DISPATCH_TO_HANDLER(OP) \
- goto OP##_LABEL
-
-# define ZEND_VM_SPEC_DISPATCH_TO_HELPER(NAME) \
- goto NAME
-
-# define ZEND_VM_SPEC_DISPATCH_TO_HELPER_EX(NAME,VAR,VAL) \
- VAR = VAL; \
- goto NAME
-
-# define ZEND_VM_CONTINUE() \
- goto zend_vm_continue
-
-# define ZEND_VM_NEXT_OPCODE() \
- CHECK_SYMBOL_TABLES() \
- EX(opline)++; \
- ZEND_VM_CONTINUE()
-
-# define ZEND_VM_SET_OPCODE(new_op) \
- CHECK_SYMBOL_TABLES() \
- EX(opline) = new_op
-
-# define ZEND_VM_INC_OPCODE() \
- if (!EG(exception)) { \
- CHECK_SYMBOL_TABLES() \
- EX(opline)++; \
- }
-
-# define ZEND_VM_RETURN_FROM_EXECUTE_LOOP() \
- free_alloca(EX(CVs)); \
- if (EX(op_array)->T < TEMP_VAR_STACK_LIMIT) { \
- free_alloca(EX(Ts)); \
- } else { \
- efree(EX(Ts)); \
- } \
- EG(in_execution) = EX(original_in_execution); \
- EG(current_execute_data) = EX(prev_execute_data); \
- return;
-
-# define ZEND_VM_LABEL(OP) (opcode_handler_t)OP
-# define ZEND_VM_NULL_LABEL (opcode_handler_t)-1
-# define ZEND_VM_SPEC_LABEL(OP,CODE) (opcode_handler_t)(CODE)
-# define ZEND_VM_SPEC_NULL_LABEL (opcode_handler_t)-1
-
-#elif ZEND_VM_KIND == ZEND_VM_KIND_GOTO
-
-# define EXECUTE_DATA &execute_data
-
-# define ZEND_VM_HELPER_VAR(X) X;
-
-# define ZEND_VM_DISPATCH() \
- goto *(void**)(EX(opline)->handler);
-
-# define ZEND_VM_CONTINUE_LABEL
-
-# define ZEND_VM_HANDLER(OP) \
- OP##_HANDLER:
-
-# define ZEND_VM_HANDLER_EX(OP) \
- OP##_HANDLER:
-
-# define ZEND_VM_HELPER(NAME) \
- NAME:
-
-# define ZEND_VM_HELPER_EX(NAME,PARAM) \
- NAME:
-
-# define ZEND_VM_SPEC_HANDLER(OP, CODE) \
- OP##_HANDLER:
-
-# define ZEND_VM_SPEC_HANDLER_EX(OP, CODE) \
- OP##_HANDLER:
-
-# define ZEND_VM_SPEC_HELPER(NAME) \
- NAME:
-
-# define ZEND_VM_SPEC_HELPER_EX(NAME,PARAM) \
- NAME:
-
-# define ZEND_VM_NULL_HANDLER() \
- ZEND_VM_NULL:
-
-# define ZEND_VM_DISPATCH_TO_HANDLER(OP) \
- goto OP##_HANDLER
-
-# define ZEND_VM_DISPATCH_TO_HELPER(NAME) \
- goto NAME
-
-# define ZEND_VM_DISPATCH_TO_HELPER_EX(NAME,VAR,VAL) \
- VAR = VAL; \
- goto NAME
-
-# define ZEND_VM_SPEC_DISPATCH_TO_HANDLER(OP) \
- goto OP##_HANDLER
-
-# define ZEND_VM_SPEC_DISPATCH_TO_HELPER(NAME) \
- goto NAME
-
-# define ZEND_VM_SPEC_DISPATCH_TO_HELPER_EX(NAME,VAR,VAL) \
- VAR = VAL; \
- goto NAME
-
-# define ZEND_VM_CONTINUE() \
- goto *(void**)(EX(opline)->handler)
-
-# define ZEND_VM_NEXT_OPCODE() \
- CHECK_SYMBOL_TABLES() \
- EX(opline)++; \
- ZEND_VM_CONTINUE()
-
-# define ZEND_VM_SET_OPCODE(new_op) \
- CHECK_SYMBOL_TABLES() \
- EX(opline) = new_op
-
-# define ZEND_VM_INC_OPCODE() \
- if (!EG(exception)) { \
- CHECK_SYMBOL_TABLES() \
- EX(opline)++; \
- }
-
-# define ZEND_VM_RETURN_FROM_EXECUTE_LOOP() \
- free_alloca(EX(CVs)); \
- if (EX(op_array)->T < TEMP_VAR_STACK_LIMIT) { \
- free_alloca(EX(Ts)); \
- } else { \
- efree(EX(Ts)); \
- } \
- EG(in_execution) = EX(original_in_execution); \
- EG(current_execute_data) = EX(prev_execute_data); \
- return;
-
-# define ZEND_VM_LABEL(OP) (opcode_handler_t)&&OP##_HANDLER
-# define ZEND_VM_NULL_LABEL &&ZEND_VM_NULL
-# define ZEND_VM_SPEC_LABEL(OP,CODE) (opcode_handler_t)&&OP##_HANDLER
-# define ZEND_VM_SPEC_NULL_LABEL &&ZEND_VM_NULL
-
-#else
-# error "Unknown ZEND_VM_KIND"
-#endif
-#define ZEND_VM_CONTINUE_JMP() ZEND_VM_CONTINUE()
+#define ZEND_VM_SET_OPCODE_HANDLER(opline) zend_vm_set_opcode_handler(opline)
#endif
View
3,423 Zend/zend_vm_def.h
3,423 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
72 Zend/zend_vm_execute.skl
@@ -0,0 +1,72 @@
+{%DEFINES%}
+
+ZEND_API void {%EXECUTOR_NAME%}(zend_op_array *op_array TSRMLS_DC)
+{
+ zend_execute_data execute_data;
+ {%HELPER_VARS%}
+
+ {%INTERANL_LABELS%}
+
+ /* Initialize execute_data */
+ EX(fbc) = NULL;
+ EX(object) = NULL;
+ if (op_array->T < TEMP_VAR_STACK_LIMIT) {
+ EX(Ts) = (temp_variable *) do_alloca(sizeof(temp_variable) * op_array->T);
+ } else {
+ EX(Ts) = (temp_variable *) safe_emalloc(sizeof(temp_variable), op_array->T, 0);
+ }
+ EX(CVs) = (zval***)do_alloca(sizeof(zval**) * op_array->last_var);
+ memset(EX(CVs), 0, sizeof(zval**) * op_array->last_var);
+ EX(op_array) = op_array;
+ EX(original_in_execution) = EG(in_execution);
+ EX(symbol_table) = EG(active_symbol_table);
+ EX(prev_execute_data) = EG(current_execute_data);
+ EG(current_execute_data) = &execute_data;
+
+ EG(in_execution) = 1;
+ if (op_array->start_op) {
+ ZEND_VM_SET_OPCODE(op_array->start_op);
+ } else {
+ ZEND_VM_SET_OPCODE(op_array->opcodes);
+ }
+
+ if (op_array->uses_this && EG(This)) {
+ EG(This)->refcount++; /* For $this pointer */
+ if (zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), NULL)==FAILURE) {
+ EG(This)->refcount--;
+ }
+ }
+
+ EG(opline_ptr) = &EX(opline);
+
+ EX(function_state).function = (zend_function *) op_array;
+ EG(function_state_ptr) = &EX(function_state);
+#if ZEND_DEBUG
+ /* function_state.function_symbol_table is saved as-is to a stack,
+ * which is an intentional UMR. Shut it up if we're in DEBUG.
+ */
+ EX(function_state).function_symbol_table = NULL;
+#endif
+
+ while (1) {
+ {%ZEND_VM_CONTINUE_LABEL%}
+#ifdef ZEND_WIN32
+ if (EG(timed_out)) {
+ zend_timeout(0);
+ }
+#endif
+
+ {%ZEND_VM_DISPATCH%} {
+ {%INTERNAL_EXECUTOR%}
+ }
+
+ }
+ zend_error_noreturn(E_ERROR, "Arrived at end of main loop which shouldn't happen");
+}
+
+{%EXTERNAL_EXECUTOR%}
+
+void {%INITIALIZER_NAME%}()
+{
+ {%EXTERNAL_LABELS%}
+}
View
1,001 Zend/zend_vm_gen.php
@@ -0,0 +1,1001 @@
+<?php
+/*
+ This script creates zend_vm_execute.h and zend_vm_opcodes.h
+ from existing zend_vm_def.h and zend_vm_execute.skl
+*/
+
+error_reporting(E_ALL);
+
+define("ZEND_VM_KIND_CALL", 1);
+define("ZEND_VM_KIND_SWITCH", 2);
+define("ZEND_VM_KIND_GOTO", 3);
+
+$op_types = array(
+ "ANY",
+ "CONST",
+ "TMP",
+ "VAR",
+ "UNUSED",
+ "CV"
+);
+
+$prefix = array(
+ "ANY" => "",
+ "TMP" => "_TMP",
+ "VAR" => "_VAR",
+ "CONST" => "_CONST",
+ "UNUSED" => "_UNUSED",
+ "CV" => "_CV",
+);
+
+$typecode = array(
+ "ANY" => 0,
+ "TMP" => 1,
+ "VAR" => 2,
+ "CONST" => 0,
+ "UNUSED" => 3,
+ "CV" => 4,
+);
+
+$op1_type = array(
+ "ANY" => "opline->op1.op_type",
+ "TMP" => "IS_TMP_VAR",
+ "VAR" => "IS_VAR",
+ "CONST" => "IS_CONST",
+ "UNUSED" => "IS_UNUSED",
+ "CV" => "IS_CV",
+);
+
+$op2_type = array(
+ "ANY" => "opline->op2.op_type",
+ "TMP" => "IS_TMP_VAR",
+ "VAR" => "IS_VAR",
+ "CONST" => "IS_CONST",
+ "UNUSED" => "IS_UNUSED",
+ "CV" => "IS_CV",
+);
+
+$op1_get_zval_ptr = array(
+ "ANY" => "get_zval_ptr(&opline->op1, EX(Ts), &free_op1, \\1)",
+ "TMP" => "_get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "VAR" => "_get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "CONST" => "_get_zval_ptr_const(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "UNUSED" => "_get_zval_ptr_unused(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "CV" => "_get_zval_ptr_cv(&opline->op1, EX(Ts), &free_op1, \\1 TSRMLS_CC)",
+);
+
+$op2_get_zval_ptr = array(
+ "ANY" => "get_zval_ptr(&opline->op2, EX(Ts), &free_op2, \\1)",
+ "TMP" => "_get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "VAR" => "_get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "CONST" => "_get_zval_ptr_const(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "UNUSED" => "_get_zval_ptr_unused(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "CV" => "_get_zval_ptr_cv(&opline->op2, EX(Ts), &free_op2, \\1 TSRMLS_CC)",
+);
+
+$op1_get_zval_ptr_ptr = array(
+ "ANY" => "get_zval_ptr_ptr(&opline->op1, EX(Ts), &free_op1, \\1)",
+ "TMP" => "_get_zval_ptr_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "VAR" => "_get_zval_ptr_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "CONST" => "_get_zval_ptr_ptr_const(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "UNUSED" => "_get_zval_ptr_ptr_unused(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "CV" => "_get_zval_ptr_ptr_cv(&opline->op1, EX(Ts), &free_op1, \\1 TSRMLS_CC)",
+);
+
+$op2_get_zval_ptr_ptr = array(
+ "ANY" => "get_zval_ptr_ptr(&opline->op2, EX(Ts), &free_op2, \\1)",
+ "TMP" => "_get_zval_ptr_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "VAR" => "_get_zval_ptr_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "CONST" => "_get_zval_ptr_ptr_const(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "UNUSED" => "_get_zval_ptr_ptr_unused(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "CV" => "_get_zval_ptr_ptr_cv(&opline->op2, EX(Ts), &free_op2, \\1 TSRMLS_CC)",
+);
+
+$op1_get_obj_zval_ptr = array(
+ "ANY" => "get_obj_zval_ptr(&opline->op1, EX(Ts), &free_op1, \\1)",
+ "TMP" => "_get_obj_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "VAR" => "_get_obj_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "CONST" => "_get_obj_zval_ptr_const(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "UNUSED" => "_get_obj_zval_ptr_unused(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "CV" => "_get_obj_zval_ptr_cv(&opline->op1, EX(Ts), &free_op1, \\1 TSRMLS_CC)",
+);
+
+$op2_get_obj_zval_ptr = array(
+ "ANY" => "get_obj_zval_ptr(&opline->op2, EX(Ts), &free_op2, \\1)",
+ "TMP" => "_get_obj_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "VAR" => "_get_obj_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "CONST" => "_get_obj_zval_ptr_const(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "UNUSED" => "_get_obj_zval_ptr_unused(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "CV" => "_get_obj_zval_ptr_cv(&opline->op2, EX(Ts), &free_op2, \\1 TSRMLS_CC)",
+);
+
+$op1_get_obj_zval_ptr_ptr = array(
+ "ANY" => "get_obj_zval_ptr_ptr(&opline->op1, EX(Ts), &free_op1, \\1)",
+ "TMP" => "_get_obj_zval_ptr_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "VAR" => "_get_obj_zval_ptr_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "CONST" => "_get_obj_zval_ptr_ptr_const(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "UNUSED" => "_get_obj_zval_ptr_ptr_unused(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC)",
+ "CV" => "_get_obj_zval_ptr_ptr_cv(&opline->op1, EX(Ts), &free_op1, \\1 TSRMLS_CC)",
+);
+
+$op2_get_obj_zval_ptr_ptr = array(
+ "ANY" => "get_obj_zval_ptr_ptr(&opline->op2, EX(Ts), &free_op2, \\1)",
+ "TMP" => "_get_obj_zval_ptr_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "VAR" => "_get_obj_zval_ptr_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "CONST" => "_get_obj_zval_ptr_ptr_const(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "UNUSED" => "_get_obj_zval_ptr_ptr_unused(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC)",
+ "CV" => "_get_obj_zval_ptr_ptr_cv(&opline->op2, EX(Ts), &free_op2, \\1 TSRMLS_CC)",
+);
+
+$op1_is_tmp_free = array(
+ "ANY" => "IS_TMP_FREE(free_op1)",
+ "TMP" => "1",
+ "VAR" => "0",
+ "CONST" => "0",
+ "UNUSED" => "0",
+ "CV" => "0",
+);
+
+$op2_is_tmp_free = array(
+ "ANY" => "IS_TMP_FREE(free_op2)",
+ "TMP" => "1",
+ "VAR" => "0",
+ "CONST" => "0",
+ "UNUSED" => "0",
+ "CV" => "0",
+);
+
+$op1_free_op = array(
+ "ANY" => "FREE_OP(free_op1)",
+ "TMP" => "zval_dtor(free_op1.var)",
+ "VAR" => "if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}",
+ "CONST" => "",
+ "UNUSED" => "",
+ "CV" => "",
+);
+
+$op2_free_op = array(
+ "ANY" => "FREE_OP(free_op2)",
+ "TMP" => "zval_dtor(free_op2.var)",
+ "VAR" => "if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}",
+ "CONST" => "",
+ "UNUSED" => "",
+ "CV" => "",
+);
+
+$op1_free_op_if_var = array(
+ "ANY" => "FREE_OP_IF_VAR(free_op1)",
+ "TMP" => "",
+ "VAR" => "if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}",
+ "CONST" => "",
+ "UNUSED" => "",
+ "CV" => "",
+);
+
+$op2_free_op_if_var = array(
+ "ANY" => "FREE_OP_IF_VAR(free_op2)",
+ "TMP" => "",
+ "VAR" => "if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}",
+ "CONST" => "",
+ "UNUSED" => "",
+ "CV" => "",
+);
+
+$op1_free_op_var_ptr = array(
+ "ANY" => "if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}",
+ "TMP" => "",
+ "VAR" => "if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}",
+ "CONST" => "",
+ "UNUSED" => "",
+ "CV" => "",
+);
+
+$op2_free_op_var_ptr = array(
+ "ANY" => "if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}",
+ "TMP" => "",
+ "VAR" => "if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}",
+ "CONST" => "",
+ "UNUSED" => "",
+ "CV" => "",
+);
+
+$list = array(); // list of opcode handlers and helpers in original order
+$opcodes = array(); // opcode handlers by code
+$helpers = array(); // opcode helpers by name
+$params = array(); // parameters of helpers
+$opnames = array(); // opcode name to code mapping
+$line_no = 1;
+
+// Writes $s into resulting executor
+function out($f, $s) {
+ global $line_no;
+ fputs($f,$s);
+ $line_no += substr_count($s, "\n");
+}
+
+// Resets #line directives in resulting executor
+function out_line($f) {
+ global $line_no, $executor_file;
+ fputs($f,"#line ".($line_no+1)." \"".$executor_file."\"\n");
+ ++$line_no;
+}
+
+// Returns name of specialized helper
+function helper_name($name, $spec, $op1, $op2) {
+ global $prefix, $helpers;
+
+ if (isset($helpers[$name])) {
+ // If we haven't helper with specified spicialized operands then
+ // using unspecialized helper
+ if (!isset($helpers[$name]["op1"][$op1]) &&
+ isset($helpers[$name]["op1"]["ANY"])) {
+ $op1 = "ANY";
+ }
+ if (!isset($helpers[$name]["op2"][$op2]) &&
+ isset($helpers[$name]["op2"]["ANY"])) {
+ $op2 = "ANY";
+ }
+ }
+ return $name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2];
+}
+
+// Generates code for opcode handler or helper
+function gen_code($f, $spec, $kind, $code, $op1, $op2) {
+ global $op1_type, $op2_type, $op1_get_zval_ptr, $op2_get_zval_ptr,
+ $op1_get_zval_ptr_ptr, $op2_get_zval_ptr_ptr,
+ $op1_get_obj_zval_ptr, $op2_get_obj_zval_ptr,
+ $op1_get_obj_zval_ptr_ptr, $op2_get_obj_zval_ptr_ptr,
+ $op1_is_tmp_free, $op2_is_tmp_free,
+ $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;
+
+ // Specializing
+ $code = preg_replace(
+ array(
+ "/OP1_TYPE/",
+ "/OP2_TYPE/",
+ "/GET_OP1_ZVAL_PTR\(([^)]*)\)/",
+ "/GET_OP2_ZVAL_PTR\(([^)]*)\)/",
+ "/GET_OP1_ZVAL_PTR_PTR\(([^)]*)\)/",
+ "/GET_OP2_ZVAL_PTR_PTR\(([^)]*)\)/",
+ "/GET_OP1_OBJ_ZVAL_PTR\(([^)]*)\)/",
+ "/GET_OP2_OBJ_ZVAL_PTR\(([^)]*)\)/",
+ "/GET_OP1_OBJ_ZVAL_PTR_PTR\(([^)]*)\)/",
+ "/GET_OP2_OBJ_ZVAL_PTR_PTR\(([^)]*)\)/",
+ "/IS_OP1_TMP_FREE\(\)/",
+ "/IS_OP2_TMP_FREE\(\)/",
+ "/FREE_OP1\(\)/",
+ "/FREE_OP2\(\)/",
+ "/FREE_OP1_IF_VAR\(\)/",
+ "/FREE_OP2_IF_VAR\(\)/",
+ "/FREE_OP1_VAR_PTR\(\)/",
+ "/FREE_OP2_VAR_PTR\(\)/",
+ "/^#ifdef\s+ZEND_VM_SPEC\s*\n/m",
+ "/^#ifndef\s+ZEND_VM_SPEC\s*\n/m",
+ "/ZEND_VM_C_LABEL\(\s*([A-Za-z_]*)\s*\)/m",
+ "/ZEND_VM_C_GOTO\(\s*([A-Za-z_]*)\s*\)/m",
+ ),
+ array(
+ $op1_type[$op1],
+ $op2_type[$op2],
+ $op1_get_zval_ptr[$op1],
+ $op2_get_zval_ptr[$op2],
+ $op1_get_zval_ptr_ptr[$op1],
+ $op2_get_zval_ptr_ptr[$op2],
+ $op1_get_obj_zval_ptr[$op1],
+ $op2_get_obj_zval_ptr[$op2],
+ $op1_get_obj_zval_ptr_ptr[$op1],
+ $op2_get_obj_zval_ptr_ptr[$op2],
+ $op1_is_tmp_free[$op1],
+ $op2_is_tmp_free[$op2],
+ $op1_free_op[$op1],
+ $op2_free_op[$op2],
+ $op1_free_op_if_var[$op1],
+ $op2_free_op_if_var[$op2],
+ $op1_free_op_var_ptr[$op1],
+ $op2_free_op_var_ptr[$op2],
+ ($op1!="ANY"||$op2!="ANY")?"#if 1\n":"#if 0\n",
+ ($op1!="ANY"||$op2!="ANY")?"#if 0\n":"#if 1\n",
+ "\\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]):""),
+ ),
+ $code);
+
+ // Updating code according to selected threading model
+ switch($kind) {
+ case ZEND_VM_KIND_CALL:
+ $code = preg_replace(
+ array(
+ "/EXECUTE_DATA/m",
+ "/ZEND_VM_DISPATCH_TO_HANDLER\(\s*([A-Z_]*)\s*\)/m",
+ "/ZEND_VM_DISPATCH_TO_HELPER\(\s*([A-Za-z_]*)\s*\)/me",
+ "/ZEND_VM_DISPATCH_TO_HELPER_EX\(\s*([A-Za-z_]*)\s*,\s*[A-Za-z_]*\s*,\s*(.*)\s*\);/me",
+ ),
+ array(
+ "execute_data",
+ "return \\1".($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2]."_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)",
+ "'return '.helper_name('\\1',$spec,'$op1','$op2').'(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)'",
+ "'return '.helper_name('\\1',$spec,'$op1','$op2').'(\\2, ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);'",
+ ),
+ $code);
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ $code = preg_replace(
+ array(
+ "/EXECUTE_DATA/m",
+ "/ZEND_VM_DISPATCH_TO_HANDLER\(\s*([A-Z_]*)\s*\)/m",
+ "/ZEND_VM_DISPATCH_TO_HELPER\(\s*([A-Za-z_]*)\s*\)/me",
+ "/ZEND_VM_DISPATCH_TO_HELPER_EX\(\s*([A-Za-z_]*)\s*,\s*([A-Za-z_]*)\s*,\s*(.*)\s*\);/me",
+ ),
+ array(
+ "&execute_data",
+ "goto \\1".($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2]."_LABEL",
+ "'goto '.helper_name('\\1',$spec,'$op1','$op2')",
+ "'\\2 = \\3; goto '.helper_name('\\1',$spec,'$op1','$op2').';'",
+ ),
+ $code);
+ break;
+ case ZEND_VM_KIND_GOTO:
+ $code = preg_replace(
+ array(
+ "/EXECUTE_DATA/m",
+ "/ZEND_VM_DISPATCH_TO_HANDLER\(\s*([A-Z_]*)\s*\)/m",
+ "/ZEND_VM_DISPATCH_TO_HELPER\(\s*([A-Za-z_]*)\s*\)/me",
+ "/ZEND_VM_DISPATCH_TO_HELPER_EX\(\s*([A-Za-z_]*)\s*,\s*([A-Za-z_]*)\s*,\s*(.*)\s*\);/me",
+ ),
+ array(
+ "&execute_data",
+ "goto \\1".($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2]."_HANDLER",
+ "'goto '.helper_name('\\1',$spec,'$op1','$op2')",
+ "'\\2 = \\3; goto '.helper_name('\\1',$spec,'$op1','$op2').';'",
+ ),
+ $code);
+ break;
+ }
+
+ out($f, $code);
+}
+
+// Generates opcode handler
+function gen_handler($f, $spec, $kind, $name, $op1, $op2, $use, $code, $lineno) {
+ global $definition_file, $prefix, $typecode, $opnames;
+
+ if (ZEND_VM_LINES) {
+ out($f, "#line $lineno \"$definition_file\"\n");
+ }
+
+ // Generate opcode handler's entry point according to selected threading model
+ switch($kind) {
+ case ZEND_VM_KIND_CALL:
+ out($f,"static int ".$name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2]."_HANDLER(ZEND_OPCODE_HANDLER_ARGS)\n");
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ if ($spec) {
+ out($f,"case ".((string)($opnames[$name]*25+($typecode[$op1]*5)+$typecode[$op2])).": /*".$name."_SPEC".$prefix[$op1].$prefix[$op2]."_HANDLER*/");
+ } else {
+ out($f,"case ".$name.":");
+ }
+ if ($use) {
+ // 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");
+ } else {
+ out($f,"\n");
+ }
+ break;
+ case ZEND_VM_KIND_GOTO:
+ out($f,$name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2]."_HANDLER:\n");
+ break;
+ }
+
+ // Generate opcode handler's code
+ gen_code($f, $spec, $kind, $code, $op1, $op2);
+}
+
+// Generates helper
+function gen_helper($f, $spec, $kind, $name, $op1, $op2, $param, $code, $lineno) {
+ global $definition_file, $prefix;
+
+ if (ZEND_VM_LINES) {
+ out($f, "#line $lineno \"$definition_file\"\n");
+ }
+
+ // Generate helper's entry point according to selected threading model
+ switch($kind) {
+ case ZEND_VM_KIND_CALL:
+ if ($param == null) {
+ out($f, "static int ".$name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2]."(ZEND_OPCODE_HANDLER_ARGS)\n");
+ } else {
+ out($f, "static int ".$name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2]."(".$param.", ZEND_OPCODE_HANDLER_ARGS)\n");
+ }
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ out($f, $name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2].":\n");
+ break;
+ case ZEND_VM_KIND_GOTO:
+ out($f, $name.($spec?"_SPEC":"").$prefix[$op1].$prefix[$op2].":\n");
+ break;
+ }
+
+ // Generate helper's code
+ gen_code($f, $spec, $kind, $code, $op1, $op2);
+}
+
+// Generates array of opcode handlers (specialized or unspecialized)
+function gen_labels($f, $spec, $kind, $prolog) {
+ global $opcodes, $op_types, $prefix, $typecode;
+
+ $next = 0;
+ if ($spec) {
+ foreach($opcodes as $num => $dsc) {
+ while ($next != $num) {
+ $op1t = $op_types;
+ foreach($op1t as $op1) {
+ if ($op1 != "ANY") {
+ $op2t = $op_types;
+ foreach($op2t as $op2) {
+ if ($op2 != "ANY") {
+ switch ($kind) {
+ case ZEND_VM_KIND_CALL:
+ out($f,$prolog."ZEND_NULL_HANDLER,\n");
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ out($f,$prolog."(opcode_handler_t)-1,\n");
+ break;
+ case ZEND_VM_KIND_GOTO:
+ out($f,$prolog."(opcode_handler_t)&&ZEND_NULL_HANDLER,\n");
+ break;
+ }
+ }
+ }
+ }
+ }
+ $next++;
+ }
+ $next = $num + 1;
+ $op1t = $op_types;
+ foreach($op1t as $op1) {
+ if ($op1 != "ANY") {
+ if (!isset($dsc["op1"][$op1])) {
+ $op1 = "ANY";
+ }
+ $op2t = $op_types;
+ foreach($op2t as $op2) {
+ if ($op2 != "ANY") {
+ if (!isset($dsc["op2"][$op2])) {
+ $op2 = "ANY";
+ }
+ if (isset($dsc["op1"][$op1]) &&
+ isset($dsc["op2"][$op2])) {
+ switch ($kind) {
+ case ZEND_VM_KIND_CALL:
+ out($f,$prolog.$dsc["op"]."_SPEC".$prefix[$op1].$prefix[$op2]."_HANDLER,\n");
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ out($f,$prolog."(opcode_handler_t)".((string)($num*25+$typecode[$op1]*5+$typecode[$op2])).",\n");
+ break;
+ case ZEND_VM_KIND_GOTO:
+ out($f,$prolog."(opcode_handler_t)&&".$dsc["op"]."_SPEC".$prefix[$op1].$prefix[$op2]."_HANDLER,\n");
+ break;
+ }
+ } else {
+ switch ($kind) {
+ case ZEND_VM_KIND_CALL:
+ out($f,$prolog."ZEND_NULL_HANDLER,\n");
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ out($f,$prolog."(opcode_handler_t)-1,\n");
+ break;
+ case ZEND_VM_KIND_GOTO:
+ out($f,$prolog."(opcode_handler_t)&&ZEND_NULL_HANDLER,\n");
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ foreach($opcodes as $num => $dsc) {
+ while ($next != $num) {
+ switch ($kind) {
+ case ZEND_VM_KIND_CALL:
+ out($f,$prolog."ZEND_NULL_HANDLER,\n");
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ out($f,$prolog."(opcode_handler_t)-1,\n");
+ break;
+ case ZEND_VM_KIND_GOTO:
+ out($f,$prolog."(opcode_handler_t)&&ZEND_NULL_HANDLER,\n");
+ break;
+ }
+ $next++;
+ }
+ $next = $num+1;
+ switch ($kind) {
+ case ZEND_VM_KIND_CALL:
+ out($f,$prolog.$dsc["op"]."_HANDLER,\n");
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ out($f,$prolog."(opcode_handler_t)".((string)$num).",\n");
+ break;
+ case ZEND_VM_KIND_GOTO:
+ out($f,$prolog."(opcode_handler_t)&&".$dsc["op"]."_HANDLER,\n");
+ break;
+ }
+ }
+ }
+
+ // Last handler
+ switch ($kind) {
+ case ZEND_VM_KIND_CALL:
+ out($f,$prolog."ZEND_NULL_HANDLER\n");
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ out($f,$prolog."(opcode_handler_t)-1\n");
+ break;
+ case ZEND_VM_KIND_GOTO:
+ out($f,$prolog."(opcode_handler_t)&&ZEND_NULL_HANDLER\n");
+ break;
+ }
+}
+
+// Generates handler for undefined opcodes (CALL threading model)
+function gen_null_handler($f) {
+ static $done = 0;
+
+ if (!$done) {
+ $done = 1;
+ out($f,"static int ZEND_NULL_HANDLER(ZEND_OPCODE_HANDLER_ARGS)\n");
+ out($f,"{\n");
+ out($f,"\tzend_error_noreturn(E_ERROR, \"Invalid opcode %d/%d/%d.\", EX(opline)->opcode, EX(opline)->op1.op_type, EX(opline)->op2.op_type);\n");
+ out($f,"\tZEND_VM_RETURN_FROM_EXECUTE_LOOP();\n");
+ out($f,"}\n\n");
+ }
+}
+
+// Generates all opcode handlers and helpers (specialized or unspecilaized)
+function gen_executor_code($f, $spec, $kind, $prolog) {
+ global $list, $opcodes, $helpers, $op_types;
+
+ if ($spec) {
+ $op1t = $op_types;
+ foreach($op1t as $op1) {
+ $op2t = $op_types;
+ foreach($op2t as $op2) {
+ foreach ($list as $lineno => $dsc) {
+ if (isset($dsc["handler"])) {
+ $num = $dsc["handler"];
+ if (isset($opcodes[$num]["op1"][$op1]) &&
+ isset($opcodes[$num]["op2"][$op2])) {
+ gen_handler($f, 1, $kind, $opcodes[$num]["op"], $op1, $op2, isset($opcodes[$num]["use"]), $opcodes[$num]["code"], $lineno);
+ }
+ } else if (isset($dsc["helper"])) {
+ $num = $dsc["helper"];
+ if (isset($helpers[$num]["op1"][$op1]) &&
+ isset($helpers[$num]["op2"][$op2])) {
+ gen_helper($f, 1, $kind, $num, $op1, $op2, $helpers[$num]["param"], $helpers[$num]["code"], $lineno);
+ }
+ } else {
+ var_dump($dsc);
+ die("??? $kind:$num\n");
+ }
+ }
+ }
+ }
+ } else {
+ foreach ($list as $lineno => $dsc) {
+ if (isset($dsc["handler"])) {
+ $num = $dsc["handler"];
+ gen_handler($f, 0, $kind, $opcodes[$num]["op"], "ANY", "ANY", isset($opcodes[$num]["use"]), $opcodes[$num]["code"], $lineno);
+ } else if (isset($dsc["helper"])) {
+ $num = $dsc["helper"];
+ gen_helper($f, 0, $kind, $num, "ANY", "ANY", $helpers[$num]["param"], $helpers[$num]["code"], $lineno);
+ } else {
+ var_dump($dsc);
+ die("??? $kind:$num\n");
+ }
+ }
+ }
+ if (ZEND_VM_LINES) {
+ out_line($f);
+ }
+
+ // Generate handler for undefined opcodes
+ switch ($kind) {
+ case ZEND_VM_KIND_CALL:
+ gen_null_handler($f);
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ out($f,"default:\n");
+ out($f,"\tzend_error_noreturn(E_ERROR, \"Invalid opcode %d/%d/%d.\", EX(opline)->opcode, EX(opline)->op1.op_type, EX(opline)->op2.op_type);\n");
+ out($f,"\tZEND_VM_RETURN_FROM_EXECUTE_LOOP();\n");
+ break;
+ case ZEND_VM_KIND_GOTO:
+ out($f,"ZEND_NULL_HANDLER:\n");
+ out($f,"\tzend_error_noreturn(E_ERROR, \"Invalid opcode %d/%d/%d.\", EX(opline)->opcode, EX(opline)->op1.op_type, EX(opline)->op2.op_type);\n");
+ out($f,"\tZEND_VM_RETURN_FROM_EXECUTE_LOOP();\n");
+ break;
+ }
+}
+
+function skip_blanks($f, $prolog, $epilog) {
+ if (trim($prolog) != "" || trim($epilog) != "") {
+ out($f, $prolog.$epilog);
+ }
+}
+
+// Generates executor from skeleton file and definition (specialized or unspecialized)
+function gen_executor($f, $skl, $spec, $kind, $executor_name, $initializer_name, $old) {
+ global $params, $skeleton_file, $line_no;
+
+ $lineno = 0;
+// $old_line_no = -1;
+ foreach ($skl as $line) {
+// if (ZEND_VM_LINES) {
+// ++$lineno;
+// if ($old_line_no+1 != $line_no) {
+// out($f,"#line $lineno \"$skeleton_file\" /* $old_line_no, $line_no*/\n");
+// }
+// $old_line_no = $line_no;
+// }
+ if (preg_match("/(.*)[{][%]([A-Z_]*)[%][}](.*)/", $line, $m)) {
+ switch ($m[2]) {
+ case "DEFINES":
+ switch ($kind) {
+ case ZEND_VM_KIND_CALL:
+ out($f,"\n");
+ out($f,"#define ZEND_VM_CONTINUE() return 0\n");
+ out($f,"#define ZEND_VM_RETURN() return 1\n");
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ out($f,"\n");
+ out($f,"#define ZEND_VM_CONTINUE() goto zend_vm_continue\n");
+ out($f,"#define ZEND_VM_RETURN() return\n");
+ break;
+ case ZEND_VM_KIND_GOTO:
+ out($f,"\n");
+ out($f,"#define ZEND_VM_CONTINUE() goto *(void**)(EX(opline)->handler)\n");
+ out($f,"#define ZEND_VM_RETURN() return\n");
+ break;
+ }
+ break;
+ case "EXECUTOR_NAME":
+ out($f, $m[1].$executor_name.$m[3]."\n");
+ break;
+ case "HELPER_VARS":
+ if ($kind != ZEND_VM_KIND_CALL) {
+ foreach ($params as $param => $x) {
+ out($f,$m[1].$param.";\n");
+ }
+ } else {
+ skip_blanks($f, $m[1], $m[3]."\n");
+ }
+ break;
+ case "INTERANL_LABELS":
+ if ($kind == ZEND_VM_KIND_GOTO) {
+ $prolog = $m[1];
+ out($f,$prolog."if (op_array == NULL) {\n");
+ out($f,$prolog."\tstatic const opcode_handler_t labels[] = {\n");
+ gen_labels($f, $spec, $kind, $prolog."\t\t");
+ out($f,$prolog."\t};\n");
+ out($f,$prolog."\tzend_opcode_handlers = (opcode_handler_t*)labels;\n");
+ out($f,$prolog."\treturn;\n");
+ out($f,$prolog."}\n");
+ } else {
+ skip_blanks($f, $m[1], $m[3]);
+ }
+ break;
+ case "ZEND_VM_CONTINUE_LABEL":
+ if ($kind == ZEND_VM_KIND_SWITCH) {
+ out($f,$m[1]."zend_vm_continue:".$m[3]."\n");
+ } else {
+ skip_blanks($f, $m[1], $m[3]);
+ }
+ break;
+ case "ZEND_VM_DISPATCH":
+ switch ($kind) {
+ case ZEND_VM_KIND_CALL:
+ out($f, $m[1]."if (EX(opline)->handler(&execute_data TSRMLS_CC) > 0)".$m[3]."\n");
+ break;
+ case ZEND_VM_KIND_SWITCH:
+ out($f, $m[1]."switch ((int)EX(opline)->handler)".$m[3]."\n");
+ break;
+ case ZEND_VM_KIND_GOTO:
+ out($f, $m[1]."goto *(void**)(EX(opline)->handler);".$m[3]."\n");
+ break;
+ }
+ break;
+ case "INTERNAL_EXECUTOR":
+ if ($kind == ZEND_VM_KIND_CALL) {
+ out($f, $m[1]."return;".$m[3]."\n");
+ } else {
+ gen_executor_code($f, $spec, $kind, $m[1]);
+ }
+ break;
+ case "EXTERNAL_EXECUTOR":
+ if ($kind == ZEND_VM_KIND_CALL) {
+ if (!$old || ZEND_VM_SPEC || (ZEND_VM_KIND != ZEND_VM_KIND_CALL)) {
+ out($f,"#undef EX\n");
+ out($f,"#define EX(element) execute_data->element\n\n");
+ gen_executor_code($f, $spec, $kind, $m[1]);
+ }
+ }
+ break;
+ case "INITIALIZER_NAME":
+ out($f, $m[1].$initializer_name.$m[3]."\n");
+ break;
+ case "EXTERNAL_LABELS":
+ $prolog = $m[1];
+ if ($kind == ZEND_VM_KIND_GOTO) {
+ out($f,$prolog."TSRMLS_FETCH();\n");
+ out($f,$prolog."zend_execute(NULL TSRMLS_CC);\n");
+ } else {
+ if ($old) {
+ out($f,$prolog."static opcode_handler_t labels[512] = {\n");
+ } else {
+ out($f,$prolog."static const opcode_handler_t labels[] = {\n");
+ }
+ gen_labels($f, $spec, $kind, $prolog."\t");
+ out($f,$prolog."};\n");
+ out($f,$prolog."zend_opcode_handlers = (opcode_handler_t*)labels;\n");
+ if ($old) {
+ out($f,$prolog."zend_vm_old_executor = 1;\n");
+ out($f,$prolog."zend_execute = old_execute;\n");
+ }
+ }
+ break;
+ default:
+ die("ERROR: Unknown keyword ".$m[2]." in skeleton file.\n");
+ }
+ } else {
+ out($f, $line);
+ }
+ }
+}
+
+function gen_vm($def, $skel) {
+ global $definition_file, $skeleton_file, $executor_file,
+ $op_types, $list, $opcodes, $helpers, $params, $opnames;
+
+ // Load definition file
+ $in = @file($def);
+ if (!$in) {
+ die("ERROR: Can not open definition file '$def'\n");
+ }
+ $definition_file = realpath($def);
+
+ // Load skeleton file
+ $skl = @file($skel);
+ if (!$skl) {
+ die("ERROR: Can not open skeleton file '$skel'\n");
+ }
+ $skeleton_file = realpath($skel);
+
+ // Parse definition file into tree
+ $lineno = 0;
+ $handler = null;
+ $helper = null;
+ $max_opcode_len = 0;
+ $max_opcode = 0;
+ foreach ($in as $line) {
+ ++$lineno;
+ if (strpos($line,"ZEND_VM_HANDLER(") === 0) {
+ if (preg_match(
+ "/^ZEND_VM_HANDLER\(\s*([0-9]+)\s*,\s*([A-Z_]+)\s*,\s*([A-Z|]+)\s*,\s*([A-Z|]+)\s*\)/",
+ $line,
+ $m) == 0) {
+ die("ERROR ($def:$lineno): Invalid ZEND_VM_HANDLER definition.\n");
+ }
+ $code = (int)$m[1];
+ $op = $m[2];
+ $len = strlen($op);
+ $op1 = array_flip(explode("|",$m[3]));
+ $op2 = array_flip(explode("|",$m[4]));
+
+ if ($len > $max_opcode_len) {
+ $max_opcode_len = $len;
+ }
+ if ($code > $max_opcode) {
+ $max_opcode = $code;
+ }
+ if (isset($opcodes[$code])) {
+ die("ERROR ($def:$lineno): Opcode with code '$code' is already defined.\n");
+ }
+ if (isset($opnames[$op])) {
+ die("ERROR ($def:$lineno): Opcode with name '$op' is already defined.\n");
+ }
+ $opcodes[$code] = array("op"=>$op,"op1"=>$op1,"op2"=>$op2,"code"=>"");
+ $opnames[$op] = $code;
+ $handler = $code;
+ $helper = null;
+ $list[$lineno] = array("handler"=>$handler);
+ } else if (strpos($line,"ZEND_VM_HELPER(") === 0) {
+ if (preg_match(
+ "/^ZEND_VM_HELPER\(\s*([A-Za-z_]+)\s*,\s*([A-Z|]+)\s*,\s*([A-Z|]+)\s*\)/",
+ $line,
+ $m) == 0) {
+ die("ERROR ($def:$lineno): Invalid ZEND_VM_HELPER definition.\n");
+ }
+ $helper = $m[1];
+ $op1 = array_flip(explode("|",$m[2]));
+ $op2 = array_flip(explode("|",$m[3]));
+ if (isset($helpers[$helper])) {
+ die("ERROR ($def:$lineno): Helper with name '$helper' is already defined.\n");
+ }
+ $helpers[$helper] = array("op1"=>$op1,"op2"=>$op2,"param"=>null,"code"=>"");
+ $handler = null;
+ $list[$lineno] = array("helper"=>$helper);
+ } else if (strpos($line,"ZEND_VM_HELPER_EX(") === 0) {
+ if (preg_match(
+ "/^ZEND_VM_HELPER_EX\(\s*([A-Za-z_]+)\s*,\s*([A-Z|]+)\s*,\s*([A-Z|]+)\s*,\s*(.*)\s*\)/",
+ $line,
+ $m) == 0) {
+ die("ERROR ($def:$lineno): Invalid ZEND_VM_HELPER definition.\n");
+ }
+ $helper = $m[1];
+ $op1 = array_flip(explode("|",$m[2]));
+ $op2 = array_flip(explode("|",$m[3]));
+ $param = $m[4];
+ if (isset($helpers[$helper])) {
+ die("ERROR ($def:$lineno): Helper with name '$helper' is already defined.\n");
+ }
+ $params[$param] = 1;
+
+ $helpers[$helper] = array("op1"=>$op1,"op2"=>$op2,"param"=>$param,"code"=>"");
+ $handler = null;
+ $list[$lineno] = array("helper"=>$helper);
+ } else if ($handler !== null) {
+ $opcodes[$handler]["code"] .= $line;
+ } else if ($helper !== null) {
+ $helpers[$helper]["code"] .= $line;
+ }
+ }
+
+ ksort($opcodes);
+
+ // Search for opcode handlers those are used by other opcode handlers
+ foreach ($opcodes as $dsc) {
+ if (preg_match("/ZEND_VM_DISPATCH_TO_HANDLER\(\s*([A-Z_]*)\s*\)/m", $dsc["code"], $m)) {
+ $op = $m[1];
+ if (!isset($opnames[$op])) {
+ die("ERROR ($def:$lineno): Opcode with name '$op' is not defined.\n");
+ }
+ $code = $opnames[$op];
+ $opcodes[$code]['use'] = 1;
+ }
+ }
+
+ // Generate opcode #defines (zend_vm_opcodes.h)
+ $code_len = strlen((string)$max_opcode);
+ $f = fopen("zend_vm_opcodes.h", "w+") or die("ERROR: Cannot create zend_vm_opcodes.h\n");
+ ksort($opcodes);
+ foreach ($opcodes as $code => $dsc) {
+ $code = str_pad((string)$code,$code_len," ",STR_PAD_LEFT);
+ $op = str_pad($dsc["op"],$max_opcode_len);
+ fputs($f,"#define $op $code\n");
+ }
+ fclose($f);
+ echo "zend_vm_opcodes.h generated succesfull.\n";
+
+ // Generate zend_vm_execute.h
+ $f = fopen("zend_vm_execute.h", "w+") or die("ERROR: Cannot create zend_vm_execute.h\n");
+ $executor_file = realpath("zend_vm_execute.h");
+
+ // Generate specialized executor
+ gen_executor($f, $skl, ZEND_VM_SPEC, ZEND_VM_KIND, "execute", "zend_init_opcodes_handlers", 0);
+
+ // Generate un-specialized executor
+ if (ZEND_VM_OLD_EXECUTOR) {
+ out($f,"\n/* Old executor */\n\n");
+ out($f,"#undef EX\n");
+ out($f,"#define EX(element) execute_data.element\n\n");
+ out($f,"#undef ZEND_VM_CONTINUE\n\n");
+ out($f,"#undef ZEND_VM_RETURN\n\n");
+ gen_executor($f, $skl, 0, ZEND_VM_KIND_CALL, "old_execute", "zend_vm_use_old_executor", 1);
+ }
+
+ // Generate zend_vm_set_opcode_handler() function
+ out($f, "void zend_vm_set_opcode_handler(zend_op* op)\n");
+ out($f, "{\n");
+ if (!ZEND_VM_SPEC) {
+ out($f, "\top->handler = zend_opcode_handlers[op->opcode];\n");
+ } else {
+ if (ZEND_VM_OLD_EXECUTOR) {
+ out($f, "\tif (zend_vm_old_executor) {\n");
+ out($f, "\t\top->handler = zend_opcode_handlers[op->opcode];\n");
+ out($f, "\t} else {\n");
+ }
+ out($f, "\t\tstatic const int zend_vm_decode[] = {\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 0 */\n");
+ out($f, "\t\t\t_CONST_CODE, /* 1 = IS_CONST */\n");
+ out($f, "\t\t\t_TMP_CODE, /* 2 = IS_TMP_VAR */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 3 */\n");
+ out($f, "\t\t\t_VAR_CODE, /* 4 = IS_VAR */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 5 */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 6 */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 7 */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 8 = IS_UNUSED */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 9 */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 10 */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 11 */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 12 */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 13 */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 14 */\n");
+ out($f, "\t\t\t_UNUSED_CODE, /* 15 */\n");
+ out($f, "\t\t\t_CV_CODE /* 16 = IS_CV */\n");
+ out($f, "\t\t};\n");
+ out($f, "\t\top->handler = zend_opcode_handlers[op->opcode * 25 + zend_vm_decode[op->op1.op_type] * 5 + zend_vm_decode[op->op2.op_type]];\n");
+ if (ZEND_VM_OLD_EXECUTOR) {
+ out($f, "\t}\n");
+ }
+ }
+ out($f, "}\n\n");
+
+ fclose($f);
+ echo "zend_vm_execute.h generated succesfull.\n";
+}
+
+function usage() {
+ echo("\nUsage: php zend_vm_gen.php [options]\n".
+ "\nOptions:".
+ "\n --with-vm-kind=CALL|SWITCH|GOTO - select threading model (default is CALL)".
+ "\n --without-specializer - disable executor specialization".
+ "\n --without-old-executor - disable old executor".
+ "\n --without-lines - disable #line directives".
+ "\n\n");
+
+}
+
+// Parse arguments
+for ($i = 1; $i < $argc; $i++) {
+ if (strpos($argv[$i],"--with-vm-kind=") === 0) {
+ $kind = substr($argv[$i], strlen("--with-vm-kind="));
+ switch ($kind) {
+ case "CALL":
+ define("ZEND_VM_KIND", ZEND_VM_KIND_CALL);
+ break;
+ case "SWITCH":
+ define("ZEND_VM_KIND", ZEND_VM_KIND_SWITCH);
+ break;
+ case "GOTO":
+ define("ZEND_VM_KIND", ZEND_VM_KIND_GOTO);
+ break;
+ default:
+ echo("ERROR: Invalid vm kind '$kind'\n");
+ usage();
+ die();
+ }
+ } else if ($argv[$i] == "--without-specializer") {
+ define("ZEND_VM_SPEC", 0);
+ } else if ($argv[$i] == "--without-old-executor") {
+ define("ZEND_VM_OLD_EXECUTOR", 0);
+ } else if ($argv[$i] == "--without-lines") {
+ define("ZEND_VM_LINES", 0);
+ } else if ($argv[$i] == "--help") {
+ usage();
+ exit();
+ } else {
+ echo("ERROR: Invalid option '".$argv[$i]."'\n");
+ usage();
+ die();
+ }
+}
+
+// Using defaults
+if (!defined("ZEND_VM_KIND")) {
+ define("ZEND_VM_KIND", ZEND_VM_KIND_CALL);
+}
+if (!defined("ZEND_VM_SPEC")) {
+ define("ZEND_VM_SPEC", 1);
+}
+if (!defined("ZEND_VM_OLD_EXECUTOR")) {
+ define("ZEND_VM_OLD_EXECUTOR", 1);
+}
+if (!defined("ZEND_VM_LINES")) {
+ define("ZEND_VM_LINES", 1);
+}
+
+gen_vm("zend_vm_def.h", "zend_vm_execute.skl");
+
+?>

0 comments on commit e50a6fd

Please sign in to comment.