CN118672588A - Intelligent contract compiling method, system, electronic equipment and object code running method - Google Patents
Intelligent contract compiling method, system, electronic equipment and object code running method Download PDFInfo
- Publication number
- CN118672588A CN118672588A CN202410637556.5A CN202410637556A CN118672588A CN 118672588 A CN118672588 A CN 118672588A CN 202410637556 A CN202410637556 A CN 202410637556A CN 118672588 A CN118672588 A CN 118672588A
- Authority
- CN
- China
- Prior art keywords
- compiling
- register
- stack
- intermediate code
- configuration information
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 160
- 230000006870 function Effects 0.000 claims description 109
- 238000005457 optimization Methods 0.000 claims description 20
- 230000002688 persistence Effects 0.000 claims 3
- 230000002085 persistent effect Effects 0.000 description 19
- 230000008569 process Effects 0.000 description 19
- 238000010586 diagram Methods 0.000 description 10
- 238000006243 chemical reaction Methods 0.000 description 8
- 238000004458 analytical method Methods 0.000 description 7
- 238000004590 computer program Methods 0.000 description 7
- 238000012545 processing Methods 0.000 description 7
- 238000004364 calculation method Methods 0.000 description 4
- 238000005516 engineering process Methods 0.000 description 4
- 230000014509 gene expression Effects 0.000 description 4
- 230000003287 optical effect Effects 0.000 description 4
- 101001121408 Homo sapiens L-amino-acid oxidase Proteins 0.000 description 3
- 102100026388 L-amino-acid oxidase Human genes 0.000 description 3
- 101100233916 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) KAR5 gene Proteins 0.000 description 3
- 238000007689 inspection Methods 0.000 description 3
- 238000007726 management method Methods 0.000 description 3
- 238000012552 review Methods 0.000 description 3
- 101000827703 Homo sapiens Polyphosphoinositide phosphatase Proteins 0.000 description 2
- 102100023591 Polyphosphoinositide phosphatase Human genes 0.000 description 2
- 101100012902 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) FIG2 gene Proteins 0.000 description 2
- 238000013461 design Methods 0.000 description 2
- 230000008030 elimination Effects 0.000 description 2
- 238000003379 elimination reaction Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 238000000638 solvent extraction Methods 0.000 description 2
- 230000003068 static effect Effects 0.000 description 2
- 230000008859 change Effects 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 230000008878 coupling Effects 0.000 description 1
- 238000010168 coupling process Methods 0.000 description 1
- 238000005859 coupling reaction Methods 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000012217 deletion Methods 0.000 description 1
- 230000037430 deletion Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 239000012634 fragment Substances 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 238000003672 processing method Methods 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 239000000126 substance Substances 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/44—Encoding
- G06F8/441—Register allocation; Assignment of physical memory space to logical memory space
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/44—Encoding
- G06F8/447—Target code generation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/30098—Register arrangements
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44505—Configuring for program initiating, e.g. using registry, configuration files
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44557—Code layout in executable memory
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45504—Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
Description
技术领域Technical Field
本公开涉及计算机技术领域,特别涉及一种智能合约编译方法、系统、电子设备和目标代码运行方法。The present disclosure relates to the field of computer technology, and in particular to a smart contract compilation method, system, electronic device, and target code running method.
背景技术Background Art
随着区块链技术的迅速发展,基于区块链的智能合约应用成为趋势。为了提升智能合约执行效率且支持跨平台执行,相关技术中提出了一种将基于栈的虚拟机集成在目标平台并利用基于栈的虚拟机来执行智能合约的方案;其中,鉴于虚拟机没有物理寄存器,故需要编译器将智能合约编译为不依靠寄存器且基于栈的虚拟机能够理解和执行的指令序列(例如,对栈进行压栈PUSH、弹栈POP等操作的指令),虚拟机在逐条执行这些指令时,会按照指令集中的定义对栈进行操作,从而完成智能合约的功能。然而,在实际应用中发现,这种处理方式下智能合约的执行性能偏低,且无法满足支持编译复杂逻辑的合约代码。With the rapid development of blockchain technology, blockchain-based smart contract applications have become a trend. In order to improve the efficiency of smart contract execution and support cross-platform execution, the relevant technology proposes a solution to integrate a stack-based virtual machine into the target platform and use the stack-based virtual machine to execute smart contracts; among them, since the virtual machine has no physical registers, the compiler is required to compile the smart contract into an instruction sequence that does not rely on registers and can be understood and executed by the stack-based virtual machine (for example, instructions for PUSH and POP operations on the stack). When the virtual machine executes these instructions one by one, it will operate the stack according to the definition in the instruction set, thereby completing the function of the smart contract. However, in actual applications, it is found that the execution performance of smart contracts under this processing method is low, and it cannot meet the requirements of supporting the compilation of contract codes with complex logic.
发明内容Summary of the invention
第一方面,本公开实施例提供了一种智能合约编译方法,所述编译方法基于编译系统,所述编译系统包括编译前端和编译后端,所述编译方法包括:In a first aspect, an embodiment of the present disclosure provides a smart contract compilation method, the compilation method is based on a compilation system, the compilation system includes a compilation front end and a compilation back end, and the compilation method includes:
所述编译前端将目标智能合约转换为对应的第一中间代码,所述第一中间代码中记载有各局部变量在对应栈帧中的偏移位置;The compiling front end converts the target smart contract into a corresponding first intermediate code, wherein the first intermediate code records the offset position of each local variable in the corresponding stack frame;
所述编译前端生成目标智能合约的运行环境初始化配置信息,并将所述运行环境初始化配置信息转换为对应的第二中间代码,所述运行环境初始化配置信息记载有内存分配信息,所述内存分配信息包括:第一配置信息,所述第一配置信息用于指示内存空间进行初始化时在所述内存空间内划分有虚拟寄存器区、栈区和堆区,所述虚拟寄存器区中的存储槽用作为虚拟寄存器;The compiling front end generates the target smart contract's runtime environment initialization configuration information, and converts the runtime environment initialization configuration information into the corresponding second intermediate code, wherein the runtime environment initialization configuration information records memory allocation information, and the memory allocation information includes: first configuration information, wherein the first configuration information is used to indicate that when the memory space is initialized, a virtual register area, a stack area, and a heap area are divided in the memory space, and a storage slot in the virtual register area is used as a virtual register;
所述编译前端生成虚拟寄存器配置信息,并将所述虚拟寄存器配置信息转换为对应的寄存器配置中间代码,所述虚拟寄存器配置信息中记载有将所述虚拟寄存器区中的两个预设固定位置处的存储槽分别用作为栈帧寄存器和栈指针寄存器;The compiling front end generates virtual register configuration information and converts the virtual register configuration information into corresponding register configuration intermediate code, wherein the virtual register configuration information records that storage slots at two preset fixed positions in the virtual register area are used as stack frame registers and stack pointer registers respectively;
所述编译前端将中间代码集发送至所述编译后端,所述中间代码集包括:所述第一中间代码、第二中间代码和所述寄存器配置中间代码;The compiling front end sends an intermediate code set to the compiling back end, wherein the intermediate code set includes: the first intermediate code, the second intermediate code and the register configuration intermediate code;
所述编译后端将所述寄存器配置中间代码编译为对应的寄存器配置目标代码;The compilation backend compiles the register configuration intermediate code into a corresponding register configuration target code;
所述编译后端将所述第二中间代码编译为对应的第二目标代码;The compiling backend compiles the second intermediate code into a corresponding second target code;
所述编译后端将所述第一中间代码编译为基于对栈帧寄存器和栈指针寄存器操作的第一目标代码。The compilation backend compiles the first intermediate code into a first target code based on operations on a stack frame register and a stack pointer register.
在一些实施例中,所述编译后端将所述第一中间代码编译为基于对栈帧寄存器和栈指针寄存器操作的第一目标代码的步骤包括:In some embodiments, the step of the compilation backend compiling the first intermediate code into a first target code based on operations on a stack frame register and a stack pointer register comprises:
所述编译后端识别所述第一中间代码中各函数方法的定义信息和调用信息;The compilation backend identifies definition information and call information of each function method in the first intermediate code;
所述编译后端将所述第一中间代码中的第一个函数方法作为待处理函数方法,所述编译后端根据所述待处理函数方法的定义信息和调用信息生成对应的栈帧布局,以及对所述待处理函数方法中变量进行寄存器分配;The compilation backend uses the first function method in the first intermediate code as the function method to be processed, generates a corresponding stack frame layout according to definition information and call information of the function method to be processed, and performs register allocation for variables in the function method to be processed;
所述编译后端根据所述待处理函数方法的栈帧布局以及变量的寄存器分配结果生成对应的基于对栈帧寄存器和栈指针寄存器操作的指令序列;The compilation backend generates a corresponding instruction sequence based on the operation of the stack frame register and the stack pointer register according to the stack frame layout of the function method to be processed and the register allocation result of the variable;
所述编译后端确定虚拟机执行所述待处理函数方法时所对应的当前栈深度;The compilation backend determines the current stack depth corresponding to when the virtual machine executes the function method to be processed;
所述编译后端判断所述待处理函数方法所对应的当前栈深度是否大于预设深度阈值;The compilation backend determines whether the current stack depth corresponding to the function method to be processed is greater than a preset depth threshold;
若判断出所述当前栈深度大于所述预设深度阈值,则所述编译后端中止编译;If it is determined that the current stack depth is greater than the preset depth threshold, the compilation backend terminates compilation;
若判断出所述当前栈深度小于或等于所述预设深度阈值,则所述编译后端检测所述待处理函数方法是否为所述第一目标代码中最后一个函数方法;If it is determined that the current stack depth is less than or equal to the preset depth threshold, the compilation backend detects whether the function method to be processed is the last function method in the first target code;
若检测出所述待处理函数方法不是所述第一目标代码中最后一个函数方法,则将所述待处理函数方法的下一个函数方法作为新的待处理函数方法,再次执行所述编译后端根据所述待处理函数方法的定义信息和调用信息生成对应的栈帧布局的步骤;If it is detected that the function method to be processed is not the last function method in the first target code, the next function method of the function method to be processed is used as a new function method to be processed, and the step of generating a corresponding stack frame layout according to the definition information and call information of the function method to be processed is executed again by the compilation backend;
若检测出所述待处理函数方法是所述第一目标代码中最后一个函数方法,则表示编译完成。If it is detected that the function method to be processed is the last function method in the first target code, it means that the compilation is completed.
在一些实施例中,在所述编译后端将所述第一中间代码编译为基于对栈帧寄存器和栈指针寄存器操作的第一目标代码步骤之前,还包括:In some embodiments, before the compilation backend compiles the first intermediate code into a first target code based on the operation of the stack frame register and the stack pointer register, the step further includes:
所述编译后端将当前栈深度初始化取值为0;The compilation backend initializes the current stack depth to 0;
所述编译后端确定虚拟机执行所述待处理函数方法时所对应的当前栈深度的步骤包括:The step of determining the current stack depth corresponding to when the virtual machine executes the function method to be processed by the compilation backend includes:
所述编译后端记录所述待处理函数方法所产生操作数的数量A和所消耗的操作数的数量B;The compilation backend records the number A of operands generated and the number B of operands consumed by the function method to be processed;
所述编译后端对所述当前栈深度进行更新以得到虚拟机执行所述待处理函数方法时所对应的当前栈深度;其中,更新后的当前栈深度等于更新前的当前栈深度加上所述待处理函数方法所产生操作数的数量A再减去所述待处理函数方法所消耗的操作数的数量B。The compilation backend updates the current stack depth to obtain the current stack depth corresponding to the virtual machine executing the function method to be processed; wherein the updated current stack depth is equal to the current stack depth before updating plus the number A of operands generated by the function method to be processed minus the number B of operands consumed by the function method to be processed.
在一些实施例中,在所述编译后端将所述第一中间代码编译为基于对栈帧寄存器和栈指针寄存器操作的第一目标代码的步骤之前,和/或在所述编译后端将所述第一中间代码编译为基于对栈帧寄存器和栈指针寄存器操作的第一目标代码的过程中,还包括:In some embodiments, before the step of the compilation backend compiling the first intermediate code into the first target code based on the operation of the stack frame register and the stack pointer register, and/or during the process of the compilation backend compiling the first intermediate code into the first target code based on the operation of the stack frame register and the stack pointer register, the step further includes:
所述编译后端对所述第一中间代码进行代码优化。The compilation backend performs code optimization on the first intermediate code.
在一些实施例中,所述第一配置信息还用于指示将内存空间内的前N个存储槽作为虚拟寄存器区,其中N≥2;In some embodiments, the first configuration information is further used to indicate that the first N storage slots in the memory space are used as virtual register areas, where N ≥ 2;
所述内存空间内第1个存储槽用作为所述栈帧寄存器,所述内存空间内第2个存储槽用作为栈指针寄存器。The first storage slot in the memory space is used as the stack frame register, and the second storage slot in the memory space is used as the stack pointer register.
在一些实施例中,所述寄存器配置中间代码位于所述中间代码集的最前端位置;In some embodiments, the register configuration intermediate code is located at the frontmost position of the intermediate code set;
所述虚拟寄存器配置信息中还记载有所述栈帧寄存器的初始值为所述栈区的起始地址。The virtual register configuration information also records that the initial value of the stack frame register is the starting address of the stack area.
在一些实施例中,在所述编译前端将目标智能合约转换为对应的第一中间代码的步骤之前,还包括:In some embodiments, before the step of converting the target smart contract into the corresponding first intermediate code by the compilation front end, the step further includes:
所述编译前端确定所述目标智能合约中的目标持久化元素,所述目标持久化元素包括:状态变量、字符串常量和/或内嵌字节码;The compilation front end determines a target persistent element in the target smart contract, where the target persistent element includes: a state variable, a string constant and/or an embedded bytecode;
所述编译前端将各所述目标持久化元素分别声明为全局变量并生成全局变量记录信息,以及将所述全局变量记录信息转化为对应的第三中间代码,所述全局变量记录信息记载有各全局变量的声明信息、各全局变量分别所占用空间大小以及内存空间进行初始化时所划分出的全局变量区的空间大小;The compiling front end declares each of the target persistent elements as a global variable and generates global variable record information, and converts the global variable record information into a corresponding third intermediate code, wherein the global variable record information records declaration information of each global variable, the size of the space occupied by each global variable, and the size of the global variable area divided when the memory space is initialized;
所述第一配置信息还用于指示内存空间进行初始化时在所述内存空间内还划分有全局变量区,且所述虚拟寄存器区、所述栈区、所述全局变量区和所述堆区四者在所述内存空间内由低地址向高地址的方向依次设置;The first configuration information is further used to indicate that a global variable area is also divided in the memory space when the memory space is initialized, and the virtual register area, the stack area, the global variable area and the heap area are arranged in sequence from a low address to a high address in the memory space;
所述内存分配信息还包括:第二配置信息,所述第二配置信息用于指示将从目标智能合约中所确认出的全局变量的编码数据拷贝至所述全局变量区;The memory allocation information further includes: second configuration information, the second configuration information being used to instruct to copy the encoded data of the global variable confirmed in the target smart contract to the global variable area;
所述中间代码集还包括所述第三中间代码。The intermediate code set also includes the third intermediate code.
第二方面,本公开实施例中还提供了一种智能合约编译系统,所述编译系统配置为能够实现如第一方面中提供的所述编译方法,所述编译系统包括:编译前端和编译后端;In a second aspect, an embodiment of the present disclosure further provides a smart contract compilation system, the compilation system is configured to implement the compilation method provided in the first aspect, the compilation system includes: a compilation front end and a compilation back end;
所述编译前端用于将目标智能合约转换为对应的第一中间代码,所述第一中间代码中记载有各局部变量在对应栈帧中的偏移位置;以及,还用于生成目标智能合约的运行环境初始化配置信息,并将所述运行环境初始化配置信息转换为对应的第二中间代码,所述运行环境初始化配置信息记载有内存分配信息,所述内存分配信息包括:第一配置信息,所述第一配置信息用于指示内存空间进行初始化时在所述内存空间内划分有虚拟寄存器区、栈区和堆区,所述虚拟寄存器区中的存储槽用作为虚拟寄存器;以及,还用于生成虚拟寄存器配置信息,并将所述虚拟寄存器配置信息转换为对应的寄存器配置中间代码,所述虚拟寄存器配置信息中记载有将所述虚拟寄存器区中的两个预设固定位置处的存储槽分别用作为栈帧寄存器和栈指针寄存器;以及,还用于将中间代码集发送至所述编译后端,所述中间代码集包括:所述第一中间代码、第二中间代码和所述寄存器配置中间代码;The compilation front end is used to convert the target smart contract into a corresponding first intermediate code, wherein the first intermediate code records the offset position of each local variable in the corresponding stack frame; and, it is also used to generate the runtime environment initialization configuration information of the target smart contract, and convert the runtime environment initialization configuration information into a corresponding second intermediate code, wherein the runtime environment initialization configuration information records memory allocation information, wherein the memory allocation information includes: first configuration information, wherein the first configuration information is used to indicate that when the memory space is initialized, a virtual register area, a stack area, and a heap area are divided in the memory space, and the storage slots in the virtual register area are used as virtual registers; and, it is also used to generate virtual register configuration information, and convert the virtual register configuration information into a corresponding register configuration intermediate code, wherein the virtual register configuration information records that the storage slots at two preset fixed positions in the virtual register area are used as stack frame registers and stack pointer registers respectively; and, it is also used to send an intermediate code set to the compilation back end, wherein the intermediate code set includes: the first intermediate code, the second intermediate code, and the register configuration intermediate code;
所述编译后端用于将所述寄存器配置中间代码编译为对应的寄存器配置目标代码;以及,还用于所述编译后端将所述第二中间代码编译为对应的第二目标代码;以及,还用于将所述第一中间代码编译为基于对栈帧寄存器和栈指针寄存器操作的第一目标代码。The compilation backend is used to compile the register configuration intermediate code into the corresponding register configuration target code; and, the compilation backend is also used to compile the second intermediate code into the corresponding second target code; and, it is also used to compile the first intermediate code into a first target code based on operations on the stack frame register and the stack pointer register.
第三方面,本公开实施例还提供了一种电子设备,其中,包括:In a third aspect, an embodiment of the present disclosure further provides an electronic device, comprising:
一个或多个处理器;one or more processors;
存储器,用于存储一个或多个程序;A memory for storing one or more programs;
当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现如第一方面中提供的所述智能合约编译方法。When the one or more programs are executed by the one or more processors, the one or more processors implement the smart contract compilation method provided in the first aspect.
第四方面,本公开实施例还提供了一种智能合约的目标代码运行方法,用于对如第一方面中提供的所述智能合约编译方法所生成的目标代码进行运行,所述智能合约的目标代码运行方法包括:In a fourth aspect, the embodiment of the present disclosure further provides a method for executing a target code of a smart contract, which is used to execute the target code generated by the smart contract compilation method provided in the first aspect, and the method for executing the target code of the smart contract comprises:
在进行内存空间初始化时,根据第二目标代码中的第一配置信息所对应的可执行代码在所述内存空间内划分出虚拟寄存器区、栈区和堆区,以及根据所述寄存器配置目标代码将所述虚拟寄存器区中的两个预设固定位置处的存储槽配置为栈帧寄存器和栈指针寄存器;When initializing the memory space, a virtual register area, a stack area and a heap area are divided in the memory space according to the executable code corresponding to the first configuration information in the second target code, and storage slots at two preset fixed positions in the virtual register area are configured as a stack frame register and a stack pointer register according to the register configuration target code;
在程序运行时,执行所述第一目标代码,其中在执行目标函数方法的指令序列时,先在帧区内生成所述目标函数方法的栈帧,然后通过将栈帧寄存器中所记载的所述目标函数方法的栈帧的起始地址加上待处理变量的偏移位置得到待处理变量的最终地址,以及根据所述最终地址来对所述待处理变量进行存储或取出操作。When the program is running, the first target code is executed, wherein when the instruction sequence of the target function method is executed, the stack frame of the target function method is first generated in the frame area, and then the final address of the variable to be processed is obtained by adding the starting address of the stack frame of the target function method recorded in the stack frame register to the offset position of the variable to be processed, and the variable to be processed is stored or retrieved according to the final address.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
图1为本公开实施例提供的一种智能合约编译方法的流程图。FIG1 is a flow chart of a smart contract compilation method provided in an embodiment of the present disclosure.
图2为本公开实施例中步骤S7的一种可选实现方法流程图。FIG. 2 is a flow chart of an optional implementation method of step S7 in the embodiment of the present disclosure.
图3为本公开实施例提供的另一种智能合约编译方法的流程图。FIG3 is a flow chart of another smart contract compilation method provided by an embodiment of the present disclosure.
图4为本公开实施例中内存空间的一种划分示意图。FIG. 4 is a schematic diagram of a partitioning of memory space in an embodiment of the present disclosure.
图5为本公开实施例提供的一种智能合约编译系统的结构框图。FIG5 is a structural block diagram of a smart contract compilation system provided in an embodiment of the present disclosure.
图6为本公开实施例提供的一种电子设备的结构示意图。FIG. 6 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure.
具体实施方式DETAILED DESCRIPTION
为使本领域技术人员更好地理解本公开的技术方案,下面结合附图和具体实施方式对本公开作进一步详细描述。In order to enable those skilled in the art to better understand the technical solution of the present disclosure, the present disclosure is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
除非另外定义,本公开使用的技术术语或者科学术语应当为本公开所属领域内具有一般技能的人士所理解的通常意义。本公开中使用的“第一”、“第二”以及类似的词语并不表示任何顺序、数量或者重要性,而只是用来区分不同的组成部分。同样,“一个”、“一”或者“该”等类似词语也不表示数量限制,而是表示存在至少一个。“包括”或者“包含”等类似的词语意指出现该词前面的元件或者物件涵盖出现在该词后面列举的元件或者物件及其等同,而不排除其他元件或者物件。Unless otherwise defined, the technical terms or scientific terms used in the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, similar words such as "one", "one" or "the" do not indicate quantitative restrictions, but indicate that there is at least one. "Include" or "comprising" and similar words mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects.
在下文中描述了本公开的许多特定的细节,以便更清楚地理解本公开。但正如本领域的技术人员能够理解的那样,可以不按照这些特定的细节来实现本公开。Many specific details of the present disclosure are described below to provide a clearer understanding of the present disclosure. However, as those skilled in the art will appreciate, the present disclosure may be implemented without following these specific details.
图1为本公开实施例提供的一种智能合约编译方法的流程图。如图1所示,该编译方法基于编译系统,编译系统包括编译前端和编译后端;在一些实施例中,编译前端与编译后端在软件层面上分离,编译前端可以更好的适配更多类型的高级编程语言,编译后端可以更利于目标平台的切换,前后端可以做到一对多,多对一的相互兼容。该编译方法包括:FIG1 is a flow chart of a smart contract compilation method provided by an embodiment of the present disclosure. As shown in FIG1 , the compilation method is based on a compilation system, and the compilation system includes a compilation front end and a compilation back end; in some embodiments, the compilation front end and the compilation back end are separated at the software level, the compilation front end can better adapt to more types of high-level programming languages, and the compilation back end can be more conducive to the switching of the target platform, and the front end and the back end can achieve one-to-many and many-to-one mutual compatibility. The compilation method includes:
步骤S1、编译前端将目标智能合约转换为对应的第一中间代码,第一中间代码中记载有各局部变量在对应栈帧中的偏移位置。Step S1, the compilation front end converts the target smart contract into the corresponding first intermediate code, and the first intermediate code records the offset position of each local variable in the corresponding stack frame.
步骤S2、编译前端生成目标智能合约的运行环境初始化配置信息,并将运行环境初始化配置信息转换为对应的第二中间代码。Step S2: The compile front end generates the operating environment initialization configuration information of the target smart contract, and converts the operating environment initialization configuration information into the corresponding second intermediate code.
其中,运行环境初始化配置信息记载有内存分配信息,内存分配信息包括:第一配置信息,第一配置信息用于指示内存空间进行初始化时在内存空间内划分有虚拟寄存器区、栈区和堆区。其中,虚拟寄存器区中的存储槽用作为虚拟寄存器。The operating environment initialization configuration information records memory allocation information, which includes: first configuration information, which is used to indicate that when the memory space is initialized, the memory space is divided into a virtual register area, a stack area, and a heap area. The storage slots in the virtual register area are used as virtual registers.
在一些实施例中,在一些实施例中,第一配置信息还用于指示将内存空间内的前N个存储槽作为虚拟寄存器区,其中N≥2;In some embodiments, in some embodiments, the first configuration information is further used to indicate that the first N storage slots in the memory space are used as virtual register areas, where N ≥ 2;
内存空间内第1个存储槽用作为栈帧寄存器,内存空间内第2个存储槽用作为栈指针寄存器。The first storage slot in the memory space is used as the stack frame register, and the second storage slot in the memory space is used as the stack pointer register.
在实际应用中,还可以根据需要在虚拟寄存器区中设置其他虚拟寄存器。本公开中仅需保证N≥2即可。In practical applications, other virtual registers may be set in the virtual register area as required. In the present disclosure, it is only necessary to ensure that N≥2.
步骤S3、编译前端生成虚拟寄存器配置信息,并将虚拟寄存器配置信息转换为对应的寄存器配置中间代码。Step S3: The compile front end generates virtual register configuration information and converts the virtual register configuration information into corresponding register configuration intermediate code.
其中,虚拟寄存器配置信息中记载有将虚拟寄存器区中的两个预设固定位置处的存储槽分别用作为栈帧寄存器和栈指针寄存器。The virtual register configuration information records that two storage slots at preset fixed positions in the virtual register area are used as a stack frame register and a stack pointer register respectively.
存储槽用作栈帧寄存器和栈指针寄存器,此时栈帧寄存器和栈指针寄存器均为虚拟寄存器,其本质为位于内存中用于模拟栈帧寄存器或栈指针寄存器的功能的特殊数据结构。The storage slot is used as a stack frame register and a stack pointer register. At this time, the stack frame register and the stack pointer register are virtual registers, which are essentially special data structures located in the memory for simulating the functions of the stack frame register or the stack pointer register.
在实际应用中,栈帧寄存器和栈指针寄存器在内存管理和函数调用中起着关键的作用。In practical applications, the stack frame register and the stack pointer register play a key role in memory management and function calls.
栈帧寄存器通常又称为帧指针寄存器(Frame Pointer Register,FP),它指向当前函数栈帧的起始处。每个函数在栈上拥有独立的帧(也称为栈帧),这些帧在函数调用时分配。在运行过程中的任一时刻,帧指针寄存器都指向当前函数栈帧的起始处,从而帮助确定局部变量和临时变量的位置。The stack frame register is often called the frame pointer register (FP), which points to the beginning of the current function stack frame. Each function has an independent frame (also called a stack frame) on the stack, which is allocated when the function is called. At any time during the execution process, the frame pointer register points to the beginning of the current function stack frame, thereby helping to determine the location of local variables and temporary variables.
栈指针寄存器(Stack Pointer Register,SP),它指向当前函数栈帧的结尾处。它主要用作内存指针,指定在该位置读取和写入内存的内存位置。栈指针寄存器的典型用途是保存属于当前函数的堆栈位,包括用户传递的参数、局部变量以及CPU信息(如子程序调用时的返回地址)。The Stack Pointer Register (SP) points to the end of the current function stack frame. It is mainly used as a memory pointer to specify the memory location at which memory is read and written. The typical use of the stack pointer register is to save the stack bits belonging to the current function, including user-passed parameters, local variables, and CPU information (such as the return address when a subroutine is called).
总的来说,栈帧寄存器和栈指针寄存器协同工作,共同管理栈上的内存片段,即栈帧,以实现函数调用、局部变量和临时变量的分配、参数传递以及返回地址的保存等功能。In general, the stack frame register and the stack pointer register work together to manage the memory fragment on the stack, namely the stack frame, to implement functions such as function calls, allocation of local variables and temporary variables, parameter passing, and saving of return addresses.
在一些实施例中,虚拟寄存器配置信息中还记载有栈帧寄存器的初始值为栈区的起始地址。In some embodiments, the virtual register configuration information also records that the initial value of the stack frame register is the starting address of the stack area.
步骤S4、编译前端将中间代码集发送至编译后端。Step S4: The compiling front end sends the intermediate code set to the compiling back end.
其中,中间代码集包括:第一中间代码、第二中间代码和寄存器配置中间代码。Among them, the intermediate code set includes: a first intermediate code, a second intermediate code and a register configuration intermediate code.
在一些实施例中,寄存器配置中间代码位于中间代码集的最前端位置,也就是说,编译后端会最先处理寄存器配置中间代码,后续运行时也会先进行栈帧寄存器和栈指针寄存器的设置,以保证对函数方法中变量的争取访问。In some embodiments, the register configuration intermediate code is located at the front end of the intermediate code set, that is, the compilation backend will first process the register configuration intermediate code, and will also set the stack frame register and stack pointer register during subsequent runtime to ensure access to variables in function methods.
步骤S5、编译后端将寄存器配置中间代码编译为对应的寄存器配置目标代码。Step S5: The compilation backend compiles the register configuration intermediate code into the corresponding register configuration target code.
步骤S6、编译后端将第二中间代码编译为对应的第二目标代码。Step S6: The compilation backend compiles the second intermediate code into a corresponding second target code.
步骤S7、编译后端将第一中间代码编译为基于对栈帧寄存器和栈指针寄存器操作的第一目标代码。Step S7: The compilation backend compiles the first intermediate code into a first target code based on operations on the stack frame register and the stack pointer register.
后续在运行智能合约的目标代码时,对于函数方法中变量的访问是基于栈帧寄存器和栈指针寄存器(也可以理解为是基于栈帧寄存器和栈指针寄存器来对智能合约中函数方法所对应栈帧进行管理);具体地,在执行智能合约内某个目标函数方法的指令序列时,先在帧区内生成目标函数方法的栈帧,然后通过将栈帧寄存器中所记载的目标函数方法的栈帧的起始地址加上待处理变量的偏移位置,即可得到待处理变量的最终地址,再根据最终地址来对待处理变量进行存储或取出操作;如此设计,可以提升对变量的访问处理效率。When the target code of the smart contract is subsequently run, the access to the variables in the function method is based on the stack frame register and the stack pointer register (it can also be understood as managing the stack frames corresponding to the function methods in the smart contract based on the stack frame register and the stack pointer register); specifically, when executing the instruction sequence of a target function method in the smart contract, the stack frame of the target function method is first generated in the frame area, and then the starting address of the stack frame of the target function method recorded in the stack frame register is added to the offset position of the variable to be processed, so as to obtain the final address of the variable to be processed, and then store or retrieve the variable to be processed according to the final address; such a design can improve the access processing efficiency of the variable.
由此可见,采用本公开实施例提供的编译方法,可以提升智能合约运行时对变量的访问速度,从而提高智能合约的执行性能。此外,本公开实施例提供的编译方法也可以适应复杂逻辑合约编写,对于函数内比较多的临时变量放在了栈帧上面,避免了临时变量太多、栈深度占用过深而导致的无法在虚拟机栈上面进行变量值的检索引用和赋值等操作的问题。It can be seen that the compilation method provided by the embodiment of the present disclosure can improve the access speed of variables when the smart contract is running, thereby improving the execution performance of the smart contract. In addition, the compilation method provided by the embodiment of the present disclosure can also adapt to the writing of complex logic contracts. For the relatively large number of temporary variables in the function, they are placed on the stack frame, avoiding the problem of being unable to retrieve, reference and assign variable values on the virtual machine stack due to too many temporary variables and too deep stack depth.
在一些实施例中,在编译后端将第一中间代码编译为基于对栈帧寄存器和栈指针寄存器操作的第一目标代码之前,和/或,在编译后端将第一中间代码编译为基于对栈帧寄存器和栈指针寄存器操作的第一目标代码的过程中,编译后端还会对第一中间代码进行代码优化。In some embodiments, before the compilation backend compiles the first intermediate code into the first target code based on operations on the stack frame register and the stack pointer register, and/or during the process of the compilation backend compiling the first intermediate code into the first target code based on operations on the stack frame register and the stack pointer register, the compilation backend also performs code optimization on the first intermediate code.
编译后端对中间代码的优化是一个复杂且关键的过程,旨在生成高效、优化的目标代码。优化方法多种多样,以下是一些主要的优化方法:The optimization of intermediate code by the compiler backend is a complex and critical process, which aims to generate efficient and optimized target code. There are many optimization methods, and the following are some of the main optimization methods:
常量折叠与常量传播优化:编译后端会识别和计算常量表达式,并将结果直接嵌入到目标代码中,避免运行时的计算开销。Constant folding and constant propagation optimization: The compilation backend recognizes and calculates constant expressions and embeds the results directly into the target code to avoid runtime computational overhead.
公共子表达式消除优化:对于在代码中多次出现的相同表达式,编译后端会只计算一次,并存储结果,供后续使用,从而避免重复计算。Common sub-expression elimination optimization: For the same expression that appears multiple times in the code, the compilation backend will only calculate it once and store the result for subsequent use, thus avoiding repeated calculations.
死代码消除优化:编译后端会检测并移除那些永远不会被执行的代码,减少目标代码的大小,提高执行效率。Dead code elimination optimization: The compilation backend detects and removes code that will never be executed, reducing the size of the target code and improving execution efficiency.
循环优化优化:对于循环结构,编译后端会进行一系列优化,如循环展开(将小循环展开成多次重复的指令序列)和循环不变量提升(将循环中不变的表达式提到循环外部计算),以减少循环开销。Loop optimization: For loop structures, the compilation backend will perform a series of optimizations, such as loop unrolling (unrolling small loops into multiple repeated instruction sequences) and loop invariant lifting (moving unchanged expressions in the loop to calculations outside the loop) to reduce loop overhead.
指令选择与重排序优化:编译后端会根据目标平台的指令集和特性,选择最优的指令序列。同时,编译后端还会对指令进行重排序,以减少依赖关系,提高并行性。Instruction selection and reordering optimization: The compiler backend will select the optimal instruction sequence based on the instruction set and characteristics of the target platform. At the same time, the compiler backend will also reorder the instructions to reduce dependencies and improve parallelism.
寄存器分配优化:这是优化过程中的重要环节。编译后端会分析中间代码中的数据访问模式,并尝试将频繁使用的变量或中间结果分配到寄存器中,以减少对内存的访问次数,提高程序运行速度。Register allocation optimization: This is an important part of the optimization process. The compiler backend analyzes the data access pattern in the intermediate code and tries to allocate frequently used variables or intermediate results to registers to reduce the number of memory accesses and increase the program running speed.
内存访问优化:编译后端会考虑如何最有效地利用缓存,包括数据对齐、减少内存访问次数、提高内存访问的局部性等策略,以减少内存访问延迟。Memory access optimization: The compilation backend will consider how to use the cache most effectively, including strategies such as data alignment, reducing the number of memory accesses, and improving the locality of memory accesses to reduce memory access latency.
分支预测优化:对于条件分支,编译后端会尝试预测分支的走向,并优化代码布局以减少分支预测错误带来的开销。Branch prediction optimization: For conditional branches, the compilation backend will try to predict the direction of the branch and optimize the code layout to reduce the overhead caused by branch prediction errors.
对智能合约的中间代码进行优化的具体过程为本领域的常规技术,此处不再赘述。The specific process of optimizing the intermediate code of the smart contract is a conventional technology in this field and will not be described in detail here.
在一些实施例中,在步骤S1中,与常规编译前端的代码转换功能类似,编译前端对目标源代码进行词法分析、语法分析、语义分析来生成对应的抽象语法树,并对抽象语法树进行解析以得到对应的第一中间代码。In some embodiments, in step S1, similar to the code conversion function of a conventional compilation front end, the compilation front end performs lexical analysis, syntactic analysis, and semantic analysis on the target source code to generate a corresponding abstract syntax tree, and parses the abstract syntax tree to obtain a corresponding first intermediate code.
其中,词法分析是指将源代码划分为一个个的单次的单词(token)。每个单词都具有特定的含义和类型,例如关键字、标识符、运算符等。这一过程通常通过正则表达式或有限自动机等方式实现,逐个读入字符并进行匹配,从而得到一系列的单词。语法分析是指给定的文法规则对单词序列进行组合和检查,以验证其是否满足语法规则;语义分析是对源代码进行静态语义检查的过程,以保证程序在运行时不会出现语义错误,这一步骤主要包括类型检查、作用域分析和符号表构建等;完成上述步骤后可以生成对应的抽象语法树(AST)。Among them, lexical analysis refers to dividing the source code into individual single words (tokens). Each word has a specific meaning and type, such as keywords, identifiers, operators, etc. This process is usually implemented through regular expressions or finite automata, reading characters one by one and matching them to obtain a series of words. Syntactic analysis refers to the combination and checking of word sequences according to given grammar rules to verify whether they meet the grammatical rules; semantic analysis is the process of static semantic checking of source code to ensure that there will be no semantic errors when the program is running. This step mainly includes type checking, scope analysis, and symbol table construction; after completing the above steps, the corresponding abstract syntax tree (AST) can be generated.
编译前端通过解析抽象语法树,生成对应的中间代码;中间代码是编译前端和后端之间的桥梁,它使得编译系统的前端和后端可以独立地进行优化和修改,而不需要对整个编译系统进行大规模的改动;对抽象语法树进行解析生成对应中间代码的过程大致包括如下步骤:遍历抽象语法树、节点转换、处理控制流、类型检查与转换、符号表管理、优化和输出中间代码。The compilation front end generates the corresponding intermediate code by parsing the abstract syntax tree; the intermediate code is the bridge between the compilation front end and the back end, which enables the front end and the back end of the compilation system to be optimized and modified independently without the need for large-scale changes to the entire compilation system; the process of parsing the abstract syntax tree to generate the corresponding intermediate code generally includes the following steps: traversing the abstract syntax tree, node conversion, processing control flow, type checking and conversion, symbol table management, optimization and output of intermediate code.
其中,“遍历抽象语法树”是指编译前端会遍历整个抽象语法树,其中遍历的方式可以是深度优先遍历(DFS)或广度优先遍历(BFS),具体取决于编译器的设计和目标语言的特性。“节点转换”是指在遍历过程中,编译前端会访问到抽象语法树的每个节点,并根据节点的类型执行相应的操作,对于每个节点,编译前端会将其转换为一种或多种中间代码指令,这些指令通常代表了某种计算或操作,例如加法、函数调用等。“处理控制流”是指在转换过程中,编译前端需要特别关注控制流结构,如条件语句(if-else)、循环语句(for,while)等,这些结构在抽象语法树中通常表现为特定的节点类型,编译前端需要将这些节点转换为适当的中间代码,以正确地表示程序的控制流。“类型检查与转换”是指在生成中间代码时,编译前端还会进行类型检查和转换,这包括检查变量的类型是否匹配,以及执行必要的类型转换以确保操作的合法性。“符号表管理”是指编译前端维护一个符号表,其中存储了程序中定义的所有变量、函数等标识符的信息;在生成中间代码时,编译前端会使用符号表来解析标识符的引用,并生成相应的中间代码指令。“优化”是指在生成中间代码的过程中,编译前端可能会进行一些简单的优化操作,例如常量折叠、无用代码删除等,这些优化可以帮助提高最终生成的目标代码的性能。“输出中间代码”是指编译前端将生成的中间代码输出到一个中间文件或内存中,供后端进一步处理,中间代码通常以一种易于分析和优化的形式表示,例如三地址码或静态单赋值形式(SSA)。Among them, "traversing the abstract syntax tree" means that the compiler front end will traverse the entire abstract syntax tree, where the traversal method can be depth-first traversal (DFS) or breadth-first traversal (BFS), depending on the design of the compiler and the characteristics of the target language. "Node conversion" means that during the traversal process, the compiler front end will access each node of the abstract syntax tree and perform corresponding operations according to the type of the node. For each node, the compiler front end will convert it into one or more intermediate code instructions, which usually represent a certain calculation or operation, such as addition, function call, etc. "Processing control flow" means that during the conversion process, the compiler front end needs to pay special attention to control flow structures, such as conditional statements (if-else), loop statements (for, while), etc. These structures are usually represented as specific node types in the abstract syntax tree. The compiler front end needs to convert these nodes into appropriate intermediate codes to correctly represent the control flow of the program. "Type checking and conversion" means that when generating intermediate codes, the compiler front end will also perform type checking and conversion, which includes checking whether the types of variables match and performing necessary type conversions to ensure the legality of the operation. "Symbol table management" means that the compilation front end maintains a symbol table, which stores the information of all variables, functions and other identifiers defined in the program; when generating intermediate code, the compilation front end will use the symbol table to resolve the reference of the identifier and generate the corresponding intermediate code instructions. "Optimization" means that in the process of generating intermediate code, the compilation front end may perform some simple optimization operations, such as constant folding, useless code deletion, etc. These optimizations can help improve the performance of the final generated target code. "Output intermediate code" means that the compilation front end outputs the generated intermediate code to an intermediate file or memory for further processing by the back end. The intermediate code is usually expressed in a form that is easy to analyze and optimize, such as three-address code or static single assignment form (SSA).
智能合约中的函数方法在被执行时会以对应的栈帧而存在于栈区,函数方法所涉及的各变量在对应栈帧中的偏移位置也会在步骤S1中得到确认。When the function method in the smart contract is executed, it will exist in the stack area as a corresponding stack frame, and the offset position of each variable involved in the function method in the corresponding stack frame will also be confirmed in step S1.
图2为本公开实施例中步骤S7的一种可选实现方法流程图。如图2所示,在一些实施例中,步骤S7包括:FIG2 is a flow chart of an optional implementation method of step S7 in an embodiment of the present disclosure. As shown in FIG2, in some embodiments, step S7 includes:
步骤S701、编译后端识别第一中间代码中各函数方法的定义信息和调用信息。Step S701: The compilation backend identifies definition information and call information of each function method in the first intermediate code.
在步骤S701结束后,编译后端将第一中间代码中的第一个函数方法作为待处理函数方法,执行下面步骤S702。After step S701 is completed, the compilation backend takes the first function method in the first intermediate code as the function method to be processed and executes the following step S702.
步骤S702、编译后端根据待处理函数方法的定义信息和调用信息生成对应的栈帧布局,以及对待处理函数方法中变量进行寄存器分配。Step S702: The compilation backend generates a corresponding stack frame layout according to the definition information and call information of the function method to be processed, and performs register allocation for the variables in the function method to be processed.
栈帧布局是函数方法执行时所需数据结构的内存表示,它包含了函数执行所需的所有局部变量、操作数、返回地址等信息。The stack frame layout is the memory representation of the data structure required for function method execution. It contains all the local variables, operands, return addresses and other information required for function execution.
步骤S703、编译后端根据待处理函数方法的栈帧布局以及变量的寄存器分配结果生成对应的基于对栈帧寄存器和栈指针寄存器操作的指令序列。Step S703: The compiling backend generates a corresponding instruction sequence based on the operation of the stack frame register and the stack pointer register according to the stack frame layout of the function method to be processed and the register allocation result of the variable.
步骤S704、编译后端确定虚拟机执行待处理函数方法时所对应的当前栈深度。Step S704: The compiling backend determines the current stack depth corresponding to the virtual machine executing the function method to be processed.
步骤S705、编译后端判断待处理函数方法所对应的当前栈深度是否大于预设深度阈值。Step S705: The compiling backend determines whether the current stack depth corresponding to the function method to be processed is greater than a preset depth threshold.
若判断出当前栈深度大于预设深度阈值,则执行步骤S706;若判断出当前栈深度小于或等于预设深度阈值,则执行步骤S707。If it is determined that the current stack depth is greater than the preset depth threshold, step S706 is executed; if it is determined that the current stack depth is less than or equal to the preset depth threshold, step S707 is executed.
步骤S706、编译后端中止编译。Step S706: The compilation backend terminates the compilation.
步骤S707、编译后端检测待处理函数方法是否为第一目标代码中最后一个函数方法。Step S707: The compilation backend detects whether the function method to be processed is the last function method in the first target code.
若检测出待处理函数方法不是第一目标代码中最后一个函数方法,则将待处理函数方法的下一个函数方法作为新的待处理函数方法,再次执行步骤S702;If it is detected that the function method to be processed is not the last function method in the first target code, the next function method of the function method to be processed is taken as a new function method to be processed, and step S702 is executed again;
若检测出待处理函数方法是第一目标代码中最后一个函数方法,则表示编译完成。If it is detected that the function method to be processed is the last function method in the first target code, it means that the compilation is completed.
通过上述过程,可以有效避免在虚拟机运行智能合约时出现数据溢出栈的问题。Through the above process, the problem of data overflow stack when the virtual machine runs the smart contract can be effectively avoided.
在一些实施例中,在编译后端将第一中间代码编译为基于对栈帧寄存器和栈指针寄存器操作的第一目标代码步骤之前,还包括:所述编译后端将当前栈深度初始化取值为0。此时,步骤S704具体包括:首先,记录待处理函数方法所产生操作数的数量A和所消耗的操作数的数量B;对当前栈深度进行更新以得到虚拟机执行待处理函数方法时所对应的当前栈深度;其中,更新后的当前栈深度等于更新前的当前栈深度加上待处理函数方法所产生操作数的数量A再减去待处理函数方法所消耗的操作数的数量B。In some embodiments, before the compilation backend compiles the first intermediate code into the first target code based on the operation of the stack frame register and the stack pointer register, it also includes: the compilation backend initializes the current stack depth to 0. At this time, step S704 specifically includes: first, recording the number of operands A generated by the function method to be processed and the number of operands B consumed; updating the current stack depth to obtain the current stack depth corresponding to the virtual machine executing the function method to be processed; wherein the updated current stack depth is equal to the current stack depth before the update plus the number of operands A generated by the function method to be processed minus the number of operands B consumed by the function method to be processed.
作为一个示例,待处理函数方法为一个算术加法操作c=a+b,此时需要先从对应栈帧中分别确定出参量a和b的地址(由FP地址+a或b的偏移地址得到),然后从对应地址中读取相应数据并加载到虚拟机的栈上面,再执行ADD加法操作,这样就是消耗用于操作a和b两个操作数,同时又产生了用于操作c的1个操作数。故,c=a+b这样的操作实际就是消耗两个操作数生成一个操作数过程,这些产生和消耗操作数的步骤可以同步记录在编译阶段。As an example, the function method to be processed is an arithmetic addition operation c=a+b. At this time, it is necessary to first determine the addresses of the parameters a and b from the corresponding stack frame (obtained by FP address + offset address of a or b), then read the corresponding data from the corresponding address and load it onto the stack of the virtual machine, and then perform the ADD addition operation, which consumes two operands for the operation a and b, and generates one operand for the operation c. Therefore, an operation such as c=a+b actually consumes two operands to generate one operand, and these steps of generating and consuming operands can be recorded synchronously in the compilation stage.
通过记录操作数深度的过程,我们可以方便定位和索引到某个变量的值是否在虚拟机的栈上面,如果需要用到这个变量的值,先从栈上面查找是否加载上去了,如果是的话就只需要通过DUP这样的复制栈操作数指令来完成,这样在栈上就多了一个操作数,同时也在栈顶上方便直接操作,如果这个变量后面已经不需要使用,也就是生命周期已经要结束了就可以通过SWAP的交换指令将其交换到栈顶上面,方便运算操作。By recording the depth of operands, we can easily locate and index whether the value of a variable is on the stack of the virtual machine. If the value of this variable is needed, first check whether it has been loaded on the stack. If so, it only needs to be completed through a copy stack operand instruction such as DUP. In this way, there is one more operand on the stack, and it is also convenient for direct operations on the top of the stack. If this variable is no longer needed, that is, its life cycle is about to end, it can be swapped to the top of the stack through the SWAP exchange instruction to facilitate calculation operations.
每一个待处理函数方法的执行会消耗或产生固定的操作数,这些都记录和同步更新当前的栈深度和虚拟机栈中的操作数,这样就相当于编译器后端模拟了虚拟机运行时栈深度的变化过程。The execution of each pending function method consumes or generates a fixed number of operands, which record and synchronously update the current stack depth and the number of operands in the virtual machine stack. This is equivalent to the compiler backend simulating the change process of the stack depth when the virtual machine is running.
在智能合约源码层面,需要持久化记录一些元素(称为持久化元素),以保证这些数据的可靠性和一致性。然而在实际应用中发现,现有的编译方法在对持久化元素的进行编译时会存在各式各样的问题。为有效改善现有技术中持久化元素在编译过程中出现的问题,本公开提供了相应解决方法。At the smart contract source code level, some elements (called persistent elements) need to be persistently recorded to ensure the reliability and consistency of these data. However, in actual applications, it is found that the existing compilation methods have various problems when compiling persistent elements. In order to effectively improve the problems that occur in the compilation process of persistent elements in the prior art, the present disclosure provides a corresponding solution.
图3为本公开实施例提供的另一种智能合约编译方法的流程图。图4为本公开实施例中内存空间的一种划分示意图。如图3和图4所示,本公开的技术方案不但包括前面实施例中的步骤S1~步骤S7,且在步骤S1之前还包括:FIG3 is a flow chart of another smart contract compilation method provided by an embodiment of the present disclosure. FIG4 is a schematic diagram of a partitioning of memory space in an embodiment of the present disclosure. As shown in FIG3 and FIG4, the technical solution of the present disclosure not only includes steps S1 to S7 in the previous embodiment, but also includes before step S1:
步骤S01、编译前端确定目标智能合约中的目标持久化元素,目标持久化元素包括:状态变量、字符串常量和/或内嵌字节码。Step S01: The compiling front end determines the target persistent elements in the target smart contract, where the target persistent elements include: state variables, string constants and/or embedded bytecodes.
步骤S02、编译前端将各目标持久化元素分别声明为全局变量并生成全局变量记录信息,以及将全局变量记录信息转化为对应的第三中间代码。Step S02: The compiling front end declares each target persistent element as a global variable and generates global variable record information, and converts the global variable record information into a corresponding third intermediate code.
其中,全局变量记录信息记载有各全局变量的声明信息、各全局变量分别所占用空间大小以及内存空间进行初始化时所划分出的全局变量区的空间大小。The global variable record information records the declaration information of each global variable, the size of the space occupied by each global variable, and the size of the global variable area divided when the memory space is initialized.
此时,在步骤S2中的第一配置信息还用于指示内存空间进行初始化时在内存空间内还划分有全局变量区,且虚拟寄存器区、栈区、全局变量区和堆区四者在内存空间内由低地址向高地址的方向依次设置。At this time, the first configuration information in step S2 is also used to indicate that a global variable area is also divided in the memory space when the memory space is initialized, and the virtual register area, stack area, global variable area and heap area are arranged in sequence from low address to high address in the memory space.
此外,内存分配信息还包括:第二配置信息,第二配置信息用于指示将从目标智能合约中所确认出的全局变量的编码数据拷贝至全局变量区。In addition, the memory allocation information also includes: second configuration information, and the second configuration information is used to indicate that the encoded data of the global variables confirmed in the target smart contract is copied to the global variable area.
与现有技术中在对程序源代码所对应内存空间进行内存分配时仅在内存空间中划分栈区和堆区所不同,本公开中内存分配信息中一方面会指示在后序对智能合约所对应内存空间进行初始化时在内存空间内划分有栈区、全局变量区和堆区,另一方面还会指示在对内存空间完成栈区、全局变量区和堆区的划分后将所有全局变量的编码数据拷贝至全局变量区。。Different from the prior art in which only the stack area and the heap area are divided in the memory space when the memory space corresponding to the program source code is allocated, the memory allocation information in the present disclosure will indicate that the memory space corresponding to the smart contract is divided into the stack area, the global variable area and the heap area when the memory space is initialized in the subsequent order, and will also indicate that the encoded data of all global variables are copied to the global variable area after the memory space is divided into the stack area, the global variable area and the heap area. .
全局变量的编码数据则是编译器将智能合约的源代码转换为字节码时生成的,是全局变量在区块链上的实际存储形式;编码数据包含了全局变量的类型信息、初始值以及它们在合约状态存储中的位置等信息。这些信息是EVM(以太坊虚拟机)执行程序时所必需的,用于正确地读取、写入和管理这些全局变量的状态。The encoding data of global variables is generated when the compiler converts the source code of the smart contract into bytecode. It is the actual storage form of global variables on the blockchain. The encoding data contains information such as the type information, initial value, and location of global variables in the contract state storage. This information is necessary for EVM (Ethereum Virtual Machine) to execute programs and is used to correctly read, write, and manage the status of these global variables.
此时,步骤S4中间代码集还包括第三中间代码。At this time, the intermediate code set in step S4 also includes the third intermediate code.
现有智能合约语言特性本身没有全局变量的概念;而在本申请中,将步骤S01所确定的选择的目标持久化元素重新声明为全局变量,并生成全局变量记录信息。此外,由于在智能合约中声明了全局变量,则后续需要编译系统对这些全局变量进行内存分配。The existing smart contract language features themselves do not have the concept of global variables; in this application, the selected target persistent element determined in step S01 is re-declared as a global variable, and global variable record information is generated. In addition, since global variables are declared in the smart contract, the compilation system is required to allocate memory for these global variables later.
全局变量的声明数据主要是指在源代码中对全局变量进行声明的部分,它告诉编译器这个变量在整个合约范围内都是有效和可访问的。声明数据通常包括变量名、变量类型以及可能的初始值(在部分场景下声明时可不需要确定初始值)。这部分数据主要是用于编译器理解代码的结构和语义,以便进行后续的编译工作。The declaration data of global variables mainly refers to the part of the source code that declares the global variable, which tells the compiler that the variable is valid and accessible throughout the contract. The declaration data usually includes the variable name, variable type, and possible initial value (in some scenarios, the initial value does not need to be determined when declaring). This part of the data is mainly used by the compiler to understand the structure and semantics of the code for subsequent compilation.
全局变量记录信息用于后序将所有全局变量的编码数据拷贝至全局变量区过程中确定各全局变量在全局变量区内的位置The global variable record information is used to determine the position of each global variable in the global variable area during the subsequent copying of the encoded data of all global variables to the global variable area.
在本公开中,将智能合约中的至少部分持久化元素声明为全局变量,然后再对智能合约进行相应编译,可以有效改善智能合约内持久化元素在编译过程中所出现的各类问题,提升编译效率。In the present disclosure, at least some persistent elements in a smart contract are declared as global variables, and then the smart contract is compiled accordingly, which can effectively improve various problems that arise during the compilation process of persistent elements in the smart contract and improve compilation efficiency.
另外,由于虚拟机不支持直接对代码区进行寻址访问,故现有技术中每次在对某个全局变量进行访问时,都需要将该全局变量先拷贝至临时内存中;在对该全局变量操作结束时再将其从临时内存中删除,然而当程序中涉及全局变量的数量较多时,在程序运行过程中需要频繁的向临时内存中拷贝全局变量,这会影响虚拟机运行性能。而在本公开的技术方案中,通过在内存分配信息中设置第一配置信息和第二配置信息以及生成相应的全局变量记录信息,其中第一配置信息用于指示内存空间进行初始化时在内存空间内划分有全局变量区,第二配置信息用于指示将从目标源代码中所确认出的全局变量的编码数据拷贝至全局变量区,全局变量记录信息记载有各全局变量的声明信息、各全局变量分别所占用空间大小以及整个全局变量区的空间大小,可使得在内存空间初始化结束后且在进入程序运行阶段之前将全部全局变量都拷贝至全局变量区,这样可以避免现有技术中出现的在程序运行过程中需要频繁的向临时内存中拷贝全局变量的问题;故,本公开的技术方案可以有效提升全局变量的访问效率、加快程序运行速度。In addition, since the virtual machine does not support direct addressing access to the code area, the prior art requires that each time a global variable is accessed, the global variable must be copied to a temporary memory first; and then deleted from the temporary memory when the operation on the global variable is completed. However, when a large number of global variables are involved in a program, the global variables must be frequently copied to the temporary memory during the program execution, which affects the virtual machine's operating performance. In the technical solution of the present invention, by setting the first configuration information and the second configuration information in the memory allocation information and generating corresponding global variable recording information, the first configuration information is used to indicate that a global variable area is divided in the memory space when the memory space is initialized, and the second configuration information is used to indicate that the encoded data of the global variables confirmed in the target source code is copied to the global variable area, and the global variable recording information records the declaration information of each global variable, the size of the space occupied by each global variable and the size of the space of the entire global variable area, so that all global variables can be copied to the global variable area after the memory space initialization is completed and before entering the program running stage, which can avoid the problem of frequently copying global variables to the temporary memory during the program running process in the prior art; therefore, the technical solution of the present invention can effectively improve the access efficiency of global variables and speed up the program running speed.
在一些实施例中,本公开中目标持久化元素包括:状态变量、字符串常量、内嵌字节码中至少之一。In some embodiments, the target persistent element in the present disclosure includes at least one of: a state variable, a string constant, and an embedded bytecode.
在一些实施例中,当步骤S01中所确定的目标持久化元素包括有状态变量时,步骤S02包括有步骤S02a。In some embodiments, when the target persistent element determined in step S01 includes a state variable, step S02 includes step S02a.
步骤S02a、在编译前端为目标智能合约中的各变量分配存储槽(slot)后,编译前端将状态变量所分配存储槽的槽号声明为全局变量。Step S02a: After the compilation front end allocates storage slots for each variable in the target smart contract, the compilation front end declares the slot number of the storage slot allocated to the state variable as a global variable.
当步骤S01中所确定的目标持久化元素包括有字符串常量时,步骤S02包括有步骤S20b。When the target persistent element determined in step S01 includes a string constant, step S02 includes step S20b.
步骤S02b、编译前端直接将字符串常量声明为全局变量。Step S02b: The compile front end directly declares the string constant as a global variable.
当步骤S01中所确定的目标持久化元素包括有内嵌字节码时,步骤S02包括有步骤S02c。When the target persistent element determined in step S01 includes embedded bytecode, step S02 includes step S02c.
步骤S02c、编译前端直接将字符串常量声明为全局变量。Step S02c: The compile front end directly declares the string constant as a global variable.
也就是说,当目标持久化元素同时包括有状态变量、字符串常量、内嵌字节码时,则对应步骤S2中同时包括有步骤S02a、步骤S02b和步骤S02c。That is, when the target persistent element includes state variables, string constants, and embedded bytecodes at the same time, the corresponding step S2 includes step S02a, step S02b, and step S02c at the same time.
在现有技术中,智能合约会有状态变量的使用和声明,为便于在生成最终字节码前做代码检查和审核,通常做法会生成一种中间语言,在生成中间语言时状态变量如果没有使用全局变量的分配方式来记录状态变量在EVM中的存储位置slot,这些变量在中间语言层面就是纯数字类型的编码,不便于做代码检查和审核,无法直接与智能合约的状态变量对应起来。而在本申请中,通过将状态变量声明为全局变量,可以将智能合约中的状态变量(全局变量)与中间语言中的全局变量符号进行绑定和映射起来,便于做检查和审核,对全局变量的访问就是对EVM中的存储位置进行访问,可以快速扫描查验到哪些代码对状态变量进行了引用和使用。In the prior art, smart contracts use and declare state variables. To facilitate code inspection and review before generating the final bytecode, an intermediate language is usually generated. When generating the intermediate language, if the state variables do not use the allocation method of global variables to record the storage location slot of the state variables in the EVM, these variables are pure digital type encodings at the intermediate language level, which is not convenient for code inspection and review, and cannot be directly matched with the state variables of the smart contract. In this application, by declaring the state variables as global variables, the state variables (global variables) in the smart contract can be bound and mapped to the global variable symbols in the intermediate language, which is convenient for inspection and review. Access to global variables is to access the storage location in the EVM, and you can quickly scan and check which codes reference and use the state variables.
在现有技术中,智能合约会有字符串常量的访问需求,如果将每个将字符串常量都直接在后端编码生成相应的字节码,会对应增加更多的代码量。在本公开中,为减少代码量消耗,采用在编译器阶段对智能合约中的字符串常量进行全局变量声明后再编码,在中间语言建立起字符串常量和全局变量的绑定关系,对全局变量的访问就是对字符串常量的访问,后端只会生成一份字节码减小了代码量,同时也更好的利用通用全局变量访问方法来寻址字符串常量,减少前端与后端的耦合。In the prior art, smart contracts have access requirements for string constants. If each string constant is directly encoded in the backend to generate corresponding bytecodes, more code will be added accordingly. In the present disclosure, in order to reduce the amount of code consumption, the string constants in the smart contract are encoded after being declared as global variables at the compiler stage, and the binding relationship between the string constants and the global variables is established in the intermediate language. The access to the global variables is the access to the string constants. The backend will only generate one bytecode to reduce the amount of code. At the same time, the general global variable access method is better used to address the string constants, reducing the coupling between the front end and the back end.
在实际应用中,智能合约会有字节码的嵌入需求(比如需要将子合约字节码或自身运行时字节码嵌入使用调用子合约或进行合约的部署交易),在本申请中将子合约字节码或自身运行时字节码作为全局变量进行声明,将这些字节码的访问使用就是对全局变量的访问寻址,这样无需生成其他特殊字节码操作处理,只需要索引到字节码的全局变量地址就可以访问。In actual applications, smart contracts may have bytecode embedding requirements (for example, the sub-contract bytecode or its own runtime bytecode needs to be embedded in the sub-contract for calling the sub-contract or performing contract deployment transactions). In this application, the sub-contract bytecode or its own runtime bytecode is declared as a global variable, and the access to these bytecodes is the access addressing of the global variable. In this way, there is no need to generate other special bytecode operations, and only the global variable address of the bytecode needs to be indexed for access.
需要说明的是,在步骤S01中哪些持久化元素会被作为目标持久化元素,可根据实际需要进行预先设定。It should be noted that which persistent elements will be used as target persistent elements in step S01 can be preset according to actual needs.
本公开实施例还提供的一种智能合约的目标代码运行方法。该运行方法用于对前面实施例提供的任一智能合约编译方法所生成的目标代码进行运行,该运行方法包括:The disclosed embodiment also provides a method for running the target code of a smart contract. The running method is used to run the target code generated by any smart contract compilation method provided in the previous embodiment, and the running method includes:
步骤BZ1、在进行内存空间初始化时,根据第二目标代码中的第一配置信息所对应的可执行代码在内存空间内划分出虚拟寄存器区、栈区和堆区,以及根据寄存器配置目标代码将虚拟寄存器区中的两个预设固定位置处的存储槽配置为栈帧寄存器和栈指针寄存器;Step BZ1, when initializing the memory space, dividing the memory space into a virtual register area, a stack area, and a heap area according to the executable code corresponding to the first configuration information in the second target code, and configuring the storage slots at two preset fixed positions in the virtual register area as a stack frame register and a stack pointer register according to the register configuration target code;
步骤BZ2、在程序运行时,执行第一目标代码,其中在执行目标函数方法的指令序列时,先在帧区内生成目标函数方法的栈帧,然后通过将栈帧寄存器中所记载的目标函数方法的栈帧的起始地址加上待处理变量的偏移位置得到待处理变量的最终地址,以及根据最终地址来对待处理变量进行存储或取出操作。Step BZ2, when the program is running, execute the first target code, wherein when executing the instruction sequence of the target function method, first generate the stack frame of the target function method in the frame area, then add the starting address of the stack frame of the target function method recorded in the stack frame register to the offset position of the variable to be processed to obtain the final address of the variable to be processed, and store or retrieve the variable to be processed according to the final address.
基于同一发明构思,本公开实施例还提供了一种智能合约编译系统。图5为本公开实施例提供的一种智能合约编译系统的结构框图。如图5所示,该程序源代码编译系统能够实现前面实施例所提供的编译方法,该编译系统包括:编译前端和编译后端。Based on the same inventive concept, the embodiment of the present disclosure also provides a smart contract compilation system. Figure 5 is a structural block diagram of a smart contract compilation system provided by the embodiment of the present disclosure. As shown in Figure 5, the program source code compilation system can implement the compilation method provided by the previous embodiment, and the compilation system includes: a compilation front end and a compilation back end.
其中,编译前端用于将目标智能合约转换为对应的第一中间代码,第一中间代码中记载有各局部变量在对应栈帧中的偏移位置;以及,还用于生成目标智能合约的运行环境初始化配置信息,并将运行环境初始化配置信息转换为对应的第二中间代码,运行环境初始化配置信息记载有内存分配信息,内存分配信息包括:第一配置信息,第一配置信息用于指示内存空间进行初始化时在内存空间内划分有虚拟寄存器区、栈区和堆区,虚拟寄存器区中的存储槽用作为虚拟寄存器;以及,还用于生成虚拟寄存器配置信息,并将虚拟寄存器配置信息转换为对应的寄存器配置中间代码,虚拟寄存器配置信息中记载有将虚拟寄存器区中的两个预设固定位置处的存储槽分别用作为栈帧寄存器和栈指针寄存器;以及,还用于将中间代码集发送至编译后端,中间代码集包括:第一中间代码、第二中间代码和寄存器配置中间代码。Among them, the compilation front end is used to convert the target smart contract into a corresponding first intermediate code, and the first intermediate code records the offset position of each local variable in the corresponding stack frame; and, it is also used to generate the operating environment initialization configuration information of the target smart contract, and convert the operating environment initialization configuration information into the corresponding second intermediate code, and the operating environment initialization configuration information records the memory allocation information, and the memory allocation information includes: the first configuration information, the first configuration information is used to indicate that when the memory space is initialized, the memory space is divided into a virtual register area, a stack area and a heap area, and the storage slots in the virtual register area are used as virtual registers; and, it is also used to generate virtual register configuration information, and convert the virtual register configuration information into the corresponding register configuration intermediate code, and the virtual register configuration information records that the storage slots at two preset fixed positions in the virtual register area are used as stack frame registers and stack pointer registers respectively; and, it is also used to send the intermediate code set to the compilation back end, and the intermediate code set includes: the first intermediate code, the second intermediate code and the register configuration intermediate code.
编译后端用于将寄存器配置中间代码编译为对应的寄存器配置目标代码;以及,还用于编译后端将第二中间代码编译为对应的第二目标代码;以及,还用于将第一中间代码编译为基于对栈帧寄存器和栈指针寄存器操作的第一目标代码。The compilation backend is used to compile the register configuration intermediate code into the corresponding register configuration target code; and, the compilation backend is also used to compile the second intermediate code into the corresponding second target code; and, it is also used to compile the first intermediate code into the first target code based on the operation of the stack frame register and the stack pointer register.
对于本实施例中编译系统中编译前端和编译后端的具体描述,可参见前面实施例中的相应内容,此处不再赘述。For the specific description of the compilation front-end and the compilation back-end in the compilation system in this embodiment, reference may be made to the corresponding contents in the previous embodiments, which will not be repeated here.
基于同一发明构思,本公开实施例还提供了一种电子设备。图6为本公开实施例提供的一种电子设备的结构示意图。如图6所示,本公开实施例提供一种电子设备包括:一个或多个处理器101、存储器102、一个或多个I/O接口103。存储器102上存储有一个或多个程序,当该一个或多个程序被该一个或多个处理器执行,使得该一个或多个处理器实现如上述实施例中任一智能合约编译方法;一个或多个I/O接口103连接在处理器与存储器之间,配置为实现处理器与存储器的信息交互。Based on the same inventive concept, an embodiment of the present disclosure also provides an electronic device. Figure 6 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. As shown in Figure 6, an embodiment of the present disclosure provides an electronic device including: one or more processors 101, a memory 102, and one or more I/O interfaces 103. One or more programs are stored on the memory 102. When the one or more programs are executed by the one or more processors, the one or more processors implement any smart contract compilation method in the above embodiments; one or more I/O interfaces 103 are connected between the processor and the memory, and are configured to implement information interaction between the processor and the memory.
其中,处理器101为具有数据处理能力的器件,包括但不限于中央处理器(CPU)等;存储器102为具有数据存储能力的器件,包括但不限于随机存取存储器(RAM,更具体如SDRAM、DDR等)、只读存储器(ROM)、带电可擦可编程只读存储器(EEPROM)、闪存(FLASH);I/O接口(读写接口)103连接在处理器101与存储器102间,能实现处理器101与存储器102的信息交互,包括但不限于数据总线(Bus)等。Among them, the processor 101 is a device with data processing capabilities, including but not limited to a central processing unit (CPU), etc.; the memory 102 is a device with data storage capabilities, including but not limited to random access memory (RAM, more specifically SDRAM, DDR, etc.), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory (FLASH); the I/O interface (read-write interface) 103 is connected between the processor 101 and the memory 102, and can realize information interaction between the processor 101 and the memory 102, including but not limited to a data bus (Bus), etc.
在一些实施例中,处理器101、存储器102和I/O接口103通过总线104相互连接,进而与计算设备的其它组件连接。In some embodiments, the processor 101 , the memory 102 , and the I/O interface 103 are connected to each other via a bus 104 , and further connected to other components of the computing device.
在一些实施例中,该一个或多个处理器101包括现场可编程门阵列。In some embodiments, the one or more processors 101 include a field programmable gate array.
根据本公开的实施例,还提供一种计算机可读介质。该计算机可读介质上存储有计算机程序,其中,该程序被处理器执行时实现如上述实施例中任一智能合约编译方法中的步骤。According to an embodiment of the present disclosure, a computer-readable medium is further provided. The computer-readable medium stores a computer program, wherein when the program is executed by a processor, the steps in any smart contract compilation method in the above-mentioned embodiment are implemented.
特别地,根据本公开实施例,上文参考流程图描述的过程可以被实现为计算机软件程序。例如,本公开的实施例包括一种计算机程序产品,包括承载在机器可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分从网络上被下载和安装,和/或从可拆卸介质被安装。在该计算机程序被中央处理单元(CPU)执行时,执行本公开的系统中限定的上述功能。In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, including a computer program carried on a machine-readable medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part, and/or installed from a removable medium. When the computer program is executed by a central processing unit (CPU), the above-mentioned functions defined in the system of the present disclosure are executed.
需要说明的是,本公开所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本公开中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本公开中,计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、RF等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
附图中的流程图和框图,图示了按照本公开各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,前述模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of the code, and the aforementioned module, program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and/or flow chart, and the combination of the boxes in the block diagram and/or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
可以理解的是,以上实施方式仅仅是为了说明本公开的原理而采用的示例性实施方式,然而本公开并不局限于此。对于本领域内的普通技术人员而言,在不脱离本公开的精神和实质的情况下,可以做出各种变型和改进,这些变型和改进也视为本公开的保护范围。It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present disclosure, but the present disclosure is not limited thereto. For those of ordinary skill in the art, various modifications and improvements can be made without departing from the spirit and substance of the present disclosure, and these modifications and improvements are also considered to be within the scope of protection of the present disclosure.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410637556.5A CN118672588A (en) | 2024-05-22 | 2024-05-22 | Intelligent contract compiling method, system, electronic equipment and object code running method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410637556.5A CN118672588A (en) | 2024-05-22 | 2024-05-22 | Intelligent contract compiling method, system, electronic equipment and object code running method |
Publications (1)
Publication Number | Publication Date |
---|---|
CN118672588A true CN118672588A (en) | 2024-09-20 |
Family
ID=92721775
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202410637556.5A Pending CN118672588A (en) | 2024-05-22 | 2024-05-22 | Intelligent contract compiling method, system, electronic equipment and object code running method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118672588A (en) |
-
2024
- 2024-05-22 CN CN202410637556.5A patent/CN118672588A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9696966B2 (en) | Software development tool to automatically generate an optimized executable | |
US6463582B1 (en) | Dynamic optimizing object code translator for architecture emulation and dynamic optimizing object code translation method | |
US7536682B2 (en) | Method and apparatus for performing interpreter optimizations during program code conversion | |
US9015690B2 (en) | Proactive loop fusion of non-adjacent loops with intervening control flow instructions | |
KR101573586B1 (en) | Systems and methods for compiler-based vectorization of non-leaf code | |
US20110138373A1 (en) | Method and apparatus for globally optimizing instruction code | |
JPH04322329A (en) | Multi-model compatible information processing system and method | |
US20080052693A1 (en) | Method of simd-ization through data reshaping, padding, and alignment | |
US8886887B2 (en) | Uniform external and internal interfaces for delinquent memory operations to facilitate cache optimization | |
JP4833206B2 (en) | Generation of unwind information for optimized programs | |
US5854933A (en) | Method for optimizing a computer program by moving certain load and store instructions out of a loop | |
US20230113783A1 (en) | Cross-platform code conversion method and device | |
US20240134666A1 (en) | Hybrid just in time load module compiler with performance optimizations | |
US7200841B2 (en) | Method and apparatus for performing lazy byteswapping optimizations during program code conversion | |
US7784042B1 (en) | Data reordering for improved cache operation | |
US20030079211A1 (en) | Method and apparatus for maintaining exception reporting for register promotion | |
TWI743698B (en) | Method and device for interpreting execution byte code instruction stream | |
JP4093484B2 (en) | Compiler, compilation method, compilation program, and recording medium | |
CN118672588A (en) | Intelligent contract compiling method, system, electronic equipment and object code running method | |
Chambers et al. | Iterative type analysis and extended message splitting: Optimizing dynamically-typed object-oriented programs | |
JPH10320212A (en) | Optimization method for cache | |
CN118672587A (en) | Intelligent contract compiling method, system, electronic equipment and object code running method | |
CN118509159B (en) | A method and device for accelerating the execution of smart contracts based on just-in-time compilation | |
CN118672586A (en) | Program source code compiling method, system, electronic device and code running method | |
CN107562430A (en) | A kind of Compilation Method of file process function for mobile π algorithmic language |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |