Compiling method and related device

By transforming the abstract syntax tree nodes during the compilation process, and directly generating relevant code for serialized objects, the problem of excessive memory usage during serialization in the existing technology is solved, and the serialization efficiency is improved.

CN119493569APending Publication Date: 2025-02-21HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311033735.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-08-15
Publication Date
2025-02-21

AI Technical Summary

Technical Problem

The prior art occupies a lot of memory resources during the serialization process, affecting the normal operation of the serialization process.

Method used

By transforming nodes in the abstract syntax tree during the compilation process, the relevant code for serialized objects is directly generated, and the process of multiple object format conversions at runtime is avoided.

Benefits of technology

The memory resources occupied by the serialization process are reduced and the efficiency of the serialization process is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119493569A_ABST
    Figure CN119493569A_ABST
Patent Text Reader

Abstract

A compiling method is applied to a compiler. In the method, in the process of compiling a source code, after the source code is converted into an abstract syntax tree, aiming at a structure marked with a serialization format in the source code, nodes related to the structure in the abstract syntax tree are transformed, and the nodes indicating the related content of a serialization object are obtained through transformation. Therefore, the executable file is obtained after the subsequent compiling processing is executed on the transformed abstract syntax tree, and the object in the serialized format can be directly created and generated when the executable file runs, so that the process that the object in the programming language format is firstly created and then is converted for multiple times to obtain the object in the serialized format is avoided; it is guaranteed that only few memory resources need to be occupied in the serialization process, and the efficiency of the serialization process is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a compilation method and related devices. Background Art

[0002] With the innovation of technology and the increase in demand, more and more serialization protocols are constantly emerging. Different serialization protocols usually appear and become popular to solve problems in specific fields. The characteristics of serialization protocols being differentiated in different fields are becoming more and more obvious, so modern programming languages ​​also have higher requirements for the support of serialization protocols, that is, modern programming languages ​​need to better support multiple serialization protocols.

[0003] At present, in order to realize that a programming language supports a variety of different serialization protocols, the relevant technology is to realize the serialization of objects in the process of running the executable file after converting the source code written in the programming language into an executable file. Specifically, when running the executable file, an object in the programming language format is first created, and then the object in the programming language format is converted into an object in the basic type format, and finally the object in the basic type format is converted into an object in a specific serialization format, thereby realizing the serialization of the object. Since the relevant technology first converts the object in the programming language format into a general basic type format, and then converts the general basic type format into a specific serialization format, in actual applications, it is possible to effectively support a variety of different serialization protocols by extending the plug-in used to realize the conversion of the object in the basic type format into the object in the specific serialization format.

[0004] However, in the related art, when running an executable file, the generated objects need to be transformed multiple times, and copy conversions between objects of different formats will occur, which will cause more memory resources to be occupied during the serialization process, easily affecting the normal operation of the serialization process. Summary of the invention

[0005] The present application provides a compilation method that can reduce the memory resources occupied by the serialization process and improve the efficiency of the serialization process.

[0006] The first aspect of the present application provides a compilation method, which is applied to a compiler. In the method, a source code to be compiled is first obtained, and a first structure in the source code is marked with a corresponding first serialization format, and the first structure is used to indicate an object to be serialized. The first serialization format marked on the first structure is used to indicate that the object indicated by the first structure needs to be serialized in the first serialization format.

[0007] Then, an abstract syntax tree corresponding to the source code is generated, and the abstract syntax tree is used to represent the syntax structure of the source code. For example, the compiler performs a compilation process of lexical analysis, syntax analysis, and semantic analysis on the source code to generate an abstract syntax tree. The abstract syntax tree is a tree representation of the abstract syntax structure of the source code, and each node on the abstract syntax tree represents a structure in the source code.

[0008] Secondly, a transformation is performed on the first node corresponding to the first structure in the abstract syntax tree to obtain a transformed abstract syntax tree, wherein the transformed abstract syntax tree includes the transformed first node. The transformed first node is used to indicate content related to the serialized object, rather than indicating a syntax structure corresponding to the first structure, thereby realizing the conversion from the programming language to the serialization format.

[0009] Finally, the transformed abstract syntax tree is compiled to obtain an executable file, which is used to generate a serialized object related to the first structure at runtime, and the format of the serialized object is the first serialization format. The transformed first node indicates the content related to the serialized object, so in the subsequent compilation process of the transformed abstract syntax tree, the content related to the serialized object will be converted into the relevant code for generating the serialized object, that is, the executable file will include the relevant code for producing the serialized object. In this way, when the executable file is run, the serialized object related to the first structure can be directly generated based on the relevant code in the executable file, and the generated serialized object is the first serialization format marked at the first structure.

[0010] In this solution, during the process of compiling the source code, after converting the source code into an abstract syntax tree, for the structure in the source code marked with the serialization format, the nodes in the abstract syntax tree related to this part of the structure are transformed, and the nodes indicating the content related to the serialized object are obtained by transformation. In this way, after the subsequent compilation process is performed on the transformed abstract syntax tree, an executable file is obtained, and the executable file can directly create and generate objects in the serialized format when running, avoiding the process of first creating an object in the programming language format and then converting it multiple times to obtain the object in the serialized format, ensuring that the serialization process only needs to occupy less memory resources and improving the efficiency of the serialization process.

[0011] In a possible implementation, the first structure is used to define a target class. The target class is a class defined in the source code, and the target class is used to indicate the type of the object to be serialized. The transformed first node is used to indicate the first function, and the first function is used to create a serialized object related to the target class. In this way, when executing the executable file, the serialized object can be directly created by calling the first function indicated by the transformed first node, without having to create an object in the programming language format again and then perform the object format conversion.

[0012] In this solution, by transforming the nodes in the abstract syntax tree into nodes indicating the serialized object creation function, the content related to the object to be serialized in the source code can be converted into the creation of the serialized object during the compilation process, so that the compiled executable file can include the content of directly creating the serialized object, ensuring that the executable file can directly create the serialized object at runtime, improving the efficiency of the serialization process and reducing the resources occupied by the serialization process.

[0013] In a possible implementation, the transformed first node is further used to indicate a second function and / or a third function, the second function is used to access a serialized object created based on the first function, and the third function is used to modify a serialized object created based on the first function. In this way, when executing the executable file, the serialized object can be accessed or modified by calling the second function or the third function indicated by the transformed first node.

[0014] In practical applications, the first node can be transformed into multiple sub-nodes, that is, the transformed first node includes multiple sub-nodes, and different sub-nodes are used to indicate different functions. For example, the transformed first node includes a first sub-node, a second sub-node, and a third sub-node, the first sub-node is used to indicate the first function, the second sub-node is used to indicate the second function, and the third sub-node is used to indicate the third function.

[0015] In this solution, by transforming the nodes in the abstract syntax tree into nodes that can also indicate functions for accessing / modifying serialized objects, it can be ensured that the compiled executable file can also have the function of accessing / modifying serialized objects at runtime, ensuring that the serialization process performed during the compilation process does not affect the normal implementation of the functions indicated by the source code, thereby ensuring the feasibility of the solution.

[0016] In a possible implementation, in the process of transforming the nodes in the abstract syntax tree, the second node in the abstract syntax tree is also transformed, so that the transformed abstract syntax tree includes the transformed second node. That is, both the first node and the second node in the abstract syntax tree need to be transformed, so as to obtain the corresponding transformed first node and transformed second node.

[0017] Among them, the second node corresponds to the second structure in the source code, the second structure is used to indicate the use of the target class defined in the first structure, and the transformed second node is used to indicate the call of the function indicated in the transformed first node, so as to realize the use of the serialized object, such as the creation, access or modification of the serialized object.

[0018] In one possible implementation, the transformed abstract syntax tree is compiled to obtain an executable file, including: compiling the transformed abstract syntax tree to obtain a target file; linking the target file with a library file to obtain an executable file, wherein the library file includes the content of the function indicated by the transformed first node.

[0019] In this solution, by placing the content related to serialized object creation in a library file and obtaining the final executable file by linking the library file, it can be ensured that the executable file can include the function content related to serialized object creation, and the usability of the solution is ensured and the expansion of the compiler is easy to implement.

[0020] In one possible implementation, in the process of the compiler performing a transformation on the first node corresponding to the first structure in the abstract syntax tree, the compiler may first load the extension plug-in corresponding to the first serialization format according to the first serialization format marked by the first structure; then, the compiler performs a transformation on the first node corresponding to the first structure in the abstract syntax tree by executing the extension plug-in to obtain the transformed first node. In other words, the operation of performing a transformation on the first node in the abstract syntax tree may be performed by the extension plug-in loaded by the compiler. That is, the compiler may follow the design in the prior art without redesigning the compiler, but may newly design an extension plug-in corresponding to the first serialization format, and implement a process different from the existing compilation process by loading this extension plug-in.

