Compiler and parallel compilation method

By introducing merge function modules into the compiler and merging differential content into the source code file, the problem that the compiler can only handle complete independent files in the existing technology is solved, and a more efficient compilation process and memory management are achieved.

CN119556940BActive Publication Date: 2025-05-09INT DIGITAL ECONOMY ACAD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510114338.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-24
Publication Date
2025-05-09
Estimated Expiration
2045-01-24

AI Technical Summary

Technical Problem

In the interactive development environment, the compiler can only compile completely independent files, resulting in the creation of completely independent files for each modification, which increases memory overhead and affects compilation efficiency.

Method used

Design a compiler that includes input modules, merge function modules and processing modules. By combining functional modules, differential content is merged into source code files, avoiding the creation of complete and independent files, and adopting a parallel compilation process to improve efficiency.

Benefits of technology

Reduces memory overhead and file conflict problems caused by creating complete independent files, improves compilation efficiency, and avoids file creation, reading and writing between the compiler and the language server.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119556940B_ABST
    Figure CN119556940B_ABST
Patent Text Reader

Abstract

The present application discloses a compiler and a parallel compilation method, wherein the compiler includes an input module, a plurality of merging function modules and a processing module, wherein the input module receives compilation information including a source code file and differential information, and then the merging function module parses the differential information to obtain differential content and differential operation information, and determines a target code file based on the differential operation information, the source code file and the differential content, and finally compiles the target code file through the processing module. The compiler provided by the present application introduces a merging function, and the differential content obtained in the development of an interactive development environment is merged into the source code file through the merging function, thereby avoiding the burden of additional memory and reading and writing caused by creating a complete and independent file for the compiler, and reducing the memory overhead caused by creating a new storage space for the differential content.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of programming language compilation, and in particular to a compiler and a parallel compilation method. Background Art

[0002] Many software developers use an interactive development environment (IDE) to develop software. In an interactive development environment, it is often necessary to make multiple independent modifications to the same project in the editor and verify them through the compiler. The compiler can only compile complete and independent files, so for each independent modification, a complete and independent file or even a workspace (including all project files) must be created to ensure that there is no conflict between the compilation processes of the independent modifications. However, this approach not only brings additional memory overhead to the code compilation process, but also affects the efficiency of code compilation.

[0003] Therefore the prior art still needs to be improved and enhanced. Summary of the invention

[0004] The technical problem to be solved by the present application is to provide a compiler and a parallel compilation method in view of the deficiencies of the prior art.

[0005] In order to solve the above technical problem, the first aspect of the present application provides a compiler, wherein the compiler includes:

[0006] An input module, used to obtain differential information and compile instructions sent by the controller, and determine a source code file based on the compile instructions;

[0007] Several merging function modules, used for parsing the differential information to obtain differential content and differential operation information, and determining the target code file based on the differential operation information, the source code file and the differential content;

[0008] The processing module is used to execute the compilation instruction to compile the target code file.

[0009] The compiler, wherein, when the number of merged function modules is a plurality of merged function modules, for any two adjacent merged function modules, the target code file determined by the merged function module located in front of the two adjacent merged function modules is used as the source code file of the merged function module located in the rear, and the differential information of the two merged function modules is the differential information corresponding to each other.

[0010] The compiler, wherein the controller is used to create a compilation process for the differential information, start the compilation process corresponding to the differential information to control the several merging function modules to parse the differential information to obtain differential content and differential operation information, and determine the target code file based on the differential operation information, the source code file and the differential content.

[0011] The compiler, wherein the compilation instruction also includes a target storage path generated by the controller for the differential information based on the differential identifier corresponding to the differential information, the target storage path includes a target address and a target file name, and the target address and / or the target file name carries the differential identifier of the differential information.

[0012] The compiler, wherein the merging function module specifically includes:

[0013] A parsing unit, used for parsing the differential information to obtain differential content and differential operation information;

[0014] A merging unit is used to determine a target code file based on the differential operation information, the source code file and the differential content.

[0015] The compiler, wherein the differential operation information is modification information of a source code file, or modification information of a syntax tree corresponding to the source code file, or modification information of an intermediate code representation generated during a compilation process.

[0016] The compiler, wherein the determining the target code file based on the differential operation information, the source code file and the differential content specifically comprises:

[0017] Reading the differential operation information, the source code file and the differential content;

[0018] The source code file is modified according to the differential operation information and the differential content to obtain a target code file.

[0019] The compiler, wherein the merging function module further comprises:

[0020] The processing unit is used to process the source code file and the differential content, and input the processed source code file and the processed differential content into the merging unit.

[0021] The compiler, wherein the processing unit specifically includes:

[0022] A code processing subunit, used for processing the source code file and inputting the processed source code file into the merging unit;

[0023] The differential content processing subunit is used to process the differential content and input the processed differential content into the merging unit.

[0024] The compiler, wherein the parsing unit is further used for:

