PHP Intermediate Code opcode

Source: Internet
Author: User

The lexical analysis and grammatical analysis of PHP are mostly handled by Flex/bison.

When parsing is complete, the Zend engine generates intermediate code (which can be omitted by using Opcache) opcode,php is built on Zend virtual machines (Zend VMs). PHP opcode is the instruction in the Zend virtual machine.

Inside the PHP implementation, opcode is represented by the following structure:
struct _ZEND_OP {
opcode_handler_t handler; handler function to invoke when executing the opcode
Znode result;
Znode OP1;
Znode OP2;
ULONG Extended_value;
UINT Lineno;
Zend_uchar opcode; OpCode code
};

It is known that the so-called opcode is the Zend of a fictional C structure with a set of instructions (about more than 130)

For example, the following code is a function that compiles when the compiler encounters a print statement:
void Zend_do_print (Znode *result,const znode *arg tsrmls_dc)
{
Zend_op *opline = Get_next_op (CG (Active_op_array) tsrmls_cc);
Opline->result.op_type = Is_tmp_var;
Opline->result.u.var = get_temporary_variable (CG (Active_op_array));
Opline->opcode = Zend_print;
OPLINE->OP1 = *arg;
Set_unused (OPLINE->OP2);
*result = opline->result;
}
This function creates a new ZEND_OP, sets the type of the return value to a temporary variable (Is_tmp_var), and applies for the temporary variable
Space, then specifies opcode as Zend_print, and assigns the passed in parameter to the first operand of the opcode. Such
At the end of this opcode, the Zend engine can get enough information to output the content. (Essentially, Zend parses the print statement by Zend_do_print function to generate the intermediate code opcode)

The opcode is stored in the op_array structure and executed opcode code in the order of the Execute function.

PHP Intermediate Code opcode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.