[0021] In this solution, the node transformation process in the abstract syntax tree is implemented by loading an extension plug-in on the compiler, which can avoid changes to the existing compiler. Instead, the existing compilation process is adjusted by adding a new extension plug-in, so that the serialized object can be directly created in the end, which reduces the changes to the existing technology and ensures the flexibility and scalability of the solution.

[0022] In a possible implementation, the extension plug-in is also used to compile the transformed first node in the transformed abstract syntax tree to obtain an executable file. That is, in the executable file, the code content corresponding to the transformed first node is actually processed by the extension plug-in loaded in the compiler. In addition, for the nodes in the transformed abstract syntax tree that have not been transformed, the original part of the compiler can be used to perform compilation processing.

[0023] In this solution, an extension plug-in is loaded on the compiler to implement the node transformation process in the abstract syntax tree and perform subsequent compilation processing on the transformed nodes. An extension plug-in can be implemented to complete all compilation processes that need to be modified, avoiding changes to the existing compiler. Instead, the existing compilation process is adjusted by adding a new extension plug-in, so as to achieve the final direct creation of serialized objects, reduce changes to existing technologies, and ensure the flexibility and scalability of the solution.

[0024] In a possible implementation, the extension plug-in is further used to report an error when a marking error is detected, where the marking error is that an object indicated by a structure marked with a serialization format in the source code cannot be converted into a serialized object under the marked serialization format.

[0025] In this solution, by using the extension plug-in to identify whether there is a structure with a serialization format mark error in the source code during the compilation process, it is possible to promptly discover the incorrectly written parts of the source code during the compilation process of the source code, so that developers can adjust the source code in a timely manner. In addition, compared with the related art that performs the object serialization process when running the executable file, this solution checks whether the object indicated in the source code can be converted into a serialized object during the compilation process, which can discover the incorrect parts of the source code earlier and ensure that the executable file can run smoothly.

[0026] In a possible implementation, the method is applied to a compiler, in which multiple extension plug-ins are deployed, and different extension plug-ins correspond to different serialization formats. That is, different extension plug-ins can be used to compile structures marked with different serialization formats in source code, so as to obtain executable files that can directly create serialized objects of different serialization formats.

[0027] In this solution, corresponding extension plug-ins are deployed for different serialization protocols, so that the compiler can process source code structures marked with different serialization formats by loading different extension plug-ins, ensuring that the programming language can effectively support multiple serialization protocols, ensuring the scalability of the solution, and achieving the effect of supporting user-defined extended serialization protocol support.

[0028] In a possible implementation, the source code also includes a third structure marked with a second serialization format, and the method also includes: performing a transformation on a third node corresponding to the third structure in an abstract syntax tree so that the transformed abstract syntax tree includes the transformed third node, and the transformed third node is used to indicate content related to the serialized object; compiling the transformed abstract syntax tree to obtain an executable file, and the executable file is used to generate a serialized object related to the first structure and a serialized object related to the third structure at runtime, and the format of the serialized object related to the third structure is the second serialization format.

[0029] In this solution, by performing different compilation processes on structures marked with different serialization formats in the source code, the final executable file can directly create serialized objects in different serialization formats, ensuring that the solution can meet the diversity requirements in different scenarios.

[0030] The second aspect of the present application provides a compilation device, including: an acquisition module, used to obtain source code to be compiled, a first structure in the source code is marked with a corresponding first serialization format, and the first structure is used to indicate an object to be serialized; a compilation module, used to generate an abstract syntax tree corresponding to the source code, the abstract syntax tree is used to represent the syntax structure of the source code; the compilation module is also used to transform the first node corresponding to the first structure in the abstract syntax tree to obtain a transformed abstract syntax tree, the transformed abstract syntax tree includes the transformed first node, and the transformed first node is used to indicate content related to the serialization object; the compilation module is also used to compile the transformed abstract syntax tree to obtain an executable file, the executable file is used to generate a serialization object related to the first structure at runtime, and the format of the serialization object is the first serialization format.

[0031] In a possible implementation, the first structure is used to define a target class class, which is used to indicate the type of an object to be serialized; the transformed first node is used to indicate a first function, which is used to create a serialized object related to the target class.

[0032] In a possible implementation, the transformed first node is further used to indicate a second function and / or a third function, the second function is used to access a serialized object created based on the first function, and the third function is used to modify the serialized object created based on the first function.

[0033] In one possible implementation, the compilation module is also used to: transform the second node in the abstract syntax tree so that the transformed abstract syntax tree includes the transformed second node; wherein the second node corresponds to a second structure in the source code, the second structure is used to indicate the use of the target class defined in the first structure, and the transformed second node is used to indicate the call of the function indicated in the transformed first node.

[0034] In a possible implementation, the compilation module is further used to: compile the transformed abstract syntax tree to obtain a target file; link the target file with a library file to obtain an executable file, wherein the library file includes the content of the function indicated by the transformed first node.

[0035] In a possible implementation, the compilation module is also used to: load an extension plug-in corresponding to the first serialization format marked by the first structure; and transform the first node corresponding to the first structure in the abstract syntax tree by executing the extension plug-in to obtain the transformed first node.

[0036] In a possible implementation, the extension plug-in is further used to compile the transformed first node in the transformed abstract syntax tree to obtain an executable file.

[0037] In a possible implementation, the extension plug-in is further used to report an error when a marking error is detected, where the marking error is that an object indicated by a structure marked with a serialization format in the source code cannot be converted into a serialized object under the marked serialization format.

[0038] In a possible implementation, the compiling device is a compiler, a plurality of extension plug-ins are deployed in the compiler, and different extension plug-ins correspond to different serialization formats.

[0039] In a possible implementation, the source code also includes a third structure marked with a second serialization format, and the compilation module is further used to: perform a transformation on a third node corresponding to the third structure in the abstract syntax tree so that the transformed abstract syntax tree includes the transformed third node, and the transformed third node is used to indicate content related to the serialized object; compile the transformed abstract syntax tree to obtain an executable file, and the executable file is used to generate a serialized object related to the first structure and a serialized object related to the third structure at runtime, and the format of the serialized object related to the third structure is the second serialization format.

[0040] A third aspect of the present application provides a compilation device, which includes: a memory and a processor; the memory stores code, and the processor is configured to execute the code. When the code is executed, the compilation device executes a method as in any one of the implementation modes of the first aspect.

[0041] A fourth aspect of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer-readable storage medium is run on a computer, the computer executes a method as in any one of the implementation modes of the first aspect.

[0042] A fifth aspect of the present application provides a computer program product, which, when executed on a computer, enables the computer to execute a method as in any one of the implementation modes of the first aspect.

[0043] In a sixth aspect, the present application provides a chip, comprising one or more processors, wherein some or all of the processors are used to read and execute a computer program stored in a memory to execute the method in any one of the implementations of the first aspect.

[0044] Optionally, the chip includes a memory, and the memory is connected to the processor through a circuit or wire. Optionally, the chip also includes a communication interface, and the processor is connected to the communication interface. The communication interface is used to receive data and / or information to be processed, and the processor obtains the data and / or information from the communication interface, processes the data and / or information, and outputs the processing results through the communication interface. The communication interface can be an input and output interface. The method provided in the present application can be implemented by one chip, or by multiple chips in collaboration.

[0045] Among them, the technical effects brought about by any design method in the second to sixth aspects can refer to the technical effects brought about by different implementation methods in the above-mentioned first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] Figure 1 A schematic diagram of a serialization process provided in an embodiment of the present application;

[0047] Figure 2 A schematic diagram of the structure of an electronic device 101 provided in an embodiment of the present application;

[0048] Figure 3 A flowchart of a compilation method provided in an embodiment of the present application;

[0049] Figure 4 A schematic diagram of a node transformation provided in an embodiment of the present application;

[0050] Figure 5 A flowchart for directly creating a serialized object at runtime provided by an embodiment of the present application;

[0051] Figure 6 A schematic diagram of a multi-stage implementation process provided for an embodiment of the present application;

[0052] Figure 7 A schematic diagram of the system architecture of a compiler provided in an embodiment of the present application;

[0053] Figure 8 A schematic diagram of the structure of a compiling device provided in an embodiment of the present application;

[0054] Fig. 9 A schematic diagram of the structure of an execution device provided in an embodiment of the present application;

[0055] Fig.10 A schematic diagram of the structure of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION

[0056] In order to make the purpose, technical solutions and advantages of the present application clearer, the embodiments of the present application are described below in conjunction with the accompanying drawings. Obviously, the described embodiments are only embodiments of a part of the present application, rather than all embodiments. It is known to those of ordinary skill in the art that with the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0057] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the descriptions used in this way can be interchanged where appropriate, so that the embodiments can be implemented in a sequence other than that illustrated or described in the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or modules is not necessarily limited to those steps or modules that are clearly listed, but may include other steps or modules that are not clearly listed or inherent to these processes, methods, products or devices. The naming or numbering of the steps that appear in the present application does not mean that the steps in the method flow must be executed in the time / logical sequence indicated by the naming or numbering. The process steps that have been named or numbered can change the execution order according to the technical purpose to be achieved, as long as the same or similar technical effects can be achieved.

[0058] The division of units in this application is a logical division. There may be other division methods when it is implemented in actual applications. For example, multiple units can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection between units can be electrical or other similar forms, which are not limited in this application. In addition, the units or sub-units described as separate components may or may not be physically separated, may or may not be physical units, or may be distributed in multiple circuit units, and some or all of the units may be selected according to actual needs to achieve the purpose of the present application.

[0059] To facilitate understanding, some technical terms involved in the embodiments of the present application are first introduced below.

[0060] (1) Source code

[0061] Source code refers to an uncompiled text file written in a certain programming language specification. It is a series of human-readable computer language instructions. In modern programming languages, source code can appear in the form of books or tapes, but the most common format is a text file. The purpose of this typical format is to compile a computer program. The ultimate goal of computer source code is to translate human-readable text into binary instructions that can be executed by a computer. This process is called compilation and is completed by a compiler.

[0062] (2) Executable file

[0063] An executable file is a file that can be run directly on a computer.

[0064] (3) Compilation (compilation, compile)

[0065] Compilation is the process of converting source code into executable files using a compiler. In simple terms, compilation is the process of converting source code written in a high-level language into a binary language that a computer can recognize. Since computers only recognize 1 and 0, the compiler actually converts the language that people are familiar with into binary.

[0066] Generally speaking, the process of a compiler translating a source code into an executable file is divided into five stages: lexical analysis; syntax analysis; semantic analysis and intermediate code generation; code optimization; and target code generation.

[0067] (4) Abstract syntax tree (AST)

[0068] An abstract syntax tree is a tree representation of the abstract syntax structure of the source code. Each node on the abstract syntax tree represents a structure in the source code. The syntax is abstract because it does not represent every detail that appears in the real syntax, but only the details that are relevant to the structure or content. For example, grouping brackets are implicit in the tree structure, so these brackets do not need to be represented as separate nodes.

[0069] Abstract syntax tree is a data structure widely used in compilers to represent the structure of source code. Abstract syntax tree is usually the result of the syntax analysis phase of a compiler, so it is often used as an intermediate representation of the program. As an important intermediate representation of the program, the basic formation process of abstract syntax tree can be roughly divided into three steps, namely, firstly, lexical analysis of the source code, grammatical analysis of the word stream generated by lexical analysis, and finally semantic analysis to form the abstract syntax tree of the source code.

[0070] (5)Serialization

[0071] Serialization is the process of converting an object's state information into a form that can be stored or transmitted. During serialization, an object writes its current state to a temporary or persistent storage area. Later, the object can be recreated by reading or deserializing the object's state from the storage area. Deserialization is the process of rebuilding the object in its original form.

[0072] Generally speaking, different serialization protocols describe different data serialization formats, and different formats have different performance in terms of space and performance. Common serialization formats include json, XML, FlatBuffers, FlexBuffers, etc.

[0073] (6) Serialized objects

[0074] A serialized object is an object stored in memory in a specific format (i.e., serialized format).

[0075] (7) Class

[0076] A class is a user-defined reference data type and is the basis for information encapsulation in object-oriented programming (OOP). Generally speaking, each class contains a data description and a set of functions that operate on data or pass messages. An instance of a class is called an object, that is, a class can be instantiated into an object.

[0077] The class encapsulates properties and methods to operate its own members. A class is a definition of an object with behavior. It describes what an object can do and how it does it. These are programs and processes that can operate on the object. It contains information about how the object behaves, including its name, properties, methods, and events.

[0078] The composition of a class includes member attributes and member methods (data members and member functions). Data members correspond to the attributes of a class. The data members of a class are also a data type and do not require memory allocation. Member functions are used to operate the attributes of a class. They are unique operations of a class, such as "students" can "attend classes", but "fruits" cannot. The operation of interaction between a class and the outside world is called an interface.

[0079] (8) Static linking

[0080] Static linking is the practice of adding the contents of a library to an executable program at link time by a linker. A linker is a separate program that links one or more library files and the object files generated by the compiler together to generate an executable file.

[0081] (9) Dynamic Linking

[0082] Dynamic linking means that the compilation system does not link the target file and the function library file together during the linking stage, but waits until the program needs to use it during operation to link the function library. In other words, dynamic linking is relative to static linking. Dynamic linking occurs when the program is running, while static linking occurs when the program is compiled.

[0083] Specifically, in the case of dynamic linking, the executable file generated by the compiler does not include the specific execution code of the required function, but indicates the relevant information of the required function. In this way, during the execution of the executable file, the execution code of the function can be obtained from the additionally loaded function library based on the relevant information of the function.

[0084] (10) Interface description language (IDL)

[0085] IDL is a computer language used to describe software component interfaces. IDL describes interfaces in a neutral way so that objects running on different platforms and programs written in different languages ​​can communicate with each other; for example, one component is written in C++ and another component is written in Java.

[0086] At present, the serialization process in the related art is mainly performed at runtime. For example, see Figure 1 , Figure 1A schematic diagram of a serialization process provided in an embodiment of the present application. Figure 1 As shown, when the compiled executable file is run, an object in the programming language format is first created in memory area 1, and then the object in the programming language format is copied and transformed, so as to obtain an object in the basic type format in memory area 2, and finally the object in the basic type format in memory area 2 is copied and transformed again, so as to obtain an object in a specific serialization format in memory area 3, thereby realizing the serialization of the object.

[0087] Although the related technology can easily implement programming language support for multiple serialization protocols, in the process of running the executable file in the related technology, it is necessary to perform multiple transformations on the generated objects, and copy conversions between objects of different formats will occur, which will result in more memory resources being occupied during the serialization process, easily affecting the normal operation of the serialization process.

[0088] The data transmission method provided in the embodiment of the present application can be applied to an electronic device equipped with a compiler, for example, a server, a mobile phone, a personal computer (PC), a laptop, a tablet computer, etc.

[0089] See also Figure 2 , Figure 2 Schematic diagram of the structure of an electronic device 101 provided in an embodiment of the present application. Figure 3 As shown, the electronic device 101 includes a processor 103, which is coupled to a system bus 105. The processor 103 may be one or more processors, each of which may include one or more processor cores. A display adapter (video adapter) 107, which may drive a display 109, which is coupled to the system bus 105. The system bus 105 is coupled to an input / output (I / O) bus via a bus bridge 111. An I / O interface 115 is coupled to the I / O bus. The I / O interface 115 communicates with a variety of I / O devices, such as an input device 117 (such as a touch screen, etc.), an external memory 121 (for example, a hard disk, a floppy disk, an optical disk or a USB flash drive), a multimedia interface, etc.). A transceiver 123 (which may send and / or receive radio communication signals), a camera 155 (which may capture static and dynamic digital video images), and an external USB port 125. Optionally, the interface connected to the I / O interface 115 may be a USB interface.

[0090] The processor 103 may be any conventional processor, including a reduced instruction set computing (RISC) processor, a complex instruction set computing (CISC) processor, or a combination thereof. Alternatively, the processor may be a dedicated device such as an ASIC.

[0091] The electronic device 101 can communicate with the software deployment server 149 through the network interface 129. Exemplarily, the network interface 129 is a hardware network interface, such as a network card. The network 127 can be an external network, such as the Internet, or an internal network, such as Ethernet or a virtual private network (VPN). Optionally, the network 127 can also be a wireless network, such as a WiFi network, a cellular network, etc.

[0092] The hard disk drive interface 131 is coupled to the system bus 105. The hard disk drive interface is connected to the hard disk drive 133. The internal memory 135 is coupled to the system bus 105. The data running in the internal memory 135 may include an operating system (OS) 137 of the electronic device 101, an application 143, and a scheduler.

[0093] The operating system includes a shell 139 and a kernel 141. Shell 139 is an interface between the user and the kernel of the operating system. The shell is the outermost layer of the operating system. The shell manages the interaction between the user and the operating system: waiting for user input, interpreting user input to the operating system, and processing various operating system output results.

[0094] The kernel 141 consists of those parts of the operating system that manage memory, files, peripherals, and system resources. The kernel 141 interacts directly with the hardware. The operating system kernel usually runs processes and provides communication between processes, provides CPU time slice management, interrupts, memory management, IO management, etc.

[0095] The following will describe in detail the compilation method provided by the embodiment of the present application. Figure 3 , Figure 3 A flowchart of a compilation method provided in an embodiment of the present application is shown in FIG. Figure 3 As shown, the compilation method includes the following steps 301-304.

[0096] Step 301: Obtain source code to be compiled, wherein a first structure in the source code is marked with a corresponding first serialization format, and the first structure is used to indicate an object to be serialized.

[0097] In this embodiment, source code refers to an uncompiled text file written in accordance with a certain programming language specification, which is a series of human-readable computer language instructions. Exemplarily, the source code can be a code written in a programming language such as java, kotlin, c, c++, python, etc. This embodiment does not limit the programming language used to write the source code.

[0098] Furthermore, in the source code, a mark may be used to indicate an object that needs to be serialized. Specifically, a first structure in the source code is marked with a first serialization format to indicate that the object indicated by the first structure needs to be serialized in the first serialization format.

[0099] The first serialization format marked by the first structure can be any serialization format, such as json, XML, FlatBuffers, FlexBuffers, etc., which is not specifically limited here. For example, the first structure can be marked with @Serializable[json] to indicate that the object indicated by the first structure needs to be serialized into json format.

[0100] Step 302: Generate an abstract syntax tree corresponding to the source code, where the abstract syntax tree is used to represent the syntax structure of the source code.

[0101] In the process of compiling the source code, the source code can be compiled through multiple steps such as lexical analysis, syntax analysis and semantic analysis to generate an abstract syntax tree corresponding to the source code. Among them, the abstract syntax tree is a tree representation of the abstract syntax structure of the source code, and each node on the abstract syntax tree represents a structure in the source code. Simply put, the abstract syntax tree is obtained after analyzing the syntax structure of the source code, and can represent the syntax structure in the source code in the form of a tree to facilitate the subsequent compilation process.

[0102] Step 303: transform the first node corresponding to the first structure in the abstract syntax tree to obtain a transformed abstract syntax tree, wherein the transformed abstract syntax tree includes the transformed first node, and the transformed first node is used to indicate content related to the serialized object.

[0103] In this embodiment, the first node in the abstract syntax tree is used to represent the first structure in the source code, and the first structure is used to indicate the object to be serialized. Therefore, the first node in the abstract syntax tree is transformed to indicate the content related to the serialized object, so that the original first node in the abstract syntax tree can be transformed into a node related to the serialized object, for example, the first node is transformed into a node for creating a serialized object. In this way, in the transformed abstract syntax tree, the transformed first node is actually used to indicate the content related to the serialized object, and no longer indicates the grammatical structure corresponding to the first structure, thereby realizing the conversion from programming language to serialization format.

[0104] The serialization format corresponding to the serialization object indicated by the transformed first node is the first serialization format, that is, the transformed first node actually indicates the content related to the serialization object in the first serialization format.

[0105] It should be noted that in this embodiment, only the nodes corresponding to the structures marked with the serialization format in the source code are transformed, and the nodes corresponding to the structures not marked with the serialization format in the source code in the abstract syntax tree are not transformed, that is, only the nodes corresponding to the objects that need to be serialized specified in the source code are transformed.

[0106] Step 304 , compile the transformed abstract syntax tree to obtain an executable file, where the executable file is used to generate a serialized object related to the first structure at runtime, and the format of the serialized object is the first serialization format.

[0107] After the transformation of the nodes of the abstract syntax tree is performed, the subsequent compilation process can be continued on the transformed abstract syntax tree to obtain the final executable file. Since in the transformed abstract syntax tree, the transformed first node indicates the content related to the serialized object, in the subsequent compilation process of the transformed abstract syntax tree, the content related to the serialized object will be converted into the relevant code for generating the serialized object, that is, the executable file will include the relevant code for producing the serialized object. In this way, when running the executable file, the serialized object related to the first structure can be directly generated based on the relevant code in the executable file, and the generated serialized object is the first serialization format marked at the first structure.

[0108] In the process of compiling the source code, after converting the source code into an abstract syntax tree, for the structure marked with the serialization format in the source code, the nodes in the abstract syntax tree related to this part of the structure are transformed, and the transformation obtains the nodes indicating the relevant content of the serialized object. In this way, after the subsequent compilation process is performed on the transformed abstract syntax tree, an executable file is obtained, and the executable file can directly create and generate objects in the serialized format at runtime, avoiding the process of first creating an object in the programming language format and then converting it multiple times to obtain the object in the serialized format, ensuring that the serialization process only takes up less memory resources. In addition, this solution is mainly executed during the compilation process of the source code, and can directly generate serialized objects at runtime, effectively improving the serialization efficiency when running the executable file.

[0109] For ease of understanding, the following describes in detail how to perform transformations on nodes in the abstract syntax tree.

[0110] Exemplarily, in the source code, the first structure is used to define a target class. The target class is a class defined in the source code, and the target class is used to indicate the type of object to be serialized. Generally speaking, an instance of a class is called an object, that is, a class can be instantiated into an object. Specifically, a class is a definition of a certain object, has behavior, and can describe what an object can do and how to do it. The class defines the procedures and processes for operating this object. The class contains information about the behavior of the object, including the name, properties, methods, and events of the object.

[0111] In general, the first structure defines the target class, and the target class is the definition of the object to be serialized. Therefore, for the first node representing the first structure in the abstract syntax tree, the first node can be transformed based on the content of the first structure represented by the first node, so that the transformed first node can directly represent the relevant content of the serialized object, and the serialized object is the object transformed after the object indicated in the first structure is serialized. In other words, in the transformation process of the first node, the content defined by the first structure corresponding to the first node is actually referenced. After knowing the type of the object indicated by the first structure, it can be determined what the serialized object obtained after the object indicated by the first structure is serialized is specifically like, so that the content of the first node is transformed into the content that directly creates this serialized object.

[0112] Specifically, the transformed first node is used to indicate the first function, and the first function is used to create a serialized object related to the target class. In this way, when executing the executable file, the serialized object can be directly created by calling the first function indicated by the transformed first node, without having to create an object in the programming language format again and then perform the object format conversion.

[0113] In this solution, by transforming the nodes in the abstract syntax tree into nodes indicating the serialized object creation function, the content related to the object to be serialized in the source code can be converted into the creation of the serialized object during the compilation process, so that the compiled executable file can include the content of directly creating the serialized object, ensuring that the executable file can directly create the serialized object at runtime, improving the efficiency of the serialization process and reducing the resources occupied by the serialization process.

[0114] Optionally, in order not to affect the subsequent use of the serialized object, the transformed first node is also used to indicate a second function and / or a third function, the second function is used to access the serialized object created based on the first function, and the third function is used to modify the serialized object created based on the first function. In this way, when the executable file is executed, the serialized object can be accessed or modified by calling the second function or the third function indicated by the transformed first node.

[0115] In practical applications, the first node can be transformed into multiple sub-nodes, that is, the transformed first node includes multiple sub-nodes, and different sub-nodes are used to indicate different functions. For example, the transformed first node includes a first sub-node, a second sub-node, and a third sub-node, the first sub-node is used to indicate the first function, the second sub-node is used to indicate the second function, and the third sub-node is used to indicate the third function.

[0116] In this solution, by transforming the nodes in the abstract syntax tree into nodes that can also indicate functions for accessing / modifying serialized objects, it can be ensured that the compiled executable file can also have the function of accessing / modifying serialized objects at runtime, ensuring that the serialization process performed during the compilation process does not affect the normal implementation of the functions indicated by the source code, thereby ensuring the feasibility of the solution.

[0117] Optionally, in the process of transforming the nodes in the abstract syntax tree, the second node in the abstract syntax tree is also transformed so that the transformed abstract syntax tree includes the transformed second node. That is, both the first node and the second node in the abstract syntax tree need to be transformed to obtain the corresponding transformed first node and transformed second node.

[0118] The second node corresponds to a second structure in the source code, the second structure is used to indicate the use of the target class defined in the first structure, and the transformed second node is used to indicate the call of the function indicated in the transformed first node.

[0119] Specifically, in the source code, the first structure actually defines the type of object that needs to be serialized (not involving operations on the object), while the second structure indicates how to use the object defined by the first structure (i.e., how to operate the object). For example, the second structure may indicate the creation of the object defined by the first structure, or the access to the object defined by the first structure, or the modification of the object defined by the first structure.

[0120] In the case where the transformed first node indicates a function related to the serialized object, the transformed second node may include content of a function call, that is, the transformed second node indicates calling the function indicated in the transformed first node, thereby realizing the use of the serialized object, such as creation, access or modification of the serialized object.