[0025] Checking whether the differential content matches the differential operation information;

[0026] If the differential content matches the differential operation information, transmitting the differential content to the merging unit;

[0027] If the differential content does not match the differential operation information, the differential content is transmitted to the processing unit.

[0028] In the compiler, the parsing units in each merging function module parse the corresponding differential contents in parallel.

[0029] A second aspect of an embodiment of the present application provides a parallel compilation method, wherein the parallel compilation method specifically includes:

[0030] receiving a plurality of differential information and corresponding compilation instructions sent by the controller, wherein the compilation instructions include a source code file;

[0031] A plurality of differential information and their corresponding compilation instructions are compiled in parallel to obtain a plurality of compilation results, wherein the compilation process is to parse the differential information to obtain differential content and differential operation information, determine a target code file based on the differential operation information, the source code file and the differential content, and compile the target code file to obtain a compilation result.

[0032] The parallel compilation method, wherein the step of determining the target code file based on the differential operation information, the source code file and the differential content specifically comprises:

[0033] Read differential operation information, source code files and differential content;

[0034] The read source code file is modified according to the read differential operation information and differential content to obtain a target code file.

[0035] The parallel compilation method, wherein before reading the differential operation information, the source code file and the differential content, the method further comprises:

[0036] Determining whether the source code file needs to be processed based on the difference information;

[0037] If the source code file needs to be processed, the source code file is processed into a content format required by the differential operation information in the differential information, and the processed source code file is used as the source code file;

[0038] If the source code file does not need to be processed, the source code file remains unchanged.

[0039] The parallel compilation method, wherein before reading the differential operation information, the source code file and the differential content, the method further comprises:

[0040] Determining whether the differential content needs to be processed based on the differential operation information;

[0041] If the difference content does not need to be processed, keep the difference content unchanged;

[0042] If the differential content needs to be processed, the differential content is processed into a content format required by the differential operation information, and the processed differential content is used as the differential content.

[0043] The parallel compilation method, wherein the compilation instruction also includes a target storage path; after compiling the target code file to obtain a compilation result, the method further includes:

[0044] The compilation result is stored based on the target storage path, wherein the target storage path includes a target address and a target file name, and the target address and / or the target file name carries a differential identifier of the differential information.

[0045] Beneficial effect: Compared with the prior art, the present application provides a compiler and a parallel compilation method, the compiler including an input module, a plurality of merging function modules and a processing module, the input module receives compilation information including source code files and differential information, and then the merging function module parses the differential information to obtain differential content and differential operation information, and determines the target code file based on the differential operation information, the source code file and the differential content, and finally compiles the target code file through the processing module. The compiler provided by the present application introduces a merging function module, and the differential content obtained in the development using the interactive development environment is merged into the source code file through the merging function in the merging function module, and the compilation process is executed in parallel for the differential content with different compilation threads without modifying the source code file and without creating storage space for the complete independent file formed after the modification, thereby avoiding the burden of additional memory and reading and writing caused by creating a complete independent file for the compiler, which not only avoids the file conflict problem, but also reduces the memory overhead caused by the new creation of storage space for the complete independent file formed after the modification. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0047] Figure 1 A functional block diagram of a compiler provided in an embodiment of the present application.

[0048] Figure 2 A flowchart illustrating the interaction between the compiler and the controller.

[0049] Figure 3 A schematic block diagram of a compiler including a merging function module is shown in FIG.

[0050] Figure 4 A flowchart of one implementation of a compiler.

[0051] Figure 5 The flowchart of another implementation of the compiler is shown in FIG.

[0052] Figure 6 The flowchart of another implementation of the compiler is shown in FIG.

[0053] Figure 7 A flowchart of a parallel compilation method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0054] The embodiments of the present application provide a compiler and a parallel compilation method. To make the purpose, technical solution and effect of the present application clearer and more specific, the present application is further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0055] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.

[0056] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with those in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.

[0057] It should be understood that the sequence numbers and sizes of the steps in this embodiment do not mean the order of execution. The execution order of each process is determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.

[0058] The application content is further explained below through the description of embodiments in conjunction with the accompanying drawings.

[0059] This embodiment provides a compiler, such as Figure 1 As shown, the compiler includes an input module 100, several merging function modules 200 and a processing module 300. The input module 100 is used to obtain the differential information and compilation instructions sent by the controller, and determine the source code file based on the compilation instructions, and transmit the compilation instructions, differential information and source code files to the merging function module 200. The merging function module 200 is used to parse the differential information to obtain differential content and differential operation information, and determine the target code file based on the differential operation information, the source code file in the compilation instruction and the differential content, and pass the target code file to the processing module 300; the processing module 300 is used to process the target code file to obtain the compilation result. The compiler provided by the present application introduces a merging function module, and the differential content obtained in the development using the interactive development environment is merged into the source code file through the merging function in the merging function module. Without modifying the source code file and without creating storage space for the differential content, the compilation process is executed in parallel for the differential content with different compilation threads, and there is no need to create and read and write files between the compiler and the language server. This not only avoids file conflicts, but also reduces the memory overhead caused by the newly created storage space for the differential content.

[0060] The embodiment of the present application does not specifically limit which high-level programming language (such as C language, C++ language, Java language, etc.) the source code file to be compiled by the compiler belongs to. The following description only takes the source code file implemented based on the C language as an example, and its principle can be extended to other types of high-level programming language source code files. At the same time, in order to more clearly explain the compiler provided by the present application, the input module 100, the merging function module 200 and the processing module 300 included in the compiler are described below.

[0061] First, the input module 100 is described. The input module 100 is used to obtain differential information and compilation instructions sent by the controller. For example, the input module 100 can communicate with the controller that controls the compiler to compile the code, and receive differential information and compilation instructions sent by the controller. After obtaining the compilation instructions, the input module 100 can determine the source file code based on the compilation instructions. For example, when the compilation instructions directly include the source file code, the input module 100 can directly read it from the compilation instructions, or, when the compilation instructions can include source code file information, the compiler reads the source file code based on the identification information of the source code file, wherein the source code file information is the identification information of the source code file, such as the root directory address, etc. In the embodiment of the present application, Figure 2 As shown, the compile instruction includes the root directory address of the source code file, and the input module 100 reads the root directory address in the compile instruction, and then reads the source file code based on the root directory address.

[0062] The differential information indicates the modification information corresponding to the source code file, and the differential information includes differential content and differential operation information. The differential content includes multiple differential types such as source code or syntax tree or intermediate code representation generated during the compilation process, and the differential operation information is the operation performed on. For example, when the differential content is source code, the differential operation information is what kind of operation needs to be performed on the source code, for example, it can be modification, addition, deletion of the source code, or modification of the syntax tree. For another example, when the differential content is a syntax tree, the differential operation information can be modification of the syntax tree, etc. For another example, when the differential content is an intermediate code representation generated during the compilation process, the differential operation information can be modification of the intermediate code representation generated during the compilation process, etc. In other words, based on the differential operation information, the modification operation that needs to be performed on the differential content can be known, and based on the differential content, different differential operation information can be set to obtain the modification content corresponding to the modification operation.

[0063] Further, the differential information in the compilation instruction may be one or more. For this purpose, the compilation instruction may further include a target storage path. When compiling based on the differential information, the target code determined based on the differential information and the source code file and the compilation result corresponding to the target code may be stored according to the target storage path to avoid the problem of conflicting inspection results generated when the differential information is compiled in parallel. Wherein, the target storage path is generated for the differential information based on the differential identifier corresponding to the differential information, and the target storage path includes a target address and a target file name, and the target address and / or the target file name carry the differential identifier of the differential information. The target address is the storage address of the compilation result, and the target file name is the file name for storing the compilation result. That is, each differential information corresponds to a target address and a target file name, and at least one of the target address and the target file name corresponding to each differential information is different, that is, the compilation result corresponding to each differential information can be stored in a file with a different file name in the same storage address, or in a file with the same file name in different storage addresses. In this way, there is no specific restriction on the target address and the target file name, as long as the storage method that can ensure that the reading and writing of each differential information does not conflict is acceptable.

[0064] The input module in the embodiment of the present application receives the compilation instruction transmitted by the controller, obtains the source code file and the target storage path corresponding to the differential information through the compilation instruction, and then transmits the source code file, the differential information and the target storage path corresponding to the differential information to the merging function module, and transmits it to the processing module through the merging function module, so as to facilitate the compilation result corresponding to the differential information according to the target storage path corresponding to the differential information, thereby avoiding the problem of compilation result conflicts caused by parallel compilation of various differential information.

[0065] The above is the description of the input module 100 , and the merging function module 200 will be described below.

[0066] At present, in the modern interactive development environment, it is often necessary to make multiple independent modifications based on the same project in the editor and verify them through the compiler. The compiler can only compile complete and independent files, so when making each independent modification, a complete and independent file or even a workspace (including all project files) will be created to ensure that there will be no conflict between the compilation processes of each independent modification. However, this processing method not only brings additional memory overhead to the code compilation process, but also affects the efficiency of code compilation. In the embodiment of the present application, a merging function module is set in the compiler, and the differential content obtained in the development of the interactive development environment is merged into the source code file through the merging function in the merging function module. When the source code file does not need to be modified and the storage space is not created for the complete independent file formed after the modification, the compilation process is executed in parallel for the differential content with different compilation threads, avoiding the burden of additional memory and reading and writing for creating a complete and independent file for the compiler, so that not only can the file conflict problem be avoided, but also the memory overhead caused by the new creation of storage space for the complete independent file formed after the modification is reduced.

[0067] Specifically, the compiler provided in the embodiment of the present application includes several merging function modules 200, and the several merging function modules can be one merging function module, such as Figure 3 or, the plurality of merged function modules 200 are multiple merged function modules (the plurality of merged function modules include 2 or more merged function modules), such as Figure 1 As shown. Moreover, when the plurality of merge function modules 200 is a plurality of merge function modules, the number of the plurality of merge function modules can be preset, can be set according to actual needs, and can also be determined according to actual use. In one implementation, after receiving a compilation instruction for a source code file, the number of merge function modules is determined according to the number of differential information or the type of differential information included in the running instruction (e.g., when determined according to the number of differential information corresponding to the source file, a merge function module is deployed for each differential information; when determined according to the type of differential information corresponding to the source file, a merge function module is set for each type of differential information, etc.), and the plurality of merge function modules are cascaded, wherein the type of differential information can be a modification to the source code, a modification to the syntax tree, a modification to the intermediate code representation, etc.

[0068] In addition, in the process of compiling in response to the compilation instruction for the source code file, if new differential information for the source code file is received, a merge function module is added between the last merge function module and the processing module, and the newly received differential information is responded to through the merge function module to directly obtain the processing result corresponding to the processing module. Of course, in actual applications, a fixed number of merge function modules can also be set. When the differential information is less than or equal to the merge function module, a merge function module is configured for each differential information. When the differential information is more than the merge function module, the merge function module can be first allocated to the number of differential information of the merge function modules, and the remaining differential information is in a waiting state. When a merge function module is executed, the differential information is allocated to the merge function module, and so on, until all differential information is responded to, and the final target code file is transmitted to the processing module.

[0069] When the plurality of merged function modules are multiple merged function modules, the multiple merged function modules process the differential content in sequence according to the differential content type and the compilation order of the compilation level. The compilation order may be source code syntax parsing into syntax tree, syntax tree compilation into multi-layer intermediate code representation, wherein the processing order of the multiple merged function modules may be in accordance with the order of the compilation process of the multi-layer intermediate code representation, etc. The processing unit may implement functions such as syntax parsing, type deduction or compilation, wherein, for any two merged function modules that are adjacent in the processing order, the target code file determined by the merged function module located in front of the two adjacent merged function modules is used as the source code file of the merged function module located behind, and the differential information of the two merged function modules is the differential information corresponding to each other. For example, two adjacent merge function modules are respectively recorded as the first merge function module and the second merge function module, the first merge function module corresponds to the first differential information, the second merge function module corresponds to the second differential information, and the first merge function module is located before the second merge function module. Then, the source code file input into the second merge function module is the target code file output by the first merge function module, the differential information input into the second merge function module is the second differential information, and the differential information input into the first merge function module is the first differential information.

[0070] like Figure 4As shown, the merging function module 200 includes a parsing unit and a merging unit, the parsing unit and the merging unit are both connected to the input module, the parsing unit is connected to the merging unit, the differential information obtained by the input module is transmitted to the parsing unit, the source code file obtained by the input module is transmitted to the merging unit, and the differential content and differential operation information obtained by the parsing unit are transmitted to the merging unit, wherein the differential operation information is the modification information of the source code file, or the modification information of the syntax tree corresponding to the source code file, or the modification information of the intermediate code generated during the compilation process. Correspondingly, the parsing unit will receive the differential information transmitted by the input module, parse the differential information to obtain the differential content and differential operation information, and transmit the differential content and differential operation obtained by the parsing to the merging unit, the merging unit will receive the source code file transmitted by the input module and the differential content and differential operation information transmitted by the parsing module, and then modify the source code file based on the differential operation information and differential content to obtain the target code file. The merging unit is used to read the differential operation information, the source code file and the differential content; and process the source code file according to the differential operation information and the differential content (for example, modify, delete and add, etc.) to obtain the target code file.

[0071] For example: Assume that the source code file obtained by the input module is:

[0072] int main(){

[0073] printf("%d\n",1);

[0074] return 0;

[0075] };

[0076] The differential information obtained by the input module is:

[0077] ---a / ac

[0078] +++b / ac

[0079] @@-1,3+1,4@@

[0080] +#include<stdio.h>

[0081] int main(){

[0082] printf("%d\n",1);

[0083] Return 0;

[0084] }.

[0085] Then the input module inputs the differential information into the parsing unit, and the parsing unit parses to obtain the differential content and differential operation information. The differential content is #include<stdio.h> ; The differential operation information is to insert the differential content in the first line. The parsing unit transmits the differential content and differential operation information to the merging unit, and the input module transmits the source code file to the merging unit. The merging unit processes the source code file according to the differential content and differential operation to obtain the target code file:

[0086] #include<stdio.h>

[0087] int main(){

[0088] printf("%d\n",1);

[0089] Return 0;

[0090] }.

[0091] It should be noted that when there are multiple merge function modules and the compilation information includes multiple differential information, the parsing unit in each merge function module parses the corresponding differential content in parallel, that is, each differential information corresponds to a merge function unit, and the parsing unit in each merge function module works in parallel, and the merge unit in each merge function module performs the modification operation on the source code file in sequence according to the cascade order of the merge function module, wherein the modification operation is determined based on the differential information. The present application performs the modification operation in sequence according to the cascade order by the merge unit, and parses the differential information in parallel by the parsing unit, so that on the one hand, it can respond to the modification operation corresponding to all differential information, and can verify all modifications made to the source code file, and on the other hand, it can enable the compiler to parse multiple differential information in parallel, improve the parsing efficiency of the differential information, and then improve the compilation efficiency of the compiler. At the same time, each merge function module in the embodiment of the present application corresponds to a differential information, and each differential information corresponds to a target address and a target file name, so that the processing result formed by the execution of each merge function module can be stored in the target address corresponding to each other and stored in the target file name, avoiding the read-write conflict problem caused by the parallel processing of the parsing modules in multiple merge function modules.

[0092] In one implementation, before modifying the source code file according to the differential operation information and the differential content, there may be a need to process the differential content and / or the source code file so that the processed differential content and the source code file can meet the modification operation requirements corresponding to the differential operation information. Figure 5As shown, the merging function module 200 may also include a processing unit, the processing unit is used to process the source code file and the differential content, and input the processed source code file and the processed differential content to the merging unit. That is, the processing unit is connected to the input module, the parsing unit and the merging unit respectively, the input module transmits the source code file to the processing unit, the parsing unit transmits the differential content to the processing unit, the processing unit processes the source code file and the differential content, and transmits the processed source code file and the processed differential content to the merging unit. Among them, the processing unit can be used for syntax parsing, type deduction and compilation, that is, the processing unit can be a syntax parsing unit, a type deduction unit or a compilation unit, etc.

[0093] It should be noted that when the controller sends the compilation instruction to the compiler, it creates a new compilation thread for each differential information to control the compilation process of the compiler, including the parameters of each layer of compilation, and determines whether the next layer of compilation is executed based on the compilation result of the previous layer. The compiler can perform multi-layer compilation according to the compilation instruction. When the compilation of the previous layer is successful, the compilation process of the next layer is carried out, and the compilation results of each layer are recorded. Among them, the compilation results and intermediate files generated during the compilation process will be stored in the target storage path, which can avoid conflicts when the compilation process is executed in parallel for multiple differential information. Each layer of the compilation process can be understood as the processing process of a merging function module, and the compilation result of each layer is the result of the processing of the processing unit in a merging function module. Each layer of the compilation process can also be understood as the whole process of compiling and processing for each differential information, and the result finally output by the compiler through the processing module for each differential information is the compilation result.

[0094] In addition, after the source code file and the differential content are input into the processing unit, the processing unit may process the source code file and the differential content, or may only process the source code file, or may only process the differential content, etc. To this end, after receiving the source code file and the differential content, the processing unit will first determine whether the source code file and the differential content need to be processed, and then process the source code file and / or the differential content that need to be processed. Among them, whether the source code file and the differential content need to be processed can be determined based on the differential operation information in the differential information, that is, whether the source code file and the differential content need to be processed can be determined by whether the modification operation performed between the differential content and the source code file matches, and whether the source code file and / or the differential content need to be processed can also be determined based on the format pre-set in the differential information.

[0095] Specifically, when the content form of the differential content and the source code file meets the content form required by the modification operation (i.e., the differential operation information in the differential information), the differential content and the source code file do not need to be modified; conversely, when the content form of the differential content does not meet the content form required by the modification operation, the differential content is processed so that the content form of the differential content meets the content form required by the modification operation; when the content form of the source code file does not meet the content form required by the modification operation, the source code file is processed so that the content form of the source code file meets the content form required by the modification operation. In addition, in actual applications, other methods can be used to determine whether the source code file and the differential content need to be processed. For example, the source code file and the differential content included in the compilation information can directly carry a processing tag, and the processing tag is used to determine whether the source code file and the differential content need to be processed, wherein the processing tag can include whether it needs to be processed or not.

[0096] Furthermore, the process of determining whether the source code file and the differential content need to be processed can be determined before being input into the processing unit, or can be determined by the processing unit, and the determination process can adopt the following determination method, and the source code file and / or the differential content that does not need to be processed can be directly input into the merging unit instead of being input into the processing unit. That is to say, when the merging function module includes a processing unit, the source code file and the differential content can also directly enter the merging unit without passing through the processing unit. In addition, the process of determining whether the source code file and the differential content need to be processed can also be performed by the processing unit, that is, after receiving the source code file and the differential content, the processing unit checks whether the source code file and the differential content need to be processed, processes them when they need to be processed, and keeps them unchanged when they do not need to be processed. Among them, the process of determining whether the source code file and the differential content need to be processed can be determined before being input into the processing unit, or can be determined by the processing unit, and the determination process can adopt the above determination method.

[0097] In a specific implementation, the determination process of whether the differential content needs to be processed is completed by the parsing unit, that is, the parsing unit is also used to check whether the differential content matches the differential operation information; if the differential content matches the differential operation information, the differential content is transmitted to the merging unit; if the differential content does not match the differential operation information, the differential content is transmitted to the processing unit. Wherein, checking whether the differential content matches the differential operation information refers to checking whether the differential content needs to be processed based on the differential operation information; if the differential content matches the differential operation information, it means that the differential content does not need to be processed, that is, the content form of the differential content meets the content form required by the differential operation, and the differential content is directly transmitted to the merging unit; if the differential content does not match the differential operation information, it means that the differential content needs to be processed, that is, the content form of the differential content does not meet the content form required by the differential operation, and the differential content is transmitted to the processing unit, and the differential content is processed by the processing unit so that the content form of the processed differential content meets the content form required by the modification operation. That is, in this specific implementation, the parsing unit determines whether the differential content needs to be processed, and if so, transmits the differential content to the processing unit; if not, transmits the differential content to the merging unit.

[0098] In a specific implementation, the process of determining whether the differential content needs to be processed can be determined based on a pre-set format of the differential information. For example, the pre-set format of the differential information is as follows:

[0099] {

[0100] "Source code modification":[..],

[0101] "Syntax tree modification":[..]

[0102] "Intermediate code representation generated during compilation":[..]

[0103] }.

[0104] In a specific implementation, the process of determining whether the source code file needs to be processed is completed by the input module, that is, the input module is also used to check whether the content form of the source code file meets the content form required by the modification operation corresponding to the differential information; if the content form of the source code file meets the content form required by the modification operation, the source code file is transmitted to the merging unit; if the content form of the source code file does not meet the content form required by the modification operation, the source code file is transmitted to the processing unit, and the source code file is processed by the processing unit so that the content form of the processed source code file meets the content form required by the modification operation. That is, this specific implementation determines whether the source code file needs to be processed through the input module, and if it needs to be processed, the source code file is transmitted to the processing unit, and if it does not need to be processed, the source code file is transmitted to the merging unit.

[0105] Specific Example 1 and Specific Example 2 are given below. In Specific Example 1, the source code file code needs to be processed, but the differential content does not need to be processed; in Specific Example 2, both the source code file code and the differential content need to be processed.

[0106] Specific example 1:

[0107] The input module reads the source code file as:

[0108] int main(){

[0109] printf("%d\n",1);

[0110] return 0;

[0111] };

[0112] The input module reads the differential information to modify the syntax tree, which is as follows:

[0113] {

[0114] "insert": {

[0115] "position": 0,

[0116] "type": "FunctionDecl", "name": "printf", "content": "int(const char*,...)"

[0117] }

[0118] };

[0119] Since the merge occurs between syntax trees, and the source code file is a code file, the source code file needs to be processed to obtain a syntax tree corresponding to the main function implementation. The difference content obtained by parsing the difference information is a function declaration named printf with a signature of int (const char*, ...), and the difference operation information is to insert the function declaration into the top-level declaration list of the syntax tree.

[0120] To this end, only the source code file needs to be processed, and the differential content does not need to be processed, that is, the differential content can be directly merged with the processed source code file. Specifically, the source code file is input into the processing unit, and the processing unit performs syntax parsing on the source code file to obtain a syntax tree corresponding to the main function implementation, and then the syntax tree of the main function implementation is input into the merging unit, and the parsing unit directly inputs the differential content and differential operation information into the merging unit, and the syntax tree of the main function implementation is processed by the merging unit to obtain a new syntax tree, wherein the printf function declaration already exists in the new syntax tree, and the subsequent processing module will not report an error that "printf" is not declared.

[0121] Specific example 2:

[0122] The input module reads the source code file as:

[0123] int main(){

[0124] printf("%d\n",1);

[0125] return 0;

[0126] };

[0127] The input module reads the differential information to modify the syntax tree, which is specifically:

[0128] {

[0129] "insert": {

[0130] "position": 0,

[0131] "src": "int printf(const char * format,...);"

[0132] }

[0133] };

[0134] Since the merge occurs between syntax trees, and the source code file is a code file, the source code file needs to be processed to obtain a syntax tree corresponding to the main function implementation. The difference content obtained by parsing the difference information is a source code with the content "int printf (const char * format, ...);", and the difference operation information is to insert the source code into the top-level declaration list of the syntax tree.

[0135] To this end, the source code file and the differential content need to be processed. Specifically, the source code file is input into the processing unit, and the source code file is parsed by the processing unit to obtain a syntax tree corresponding to the main function implementation, and then the syntax tree of the main function implementation is input into the merging unit. The parsing unit directly transmits the differential content to the processing unit, and the processing unit processes the differential content into a syntax tree corresponding to the printf function declaration, and transmits the syntax tree corresponding to the printf function declaration to the merging unit. The merging unit processes the syntax tree of the main function implementation to obtain a new syntax tree, wherein the printf function declaration already exists in the new syntax tree, and the subsequent processing module will not report an error that "printf" is not declared.

