Compilation Method, Device and Computer-Readable Storage Medium
By using a syntax tree during the compilation process to accurately locate the changing areas of the source code and perform incremental compilation, the problem of low resource utilization in the existing technology is solved, and an efficient and real-time compilation process is achieved.
Patent Information
- Application Number
- CN202411974948.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-05-27
- Estimated Expiration
- 2044-12-30
AI Technical Summary
In existing compilation technology, resource utilization is low because even if the source code is partially changed, full compilation will be performed, resulting in duplicate processing of unchanged code.
By obtaining the syntax tree of the current source code, iterates over the syntax tree to determine the target node that changes relative to the historical source code, determine the functional units that need to be compiled based on the target node, and perform incremental compilation to generate the target code.
It realizes a more efficient compilation process, reduces processing of unchanged code, improves resource utilization and compilation efficiency, and is suitable for embedded device application scenarios with high real-time and dynamic updates.
Smart Images

Figure CN119376738B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technologies, and in particular, to a compilation method, apparatus, and computer-readable storage medium. Background Art
[0002] In the field of computer technologies, compilation is a process in computer science of converting source code (such as a high-level programming language) into target code (such as machine code).
[0003] In related technologies, regardless of whether the source code to be compiled has changed, full compilation is performed on the source code to be compiled, that is, the source code to be compiled is completely compiled from the beginning. Summary of the Invention
[0004] The inventors of the present disclosure have found the following problems in the above related technologies: The utilization rate of resources during the compilation process is relatively low.
[0005] To solve the above problems, the embodiments of the present disclosure provide the following solutions.
[0006] According to some embodiments of the present disclosure, there is provided a compilation method, including: obtaining a current syntax tree corresponding to the current source code, where the current syntax tree includes subtrees corresponding to each functional unit among multiple functional units of the current source code, the subtree includes a parent node and child nodes, the child nodes are determined based on context information of each functional unit, and the context information includes parameter information of each functional unit and / or sub-operations within each functional unit; traversing the current syntax tree, and determining target nodes in the subtree that have changed relative to a historical syntax tree corresponding to historical source code from the parent node and the child nodes; determining a target compilation unit among the multiple functional units based on the target nodes; and performing compilation on the current source code based on the target compilation unit to obtain target code.
[0007] In some embodiments, the determining a target compilation unit among the multiple functional units based on the target nodes includes: in response to the target node being the parent node, determining the functional unit corresponding to the subtree where the target node is located as the target compilation unit; or in response to the target node being the child node, determining the target compilation unit according to the target node and context information of the functional unit corresponding to the subtree where the target node is located.
[0008] In some embodiments, determining the target compilation unit according to the context information of the target node and the functional unit corresponding to the subtree where the target node is located includes: in response to the target node being a child node determined based on the parameter information of the functional unit corresponding to the subtree where the target node is located, determining the functional unit corresponding to the subtree where the target node is located as the target compilation unit; or in response to the target node being a child node determined based on the sub-operations within the functional unit corresponding to the subtree where the target node is located, determining the sub-operation corresponding to the target node as the target compilation unit.
[0009] In some embodiments, the parameter information of each functional unit includes the data dependency of each functional unit, and performing compilation on the current source code based on the target compilation unit includes: in response to the target node being a child node determined based on the data dependency of the functional unit corresponding to the subtree where the target node is located, determining a specified functional unit among the multiple functional units, where there is a logical dependency between the specified functional unit and the functional unit corresponding to the subtree where the target node is located; judging whether there is a syntax error in the current source code according to the data dependency of the specified functional unit and the data dependency of the functional unit corresponding to the subtree where the target node is located; in response to judging that there is no syntax error in the current source code, performing compilation on the current source code based on the target compilation unit.
[0010] In some embodiments, the parameter information includes at least one of the input information, output information, and scope information of each functional unit.
[0011] In some embodiments, traversing the current syntax tree to determine the target node in the subtree that has changed relative to the historical syntax tree corresponding to the historical source code from the parent node and the child nodes includes: traversing the current syntax tree to determine the current hash value of the parent node; comparing the current hash value of the parent node with the historical hash value of the parent node in the historical syntax tree; determining the target node from the parent node and the child nodes according to the result of the comparison.
[0012] In some embodiments, determining the target node from the parent node and the child nodes according to the result of the comparison includes: in response to the result of the comparison being that the current hash value of the parent node is different from the historical hash value of the parent node in the historical syntax tree, determining the parent node as the target node; or in response to the result of the comparison being that the current hash value of the parent node is the same as the historical hash value of the parent node in the historical syntax tree, determining the target node from the child nodes.
[0013] In some embodiments, determining the target node from the child nodes includes: comparing the current hash value of the child node with the historical hash value of the child node in the historical syntax tree, where the current hash value of the child node is determined by traversing the current syntax tree; and in response to the result of the comparison being that the current hash value of the child node is different from the historical hash value of the child node in the historical syntax tree, determining the child node as the target node.
[0014] In some embodiments, performing compilation on the current source code based on the target compilation unit to obtain target code includes: determining a specified compilation unit among the multiple functional units that has a logical dependency with the target compilation unit; performing compilation on the target compilation unit and the specified compilation unit to obtain new compiled code; and obtaining the target code based on the new compiled code.
[0015] In some embodiments, the compilation method further includes: storing the new compiled code in a cache area.
[0016] In some embodiments, obtaining the target code based on the new compiled code includes: detecting existing compiled code corresponding to other functional units among the multiple functional units in the cache area except the target compilation unit and the specified compilation unit; and in response to detecting the existing compiled code corresponding to the other functional units in the cache area, integrating the detected existing compiled code and the new compiled code to obtain the target code.
[0017] In some embodiments, obtaining the target code based on the new compiled code includes: detecting existing compiled code corresponding to other functional units among the multiple functional units in the cache area except the target compilation unit and the specified compilation unit; in response to not detecting the existing compiled code corresponding to the other functional units in the cache area, performing compilation on the other functional units to obtain other new compiled code; and integrating the other new compiled code and the new compiled code to obtain the target code.
[0018] In some embodiments, the cache area includes a first area and a second area; storing the new compiled code in the cache area includes: storing a first result of the new compiled code in the first area, and storing a second result of the new compiled code in the second area, where the second result is calculated based on the first result.
[0019] In some embodiments, obtaining the target code based on the newly compiled code includes: detecting a second result of existing compiled code corresponding to other functional units in the plurality of functional units except the target compilation unit and the specified compilation unit in the second region; in response to detecting the second result of the existing compiled code in the second region, integrating the detected second result of the existing compiled code and the newly compiled code to obtain the target code; in response to not detecting the second result of the existing compiled code in the second region, detecting a first result of the existing compiled code in the first region; in response to detecting the first result of the existing compiled code in the first region, compiling the other functional units based on the first result of the existing compiled code to obtain other newly compiled code, and integrating the other newly compiled code and the newly compiled code to obtain the target code.
[0020] In some embodiments, at least one or more of the plurality of functional units are predefined functional units in a predefined functional unit library.
[0021] According to some other embodiments of the present disclosure, there is provided a compilation apparatus, including: a memory; and a processor coupled to the memory, the processor being configured to execute the compilation method in any of the above embodiments based on instructions stored in the memory device.
[0022] According to some further embodiments of the present disclosure, there is provided a computer-readable storage medium having computer instructions stored thereon, and when the instructions are executed by a processor, the compilation method in any of the above embodiments is implemented.
[0023] According to some still further embodiments of the present disclosure, there is further provided a computer program product including instructions, and when the instructions are executed by a processor, the processor is caused to execute the compilation method according to any of the above embodiments.
[0024] In the above embodiments, based on the current syntax tree corresponding to the current code, a target node that has changed relative to the historical syntax tree can be determined from the parent node and the child node in the subtree of the current syntax tree. Based on the target node, a target compilation unit is determined from the plurality of functional units of the current source code, and the current source code is compiled based on the determined target compilation unit to obtain the target code. In this way, by determining the target compilation unit by determining the target node from the subtree, the area where the current source code has changed relative to the historical source code can be accurately located within each functional unit, achieving a smaller granularity of difference detection, which helps to accurately narrow the compilation scope, not only improving the compilation efficiency but also improving the resource utilization rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The accompanying drawings, which form a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0026] Reference will now be made in detail to various exemplary embodiments of the present disclosure with reference to the accompanying drawings. It should be noted that: unless otherwise specifically stated, the relative arrangements of components and steps, numerical expressions, and numerical values set forth in these embodiments do not limit the scope of the present disclosure.
[0027] Figure 1 Flowcharts showing some embodiments of the compilation method of the present disclosure.
[0028] Figure 2 Structural diagrams of the current syntax trees of some embodiments of the present disclosure are shown.
[0029] Figure 3 Shown Figure 1 Flowcharts of some embodiments of step 140 in
[0030] Figure 4 Shown Figure 1 Flowcharts of some other embodiments of step 140 in
[0031] Figure 5 Block diagrams of some embodiments of the compilation apparatus of the present disclosure are shown.
[0032] Figure 6 Block diagrams of some other embodiments of the compilation apparatus of the present disclosure are shown.
[0033] Figure 7 Block diagrams of some further embodiments of the compilation apparatus of the present disclosure are shown. Detailed Description of Specific Embodiments
[0034] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that: unless otherwise specifically stated, the relative arrangements of components and steps, numerical expressions, and numerical values set forth in these embodiments do not limit the scope of the present disclosure.
[0035] At the same time, it should be understood that, for the sake of convenience of description, the dimensions of the various parts shown in the drawings are not drawn according to actual proportional relationships.
[0036] The following description of at least one exemplary embodiment is merely illustrative in nature and in no way limits the present disclosure, its application, or its use.
[0037] Techniques, methods, and devices known to those of ordinary skill in the relevant art may not be discussed in detail, but where appropriate, such techniques, methods, and devices should be considered as part of the specification.
[0038] In all the examples shown and discussed here, any specific values should be construed as merely exemplary and not as a limitation. Therefore, other examples of the exemplary embodiments may have different values.
[0039] It should be noted that like reference numerals and letters refer to like items in the following figures, and thus, once an item is defined in one figure, further discussion thereof is not required in subsequent figures.
[0040] As described above, in the related art, even if a large amount of unchanged parts are included in the source code to be compiled, the full-scale compilation method is adopted to process the source code to be compiled. In this way, a large amount of resources will be wasted to reprocess the unchanged code during the compilation process, resulting in the waste of CPU resources during the compilation process, and further resulting in low resource utilization.
[0041] Embedded devices are widely used in scenarios such as autonomous driving, smart home, and industrial automation. Moreover, these application scenarios usually have relatively high requirements for the real-time performance, update efficiency, and running stability of algorithms. However, the full-scale compilation method has great limitations in these application scenarios of embedded devices.
[0042] For example, in the scenario of autonomous driving, the obstacle detection algorithm deployed on the embedded device needs to update part of the logic of the algorithm in real time according to the change of the environment. However, even if only the logic of one functional unit changes, the full-scale compilation method needs to completely parse the entire algorithm file and compile it from scratch, resulting in the compilation time being positively correlated with the overall scale of the code, thus resulting in low compilation efficiency and difficulty in meeting the high real-time requirements.
[0043] Another example is that in the scenario of industrial automation, the control algorithm deployed on the embedded device needs to be dynamically optimized according to the data of the sensor. However, on the one hand, the full-scale compilation method cannot accurately locate the changed part of the algorithm, resulting in the inability to quickly verify the effect after the algorithm optimization, thus resulting in low algorithm optimization efficiency; on the other hand, in the full-scale compilation method, the algorithm can only be updated after the system pauses operation, which not only causes the system to be unable to respond to the algorithm change in time, thus resulting in insufficient dynamic performance of the algorithm, but also because the system cannot run continuously, resulting in low running stability of the system.
[0044] In view of this, the present disclosure proposes a compilation technical solution, which can accurately locate the changed part in the current source code based on the syntax tree corresponding to the current source code, and then execute compilation on the current source code based on the changed part, thereby accurately narrowing the compilation scope, not only improving the compilation efficiency, but also reducing the resource consumption of the CPU and improving the resource utilization rate.
[0045] It should be noted that the compilation technology solution proposed in this disclosure is applicable to various application scenarios of embedded devices. That is, by using the compilation technology solution proposed in this disclosure, the source code of various algorithms (such as the collision detection algorithm in the autonomous driving scenario) deployed on the embedded device can be compiled, thereby improving the real-time performance of the algorithm and the running stability of the system on the basis of improving resource utilization.
[0046] Figure 1 The flowchart showing some embodiments of the compilation method of this disclosure.
[0047] As Figure 1 shown, in step 110, obtain the current syntax tree corresponding to the current source code.
[0048] Here, the current syntax tree includes subtrees corresponding to each functional unit among multiple functional units of the current source code. The subtree may include a parent node and child nodes. Among them, the child nodes are determined based on the context information of each functional unit, and the context information of each functional unit may include parameter information of each functional unit and / or sub-operations within each functional unit.
[0049] In other words, the current syntax tree can represent the syntax structure of the current source code. The subtree corresponding to each functional unit can represent the syntax structure of that functional unit. The child nodes of each functional unit may include child nodes determined based on the parameter information of that functional unit and / or child nodes determined based on the sub-operations within that functional unit.
[0050] In some embodiments, by performing syntax parsing on the current source code, the current syntax tree corresponding to the current source code can be generated.
[0051] For example, by performing syntax parsing on the current source code, the logical dependencies in terms of syntax among multiple functional units of the current source code, the operation type (also known as the task type) of each functional unit, and the context information of each functional unit can be determined. The logical dependencies in syntax among multiple functional units can be determined based on the input-output relationships among multiple functional units. The operation type of each functional unit can be determined based on the functions that each functional unit can implement.
[0052] Based on the operation type of each functional unit, the parent node in the subtree corresponding to each functional unit can be determined. Based on the context information of each functional unit, the child nodes in the subtree corresponding to each functional unit can be determined. Based on the logical dependencies among multiple functional units, the connection relationships among multiple subtrees corresponding to multiple functional units can be determined.
[0053] In step 120, traverse the current syntax tree, and determine the target nodes in the subtree that have changed relative to the historical syntax tree corresponding to the historical source code from the parent node and child nodes.
[0054] For example, the historical source code may be a historical version of the current source code. The historical syntax tree may represent the syntax structure of the historical source code. For example, the historical source code may be the source code of the previous compilation. The historical syntax tree may be the syntax tree generated during the previous compilation corresponding to the source code of the previous compilation.
[0055] In some embodiments, by traversing the current syntax tree, the current hash values of the parent node and the child node can be determined, and based on the current hash values of the parent node and the child node, the target node where the historical syntax tree in the subtree has changed can be determined. The method for determining the target node will be further described in combination with some embodiments later.
[0056] In step 130, based on the target node, the target compilation unit among multiple functional units is determined.
[0057] For example, according to whether the target node is a parent node or a child node, the target compilation unit among multiple functional units can be determined accordingly.
[0058] It should be understood that the target node can reflect the changes in the current source code relative to the historical source code. The target compilation unit may include the relevant code where the current source code has changed relative to the historical source code.
[0059] In step 140, based on the target compilation unit, the current source code is compiled to obtain the target code.
[0060] In some embodiments, the current source code can be compiled based on the target compilation unit and the specified compilation unit that has a logical dependency with the target compilation unit to obtain the target code. For example, the target code may be executable code that can be directly executed by a machine.
[0061] In some embodiments, the compiled target code can be directly loaded into the runtime environment without restarting or interrupting the system, thereby improving the stability of the system operation.
[0062] In the above embodiments, based on the current syntax tree corresponding to the current code, the target node where the subtree of the current syntax tree has changed relative to the historical syntax tree can be determined from the parent node and the child node. Based on the target node, the target compilation unit is determined from multiple functional units of the current source code, and based on the determined target compilation unit, the current source code is compiled to obtain the target code.
[0063] In this way, since the current syntax tree includes subtrees corresponding to each functional unit, and the subtrees corresponding to each functional unit include child nodes determined based on the context information of each functional unit, the current syntax tree can not only reflect the substructure of each functional unit in the syntax structure of the current source code, but also reflect the parameter information of each functional unit and / or the sub-operations within each functional unit.
[0064] Therefore, by determining the target node from the subtree of the current syntax tree to determine the target compilation unit, it is possible to accurately locate the area where the current source code has changed relative to the historical source code within each functional unit. In this way, fine-grained difference detection is achieved, and the compilation scope is accurately narrowed, which not only improves the compilation efficiency but also improves the resource utilization rate.
[0065] To better understand the compilation technical solution proposed in the present disclosure, the syntax tree in the present disclosure will be schematically described below in combination with some embodiments.
[0066] In some embodiments, the parameter information of each functional unit includes at least one of the input information, output information, and scope information of each functional unit. For example, the parameter information of each functional unit may include the input information, output information, and scope information of each functional unit. The child nodes of each functional unit may include input child nodes determined based on the input information of the functional unit, output child nodes determined based on the output information of the functional unit, and scope child nodes determined based on the scope information of the functional unit.
[0067] In some embodiments, the parameter information of each functional unit may include the data dependency of each functional unit. The child nodes of each functional unit may include data dependency child nodes determined based on the data dependency of the functional unit. For example, the data dependency may include the data on which the corresponding functional unit depends for execution.
[0068] It should be noted that in the present disclosure, the logical dependency between functional units refers to the dependency relationship determined based on the input-output relationship between functional units (i.e., the dependency in terms of syntax). The data dependency in the parameter information of a functional unit refers to the dependency of the functional unit on specific data determined based on the execution logic of the functional unit (i.e., the dependency in terms of data flow).
[0069] For example, by embedding the specific data on which the execution of the functional unit depends into relevant fields (such as the dependent_on field), the data dependency of the functional unit can be reflected, so that the syntax error can be judged based on the data dependency of the functional unit and the logical dependency between functional units. The related implementation of judging syntax errors will be further described below in combination with some embodiments.
[0070] In some embodiments, the parameter information of each functional unit may further include other parameter information required to execute the functional unit. The child nodes of each functional unit may also include other child nodes determined based on the other parameter information.
[0071] For example, each functional unit in the current source code may correspond to a subtree in the current syntax tree. The operation type of each functional unit may correspond to the parent node in the subtree, and the different attributes of each functional unit may respectively correspond to different child nodes in the subtree.
[0072] Assume that the current source code includes two functional units, SignalService and Project, and part of the relevant code is shown below.
[0073] SignalService: id=spool_0, output=x_4, input=`signal_queue`(signals=`msg_time,110,111,112,113,114,115,116,117`, frequency=`20hz`).
[0074] Project: id=spool_1, output=x_3, input=x_4(selects=`msg_time,110,111,112,113,114,115,116,117`).
[0075] Among them, SignalService is used to process the signals in the signal queue at a certain processing frequency. Project is used to take the processed signals output by SignalService as input and perform signal selection operations according to certain conditions.
[0076] Each functional unit may include one or more attributes such as task type, task identifier, input, output, data dependency, and sub-operations. For example, the task type of SignalService is type = "SignalService", the task identifier is id="spool_0", the input is input="ignal_queue", the output is output="x_4", and the data dependency can be described as dependent_on=" msg_time,110,111,112,113,114,115,116,117".
[0077] It can be understood that each functional unit may also include other attributes corresponding to other parameter information. For example, SignalService may also include a frequency attribute corresponding to the frequency parameter, and the frequency attribute can be described as frequency="20hz".
[0078] Figure 2 The figure shows the structural diagram of the current syntax tree of some embodiments of the present disclosure.
[0079] As Figure 2 shown, in the subtree S corresponding to SignalService, the parent node SignalService is determined based on the operation type (such as the task type type = "SignalService"); the scope child node scope is determined based on the scope information (such as the task identifier id = "spool_0"); the input child node input is determined based on the input information (such as input = "signal_queue"); the output child node output is determined based on the output information (such as output = "x_4"); the data dependency child node Dependency is determined based on the data on which the execution of SignalService depends (such as dependent_on = "msg_time,110,111,112,113,114,115,116,117"). In addition, other child nodes (such as frequency) determined based on other parameter information (such as frequency = "20hz") may also be included in the subtree corresponding to SignalService.
[0080] In the subtree P corresponding to Project, the parent node Project is determined based on the operation type (such as the task type type = "Project "); the scope child node scope is determined based on the scope information (such as the task identifier id = "spool_1"); the input child node input is determined based on the input information (such as input = "x_4"); the output child node output is determined based on the output information (such as output = "x_3"); the data dependency child node Dependency is determined based on the data on which the execution of Project depends (such as dependent_on = "msg_time,110,111,112,113,114,115,116,117"). Here, since Project also contains a sub-operation selects, operation child nodes selects determined based on the sub-operation may also be included in the subtree P corresponding to Project.
[0081] From the fact that the input of Project is the output of SignalService, it can be seen that there is a logical dependency between Project and SignalService in terms of syntax. Therefore, based on this logical dependency, the subtree P corresponding to Project and the subtree S corresponding to SignalService can be connected. For example, as Figure 2As shown, the subtree P corresponding to Project and the subtree S corresponding to SignalService can be connected through the parent node.
[0082] It can be seen that the syntax tree in the present disclosure can not only reflect the logical dependencies in terms of syntax between functional units, but also reflect the parameter information of the functional units themselves (such as input information, output information, scope information, and data dependencies) and sub-operation information.
[0083] In other words, the syntax tree in the present disclosure can combine the context information of each functional unit with the syntax structure between multiple functional units, so that the syntax tree can not only describe the static structure of the code, but also reflect the dynamic behavior of the program. Based on the syntax tree in the present disclosure, multi-dimensional difference detection can be realized, and then the accurate positioning of code changes can be achieved, thus supporting efficient incremental compilation.
[0084] In some embodiments, at least one or more of the multiple functional units in the current source code may be predefined functional units in a predefined functional unit library. The predefined functional unit library is also called an operator library, and the predefined functional unit is also called an operator.
[0085] For example, one or more predefined functional units for implementing various functions (such as mathematical operations, logical control, data processing, etc.) can be predefined in the predefined functional unit library.
[0086] For example, the input, output, and execution logic of each operator in the operator library can be predefined. Taking the Signal Processing Operator as an example, it can be predefined that the input of the signal processing operator is a signal queue, the output is the processed signal, and the execution logic is to process the signals in the signal queue at a certain processing frequency to output the processed signal.
[0087] In some embodiments, the current source code can be syntactically parsed according to the predefined functional unit library (i.e., the operator library) to generate a current syntax tree corresponding to the current source code.
[0088] For example, through syntax parsing, the mapping relationship between each predefined functional unit (i.e., each operator) in the predefined functional unit library and the nodes of the current syntax tree can be determined. For example, SignalService, as a signal processing operator, maps this operator to the parent and child nodes in the subtree corresponding to SignalService based on the various attributes of this operator. Another example is that Project, as a data processing operator, maps this operator to the parent and child nodes in the subtree corresponding to Project based on the various attributes of this operator.
[0089] By dividing the algorithm functions into independent operator units, each code modification can only trigger the recompilation of the relevant operators that have changed. In this way, the system can perform incremental compilation efficiently and ensure the update is completed in a short time. For example, when a certain operator is modified, the incremental compilation pipeline can regenerate the new compiled code of this operator and connect it to the existing runtime environment to achieve seamless loading of the code and dynamic update of the algorithm.
[0090] Next, some embodiments will be combined to further illustrate the method of compiling based on the syntax tree of the present disclosure.
[0091] First, some embodiments will be combined to schematically illustrate the related implementation of step 120.
[0092] In some embodiments, by traversing the current syntax tree, the field content corresponding to each node in the current syntax tree can be compared one by one to determine the target node. For example, compare the Dependency node in the subtree corresponding to Project. The field content corresponding to this node in the historical syntax tree is "msg_time,110,111,112,113,114,115,116,117", and the field content corresponding to this node in the current syntax tree is "msg_time,110,111,112,113,114,115,116 ". By the change of the field content, it can be determined that this node has changed, and thus this node can be marked as the target node.
[0093] In some embodiments, by traversing the current syntax tree, the current hash value of the parent node can be determined. Compare the current hash value of the parent node with the historical hash value of the parent node in the historical syntax tree, and then according to the comparison result, determine the target node in the subtree of the current syntax tree that has changed relative to the historical syntax tree from the parent node and the child nodes.
[0094] As described above, the historical syntax tree is the syntax tree corresponding to the historical source code. For example, the historical source code can be a certain historical version of the current source code. Compare the current hash value of the parent node with the historical hash value of the parent node in the historical syntax tree, that is, compare the current hash value of the parent node in the current syntax tree with the historical hash value of the parent node in a certain historical syntax tree.
[0095] For example, the historical source code can be the source code of the previous compilation. The historical syntax tree can be the syntax tree generated during the previous compilation. Compare the current hash value of the parent node with the historical hash value of the parent node in the syntax tree generated during the previous compilation, and determine the target node that has changed in the subtree of the current syntax tree relative to the syntax tree generated during the previous compilation according to the comparison result. Here, the target node reflects the changes in the current source code relative to the source code of the previous compilation.
[0096] Taking the SignalService functional unit described above as an example, the hash value of the parent node in the subtree corresponding to SignalService can be obtained at least by calculating the hash of the operation type of the SignalService functional unit. For example, the hash value of the parent node in the subtree corresponding to SignalService can be obtained by concatenating each attribute (such as task type, task identifier, input, output, data dependency, etc.) of the SignalService functional unit into a string and then performing hash processing using a hash algorithm (such as the MD5 algorithm).
[0097] In the above embodiments, the target node can be determined from the parent node and the child nodes by comparing the hash values of the parent node, with low computational complexity and low memory occupancy, which helps to further improve the resource utilization rate.
[0098] In some embodiments, in response to the comparison result that the current hash value of the parent node is different from the historical hash value of the parent node in the historical syntax tree, the parent node can be determined as the target node. For example, the difference between the current hash value of the parent node and the historical hash value of the parent node in the historical syntax tree can at least indicate that the operation type of the functional unit corresponding to the subtree where the parent node is located has changed.
[0099] In this case, it is not necessary to further detect the child nodes in the subtree where the parent node is located, which can further reduce resource waste and thus further improve the resource utilization rate.
[0100] In some embodiments, in response to the result of the comparison indicating that the current hash value of the parent node is the same as the historical hash value of the parent node in the historical syntax tree, a target node can be determined from the child nodes. For example, the fact that the current hash value of the parent node is the same as the historical hash value of the parent node in the historical syntax tree can indicate that the operation type of the functional unit corresponding to the subtree where the parent node is located has not changed. In this case, the child nodes in the subtree where the parent node is located can be further detected to determine a target node from the child nodes.
[0101] In this way, even if the parent node in the subtree has not changed, a target node can still be determined from the child nodes that can reflect the context information of the corresponding functional unit, so as to accurately narrow the scope of subsequent compilation. Thus, the compilation efficiency is further improved, and the utilization rate of resources is increased.
[0102] In some embodiments, the current hash value of the child node is compared with the historical hash value of the child node in the historical syntax tree, where the current hash value of the child node is determined by traversing the current syntax tree.
[0103] Still taking the SignalService functional unit described above as an example, the hash value of the child node in the subtree corresponding to SignalService can be obtained by concatenating the field content corresponding to the child node into a string and then performing hash processing using a hash algorithm (such as the MD5 algorithm).
[0104] For example, when the current hash value of the parent node in the subtree is the same as the historical hash value, the subtree can be further traversed to determine the current hash value of the child nodes in the subtree. For example, the number of child nodes can be multiple. By traversing the current syntax tree, the current hash value of each child node in the subtree can be determined.
[0105] In response to the result of the comparison indicating that the current hash value of the child node is different from the historical hash value of the child node in the historical syntax tree, the child node is determined as the target node.
[0106] It can be understood that when the number of child nodes is multiple, for each child node, the current hash value of the child node can be compared with the historical hash value of the child node. And the child nodes with different current hash values and historical hash values are determined as target nodes. In other words, one or more child nodes can be determined as target nodes.
[0107] For example, starting from a parent node that is a root node, each subtree can be recursively detected. If the parent node of the subtree has not changed, the child nodes of the subtree are recursively detected until the finest-grained child nodes are detected, so as to detect all the changed child nodes.
[0108] In the above embodiments, by comparing the hash values of child nodes, the target nodes reflecting the changes of the current source code relative to the historical source code can be determined comprehensively and accurately, thereby realizing more fine-grained difference detection, which helps to more precisely narrow the scope of subsequent compilation.
[0109] In some embodiments, after each code change, the corresponding syntax tree can be regenerated, and the hash value of each node in the syntax tree can be calculated. Then, the hash values of the nodes in the current syntax tree are compared with the hash values of the nodes in the historical syntax tree, and the nodes with changed hash values are determined as target nodes.
[0110] Next, some embodiments are combined to schematically illustrate the related implementation of step 130.
[0111] In some embodiments, in response to the target node being a parent node, the functional unit corresponding to the subtree where the target node is located can be determined as the target compilation unit.
[0112] For example, the parent node in the subtree can correspond to the operation type of the functional unit corresponding to the subtree. The target node being a parent node can at least indicate that the operation type of the functional unit corresponding to the subtree where the target node is located has changed. In this case, the functional unit corresponding to the subtree where the target node is located is determined as the target compilation unit, so as to recompile the functional unit corresponding to the subtree where the target node is located during the compilation of the current source code.
[0113] For example, assume that the SignalService functional unit is replaced by the Filter functional unit in the current source code (i.e., the operation type changes from SignalService to Filter). In response to the target node being the parent node in the subtree corresponding to Filter, it can be determined that the functional unit corresponding to the subtree where the target node is located has changed as a whole. Thus, the Filter functional unit is determined as the target compilation unit, so as to recompile the whole Filter functional unit during the compilation of the current source code.
[0114] In the above embodiments, once the changed target node is a parent node, the functional unit corresponding to the subtree where the target node is located is determined as the target compilation unit, so as to perform the compilation of the current source code based on the functional unit corresponding to the subtree where the target node is located. In this way, on the basis of accurately narrowing the compilation scope, the reliability of compilation is ensured.
[0115] In some embodiments, in response to the target node being a child node, the target compilation unit can be determined according to the context information of the target node and the functional unit corresponding to the subtree where the target node is located.
[0116] Since the child nodes in the subtree corresponding to each functional unit are determined based on the context information of each functional unit, in response to the target node being a child node, the target compilation unit can be determined by combining the target node and the context information corresponding to the target node.
[0117] As described above, the context information of each functional unit includes the parameter information of each functional unit and / or the sub-operations within each functional unit. That is to say, the child nodes of each functional unit can include the child nodes determined based on the parameter information of the functional unit and / or the child nodes determined based on the sub-operations within the functional unit.
[0118] Based on this, in some embodiments, in response to the target node being a child node determined based on the parameter information of the functional unit corresponding to the subtree where the target node is located, the functional unit corresponding to the subtree where the target node is located can be determined as the target compilation unit.
[0119] In other words, in the case where the target node is a child node and the target node is a child node determined based on the parameter information of the functional unit corresponding to the subtree where it is located, the functional unit corresponding to the subtree where the target node is located is determined as the target compilation unit.
[0120] For example, assume that the input information of the SignalService functional unit changes in the current source code. In response to the target node being an input child node determined based on the input information in the subtree corresponding to SignalService, it can be determined that the functional unit corresponding to the subtree where the target node is located will change as a whole due to the change in the input. Thus, the SignalService functional unit is determined as the target compilation unit so that the whole of the SignalService functional unit can be recompiled during the compilation of the current source code.
[0121] In some embodiments, in response to the target node being a child node determined based on the sub-operations within the functional unit corresponding to the subtree where the target node is located, the sub-operation corresponding to the target node can be determined as the target compilation unit.
[0122] In other words, in the case where the target node is a child node and the target node is a child node determined based on the sub-operations within the functional unit corresponding to the subtree where it is located, the sub-operation corresponding to the target node is determined as the target compilation unit.
[0123] For example, assume that the sub-operation "selects" of the Project functional unit in the current source code is replaced with "collection". In response to the target node being the operation sub-node determined based on the sub-operation "collection" in the subtree corresponding to Project, it can be determined that the changed part in the functional unit corresponding to the subtree where the target node is located is the sub-operation. Thus, the changed sub-operation "collection" can be determined as the target compilation unit, so as to recompile the sub-operation "collection" during the compilation of the current source code.
[0124] For another example, assume that the selection condition of the sub-operation "selects" of the Project functional unit in the current source code has changed. In response to the target node being the operation sub-node determined based on the sub-operation "selects" in the subtree corresponding to Project, it can be determined that the changed part in the functional unit corresponding to the subtree where the target node is located is the sub-operation. Thus, the changed sub-operation "selects" can be determined as the target compilation unit, so as to recompile the sub-operation "selects" during the compilation of the current source code.
[0125] It can be understood that a functional unit may include one or more independent sub-operations. By accurately determining the changed sub-operation as the target compilation unit, the sub-operation can be extracted as an independent compilation unit, thereby further narrowing the compilation scope of the subsequent compilation and further improving the resource utilization rate.
[0126] Next, some embodiments will be combined to illustrate the related implementation of step 140 schematically.
[0127] As mentioned above, in some embodiments, the parameter information of each functional unit may include the data dependency of the functional unit.
[0128] For example, in response to the target node being the sub-node determined based on the data dependency of the functional unit corresponding to the subtree where the target node is located, it can be determined whether there are syntax errors in the current source code according to the data dependency of the functional unit corresponding to the subtree where the target node is located, and the current source code can be compiled according to the judgment result.
[0129] The following will be further described in conjunction with Figure 3 this. Figure 3 Show Figure 1 a flowchart of some embodiments of step 140 in
[0130] As Figure 3 shown, in step 310, in response to the target node being the sub-node determined based on the data dependency of the functional unit corresponding to the subtree where the target node is located, a specified functional unit among multiple functional units is determined.
[0131] Here, there is a logical dependency between the specified functional unit and the functional units corresponding to the subtree where the target node is located.
[0132] For example, see Figure 2 , the functional unit corresponding to the subtree where the target node is located is the Project functional unit, and the specified functional unit having a logical dependency with the Project functional unit is the SignalService functional unit.
[0133] In step 320, according to the data dependencies of the specified functional unit and the functional units corresponding to the subtree where the target node is located, it is determined whether there are syntax errors in the current source code.
[0134] In some embodiments, according to the data dependencies of the specified functional unit and the functional units corresponding to the subtree where the target node is located, the data flow direction between the two functional units can be determined. According to whether the data flow direction between the two functional units matches the logical dependency between the two functional units, it can be determined whether there are syntax errors in the current source code.
[0135] For example, see Figure 2 , according to the logical dependency between the Project functional unit and the SignalService functional unit, it can be known that the output of SignalService is the input of Project, so the data flow direction between the two functional units is from SignalService to Project. That is, the data on which Project depends should be a subset of the data on which SignalService depends.
[0136] Taking the functional unit corresponding to the subtree where the target node is located as the Project functional unit as an example. In response to the data dependency sub-node Dependency in the subtree P corresponding to Project being the target node that has changed, it can be determined whether the data flow direction between the two functional units matches the logical dependency between the two functional units according to whether the data on which Project depends is a subset of the data on which SignalService depends.
[0137] For example, in the current source code, assume that the data on which Project depends changes from "msg_time,110,111,112,113,114,115,116,117" to "msg_time,110,111,112,113,114,115,116,117,118". As a result, the data-dependent child node Dependency in the subtree P corresponding to Project changes due to the newly added dependency data "118". However, the data on which SignalService depends remains "msg_time,110,111,112,113,114,115,116,117", that is, the data-dependent child node Dependency in the subtree S corresponding to SignalService does not change.
[0138] Since the data "118" is newly added to the data on which Project depends, but this newly added data does not belong to the data on which SignalService depends, the data on which Project depends is no longer a subset of the data on which SignalService depends. Therefore, it can be determined that the data flow between the two functional units Project and SignalService does not match the logical dependency between these two functional units, and thus it can be judged that there is a syntax error in the current source code.
[0139] Another example, in the current source code, assume that the data on which Project depends changes from "msg_time,110,111,112,113,114,115,116,117" to "msg_time,110,111,112,113,114,115,116". As a result, the data-dependent child node Dependency in the subtree P corresponding to Project changes due to the reduced dependency data "117". However, the data on which SignalService depends remains "msg_time,110,111,112,113,114,115,116,117".
[0140] In this case, even though the data "117" is reduced from the data on which Project depends, since the data on which Project depends after the reduction is still a subset of the data on which SignalService depends, it can be determined that the data flow between the two functional units Project and SignalService matches the logical dependency between these two functional units, and thus it can be judged that there is no syntax error in the current source code.
[0141] In step 330, in response to determining that there are no syntax errors in the current source code, compile the current source code based on the target compilation unit.
[0142] In some embodiments, in response to determining that there are syntax errors in the current source code, do not compile the current source code. For example, the current source code can be modified to resolve the syntax errors and then the modified current source code can be compiled.
[0143] In the above embodiments, during the compilation process, it is also possible to check whether there are syntax errors in the current source code according to the logical dependencies and data dependencies between functional units, so as to compile the current source code when there are no syntax errors.
[0144] In this way, it is possible to implement syntax checking of the current source code through double checking of the logical dependencies in terms of syntax and data dependencies in terms of data flow of functional units. Compared with performing syntax checking only according to the logical dependencies in terms of syntax of functional units, on the basis of accurately narrowing the compilation scope, the accuracy of syntax checking is improved, thereby further improving the reliability of compilation.
[0145] Next, some embodiments will be further combined to further illustrate the method of compiling the current source code based on the target compilation unit.
[0146] Figure 4 Shown Figure 1 Another flowchart of step 140 in the embodiment.
[0147] In step 410, determine the specified compilation unit among the multiple functional units that has a logical dependency with the target compilation unit.
[0148] In some embodiments, the specified compilation unit can be determined from the multiple functional units according to the input-output relationship of the target compilation unit.
[0149] In some embodiments, the target compilation unit is the functional unit corresponding to the subtree where the target node is located, and the specified compilation unit can include another functional unit that directly or indirectly has a logical dependency with the functional unit corresponding to the subtree where the target node is located. For example, the specified compilation unit can include other functional units that directly or indirectly depend on the functional unit corresponding to the subtree where the target node is located.
[0150] For example, please refer to Figure 2 the example shown. Assume that the target compilation unit is SignalService. Since the output of SignalService affects the input of Project, that is, Project logically depends on SignalService, Project can be determined as the specified compilation unit.
[0151] In some embodiments, the target compilation unit is a sub-operation within the functional unit corresponding to the subtree where the target node is located, and the specified compilation unit may include another sub-operation that has a logical dependency with the sub-operations corresponding to the target node. For example, the specified compilation unit may include other operations that directly or indirectly depend on the sub-operations corresponding to the target node. For example, the specified compilation unit may include other operations that have a function call relationship with the sub-operations corresponding to the target node.
[0152] For example, please continue to refer to Figure 2 the example shown, assuming that Project includes the sub-operation selects and the sub-operation filter ( Figure 2 not shown), and the output of selects affects the input of filter. Taking the target compilation unit as selects as an example, since filter logically depends on selects, filter can be determined as the specified compilation unit.
[0153] It can be understood that the target compilation unit may include the relevant code where the current source code has changed compared to the historical source code. The specified compilation unit may include another part of the code that is directly or indirectly affected by the changed relevant code.
[0154] That is to say, through the syntax tree embedded with the context information of each functional unit, the present disclosure can further detect whether the changed code has caused changes across functional units or sub-operations (such as across functions), thereby achieving accurate determination of the compilation scope.
[0155] In step 420, compile the target compilation unit and the specified compilation unit to obtain new compiled code.
[0156] In some embodiments, compilation may not be performed on other functional units in the multiple functional units except for the target compilation unit and the specified compilation unit.
[0157] In step 430, obtain the target code based on the new compiled code.
[0158] In some embodiments, the existing compiled code corresponding to other functional units in the multiple functional units except for the target compilation unit and the specified compilation unit may be obtained, and then the new compiled code and the existing compiled code are integrated to obtain the target code.
[0159] In the above embodiments, during the process of compiling the current source code based on the target compilation unit, not only the target compilation unit is compiled, but also the specified compilation units directly or indirectly affected by the target compilation unit are compiled. In this way, on the basis of accurately narrowing the compilation scope, the potential impact of code changes on the overall algorithm logic corresponding to the current source code is reduced, thereby further improving the reliability of compilation.
[0160] In other words, in this way, not only can the relevant codes with changes in the current source code be identified, but also the potential impact of these changed relevant codes on the overall algorithm logic corresponding to the current source code can be deeply analyzed, realizing accurate marking of the compilation scope and ensuring the reliability of compilation.
[0161] Next, some embodiments will be combined to schematically illustrate the relevant implementation of step 430.
[0162] In some embodiments, the newly compiled code can be stored in the cache area. In this way, subsequent reuse can be facilitated.
[0163] In some embodiments, after each compilation is completed, the target code and the corresponding syntax tree can be stored in the cache area.
[0164] In some embodiments, existing compiled codes corresponding to other functional units except the target compilation unit and the specified compilation unit can be detected in the cache area, and the target code can be obtained according to the detection results and the newly compiled code. In this way, during the compilation process, it is possible to preferentially query whether there is existing compiled code that can be reused in the cache area, so as to reduce repeated compilation and resource consumption.
[0165] In some embodiments, in response to detecting existing compiled codes corresponding to other functional units in the cache area, the detected existing compiled codes and the newly compiled code are integrated to obtain the target code.
[0166] For example, in response to detecting existing compiled codes corresponding to other functional units in the cache area, the target compilation unit and the specified compilation unit can be compiled, while other functional units are not compiled. Then, the detected existing compiled codes and the newly compiled code obtained by compilation are integrated to obtain the target code.
[0167] In some embodiments, in response to not detecting existing compiled codes corresponding to other functional units in the cache area, other functional units can be compiled to obtain other newly compiled codes. Then, the other newly compiled codes and the newly compiled code are integrated to obtain the target code.
[0168] For example, in response to the non-detection of existing compiled code corresponding to other functional units in the cache area, compilation can be performed on the target compilation unit, the specified compilation unit, and other functional units. Subsequently, the newly compiled code and the newly compiled code obtained by integration compilation are integrated to obtain the target code.
[0169] In the above embodiments, during the process of compiling the current source code based on the target compilation unit, for other functional units not affected by the target compilation unit, the corresponding existing compiled code can be detected in the cache, and in response to the detection of the corresponding existing compiled code, the existing compiled code can be directly reused, thus eliminating the need for repeated compilation.
[0170] In this way, on the basis of accurately narrowing the compilation scope, the existing compiled code can be quickly reused, skipping the compilation of some functional units, thereby further improving the compilation efficiency and reducing resource consumption.
[0171] In some embodiments, the cache area may include a first area and a second area.
[0172] For example, the first result of the newly compiled code can be stored in the first area, and the second result of the newly compiled code can be stored in the second area, where the second result is calculated based on the first result. For example, the second result may be the final result obtained after compiling the target compilation unit and the specified compilation unit, and the first result may be the intermediate result obtained after compiling the target compilation unit and the specified compilation unit.
[0173] In this way, hierarchical storage of compilation results can be achieved, so that the compilation results that can be reused can be quickly found subsequently, which helps to improve the compilation efficiency.
[0174] In some embodiments, the second result of the existing compiled code corresponding to other functional units except the target compilation unit and the specified compilation unit among the multiple functional units can be detected in the second area.
[0175] In response to the detection of the second result of the existing compiled code in the second area, the detected second result of the existing compiled code and the newly compiled code are integrated to obtain the target code.
[0176] In response to the non-detection of the second result of the existing compiled code in the second area, the first result of the existing compiled code is detected in the first area.
[0177] For example, the second result of the existing compiled code may be the final result obtained after compiling other functional units, and the first result of the existing compiled code may be the intermediate result obtained after compiling other functional units. It should be understood that the second result of the existing compiled code is calculated based on the first result of the existing compiled code.
[0178] In the above embodiments, once the second result of the existing compiled code is detected in the second region, the second result of the detected existing compiled code and the new compiled code can be integrated to obtain the target code. In this way, the second result of the existing compiled code can be directly reused without repeatedly executing the compilation process for obtaining the second result, thereby improving the compilation efficiency and reducing resource consumption.
[0179] In some embodiments, in response to detecting the first result of the existing compiled code in the first region, other functional units are compiled based on the first result of the existing compiled code to obtain other new compiled codes, and the other new compiled codes and the new compiled code are integrated to obtain the target code.
[0180] In the above embodiments, even if the second result of the existing compiled code is not detected in the second region, further detection can still be performed in the first region to determine whether there is a reusable compilation result. Once the first result of the existing compiled code is detected in the first region, other functional units can be compiled based on the first result of the existing compiled code, that is, the first result of the existing compiled code is directly reused. In this way, the compilation process for obtaining the first result does not need to be repeatedly executed, improving the compilation efficiency and reducing resource consumption.
[0181] In some embodiments, in response to not detecting the first result of the existing compiled code in the first region, other functional units are compiled to obtain other new compiled codes, and the other new compiled codes and the new compiled code are integrated to obtain the target code. That is to say, other functional units are recompiled only when there is no existing compiled code that can be reused, thereby improving the resource utilization rate.
[0182] It should be understood that the cache region including the first region and the second region is merely an example. In fact, the cache region may include multiple regions for storing data with different granularities. For example, the cache region may include a region for storing data with the smallest granularity (such as the source data required for executing each functional unit), a region for storing data with intermediate granularity (such as intermediate results calculated based on the source data), and a region for storing data with the largest granularity (such as the final results calculated based on the intermediate results).
[0183] This hierarchical storage mechanism can improve the data access speed, thereby helping to improve the compilation efficiency.
[0184] In some embodiments, the compiled target code can be loaded into the runtime environment, thereby realizing the real-time deployment of the target code. For example, the compiled target code can be seamlessly loaded into the runtime environment through dynamic linking technology to achieve the immediate effect of code update.
[0185] In addition, by deploying the updated code in real time, it can ensure that the system updates the algorithm without interruption. That is to say, during the entire compilation process, there is no need to restart or shut down the system, which can ensure the seamless transition of the updated algorithm in the system, guarantee the continuity of the system operation, and thus improve the stability of the system operation.
[0186] In the present disclosure, semantic-level difference detection can be achieved based on the current syntax tree, so as to accurately determine the compilation scope. The core idea of the present disclosure is to deeply analyze the syntax structure of the current source code and the context information of each functional unit in the current source code based on the current syntax tree, so as to identify the potential impact of the current source code on the overall algorithm logic caused by code changes. Thus, independent compilation units with smaller granularity can be extracted from multiple functional units, which not only reduces the consumption of CPU resources, but also realizes efficient compilation.
[0187] The compilation technical solution proposed in the present disclosure breaks through the limitations of the full-scale compilation method and successfully realizes the incremental and immediate characteristics of compilation. The incremental characteristic can significantly reduce the compilation scope, make the compilation time positively correlated with the scale of code changes, and effectively improve the compilation efficiency. The immediate characteristic enables the system to quickly respond to code changes and complete algorithm updates under high real-time requirements, thus ensuring the continuity of the system (such as an embedded system) operation and improving the system's rapid adaptation ability to algorithm changes.
[0188] In other words, these characteristics can guarantee the efficient operation and dynamic update ability of various algorithms in the embedded application scenario.
[0189] Figure 5 The block diagram showing some embodiments of the compilation device of the present disclosure.
[0190] As Figure 5 shown, the compilation device 500 includes an acquisition module 501, a determination module 502, and a compilation module 503.
[0191] The acquisition module 501 can be configured to acquire the current syntax tree corresponding to the current source code. The current syntax tree includes subtrees corresponding to each functional unit among multiple functional units of the current source code. The subtree includes a parent node and child nodes, and the child nodes are determined based on the context information of each functional unit. The context information of each functional unit includes parameter information of each functional unit and / or sub-operations within each functional unit.
[0192] The determination module 502 can be configured to traverse the current syntax tree, determine target nodes in the subtree that have changed relative to the historical syntax tree corresponding to the historical source code from the parent node and child nodes, and determine target compilation units among multiple functional units based on the target nodes.
[0193] The compilation module 503 may be configured to perform compilation on the current source code based on a target compilation unit to obtain target code.
[0194] In some embodiments, the compilation device 500 may further include other modules that perform other operations in the foregoing embodiments.
[0195] Figure 6 A block diagram showing other embodiments of the compilation device of the present disclosure.
[0196] As Figure 6 shown, the compilation device 600 of this embodiment includes: a memory 601 and a processor 602 coupled to the memory 601. The processor 602 is configured to execute the compilation method in any one of the embodiments of the present disclosure based on instructions stored in the memory 601.
[0197] Among them, the memory 601 may include, for example, a system memory, a fixed non-volatile storage medium, etc. The system memory stores, for example, an operating system, application programs, a boot loader, a database, and other programs.
[0198] Figure 7 A block diagram showing still other embodiments of the compilation device of the present disclosure.
[0199] As Figure 7 shown, the compilation device 700 of this embodiment includes: a memory 701 and a processor 702 coupled to the memory 701. The processor 702 is configured to execute the compilation method in any of the foregoing embodiments based on instructions stored in the memory 701.
[0200] The memory 701 may include, for example, a system memory, a fixed non-volatile storage medium, etc. The system memory stores, for example, an operating system, application programs, a boot loader, and other programs.
[0201] The compilation device 700 may further include an input / output interface 703, a network interface 704, a storage interface 705, etc. These interfaces 703, 704, 705 and the memory 701 and the processor 702 may be connected through a bus 706, for example. Among them, the input / output interface 703 provides a connection interface for input / output devices such as a display, a mouse, a keyboard, a touch screen, a microphone, and a speaker. The network interface 704 provides a connection interface for various networking devices. The storage interface 705 provides a connection interface for external storage devices such as an SD card and a USB flash drive.
[0202] Those skilled in the art should understand that the embodiments of the present disclosure can be provided as methods, systems, or computer program products. Therefore, the present disclosure can take the form of an all-hardware embodiment, an all-software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present disclosure can take the form of a computer program product implemented on one or more computer-usable non-transitory storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0203] So far, the compilation technical solution according to the present disclosure has been described in detail. To avoid obscuring the concept of the present disclosure, some details well known in the art have not been described. Those skilled in the art can fully understand how to implement the technical solution disclosed herein based on the above description.
[0204] The methods and systems of the present disclosure can be implemented in many ways. For example, the methods and systems of the present disclosure can be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the methods is only for illustration, and the steps of the methods of the present disclosure are not limited to the specific order described above, unless otherwise specifically stated. In addition, in some embodiments, the present disclosure can also be implemented as a program recorded in a recording medium, and these programs include machine-readable instructions for implementing the methods according to the present disclosure. Therefore, the present disclosure also covers the recording medium storing the programs for executing the methods according to the present disclosure.
[0205] Although some specific embodiments of the present disclosure have been described in detail by way of examples, those skilled in the art should understand that the above examples are only for illustration and not for limiting the scope of the present disclosure. Those skilled in the art should understand that the above embodiments can be modified without departing from the scope and spirit of the present disclosure.
Claims
1. A compilation method, comprising: Acquire a current syntax tree corresponding to a current source code, the current syntax tree comprising a subtree corresponding to each of a plurality of functional units of the current source code, the connection relationship between the subtrees being determined based on the logical dependencies between the plurality of functional units, the subtree corresponding to each functional unit comprising a parent node and a child node, the child node being determined based on context information of each functional unit, the context information comprising parameter information of each functional unit and a sub-operation within each functional unit, the subtree corresponding to each functional unit comprising an input child node determined based on input information in the parameter information, an output child node determined based on output information in the parameter information, a scope child node determined based on scope information in the parameter information, and a data dependency child node determined based on data dependency in the parameter information; Traversing the current syntax tree, determining, from the parent node and the child node, a target node in the child tree that has changed relative to a historical syntax tree corresponding to the historical source code; Based on the target node, determining a target compilation unit among the plurality of functional units; Compiling the current source code based on the target compilation unit to obtain a target code includes: In response to the target node being the data dependent child node, determining a specified functional unit among the plurality of functional units, wherein there is a logical dependency between the specified functional unit and a functional unit corresponding to the subtree where the target node is located; Determining whether the current source code has a syntax error according to the data dependency of the specified functional unit and the data dependency of the functional unit corresponding to the subtree where the target node is located; In response to determining that the current source code does not have a syntax error, compiling the current source code based on the target compiling unit.
2. The compiling method according to claim 1, wherein: The determining, based on the target node, a target compilation unit among the plurality of functional units comprises: In response to the target node being the parent node, determining a functional unit corresponding to the subtree where the target node is located as the target compilation unit; In response to the target node being a child node determined based on parameter information of a functional unit corresponding to a subtree where the target node is located, determining a functional unit corresponding to the subtree where the target node is located as the target compilation unit; and In response to the target node being a child node determined based on a sub-operation in a functional unit corresponding to a subtree where the target node is located, the sub-operation corresponding to the target node is determined as the target compilation unit.
3. The compiling method according to claim 1, wherein: The output of the designated functional unit is the input of the functional unit corresponding to the subtree where the target node is located. The determining whether the current source code has a syntax error according to the data dependency of the designated functional unit and the data dependency of the functional unit corresponding to the subtree where the target node is located comprises: Based on whether the data on which the functional unit corresponding to the subtree where the target node is located depends is a subset of the data on which the specified functional unit depends, determine whether the data flow between the functional unit corresponding to the subtree where the target node is located and the specified functional unit is consistent with the logical dependency between the functional unit corresponding to the subtree where the target node is located and the specified functional unit, so as to determine whether there is a syntax error in the current source code.
4. The compiling method according to any one of claims 1 to 3, wherein: The traversing the current syntax tree and determining, from the parent node and the child node, a target node in the child tree that has changed relative to a historical syntax tree corresponding to the historical source code comprises: Traversing the current syntax tree to determine the current hash value of the parent node; Compare the current hash value of the parent node with the historical hash value of the parent node in the historical syntax tree; According to the comparison result, the target node is determined from the parent node and the child node.
5. The compiling method according to claim 4, wherein: Determining the target node from the parent node and the child node according to the comparison result includes: In response to the comparison result being that the current hash value of the parent node is different from the historical hash value of the parent node in the historical syntax tree, determining the parent node as the target node; or In response to the comparison result that the current hash value of the parent node is the same as the historical hash value of the parent node in the historical syntax tree, the target node is determined from the child nodes.
6. The compiling method according to claim 5, wherein: The determining the target node from the child nodes comprises: Compare the current hash value of the child node with the historical hash value of the child node in the historical syntax tree, wherein the current hash value of the child node is determined by traversing the current syntax tree; In response to the comparison of the current hash value of the child node with the historical hash value of the child node in the historical syntax tree showing that the current hash value of the child node is different from the historical hash value of the child node in the historical syntax tree, the child node is determined as the target node.
7. The compiling method according to any one of claims 1 to 3, wherein: The compiling the current source code based on the target compilation unit to obtain the target code includes: Determine a specified compilation unit among the plurality of functional units that has a logical dependency on the target compilation unit; Compiling the target compilation unit and the specified compilation unit to obtain a new compiled code; The target code is obtained based on the new compiled code.
8. The compiling method according to claim 7, further comprising: storing the new compiled code in a cache area; Wherein, obtaining the target code based on the new compiled code comprises: Detecting in the cache area existing compiled codes corresponding to other functional units among the plurality of functional units except the target compilation unit and the designated compilation unit; In response to detecting existing compiled codes corresponding to the other functional units in the cache area, integrating the detected existing compiled codes and the new compiled codes to obtain the target code; and In response to not detecting the existing compiled code corresponding to the other functional unit in the cache area, compiling the other functional unit to obtain other new compiled code, and integrating the other new compiled code with the new compiled code to obtain the target code.
9. The compiling method according to claim 8, wherein: The cache area includes a first area and a second area; The storing the new compiled code in the cache area comprises: A first result of the newly compiled code is stored in the first area, and a second result of the newly compiled code is stored in the second area, where the second result is calculated based on the first result.
10. The compiling method according to claim 9, wherein: The obtaining of the target code based on the new compiled code comprises: Detecting in the second region a second result of existing compiled codes corresponding to other functional units among the plurality of functional units except the target compilation unit and the designated compilation unit; In response to detecting a second result of the existing compiled code in the second region, integrating the detected second result of the existing compiled code and the new compiled code to obtain the target code; In response to not detecting the second result of the existing compiled code in the second area, detecting the first result of the existing compiled code in the first area; In response to detecting a first result of the existing compiled code in the first region, compiling the other functional units based on the first result of the existing compiled code to obtain other new compiled codes, and integrating the other new compiled codes and the new compiled code to obtain the target code.
11. The compiling method according to any one of claims 1 to 3, wherein: At least one or more functional units among the plurality of functional units are predefined functional units in a predefined functional unit library.
12. A compiling device, comprising: an acquisition module, configured to acquire a current syntax tree corresponding to a current source code, the current syntax tree comprising a subtree corresponding to each of a plurality of function units of the current source code, the connection relationship between the subtrees being determined based on a logical dependency between the plurality of function units, the subtree corresponding to each function unit comprising a parent node and a child node, the child node being determined based on context information of each function unit, the context information comprising parameter information of each function unit and a sub-operation within each function unit, the subtree corresponding to each function unit comprising an input child node determined based on input information in the parameter information, an output child node determined based on output information in the parameter information, a scope child node determined based on scope information in the parameter information, and a data dependency child node determined based on data dependency in the parameter information; a determination module configured to traverse the current syntax tree, determine, from the parent node and the child node, a target node in the child tree that has changed relative to a historical syntax tree corresponding to the historical source code, and determine, based on the target node, a target compilation unit among the plurality of functional units; a compiling module, configured to compile the current source code based on the target compiling unit to obtain a target code, Wherein, the compiling module is configured as follows: In response to the target node being the data dependent child node, determining a specified functional unit among the plurality of functional units, wherein there is a logical dependency between the specified functional unit and a functional unit corresponding to the subtree where the target node is located; Determining whether the current source code has a syntax error according to the data dependency of the specified functional unit and the data dependency of the functional unit corresponding to the subtree where the target node is located; In response to determining that the current source code does not have a syntax error, compiling the current source code based on the target compiling unit.
13. A compiling device, comprising: Memory; and A processor coupled to the memory, wherein the processor is configured to execute the compiling method according to any one of claims 1 to 11 based on instructions stored in the memory.
14. A computer-readable storage medium having computer instructions stored thereon, wherein when the instructions are executed by a processor, the compiling method according to any one of claims 1 to 11 is implemented.
15. A computer program product, comprising instructions, which, when executed by a processor, cause the processor to perform the compilation method according to any one of claims 1 to 11.
Citation Information
Patent Citations
A program code similarity quick comparison method based on an abstract syntax tree,
CN109445834A
Code compiling detection method and automatic compiling platform
CN118963772A