[0121] For example, see Figure 4 , Figure 4 A schematic diagram of a node transformation provided in an embodiment of the present application. Figure 4 As shown, Figure 4 The code shown on the left is the source code, and the source code includes two structures. The structure represented by the code above the source code is the class definition structure (corresponding to the first structure mentioned above), which is used to define the class Rectangle; the structure represented by the code below the source code is the class usage structure (corresponding to the second structure mentioned above), which is used to create a classRectangle object.

[0122] After transforming the node representing the class definition structure in the abstract syntax tree, the transformed node is used to indicate the creation function of the serialized object (i.e. Figure 4 The constructor shown in ), the access function of the serialized object (i.e. Figure 4 ) and the modification function of the serialized object (i.e. Figure 4 Reading member variables as shown in ), where the serialized object is the serialized object corresponding to the class Rectangle object.

[0123] After transforming the node representing the class usage structure in the abstract syntax tree, the transformed node is used to indicate the call to the creation function of the above serialized object (i.e. Figure 4 ) as shown in the constructor call in .

[0124] In simple terms, when the compiler recognizes the use of Class Rectangle, it transforms the creation of the original programming language object Rectangle(1,2) into calling the creation function of the above serialized object, thereby directly creating the serialized object and avoiding the creation of the original programming language object.

[0125] Optionally, in the process of the compiler performing a transformation on the first node corresponding to the first structure in the abstract syntax tree, the compiler may first load an extension plug-in corresponding to the first serialization format according to the first serialization format marked by the first structure; then, the compiler performs a transformation on the first node corresponding to the first structure in the abstract syntax tree by executing the extension plug-in to obtain the transformed first node. In other words, the operation of performing a transformation on the first node in the abstract syntax tree may be performed by the extension plug-in loaded by the compiler. That is, the compiler may follow the design in the prior art without redesigning the compiler, but may newly design an extension plug-in corresponding to the first serialization format, and implement a process different from the existing compilation process (i.e., the process of performing a transformation on the nodes in the abstract syntax tree) by loading this extension plug-in.

[0126] In this solution, the node transformation process in the abstract syntax tree is implemented by loading an extension plug-in on the compiler, which can avoid changes to the existing compiler. Instead, the existing compilation process is adjusted by adding a new extension plug-in, so that the serialized object can be directly created in the end, which reduces the changes to the existing technology and ensures the flexibility and scalability of the solution.

[0127] Optionally, the extension plug-in loaded on the compiler is also used to compile the transformed first node in the transformed abstract syntax tree to obtain an executable file. Since in the transformed abstract syntax tree, the transformed first node is used to indicate the relevant content of the serialized object, and the serialized object corresponds to a specific serialization format, the original design in the compiler is often difficult to perform subsequent compilation processing on the transformed first node. Therefore, in this embodiment, the transformed first node is compiled by the extension plug-in loaded by the compiler to generate the code corresponding to the transformed first node. That is to say, in the executable file, the code content corresponding to the transformed first node is actually obtained by processing the extension plug-in loaded in the compiler. In addition, for the nodes in the transformed abstract syntax tree that have not been transformed, the original part of the compiler can be used to perform compilation processing.

[0128] In this solution, an extension plug-in is loaded on the compiler to implement the node transformation process in the abstract syntax tree and perform subsequent compilation processing on the transformed nodes. An extension plug-in can be implemented to complete all compilation processes that need to be modified, avoiding changes to the existing compiler. Instead, the existing compilation process is adjusted by adding a new extension plug-in, so as to achieve the final direct creation of serialized objects, reduce changes to existing technologies, and ensure the flexibility and scalability of the solution.

[0129] Optionally, multiple extension plug-ins are deployed in the compiler, and different extension plug-ins correspond to different serialization formats. That is, different extension plug-ins can be used to compile structures marked with different serialization formats in the source code, so as to obtain executable files that can directly create serialized objects of different serialization formats.

[0130] For example, for source code 1, if a certain structure in source code 1 is marked with serialization format 1, the compiler may load extension plug-in 1 corresponding to serialization format 1 to compile this part of the structure during the compilation process. For source code 2, if a certain structure in source code 2 is marked with serialization format 2, the compiler may load extension plug-in 2 corresponding to serialization format 2 to compile this part of the structure during the compilation process. Similarly, for structures in source code marked with different serialization formats, the compiler may find the corresponding extension plug-in among the deployed multiple extension plug-ins according to the marked serialization format, and implement the compilation of this part of the structure by executing the extension plug-in.

[0131] In this solution, corresponding extension plug-ins are deployed for different serialization protocols, so that the compiler can process source code structures marked with different serialization formats by loading different extension plug-ins, ensuring that the programming language can effectively support multiple serialization protocols, ensuring the scalability of the solution, and achieving the effect of supporting user-defined extended serialization protocol support.

[0132] Optionally, for the extension plug-in loaded in the compiler, the extension plug-in is also used to report an error when a tag error is detected. The tag error refers to the object indicated by the structure marked with a serialization format in the source code cannot be converted into a serialized object under the marked serialization format.

[0133] Specifically, for a specific serialization protocol, in the source code written in a programming language, the objects indicated by some structures in the source code (for example, objects defined by a class) may not be converted into serialized objects in the serialization format defined by the serialization protocol. That is, some objects indicated in the source code do not support the serialization process under a specific serialization protocol. In this case, the extension plug-in loaded by the compiler can be used to identify whether the object indicated by the structure marked with a serialization format in the source code can be converted into a serialized object in a corresponding format. If the object indicated by the structure marked with a serialization format in the source code cannot be converted into a serialized object in a corresponding format, it means that the source code is incorrectly written, so the extension plug-in reports an error in time to remind the developer of the source code to adjust the source code in time.

[0134] In this solution, by using the extension plug-in to identify whether there is a structure with a serialization format mark error in the source code during the compilation process, it is possible to promptly discover the incorrectly written parts of the source code during the compilation process of the source code, so that developers can adjust the source code in a timely manner. In addition, compared with the related art that performs the object serialization process when running the executable file, this solution checks whether the object indicated in the source code can be converted into a serialized object during the compilation process, which can discover the incorrect parts of the source code earlier and ensure that the executable file can run smoothly.

[0135] In some embodiments, different objects indicated in the same source code may also be converted to different serialization formats, that is, different structures in the source code may be marked with different serialization formats to indicate that different types of objects are converted to serialized objects in different serialization formats. In this case, nodes corresponding to different serialization formats may be transformed into corresponding serialization formats respectively, so that the final executable file can directly create serialized objects in different serialization formats.

[0136] For example, in the above Figure 3 In the embodiment described, the source code also includes a third structure marked with a second serialization format, and the third structure is also used to indicate an object to be serialized. Moreover, the objects indicated by the third structure and the first structure are different.

[0137] During the compilation process, after the abstract syntax tree corresponding to the source code is generated, the third node corresponding to the third structure in the abstract syntax tree can be transformed so that the transformed abstract syntax tree includes the transformed third node, and the transformed third node is used to indicate the content related to the serialized object. In addition, the format of the serialized object indicated by the transformed third node is different from that of the serialized object indicated by the transformed first node.

[0138] Then, the transformed abstract syntax tree is compiled to obtain an executable file, wherein the executable file is used to generate serialized objects related to the first structure and serialized objects related to the third structure at runtime, and the format of the serialized objects related to the third structure is the second serialization format.

[0139] During the compilation process, the compiler may load an extension plug-in corresponding to the second serialization format to implement the above-mentioned node transformation and compile the transformed third node.

[0140] In this solution, by performing different compilation processes on structures marked with different serialization formats in the source code, the final executable file can directly create serialized objects in different serialization formats, ensuring that the solution can meet the diversity requirements in different scenarios.

[0141] It is understandable that, since the present embodiment transforms the nodes in the abstract syntax tree into nodes indicating the relevant content of the serialized object, and finally enables the compiled executable file to directly generate the serialized object at runtime, during the compilation process of the source code, it is often necessary to prepare the content of the serialized object to be generated, that is, to prepare the specific content of the function indicated by the transformed node.

[0142] In this embodiment, in the transformed abstract syntax tree, there may be multiple ways to prepare the specific content of the function related to the serialization object indicated by the transformed node.

[0143] Implementation method 1: The transformed node indicates the specific content of the function related to the serialized object.

[0144] Specifically, during the process of transforming a node, the extension plug-in in the compiler prepares the specific contents included in the function indicated by the node in the transformed node, that is, the transformed node includes the specific contents of the first function, the second function, the third function, etc. In this way, during the subsequent compilation process of the transformed node, the specific contents of the function included in the transformed node can be converted into code in an executable file, so that the executable file includes the specific contents of the function related to the serialized object.