[0136] Furthermore, since the processing unit is used to process the source code file and the differential content, for this purpose, Figure 6 As shown, the processing unit may include two sub-processing units, which are respectively recorded as a code processing sub-unit and a differential content processing sub-unit. The code processing sub-unit is used to process the source code file and input the processed source code file into the merging unit. The differential content processing sub-unit is used to process the differential content and input the processed differential content into the merging unit. In this way, the source code file and the differential content can be processed in parallel by the code processing sub-unit and the differential content processing sub-unit to improve the processing efficiency. Of course, in actual applications, the processing unit does not have a code processing sub-unit and a differential content processing sub-unit, but the processing unit processes the source code file and the differential content. That is, when the source code file and the differential content need to be processed at the same time, they can be processed in the order of source code file-differential content or differential content-source code file. In this way, the problem of idle sub-processing units caused by only the source code file or the differential file needing to be processed can be avoided.

[0137] The above is the description of the merging function module 200 , and the processing module 300 will be described below.

[0138] The processing module 300 is used to process the target code file determined by the merging function module, wherein the processing module 300 can perform syntax analysis, type deduction or compilation on the target code file. In addition, the processing module 300 stores the compilation result corresponding to the target code file in a preset storage address, for example, presetting the target address and target file name of the compilation result corresponding to the processing module, and then in the process of the processing module processing the target code file, the intermediate result and the final result obtained by the processing are kept in the file named as the target file name in the target address.

[0139] In summary, the present embodiment provides a compiler, the compiler includes an input module, at least one merging function module and a compiling module, the input module is used to receive compiling instructions, at least one merging function module is used to parse the differential information to obtain differential content and differential operation information, and determine the target code file based on the differential operation information, the source code file and the differential content; the compiling module is used to execute the compiling instruction to compile the target code file. The compiler provided in the embodiment of the present application integrates the merging function, so that the compiler can obtain the target code file according to the differential content, and does not need to modify the source code file and does not create storage space for the modified content. In the case of parallel execution of the compilation process for the differential content with different compiling threads, it can not only reduce the memory overhead caused by creating storage space for the modified content in the prior art, but also avoid the problem of file reading and writing. In particular, when developing in an interactive development environment, the differential information corresponding to the target code file generated by the language server can be directly transmitted to the compiler, and the compiler can merge the differential content into the source code to obtain the target code file through the merging function of the merging function module, avoiding the creation and reading and writing of files between the compiler and the language server.

[0140] Based on the above compiler, the embodiment of the present application also provides a parallel compilation method, such as Figure 7 As shown, the parallel compilation method specifically includes:

[0141] S10, receiving a plurality of differential information and corresponding compilation instructions sent by the controller, wherein the compilation instructions include a source code file;

[0142] S20. Compile a number of differential information and their corresponding compilation instructions in parallel to obtain a number of compilation results, wherein the compilation process is to parse the differential information to obtain differential content and differential operation information, determine the target code file based on the differential operation information, the source code file and the differential content, and compile the target code file to obtain the compilation result.

[0143] In one implementation, determining the target code file based on the differential operation information, the source code file, and the differential content specifically includes:

[0144] Read differential operation information, source code files and differential content;

[0145] The read source code file is modified according to the read differential operation information and differential content to obtain a target code file.

[0146] In one implementation, before reading the differential operation information, the source code file, and the differential content, the method further includes:

[0147] Determining whether the source code file needs to be processed based on the difference information;

[0148] If the source code file needs to be processed, the source code file is processed into a content format required by the differential operation information in the differential information, and the processed source code file is used as the source code file;

[0149] If the source code file does not need to be processed, the source code file remains unchanged.

[0150] In one implementation, before reading the differential operation information, the source code file, and the differential content, the method further includes:

[0151] Determining whether the differential content needs to be processed based on the differential operation information;

[0152] If the difference content does not need to be processed, keep the difference content unchanged;

[0153] If the differential content needs to be processed, the differential content is processed into a content format required by the differential operation information, and the processed differential content is used as the differential content.

[0154] In one implementation, the compilation instruction further includes a target path; after compiling the target code file to obtain a compilation result, the method further includes:

[0155] The compilation result is stored based on the target path, wherein the target address and / or the target file name carries a differential identifier corresponding to the differential information, the target path includes a target address and a target file name, and the target address and / or the target file name carries the differential identifier of the differential information.

[0156] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. 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.

Claims

