저장용

    7.0.12 기준

    #define AG(v) (alloc_globals.v)
    #define BG(v) (basic_globals.v)
    #define CG(v) (compiler_globals.v)
    #define EG(v) (executor_globals.v)
    #define FG(v) (file_globals.v)
    #define OG(v) (output_globals.v)
    #define PG(v) (core_globals.v)
    #define SG(v) (sapi_globals.v)
    #define EX(element) ((execute_data)->element)
    #define FC(member) (CG(file_context).member)
    #define SCNG LANG_SCNG
    #define LANG_SCNG language_scanner_globals
    
    int main(int argc, char *argv[]);
    // sapi/fpm/fpm/fpm_main.c
    	PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle);
    	// &file_handle
    	// main/fopen_wrappers.c
    	PHPAPI int php_execute_script(zend_file_handle *primary_file);
    	// &file_handle
    	// main/main.c
    		int zend_startup(zend_utility_functions *utility_functions, char **extensions);
    		// &zuf, NULL
    		// Zend/zend.c
    		ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...);
    		// ZEND_REQUIRE, NULL, 3, prepend_file_p, primary_file, append_file_p
    		// Zend/zend.c
    			ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type);
    			ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type);
    			// file_handle, type
    			// Zend/zend_compile.c
    			// Zend/zend_language_scanner.c
    				ZEND_API int open_file_for_scanning(zend_file_handle *file_handle);
    				// file_handle
    				// Zend/zend_language_scanner.c
    					ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t *len);
    					// file_handle, &buf, &size
    					// Zend/zend_stream.c
    					ZEND_API void zend_llist_add_element(zend_llist *l, void *element);
    					// &CG(open_files), file_handle
    					// Zend/zend_llist.c
    					ZEND_API int zend_multibyte_set_filter(const zend_encoding *onetime_encoding);
    					// NULL
    					// Zend/zend_language_scanner.c
    					static void yy_scan_buffer(char *str, unsigned int len);
    					// buf, (unsigned int)size
    					// Zend/zend_language_scanner.c
    				int zendparse();
    				// Zend/zend_language_parser.c
    				void init_op_array(zend_op_array *op_array, zend_uchar type, int initial_ops_size);
    				// op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE
    				// Zend/zend_opcode.c
    				ZEND_API int pass_two(zend_op_array *op_array);
    				// op_array
    				// Zend/zend_opcode.c
    			ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle);
    			// file_handle
    			// Zend/zend_language_scanner.c
    			ZEND_API void zend_execute(zend_op_array *op_array, zval *return_value);
    			// op_array, retval
    			// Zend/zend_vm_execute.h
    				static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame(uint32_t call_info, zend_function *func, uint32_t num_args, zend_class_entry *called_scope, zend_object *object);
    				// call_info, fbc, opline->extended_value, called_scope, object
    				// Zend/zend_execute.h
    					static zend_always_inline zend_execute_data *zend_vm_stack_push_call_frame_ex(uint32_t used_stack, uint32_t call_info, zend_function *func, uint32_t num_args, zend_class_entry *called_scope, zend_object *object);
    					// used_stack, call_info, func, num_args, called_scope, object
    					// Zend/zend_execute.h
    				static zend_always_inline void i_init_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value);
    				// execute_data, op_array, return_value
    				// Zend/zend_execute.c
    				ZEND_API void (*zend_execute_ex)(zend_execute_data *execute_data);
    				ZEND_API void execute_ex(zend_execute_data *ex);
    				// execute_data
    				// Zend/zend_execute.h
    				// Zend/zend_vm_execute.h
    				static zend_always_inline void zend_vm_stack_free_call_frame(zend_execute_data *call);
    				// execute_data
    				// Zend/zend_execute.h
    					static zend_always_inline void zend_vm_stack_free_call_frame_ex(uint32_t call_info, zend_execute_data *call);
    					// ZEND_CALL_INFO(call), call
    					// Zend/zend_execute.h
    			ZEND_API void destroy_op_array(zend_op_array *op_array);
    			// op_array
    			// Zend/zend_opcode.c

    zendparse()는 php 코드의 파싱 역할,

    pass_two(), 그리고 위에는 안적었지만 pass_two()와 같이 쓰는 함수들은 바이트코드로 컴파일하는 역할로 보인다.

    이 두가지가 compile_file()에서 처리된다.


    그러고 나서 zend_execute()를 통해 바이트코드를 실행한다고 생각된다.


    자세한 작동 원리는 더 알아봐야된다.

    Posted by 코요

티스토리 툴바