[0145] Implementation method 2: The transformed node only indicates the functions related to the serialized object, and the specific contents of the functions related to the serialized object are linked with the compiled target file in a static linking manner to obtain the final executable file.

[0146] Exemplarily, the transformed node is actually a declaration of a function related to the serialized object (such as the name of the function and other related information), but does not include the specific content of the function. In this way, after the compiler compiles the transformed abstract syntax tree, a target file is obtained; then, the target file is linked to the library file to obtain an executable file, wherein the library file includes the content of the function indicated by the transformed first node. In other words, the library file is a function library file, which includes the specific content of the function indicated by the transformed node. By linking the pre-prepared function library file with the compiled target file, an executable file including the function content related to the serialized object can be obtained, ensuring that the executable file can directly create a serialized object at runtime.

[0147] Implementation method 3: the transformed node only indicates the functions related to the serialized object, and the specific contents of the functions related to the serialized object are linked to the executable file in a dynamic linking manner.

[0148] In implementation 3, the transformed node is also a declaration of a function related to the serialized object, but does not include the specific content of the function. In the dynamic linking scenario, the executable file generated by the compiler does not include the specific execution code of the function related to the serialized object, but indicates the relevant information of the function related to the serialized object.

[0149] In addition, the runtime environment of the executable file needs to pre-deploy the function library required for dynamic linking. In this way, during the runtime of the executable file, the execution code of the function related to the serialized object can be obtained in the additionally loaded function library based on the relevant information of the function.

[0150] For ease of understanding, the execution process of the compilation method provided in the embodiment of the present application will be described in detail below with reference to specific examples.

[0151] See also Figure 5 , Figure 5 A flowchart for directly creating a serialized object at runtime is provided in an embodiment of the present application. Figure 5 As shown, in order to directly create a serialized object at runtime, the following steps 501-504 may be performed.

[0152] Step 501, according to the syntax of the programming language and the serialization protocol characteristics, specify the syntax rules corresponding to the serialization object in the programming language, and generate an extension plug-in.

[0153] During the development phase, you can specify alternative representations of serialized objects in a programming language based on the syntax of the programming language and the characteristics of the serialization protocol corresponding to the serialization process to be performed. That is, determine which grammatical structures in the programming language can be converted into serialized objects. If the serialization protocol A has a struct structure, refer to the following:

[0154] struct Vec3{

[0155] x: float;

[0156] y: float;

[0157] z: float;

[0158] }

[0159] The struct structure contains the type name, members and other structures, so it is necessary to find a corresponding specific structure with similar syntax in the programming language and mark it with specific syntax, such as @Serializable[flat], to distinguish it from programming language objects that do not need to be serialized. For example, a possible programming language is written as follows:

[0160] @Serializable[flat]

[0161] struct Vec3{

[0162] var x:Float;

[0163] var y:Float;

[0164] var z:Float;

[0165] }

[0166] In addition, when specifying grammatical rules, you need to pay attention to type mapping and other grammatical restrictions. For example, programming language objects may have more advanced grammatical abstractions such as generic syntax, while serialization protocol syntax usually does not have this grammatical feature. You can specify the rule: @Serializable[flat] cannot modify generic struct types. In this way, the compilation plug-in will recognize and report errors in the following scenarios:

[0167] @Serializable[flat]

[0168] struct Vec3 <t>{ / / error:@Serializable[flat]unsupport generic typedefine.

[0169] var x:Float;

[0170] var y:Float;

[0171] var z:Float;

[0172] var zz:T

[0173] }

[0174] After determining the grammatical rules corresponding to the serialized object in the programming language, an extension plug-in can be generated based on the relationship between the serialized object and the alternative representation in the programming language. The extension plug-in can support the identification of alternative representations in the programming language during the compilation phase and convert them into code related to the serialized object.

[0175] Step 502: Add an extension plug-in to the compiler.

[0176] In this step, developers can modify the structure of native language compilers that do not support extensions so that they can support loading extension plug-ins to process intermediate structures at each stage. For compilers that support loading extension plug-ins, there is no need to modify the structure of these compilers.

[0177] Generally, the processing of the syntax parser (Parser), semantic processing module (Sema), and code generation module (Codegen) at each stage of the compiler is a traversal process of different intermediate structures. After the Parser traverses the source code, it obtains the abstract syntax tree, and then performs several traversals on the abstract syntax tree to meet the input of the next stage; the type deduction and checking in Sema are also completed in several traversals of the abstract syntax tree, and the code generation of codegen also collects the required information in several intermediate structure traversals, and finally performs the executable file generation process. This step needs to be extended for the above process to support loading and executing specific user-defined traversal methods to handle the rule checking and conversion required to support multi-language serialization protocols. Specifically, this step can be to add an extension plug-in corresponding to the serialization protocol to the compiler, and the extension plug-in can support the rule checking and conversion required for multi-language serialization protocols in the above multiple processes.

[0178] Step 503: The compiler compiles the source code into an executable file that can directly create a serialized object by loading the extension plug-in.

[0179] This step is the process of compiler compiling source code, which needs to be performed after the previous two steps are completed. Based on the rules and extension framework, the various compiler steps of the serialization protocol are extended, including implementing specific syntax for the serialization protocol, such as the annotation @Serializable[flat]; implementing syntax and semantic restriction checks for the protocol, reporting errors in prohibited scenarios, and converting the syntax of the serialized object into a direct serialization object creation method or inline instruction in the correct scenario; generating the corresponding IDL description of the serialization protocol based on the @Serializable[flat] related definition for multi-language collaboration; and supporting conversion from existing IDL files to the corresponding @Serializable[flat] related host language code.

[0180] In general, in this step, the compiler compiles the source code into an executable file that can directly create a serialized object by loading an extension plug-in for a specific serialization protocol. The specific process can be referred to above. Figure 4 The embodiments described.

[0181] Step 504: Run the executable file to directly create a serialized object.

[0182] This step is performed at runtime, that is, after the executable file is compiled, the serialized object is directly created by running the executable file, without first creating the object of the programming language corresponding to the source code and then performing object conversion, thereby improving serialization efficiency.

[0183] See also Figure 6 , Figure 6 A schematic diagram of a multi-stage implementation process provided by an embodiment of the present application. Figure 6 As shown, in order to directly create serialized objects at runtime, there are three stages, namely the development stage, the compilation stage and the running stage.

[0184] During the development phase, when writing source code, program developers need to mark the objects that need to be serialized in the source code, and mark the serialization formats corresponding to the serialization processes that need to be performed on these objects. Compiler developers can develop extension plug-ins for each serialization protocol based on the syntax characteristics of the programming language and serialization protocol.

[0185] In the compilation phase, the compiler takes source code marked with serialization format as input, selects to load corresponding extension plug-ins according to the serialization format marked in the source code, and implements the compilation processing of objects marked with serialization format in the source code by executing the extension plug-ins. Specifically, the compiler includes multiple modules such as syntax parser, semantic processing module and code generation module, which are used to perform different processing in the compilation process.

[0186] Specifically, the program code for implementing the compilation method provided in this embodiment exists in the compiler (solidified part) and in a separate extension plug-in (extension part). When the compiler compiles the source code containing @Serializable[A], it will search and load the corresponding serialization protocol extension plug-in and perform specific serialization protocol processing on the type modified by @Serializable[A], thereby directly creating an object (i.e., a serialized object) that meets the corresponding serialization protocol A layout.

[0187] At runtime, serialized objects can be created directly by running the executable file.

[0188] See also Figure 7 , Figure 7 A schematic diagram of the system architecture of a compiler provided in an embodiment of the present application. Figure 7 As shown in the figure, the structure in the compiler is mainly divided into two types: fixed part and extended part. The fixed part refers to the part that is developed once and does not need to be changed as new serialization protocols are supported. The extended part refers to the part that needs to be extended for each new serialization protocol. Figure 7 Among them, infrastructure, annotation processing, built-in type parsing, built-in type support and other parts are solidified parts; extended json annotations, extended ProtoBuffer annotations, extended FlatBuffer annotations and other extended serialization protocol annotations, semantic checking, IDL generation, serialization object management and serialization compiler are extended parts, which are implemented by extension plug-ins.

[0189] In the compiler, the curing part includes the following parts.

[0190] 1. Infrastructure: Provides a series of grammar rules and definitions for extending serialization protocol support.

[0191] 2. Parser: Support for annotation syntax, parsing of specific forms such as @Serializable[json] or @Json. Among them, @Serializable[json] is a parameter-containing form, the parameter content is json, and the parameter check can be performed in the subsequent semantic (Sema) stage; @Json is a parameter-free form. If the latter form is used, the Parser processing needs to be adjusted to the extension part. In this embodiment, examples are given with parameter forms.