1. A compiler, characterized in that: The compiler comprises: An input module, used to obtain differential information and compile instructions sent by the controller, and determine a source code file based on the compile instructions; Several merging function modules, used for parsing the differential information to obtain differential content and differential operation information, and determining the target code file based on the differential operation information, the source code file and the differential content, wherein the differential operation information is modification information of the source code file, or modification information of the syntax tree corresponding to the source code file, or modification information of the intermediate code representation generated during the compilation process; A processing module, used for executing the compilation instruction to compile the target code file; Among them, when the several merged function modules are multiple merged function modules, the number of merged function modules is determined according to the number of differential information or the type of differential information, and the multiple merged function modules process the differential content in sequence according to the differential content type and the compilation order of the compilation level, and for any two adjacent merged function modules, the target code file determined by the previous merged function module of the two adjacent merged function modules is used as the source code file of the subsequent merged function module, and the differential information of the two merged function modules is the differential information corresponding to each other.

2. The compiler according to claim 1, characterized in that The controller is used to create a compilation process for the differential information, start the compilation process corresponding to the differential information to control the several merging function modules to parse the differential information to obtain differential content and differential operation information, and determine the target code file based on the differential operation information, the source code file and the differential content.

3. The compiler according to claim 1, characterized in that The compilation instruction also includes a target storage path generated by the controller for the differential information based on the differential identifier corresponding to the differential information, the target storage path includes a target address and a target file name, and the target address and / or the target file name carries the differential identifier of the differential information.

4. The compiler according to claim 1, characterized in that The merging function module specifically includes: A parsing unit, used for parsing the differential information to obtain differential content and differential operation information; A merging unit is used to determine a target code file based on the differential operation information, the source code file and the differential content.

5. The compiler according to claim 4, characterized in that The determining of the target code file based on the differential operation information, the source code file and the differential content specifically includes: Reading the differential operation information, the source code file and the differential content; The source code file is modified according to the differential operation information and the differential content to obtain a target code file.

6. The compiler according to claim 5, characterized in that The merging function module also includes: The processing unit is used to process the source code file and the differential content, and input the processed source code file and the processed differential content into the merging unit.

7. The compiler according to claim 6, characterized in that The processing unit specifically includes: A code processing subunit, used for processing the source code file and inputting the processed source code file into the merging unit; The differential content processing subunit is used to process the differential content and input the processed differential content into the merging unit.

8. The compiler according to claim 6, characterized in that The parsing unit is also used for: Checking whether the differential content matches the differential operation information; If the differential content matches the differential operation information, transmitting the differential content to the merging unit; If the differential content does not match the differential operation information, the differential content is transmitted to the processing unit.

9. The compiler according to claim 4, characterized in that: The parsing units in each merging functional module parse the corresponding differential contents in parallel.

10. A parallel compilation method, characterized in that: The parallel compilation method specifically includes: receiving a plurality of differential information and corresponding compilation instructions sent by the controller, wherein the compilation instructions include a source code file; A plurality of differential information and corresponding compilation instructions are compiled in parallel to obtain a plurality of compilation results, wherein the compilation process is to parse the differential information to obtain differential content and differential operation information, determine a target code file based on the differential operation information, the source code file and the differential content, and compile the target code file to obtain a compilation result, wherein the determination of the target code file based on the differential operation information, the source code file and the differential content is executed by a merging function module in the compiler, and when the compiler includes a plurality of merging function modules, the number of merging function modules is determined according to the number of differential information or the type of differential information, the plurality of merging function modules process the differential content in sequence according to the type of differential content and the compilation order of the compilation level, and for any two adjacent merging function modules, the target code file determined by the merging function module located in front of the two adjacent merging function modules is used as the source code file of the merging function module located in the back, and the differential information of the two merging function modules is the corresponding differential information, wherein the differential operation information is the modification information of the source code file, or the modification information of the syntax tree corresponding to the source code file, or the modification information of the intermediate code representation generated during the compilation process.

11. The parallel compilation method according to claim 10, characterized in that: The determining of the target code file based on the differential operation information, the source code file and the differential content specifically includes: Read differential operation information, source code files and differential content; The read source code file is modified according to the read differential operation information and differential content to obtain a target code file.

12. The parallel compilation method according to claim 11, characterized in that: Before reading the differential operation information, the source code file and the differential content, the method further includes: Determining whether the source code file needs to be processed based on the difference information; If the source code file needs to be processed, the source code file is processed into a content format required by the differential operation information in the differential information, and the processed source code file is used as the source code file; If the source code file does not need to be processed, the source code file remains unchanged.

13. The parallel compilation method according to claim 11 or 12, characterized in that: Before reading the differential operation information, the source code file and the differential content, the method further includes: Determining whether the differential content needs to be processed based on the differential operation information; If the difference content does not need to be processed, keep the difference content unchanged; If the differential content needs to be processed, the differential content is processed into a content format required by the differential operation information, and the processed differential content is used as the differential content.

14. The parallel compilation method according to claim 13, characterized in that: The compile instruction also includes a target storage path; after compiling the target code file to obtain a compile result, the method further includes: The compilation result is stored based on the target storage path, wherein the target storage path includes a target address and a target file name, and the target address and / or the target file name carries a differential identifier of the differential information.

Citation Information

Patent Citations

  • Code testing method and device

    CN115129574A