[0192] 3. Semantic processing part (Sema): Performs structural transformation of the inherent abstract syntax tree of objects modified by annotations such as @Serializable[flat], such as converting object creation and object member access into function calls with specific names. The content of the transformation depends on the serialization protocol. Specifically, Figure 4 The content shown explains the process of this structural transformation.

[0193] It should be noted that this form of conversion is not unique. Figure 4 In the example, the right-hand function is directly expanded into inline instructions in the subsequent compilation stage and optimized with the help of other common optimization methods in the industry. The key point is that the object creation and access on the left side are directly processed as serialized object creation and access at runtime, without other intermediate processes (such as copying objects in other formats, etc.).

[0194] 4. Compiler plug-in structure: This part is the inherent structure that the compiler needs to support. The processing of Parser, Sema, and Codegen in each stage of the compiler is a traversal process of different intermediate structures. Parser traverses the source code to obtain AST, and then performs several traversals on AST to meet the input of the next stage. The type deduction and checking in Sema are also completed in several traversals of AST. The code generation of codegen also collects the required information in several intermediate structure traversals, and finally performs the actual generation process. The above three processes all extend support for loading and executing specific user-defined traversal methods to extend support for the processing required for multi-language serialization protocols.

[0195] In the compiler, the extension part includes the following parts.

[0196] 1. The user's development paradigm, including the extended protocol syntax and a series of rules and definitions for the syntax. The detailed implementation depends on the design differences between the grammatical characteristics of the programming language and the serialization protocol to be implemented;

[0197] 2. The extended semantic check module (Sema) needs to perform semantic checks based on the development paradigm and rule definitions of the serialization protocol in the programming language (i.e., check the semantic rules related to serialization). In addition, it performs desugaring of functions such as serialization object creation, access or modification, and function calls.

[0198] 3. The code generation module (CodeGen) needs to generate the IDL file of the serialization protocol according to the source code programmed by the user, as well as the creation, access and life cycle management of the serialization protocol objects. Among them, IDL generation refers to the generation of serialization IDL and meta information based on the object layout information generated in the Sema stage. In addition, the IDL generation step is optional, and whether to execute the IDL generation step depends on the content of the source code.

[0199] Based on the compilation architecture and compilation method provided by this embodiment, in the case of the same source code and the serialization protocol to be converted, the scheme of the related technology and the scheme of this embodiment are respectively used to perform the serialization process. Among them, in the related technology, the executable file performs the serialization process at runtime. It is necessary to first create an object in the programming language format, and then perform the format conversion of the object to obtain the serialized object, which requires a total of 22MB of memory space. In this solution, the executable file directly creates a serialized object at runtime, and only occupies 8MB of memory space. From the above experimental comparison, it can be seen that when this solution runs an executable file to create a serialized object, the memory space occupied is close to 1 / 3 of that in the related technology, which effectively reduces the memory resources occupied by the serialization process and improves the efficiency of the serialization process.

[0200] The above embodiments introduce the compilation method provided by the embodiments of the present application. The following will introduce the device for executing the above compilation method.

[0201] See also Figure 8 , Figure 8 A schematic diagram of the structure of a compiling device provided in an embodiment of the present application. Figure 8 As shown, the compilation device includes: an acquisition module 801, which is used to obtain source code to be compiled, wherein a first structure in the source code is marked with a corresponding first serialization format, and the first structure is used to indicate an object to be serialized; a compilation module 802, which is used to generate an abstract syntax tree corresponding to the source code, and the abstract syntax tree is used to represent the syntax structure of the source code; the compilation module 802 is also used to transform the first node corresponding to the first structure in the abstract syntax tree to obtain a transformed abstract syntax tree, and the transformed abstract syntax tree includes a transformed first node, and the transformed first node is used to indicate content related to the serialization object; the compilation module 802 is also used to compile the transformed abstract syntax tree to obtain an executable file, and the executable file is used to generate a serialization object related to the first structure at runtime, and the format of the serialization object is the first serialization format.

[0202] In a possible implementation, the first structure is used to define a target class class, which is used to indicate the type of an object to be serialized; the transformed first node is used to indicate a first function, which is used to create a serialized object related to the target class.

[0203] In a possible implementation, the transformed first node is further used to indicate a second function and / or a third function, the second function is used to access a serialized object created based on the first function, and the third function is used to modify the serialized object created based on the first function.

[0204] In one possible implementation, the compilation module 802 is also used to: transform the second node in the abstract syntax tree so that the transformed abstract syntax tree includes the transformed second node; wherein the second node corresponds to a second structure in the source code, the second structure is used to indicate the use of the target class defined in the first structure, and the transformed second node is used to indicate the call of the function indicated in the transformed first node.

[0205] In a possible implementation, the compiling module 802 is further used to: compile the transformed abstract syntax tree to obtain a target file; link the target file with a library file to obtain an executable file, wherein the library file includes the content of the function indicated by the transformed first node.

[0206] In a possible implementation, the compilation module 802 is also used to: load an extension plug-in corresponding to the first serialization format according to the first serialization format marked by the first structure; and transform the first node corresponding to the first structure in the abstract syntax tree by executing the extension plug-in to obtain the transformed first node.

[0207] In a possible implementation, the extension plug-in is further used to compile the transformed first node in the transformed abstract syntax tree to obtain an executable file.

[0208] In a possible implementation, the extension plug-in is further used to report an error when a marking error is detected, where the marking error is that an object indicated by a structure marked with a serialization format in the source code cannot be converted into a serialized object under the marked serialization format.

[0209] In a possible implementation, the compiling device is a compiler, a plurality of extension plug-ins are deployed in the compiler, and different extension plug-ins correspond to different serialization formats.

[0210] In a possible implementation, the source code also includes a third structure marked with a second serialization format, and the compilation module 802 is also used to: perform a transformation on a third node corresponding to the third structure in the abstract syntax tree so that the transformed abstract syntax tree includes the transformed third node, and the transformed third node is used to indicate content related to the serialized object; compile the transformed abstract syntax tree to obtain an executable file, and the executable file is used to generate a serialized object related to the first structure and a serialized object related to the third structure at runtime, and the format of the serialized object related to the third structure is the second serialization format.

[0211] Next, an execution device provided by an embodiment of the present application is introduced. Fig. 9 , Fig. 9 This is a schematic diagram of the structure of an execution device provided in an embodiment of the present application. The execution device 900 can be specifically a mobile phone, a tablet, a laptop, a smart wearable device, a server, etc., which is not limited here. Specifically, the execution device 900 includes: a receiving module 901, a sending module 902, a processor 903 and a memory 904 (wherein the number of processors 903 in the execution device 900 can be one or more, Fig. 9 In the example, a processor 903 is used, where the processor 903 may include an application processor 9031 and a communication processor 9032. In some embodiments of the present application, the receiving module 901, the sending module 902, the processor 903 and the memory 904 may be connected via a bus or other means.

[0212] The memory 904 may include a read-only memory and a random access memory, and provides instructions and data to the processor 903. A portion of the memory 904 may also include a non-volatile random access memory (NVRAM). The memory 904 stores processor and operation instructions, executable modules or data structures, or subsets thereof, or extended sets thereof, wherein the operation instructions may include various operation instructions for implementing various operations.

[0213] The processor 903 controls the operation of the execution device. In a specific application, the various components of the execution device are coupled together through a bus system, wherein the bus system includes not only a data bus but also a power bus, a control bus, and a status signal bus, etc. However, for the sake of clarity, various buses are referred to as bus systems in the figure.

[0214] The method disclosed in the above embodiment of the present application can be applied to the processor 903, or implemented by the processor 903. The processor 903 can be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 903. The above processor 903 can be a general processor, a digital signal processor (digital signal processing, DSP), a microprocessor or a microcontroller, and can further include an application specific integrated circuit (application specific integrated circuit, ASIC), a field programmable gate array (field-programmable gate array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The processor 903 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to execute, or the hardware and software modules in the decoding processor can be combined and executed. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 904, and the processor 903 reads the information in the memory 904 and completes the steps of the above method in combination with its hardware.

[0215] The receiving module 901 can be used to receive input digital or character information, and generate signal input related to the relevant settings and function control of the execution device. The sending module 902 can be used to output digital or character information through the first interface; the sending module 902 can also be used to send instructions to the disk group through the first interface to modify the data in the disk group; the sending module 902 can also include a display device such as a display screen.

[0216] In one embodiment of the present application, the processor 903 is configured to execute Figure 3 The method in the corresponding embodiment.

[0217] The electronic device provided in the embodiment of the present application may specifically be a chip, and the chip includes: a processing unit and a communication unit, wherein the processing unit may be, for example, a processor, and the communication unit may be, for example, an input / output interface, a pin or a circuit, etc. The processing unit may execute computer execution instructions stored in the storage unit so that the chip in the execution device executes the rendering method described in the above embodiment. Optionally, the storage unit is a storage unit in the chip, such as a register, a cache, etc. The storage unit may also be a storage unit located outside the chip in the wireless access device, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.

[0218] See also Fig.10 , Fig.10 This is a schematic diagram of the structure of a computer-readable storage medium provided in an embodiment of the present application. The present application also provides a computer-readable storage medium. In some embodiments, the above Figure 3 The disclosed methods may be implemented as computer program instructions encoded in a machine-readable format on a computer-readable storage medium or on other non-transitory media or articles of manufacture.

[0219] Fig.10 Schematically illustrates a conceptual partial view of an example computer-readable storage medium including a computer program for executing a computer process on a computing device, arranged in accordance with at least some embodiments presented herein.

[0220] In one embodiment, the computer readable storage medium 1000 is provided using a signal bearing medium 1001. The signal bearing medium 1001 may include one or more program instructions 1002, which when executed by one or more processors may provide the above-mentioned Figure 5 The functions or parts of the functions described. In addition, Fig.10 Program instructions 1002 in also describe example instructions.

[0221] In some examples, signal bearing medium 1001 may include computer readable medium 1003 such as, but not limited to, a hard drive, a compact disk (CD), a digital video disk (DVD), a digital tape, memory, ROM or RAM, and the like.

[0222] In some embodiments, the signal bearing medium 1001 may include a computer recordable medium 1004, such as, but not limited to, a memory, a read / write (R / W) CD, a R / W DVD, etc. In some embodiments, the signal bearing medium 1001 may include a communication medium 1005, such as, but not limited to, a digital and / or analog communication medium (e.g., a fiber optic cable, a waveguide, a wired communication link, a wireless communication link, etc.). Thus, for example, the signal bearing medium 1001 may be communicated by a wireless form of the communication medium 1005 (e.g., a wireless communication medium complying with the IEEE 802 standard or other transmission protocol).

[0223] The one or more program instructions 1002 may be, for example, computer executable instructions or logic implementation instructions. In some examples, the computing device of the computing device may be configured to provide various operations, functions, or actions in response to the program instructions 1002 communicated to the computing device via one or more of the computer readable medium 1003, the computer recordable medium 1004, and / or the communication medium 1005.

[0224] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0225] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a server, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.

[0226] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0227] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0228] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0229] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0230] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.

[0231] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.< / t>

Claims

1. A compiling method, characterized in that: include: Obtaining source code to be compiled, wherein a first structure in the source code is marked with a corresponding first serialization format, and the first structure is used to indicate an object to be serialized; Generate an abstract syntax tree corresponding to the source code, where the abstract syntax tree is used to represent the grammatical structure of the source code; Performing a transformation on a first node corresponding to the first structure in the abstract syntax tree to obtain a transformed abstract syntax tree, wherein the transformed abstract syntax tree includes the transformed first node, and the transformed first node is used to indicate content related to the serialized object; The transformed abstract syntax tree is compiled to obtain an executable file, wherein the executable file is used to generate a serialized object related to the first structure at runtime, and the format of the serialized object is the first serialization format.

2. The method according to claim 1, characterized in that The first structure is used to define a target class, and the target class is used to indicate the type of the object to be serialized; The transformed first node is used to indicate a first function, and the first function is used to create a serialized object related to the target class.

3. The method according to claim 2, characterized in that The transformed first node is further used to indicate a second function and / or a third function, wherein the second function is used to access a serialized object created based on the first function, and the third function is used to modify the serialized object created based on the first function.

4. The method according to claim 2 or 3, characterized in that: The method further comprises: transforming the second node in the abstract syntax tree so that the transformed abstract syntax tree includes the transformed second node; The second node corresponds to a second structure in the source code, the second structure is used to indicate the use of a target class defined in the first structure, and the transformed second node is used to indicate the call of a function indicated in the transformed first node.

5. The method according to any one of claims 2 to 4, characterized in that: The step of compiling the transformed abstract syntax tree to obtain an executable file includes: Compiling the transformed abstract syntax tree to obtain a target file; The target file is linked with a library file to obtain the executable file, wherein the library file includes the content of the function indicated by the transformed first node.

6. The method according to any one of claims 1 to 5, characterized in that: The performing transformation on the first node corresponding to the first structure in the abstract syntax tree to obtain the transformed first node includes: According to the first serialization format marked by the first structure, load the extension plug-in corresponding to the first serialization format; By executing the extension plug-in, a first node corresponding to the first structure in the abstract syntax tree is transformed to obtain a transformed first node.

7. The method according to claim 6, characterized in that The extension plug-in is also used to compile the transformed first node in the transformed abstract syntax tree to obtain the executable file.

8. The method according to claim 6 or 7, characterized in that: The extension plug-in is also used to report an error when a marking error is detected, wherein the marking error is that an object indicated by a structure marked with a serialization format in the source code cannot be converted into a serialized object under the marked serialization format.

9. The method according to any one of claims 6 to 8, characterized in that: The method is applied to a compiler, in which a plurality of extension plug-ins are deployed, and different extension plug-ins correspond to different serialization formats.

10. The method according to any one of claims 1 to 9, characterized in that: The source code also includes a third structure marked with a second serialization format, and the method further includes: Performing transformation on a third node corresponding to the third structure in the abstract syntax tree, so that the transformed abstract syntax tree includes the transformed third node, and the transformed third node is used to indicate content related to the serialized object; The transformed abstract syntax tree is compiled to obtain an executable file, wherein the executable file is used to generate a serialized object related to the first structure and a serialized object related to the third structure at runtime, and the format of the serialized object related to the third structure is the second serialization format.

11. A compiling device, characterized in that: include: An acquisition module, used for acquiring source code to be compiled, wherein a first structure in the source code is marked with a corresponding first serialization format, and the first structure is used for indicating an object to be serialized; A compiling module, used to generate an abstract syntax tree corresponding to the source code, wherein the abstract syntax tree is used to represent the syntax structure of the source code; The compiling module is further used to transform the first node corresponding to the first structure in the abstract syntax tree to obtain a transformed abstract syntax tree, wherein the transformed abstract syntax tree includes the transformed first node, and the transformed first node is used to indicate content related to the serialized object; The compilation module is further used to compile the transformed abstract syntax tree to obtain an executable file, and the executable file is used to generate a serialized object related to the first structure at runtime, and the format of the serialized object is the first serialization format.

12. The device according to claim 11, characterized in that The first structure is used to define a target class, and the target class is used to indicate the type of the object to be serialized; The transformed first node is used to indicate a first function, and the first function is used to create a serialized object related to the target class.

13. The device according to claim 12, characterized in that The transformed first node is further used to indicate a second function and / or a third function, wherein the second function is used to access a serialized object created based on the first function, and the third function is used to modify the serialized object created based on the first function.

14. The device according to claim 12 or 13, characterized in that The compilation module is also used for: transforming the second node in the abstract syntax tree so that the transformed abstract syntax tree includes the transformed second node; The second node corresponds to a second structure in the source code, the second structure is used to indicate the use of a target class defined in the first structure, and the transformed second node is used to indicate the call of a function indicated in the transformed first node.

15. The device according to any one of claims 12 to 14, characterized in that: The compilation module is also used for: Compiling the transformed abstract syntax tree to obtain a target file; The target file is linked with a library file to obtain the executable file, wherein the library file includes the content of the function indicated by the transformed first node.

16. The device according to any one of claims 11 to 15, characterized in that: The compilation module is also used for: According to the first serialization format marked by the first structure, load the extension plug-in corresponding to the first serialization format; By executing the extension plug-in, a first node corresponding to the first structure in the abstract syntax tree is transformed to obtain a transformed first node.

17. The device according to claim 16, characterized in that The extension plug-in is also used to compile the transformed first node in the transformed abstract syntax tree to obtain the executable file.

18. The device according to claim 16 or 17, characterized in that The extension plug-in is also used to report an error when a marking error is detected, wherein the marking error is that an object indicated by a structure marked with a serialization format in the source code cannot be converted into a serialized object under the marked serialization format.

19. A compiling device, characterized in that: The device comprises a memory and a processor; the memory stores codes, the processor is configured to execute the codes, and when the codes are executed, the device executes the method according to any one of claims 1 to 10.

20. A computer storage medium, characterized in that The computer storage medium stores instructions, which, when executed by a computer, cause the computer to implement the method of any one of claims 1 to 10.

21. A computer program product, characterized in that The computer program product stores instructions, which, when executed by a computer, cause the computer to implement the method according to any one of claims 1 to 10.