Precompilation method, device and computer program product

By parsing and analyzing the header file reference relationship in the source file, automatically filtering and adding it to the precompiled header file, the problem of traditional precompilation technology relying on subjective selection is solved, and a more efficient compilation process is achieved.

CN114968247BActive Publication Date: 2025-05-16ALIBABA GROUP HOLDING LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202110199012.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-02-22
Publication Date
2025-05-16
Estimated Expiration
2041-02-22

AI Technical Summary

Technical Problem

In large-scale C/C++ projects, traditional precompilation technology relies on the subjective choices of developers, resulting in limited speed-up effect of compilation time.

Method used

By parsing the source files contained in the target object, determining the number of header files and source files directly referenced by the source file, extracting the characteristic information of the header file, and determining whether to add the header file to the precompiled header file based on this information, thereby realizing automated precompilation processing.

Benefits of technology

By automatically extracting and filtering the feature information of the header file, a precompiled header file containing the important header files that are actually referenced in the target object is generated, which significantly improves the compilation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114968247B_ABST
    Figure CN114968247B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a precompilation method, device and computer program product, the method comprising: parsing the source files contained in the target object to determine the number of header files and source files directly referenced by the source files; determining the characteristic information of the header files; determining whether to add the header files to the precompiled header files corresponding to the target object according to the characteristic information of the header files and the number of source files; and precompilation processing of the precompiled header files corresponding to the target object. By automatically extracting the characteristic information of the header files directly referenced by the source files, combined with the characteristic information of the header files, a precompiled header file containing the important header files actually referenced in the target object is automatically and accurately generated, so that when the target object is compiled based on the precompiled header file, a higher compilation efficiency can be obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a pre-compilation method, device and computer program product. Background Art

[0002] Large C / C++ projects contain hundreds or thousands of header files and source files, and compiling them once usually takes dozens of minutes or even hours. Fortunately, many compilers currently provide precompilation technology. By using precompilation technology in a project, the overall compilation time of the project can be greatly shortened.

[0003] In the traditional solution, developers directly select the header files that need to be precompiled from several header files included in the project to generate a precompiled header file, and then perform precompilation processing on the precompiled header file. However, the developer selects the header file used to generate the precompiled header file based on subjective experience, and the final result may have limited effect on speeding up the compilation time. Summary of the invention

[0004] The embodiments of the present invention provide a pre-compilation method, apparatus, device and computer program product, which can improve compilation efficiency.

[0005] In a first aspect, an embodiment of the present invention provides a precompilation method, the method comprising:

[0006] Parse the source files included by the target object to determine the number of header files and source files directly referenced by the source files;

[0007] Determining characteristic information of the header file;

[0008] Determining whether to add the header file to a precompiled header file corresponding to the target object according to the characteristic information of the header file and the number of the source files;

[0009] Precompile the precompiled header file corresponding to the target object.

[0010] In a second aspect, an embodiment of the present invention provides a pre-compilation device, the device comprising:

[0011] A parsing module, used for parsing the source files included in the target object to determine the number of header files and source files directly referenced by the source files;

[0012] A first determining module, used to determine characteristic information of the header file;

[0013] A second determination module, configured to determine whether to add the header file to the precompiled header file corresponding to the target object according to the characteristic information of the header file and the number of the source files;

[0014] The pre-compilation module is used to pre-compile the pre-compiled header file corresponding to the target object.

[0015] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: a memory and a processor; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor can at least implement the precompilation method described in the first aspect.

[0016] In a fourth aspect, an embodiment of the present invention provides a computer program product, comprising: a computer program, when the computer program is executed by a processor of an electronic device, the processor can at least implement the precompilation method as described in the first aspect.

[0017] In an embodiment of the present invention, before a target object (such as a project or a functional module in a project) including several source files and several header files needs to be compiled, a precompiled header file corresponding to the target object is first generated, so as to improve the compilation efficiency of the target object based on the precompilation result of the precompiled header file. To generate the precompiled header file corresponding to the target object, first, several source files included in the target object are parsed to obtain header files directly referenced by the source files, and the number of source files included in the target object. In fact, multiple header files are often obtained, each of which is directly referenced by one or more source files, and the following processing is performed for each of the multiple header files: determining the characteristic information of the header file, determining whether to add the header file to the precompiled header file corresponding to the target object in combination with the characteristic information of the header file and the number of the source files, and if the determination result is yes, then adding the header file to the precompiled header file, so that the header file will be precompiled in the precompilation process.

[0018] In the above scheme, by automatically extracting the characteristic information of the header files directly referenced by the source files and combining the characteristic information of the header files, a precompiled header file containing the important header files actually referenced in the target object is automatically and accurately generated, so that when the target object is compiled based on the precompiled header file, higher compilation efficiency can be obtained. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0020] Figure 1 A flowchart of a pre-compilation method provided by an embodiment of the present invention;

[0021] Figure 2 A schematic diagram of the organizational structure of a project provided by an embodiment of the present invention;

[0022] Figure 3 A schematic diagram of the organizational structure of a source file provided by an embodiment of the present invention;

[0023] Figure 4 A flowchart of a pre-compilation method provided by an embodiment of the present invention;

[0024] Figure 5 A schematic diagram of the structure of a pre-compilation device provided by an embodiment of the present invention;

[0025] Figure 6 For Figure 5 A schematic diagram of the structure of an electronic device corresponding to the pre-compilation device provided in the illustrated embodiment. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0027] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings, and "multiple" generally includes at least two.

[0028] As used herein, the words "if" and "if" may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.

[0029] In addition, the step sequence in the following method embodiments is only an example and not a strict limitation.

[0030] The pre-compilation method provided in the embodiment of the present invention can be performed by an electronic device. The electronic device can be a terminal device such as a PC, a laptop, a tablet computer, etc. The electronic device can also be a server in the cloud. The server can be a physical server including an independent host, or it can also be a virtual server, or it can also be a cloud server. The above electronic device will have a certain type of operating system. A compiler is running in the above electronic device, and the above pre-compilation method can be specifically performed by the compiler.

[0031] The following describes in detail the execution process of the pre-compilation method provided by the embodiment of the present invention.

[0032] Figure 1 A flowchart of a pre-compilation method provided by an embodiment of the present invention is as follows Figure 1 As shown, the method comprises the following steps:

[0033] 101. Parse the source files included in the target object to determine the number of header files and source files directly referenced by the source files.

[0034] 102. Determine characteristic information of the header file.

[0035] 103. Determine whether to add the header file to a precompiled header file corresponding to a target object according to the characteristic information of the header file and the number of the source files.

[0036] 104. Precompile the precompiled header file corresponding to the target object.

[0037] In the embodiment of the present invention, the above-mentioned target object can be a project or any functional module contained in a project. No matter it is a project or any functional module contained in a project, it can be compiled into a target program of a target operating system through compilation. That is, the target operating system refers to the operating system that finally runs the compiled target program. For example, if the target program of the project is a Windows program, then the target operating system is Windows; if the target program of the project is a Linux program, then the target operating system is Linux. The principle of header file precompilation is the same.

[0038] A project may contain multiple functional modules. In the case of multiple functional modules in a project, a precompiled header file corresponding to each functional module can be generated, such as Figure 2 As shown in , assuming that a project includes function module A, function module B and function module C, then a precompiled header file 1 corresponding to function module A, a precompiled header file 2 corresponding to function module B, and a precompiled header file 3 corresponding to function module C can be generated in the end.

[0039] In practical applications, assuming that a project is a project for developing a book borrowing management application (App), the project may include two functional modules, namely, a user management module and a book management module. Based on the solution provided by the embodiment of the present invention, corresponding precompiled header files can be generated for the two functional modules respectively. In this way, when compiling the project, the precompiled header file corresponding to the functional module will be used when compiling the user management module, and the precompiled header file corresponding to the functional module will be used when compiling the book management module.

[0040] It should be noted that, in the embodiment of the present invention, the precompiled header file refers to a special header file composed of header files that need to be precompiled. For example, assuming that the header files that need to be precompiled include the three header files ah, bh, and ch, then the final precompiled header file will include these three header files. Assuming that the precompiled header file is named X1.h, then the header file X1.h includes the three header files ah, bh, and ch that need to be precompiled.

[0041] In summary, the role of the precompiled header file in the source file compilation process is: first precompile the precompiled header file X1.h through precompilation to obtain the precompiled results corresponding to the header files contained in the precompiled header file. When compiling a source file (assuming it is Yc), assuming that the source file Yc references the header file ah contained in the precompiled header file, then directly replace the header file ah referenced in the source file Yc with the precompiled result of the header file ah.

[0042] It can be understood that a target object (such as a project, or a functional module included in the project) will include several source files and several header files. In simple terms, the process of generating a precompiled header file corresponding to the target object is to select header files that can be added to the precompiled header file from the several header files included in the target object.

[0043] In addition, the timing of generating the precompiled header file corresponding to the target object may be when the target object is initially created, or after the target object is optimized, such as optimizing some source files and header files contained in the target object. Assuming that after the target object is initially created, a first precompiled header file corresponding to the target object is obtained, as the target object is optimized, the originally generated first precompiled header file may not be suitable for the optimized target object. At this time, it is necessary to trigger the generation of the second precompiled header file for the optimized target object again, and the second precompiled header file obtained at this time may be different from the first precompiled header file.

[0044] In order to obtain the precompiled header file corresponding to the target object, first, it is necessary to parse several source files included in the target object to determine the number of header files directly referenced by the source files and the number of source files, where the number of source files here refers to the total number of source files included in the target object.

[0045] To illustrate the meaning of header files directly referenced by source files, combined with Figure 3 To illustrate the organizational structure of the source file. Figure 3 As shown in the figure, suppose a source file is named 1.c, and the source file includes the following two lines of code: #include<a.h> , #include<b.h> That is to say, the source file directly references the two header files ah and bh through the precompilation directive include. Based on this, the header files directly referenced by a source file in this article are the header files directly referenced by the precompilation directive include in the source file. In addition, suppose that the header file ah references the header file aa.h through the precompilation directive include, and the header file bh references the two header files bb.h and cc.h through the precompilation directive include, then aa.h, bb.h and cc.h are the header files indirectly referenced by the source file 1.c. Figure 3 As shown in , if the source files are parsed layer by layer, according to the reference relationship of the header files, a tree structure as shown in the figure can be formed. The root node of the tree structure is the source file 1.c. The first-level child nodes are the header files directly referenced by the source file, and the child nodes of other levels are the header files indirectly referenced by the source file. However, it is understandable that, for example, in Figure 3 In the example, although the header file aa.h is indirectly referenced by the source file 1.c, the header file aa.h is directly referenced by the header file ah.

[0046] By performing the above analysis on each source file included in the target object, the header files directly referenced in each source file can be obtained, and the header files directly referenced in each source file can be summarized to obtain the header files directly referenced by one or more source files among the header files included in the target object. Assuming that the target object includes N header files, after the above analysis, it is determined that M of the header files are directly referenced by source files, where N>M>1.

[0047] It can be understood that this does not mean that the M header files are directly referenced by one or some source files at the same time, but that any header file among the M header files has one or more source files that directly reference it.

[0048] In addition, after the above-mentioned M header files are determined from the N header files, it can be understood that the precompiled header file corresponding to the target object is selected from the M header files.

[0049] After obtaining the above-mentioned M header files, for each of the header files, characteristic information reflecting its importance in the target object is determined, so as to combine the characteristic information of each header file and determine the header file that needs to be added to the precompiled header file corresponding to the target object from the M header files.

[0050] Optionally, the characteristic information of the header file includes at least one of the following: the number of times the header file is directly referenced in the source file, the type parameter of the header file, and the complexity parameter of the header file. Optionally, the complexity parameter of the header file includes at least one of the following parameters: the number of macros defined in the header file, the number of other header files introduced in the header file, and the file size of the header file.

[0051] Taking any header file i among M header files as an example, by parsing each source file contained in the target object, it can be known whether each source file directly references header file i, and the number of source files that directly reference header file i is counted, that is, the number of times header file i is directly referenced in the source file.

[0052] In actual applications, the types of header files can include the following: system header files, third-party library header files, and project-defined header files. Among them, system header files refer to header files that come with the target operating system. For example, if the target program is a Windows program, the target operating system is Windows, and the system header files at this time are header files that come with the Windows system; if the target program is Linux, the target operating system is Linux, and the system header files at this time are header files that come with the Linux system. Third-party library header files refer to header files provided in third-party function libraries. The corresponding type parameters can be set in advance for each type of header file, which can be a coefficient. For example, the type parameter of the system header file is 60, the type parameter of the third-party library header file is 30, and the type parameter of the custom header file in this project is 0.

[0053] When developing a project, developers will store different types of header files in different directories. Therefore, the type of header file can be determined based on the name of the storage directory corresponding to the header file.

[0054] Therefore, for header file i, the corresponding type is determined by querying the name of the directory storing header file i, and then the corresponding type parameter is determined.

[0055] In header file i, other header files may be introduced, and operations such as macro definition, variable definition, and template definition may also be included. In the embodiment of the present invention, the complexity parameter of the header file is defined in combination with the operations included in the header file. For example, the complexity parameter of header file i may include one or more of the following three parameters: the number of macros defined in header file i, the number of other header files introduced in header file i, and the file size of header file i.

[0056] After obtaining the above characteristic information of header file i, it can be determined whether to add header file i to the precompiled header file corresponding to the target object, that is, whether to use header file i as the precompiled object corresponding to the target object, based on the characteristic information of header file i and the number of source files included in the target object.

[0057] Optionally, when the characteristic information of the adopted header file i includes the number of times the header file i is directly referenced in the source file, whether to add the header file i to the precompiled header file corresponding to the target object can be determined according to the following method:

[0058] Determine the ratio of the number of times header file i is directly referenced in source files (i.e., all source files included in the target object) to the number of source files included in the target object. If the ratio is greater than a set threshold, determine to add header file i to the precompiled header file corresponding to the target object.

[0059] Assume that the number of times header file i is directly referenced by source file is represented as Tf, and the number of source files included in the target object is represented as Cf, that is, if Tf / Cf is greater than the set threshold, it is determined that header file i is added to the precompiled header file corresponding to the target object, otherwise, it is not required to be added. At this time, assuming that Wf represents the importance value of header file i, then Wf = Tf / Cf.

[0060] Optionally, when the characteristic information of the adopted header file i includes the number of times the header file i is directly referenced in the source file and the type parameter of the header file i, it can be determined whether to add the header file i to the precompiled header file corresponding to the target object according to the following method:

[0061] Determine the number of times header file i is directly referenced in the source file, multiplied by the type parameter of header file i;

[0062] If the product is greater than a set threshold, it is determined to add the header file i to the precompiled header file corresponding to the target object.

[0063] Assuming that the type parameter of header file i is represented by Lf, and the number of times header file i is directly referenced in the source file is represented by Tf, if Lf*Tf is greater than the set threshold, it is determined that header file i is added to the precompiled header file corresponding to the target object, otherwise, it is not necessary to add it. At this time, assuming that Wf represents the importance value of header file i, then Wf=Lf*Tf.

[0064] Optionally, when the characteristic information of the adopted header file i includes the number of times the header file i is directly referenced in the source file and the type parameter of the header file i, it can also be determined whether to add the header file i to the precompiled header file corresponding to the target object according to the following method:

[0065] Determine the ratio of the number of times header file i is directly referenced in source files to the number of source files;

[0066] Determine the number of times header file i is directly referenced in the source file, multiplied by the type parameter of header file i;

[0067] Determining a sum of the ratio and the product;

[0068] If the sum is greater than the set threshold, it is determined that the header file is added to the precompiled header file corresponding to the target object.

[0069] Assume that the type parameter of header file i is represented by Lf, the number of times header file i is directly referenced in source file ( is represented by Tf, and the number of source files included in the target object is represented by Cf. If Tf / Cf+Lf*Tf is greater than a set threshold, it is determined that header file i is added to the precompiled header file corresponding to the target object. Otherwise, it may not be added. At this time, assuming that Wf represents the importance value of header file i, Wf=Tf / Cf+Lf*Tf.

[0070] Optionally, when the characteristic information of the adopted header file i includes the complexity parameters of the header file i, such as the number of macros defined in the header file i, the number of other header files introduced in the header file i, and the file size of the header file i, it can be determined whether to add the header file i to the precompiled header file corresponding to the target object according to the following method:

[0071] Calculate the sum of the number of macros defined in header file i, the number of other header files introduced in header file i, and the file size of header file i. If the sum is greater than a set threshold, determine to add header file i to the precompiled header file corresponding to the target object. Otherwise, it may not be added.

[0072] Optionally, the sum of the above three items can be calculated in the following way:

[0073] If+Mf / 100+Sf / 1024

[0074] Where If represents the number of other header files introduced by header file i, Mf represents the number of macros defined in header file i, and Sf represents the file size of header file i. At this time, assuming that Wf represents the importance value of header file i, then Wf=If+Mf / 100+Sf / 1024. Where If+Mf / 100+Sf / 1024 is also the complexity coefficient of header file i.

[0075] The above example shows that the complexity of the header file i includes the above three types of information. The same applies when only one or two of them are included.

[0076] Optionally, when the characteristic information of the adopted header file i includes the number of times the header file i is directly referenced in the source file, the type parameter of the header file i, the number of macros defined in the header file i, the number of other header files introduced in the header file i, and the file size of the header file i, it can be determined whether to add the header file i to the precompiled header file corresponding to the target object according to the following method:

[0077] Determine the ratio of the number of times header file i is directly referenced in source files to the number of source files;

[0078] Determine the number of times header file i is directly referenced in the source file, multiplied by the type parameter of header file i;

[0079] Determine the complexity coefficient of header file i according to the complexity parameter of header file i;

[0080] Determining a sum of the ratio, the product, and the complexity coefficient;

[0081] If the sum is greater than the set threshold, it is determined to add the header file i to the precompiled header file corresponding to the target object.

[0082] Combined with the above assumptions, optionally, at this time, there can be:

[0083] Wf=Lf*Tf+(Tf / Cf)*100*3+(If+Mf / 100+Sf / 1024)*1.5

[0084] If Wf is greater than the set threshold, it is determined that the header file i is added to the precompiled header file corresponding to the target object, otherwise, it is not added.

[0085] Wherein, Wf represents the importance value of header file i, 3 ​​and 1.5 are preset coefficients, which are only used as examples and can also be regarded as other values.

[0086] In summary, the importance of a header file among several header files included in the target object can be determined in combination with one or more characteristic information of the header file. Only header files whose importance meets the requirements will be selected as precompiled objects corresponding to the target object and added to the precompiled header file corresponding to the target object, thereby realizing the generation of a precompiled header file for the target object. When compiling the target object, better compilation efficiency can be obtained based on the precompiled header file.

[0087] Figure 4 A flowchart of a pre-compilation method provided by an embodiment of the present invention is as follows Figure 4 As shown, the method comprises the following steps:

[0088] 401. Parse the source files included in the target object to determine the number of header files and source files directly referenced by the source files.

[0089] 402. Obtain the operating system type of the target operating system of the header file.

[0090] As mentioned above, the target operating system refers to the operating system that runs the compiled target program.

[0091] 403. If the operating system type is a preset first operating system, determine feature information of the header file.

[0092] 404. If the operating system type is a preset second operating system, obtain the number of target parameters defined in the header file, and if the number of target parameters defined in the header file is less than or equal to a set threshold, determine feature information of the header file.

[0093] 405. Determine whether to add the header file to the precompiled header file corresponding to the target object according to the characteristic information of the header file and the number of source files.

[0094] 406. Precompile the precompiled header file corresponding to the target object.

[0095] The other embodiments described above describe how to determine whether to add a header file to the precompiled header file corresponding to the target object based on the characteristic information of the header file. In this embodiment, in addition to being based on the characteristic information of the header file, the determination of whether to add a header file to the precompiled header file corresponding to the target object may also be based on the operating system type of the target operating system corresponding to the target object. Because the compilers of different target operating systems are different, for example, if the target program is a Windows program, the compiler may be a Visual Studio compiler running on Windows, or a program that can be run on Windows compiled by a cross compiler on a Linux platform, and the computing processing capabilities of different compilers are different.

[0096] Optionally, in an embodiment of the present invention, two different types of target operating systems may be considered, referred to as a first operating system and a second operating system, respectively, wherein it is assumed that the processing capability of a compiler supported by the first operating system is higher than the processing capability of a compiler supported by the second operating system.

[0097] Based on the above assumption, optionally, it can be determined whether to perform the step of determining the characteristic information of the header file according to the operating system type of the target operating system of the header file. Specifically, if the operating system type of the target operating system of the header file is the first operating system, the step of determining the characteristic information of the header file is performed. That is, when the first operating system is used, it can be determined whether to add the header file to the precompiled header file corresponding to the target object according to the characteristic information of the header file.

[0098] If the operating system type of the target operating system of the header file is the second operating system, at this time, it is necessary to first obtain the number of target parameters defined in the header file, so as to determine whether to execute the step of determining the characteristic information of the header file according to the number of target parameters defined in the header file, wherein the target parameters include variables and / or templates. Among them, if the number of target parameters defined in the header file is less than or equal to the set threshold, the step of determining the characteristic information of the header file is executed; if the number of target parameters defined in the header file is greater than the set threshold, the step of determining the characteristic information of the header file is not executed. That is to say, at this time, only when the number of target parameters defined in the header file is less than or equal to the set threshold, can it be determined whether to add the header file to the precompiled header file corresponding to the target object according to the characteristic information of the header file. Among them, the above-mentioned set threshold is, for example, 0.

[0099] Optionally, corresponding operating system coefficients may be set in advance for different types of target operating systems. Referring to the description in the aforementioned other embodiments, after determining Wf in the foregoing text based on the characteristic information of the header file i, the product of Wf and the operating system coefficient corresponding to the target operating system of the header file is used as a factor to determine whether to add the header file i to the precompiled header file corresponding to the target object. Specifically, if the product is greater than a set threshold, the header file i is added to the precompiled header file corresponding to the target object. It can be understood that, at this time, the operating system coefficient corresponding to the operating system supporting the compiler with higher processing power is higher.

[0100] In this embodiment, since different types of target operating systems support different compilers, and different compilers have different specific implementations of precompilation, the type of operating system is comprehensively considered when generating the precompiled header file corresponding to the target object. For the second operating system (assuming that the processing power of the compiler it supports is weak), since adding the header file containing template definitions and variable definitions to the precompiled header file may slow down the compilation speed, under the second operating system, when a header file contains template definitions and variable definitions (or contains a large number of them), the header file may not be added to the precompiled header file.

[0101] In practical applications, an operating system coefficient Of can be defined. For the above-mentioned division of the first operating system and the second operating system, the value of Of can include two values: 0 and 1. For the header file i in the above text, when the operating system type of the target operating system of the header file is the first operating system, Of = 1; when the operating system type of the target operating system of the header file is the second operating system, and the number of target parameters defined in the header file i is less than or equal to the set threshold, Of = 1; when the operating system type of the target operating system of the header file is the second operating system, and the number of target parameters defined in the header file i is greater than the set threshold, Of = 0.

[0102] In the case of determining whether to add a header file to the precompiled header file corresponding to the target object in combination with the operating system type of the above-mentioned target operating system, assuming that the evaluation index ultimately used to determine whether to add a header file to the precompiled header file corresponding to the target object is expressed as Wf', then Wf'=Wf*Of, wherein Wf is the result calculated only based on the characteristic information of the header file. The calculation process can refer to the description in the other aforementioned embodiments. For example, optionally, Wf'=[Lf*Tf+(Tf / Cf)*100*3+(If+Mf / 100+Sf / 1024)*1.5]*Of.

[0103] The following will describe in detail the pre-compilation device of one or more embodiments of the present invention. Those skilled in the art will appreciate that these devices can be configured using commercially available hardware components through the steps taught in this solution.

[0104] Figure 5 A schematic diagram of the structure of a pre-compilation device provided by an embodiment of the present invention is shown in FIG. Figure 5 As shown, the device includes: a parsing module 11, a first determining module 12, a second determining module 13, and a pre-compilation module 14.

[0105] The parsing module 11 is used to parse the source files included in the target object to determine the number of header files and source files directly referenced by the source files.

[0106] The first determining module 12 is used to determine the characteristic information of the header file.

[0107] The second determining module 13 is used to determine whether to add the header file to the precompiled header file corresponding to the target object according to the characteristic information of the header file and the number of the source files.

[0108] The pre-compilation module 14 is used to pre-compile the pre-compiled header file corresponding to the target object.

[0109] Optionally, the target object includes: any functional module included in the project.

[0110] Optionally, the first determination module 12 may be specifically configured to: obtain an operating system type of a target operating system of the header file; and determine, according to the operating system type, whether to execute a step of determining feature information of the header file.

[0111] Among them, optionally, the first determination module 12 can be specifically used for: if the operating system type is a preset first operating system, executing the step of determining the characteristic information of the header file; if the operating system type is a preset second operating system, obtaining the number of target parameters defined in the header file, the target parameters including variables and / or templates; and determining whether to execute the step of determining the characteristic information of the header file based on the number of target parameters defined in the header file.

[0112] Among them, in the process of determining whether to execute the step of determining the characteristic information of the header file according to the number of target parameters defined in the header file, the first determination module 12 can be specifically used to: if the number of target parameters defined in the header file is less than or equal to the set threshold, then execute the step of determining the characteristic information of the header file; if the number of target parameters defined in the header file is greater than the set threshold, then do not execute the step of determining the characteristic information of the header file.

[0113] Optionally, the characteristic information includes at least one of the following: the number of times the header file is directly referenced in the source file, the type parameter of the header file, and the complexity parameter of the header file; the complexity parameter of the header file includes at least one of the following parameters: the number of macros defined in the header file, the number of other header files introduced in the header file, and the file size of the header file.

[0114] Optionally, the second determination module 13 can be specifically used to: determine the ratio of the number of times the header file is directly referenced in the source file to the number of the source files; determine the product of the number of times the header file is directly referenced in the source file and a type parameter of the header file; determine the sum of the ratio and the product; if the sum is greater than a set threshold, determine to add the header file to the precompiled header file corresponding to the target object.

[0115] Among them, optionally, the second determination module 13 can be specifically used to: determine the ratio of the number of times the header file is directly referenced in the source file to the number of the source files; determine the product of the number of times the header file is directly referenced in the source file and the type parameter of the header file; determine the complexity coefficient of the header file based on the complexity parameter of the header file; determine the sum of the ratio, the product and the complexity coefficient; if the sum is greater than a set threshold, determine to add the header file to the precompiled header file corresponding to the target object.

[0116] Figure 5 The device shown can perform the aforementioned Figures 1 to 4 The pre-compilation method provided in the illustrated embodiment, the detailed execution process and technical effects are described in the aforementioned embodiment and will not be repeated here.

[0117] In one possible design, the above Figure 5 The structure of the pre-compilation device shown can be implemented as an electronic device, such as Figure 6 As shown, the electronic device may include: a processor 21 and a memory 22. The memory 22 stores executable code. When the executable code is executed by the processor 21, the processor 21 can at least implement the above-mentioned Figures 1 to 4 The pre-compilation method provided in the illustrated embodiment.

[0118] Optionally, the electronic device may further include a communication interface 23 for communicating with other devices.

[0119] In addition, an embodiment of the present invention provides a computer program product, wherein the computer program product includes a computer program, and when the computer program is executed by a processor of an electronic device, the processor can at least implement the above-mentioned Figures 1 to 4 The pre-compilation method provided in the illustrated embodiment.

[0120] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. Those of ordinary skill in the art may understand and implement the present invention without creative effort.

[0121] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by adding a necessary general hardware platform, and of course can also be implemented by combining hardware and software. Based on such an understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a computer product, and the present invention can be in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

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

Claims

1. A pre-compilation method, comprising: Parsing the source files included in the target object to determine the number of header files and source files directly referenced by the source files, wherein the target object is a project or a functional module in a project, and the number of source files refers to the total number of source files included in the target object; Determining characteristic information of the header file; Determining whether to add the header file to a precompiled header file corresponding to the target object according to the characteristic information of the header file and the number of the source files; A precompilation process is performed on the precompiled header file corresponding to the target object, so as to improve the compilation efficiency of the target object based on the precompilation result of the precompiled header file.

2. The method according to claim 1, wherein: The method further comprises: Obtaining the operating system type of the target operating system of the header file; According to the operating system type, it is determined whether to execute the step of determining the characteristic information of the header file.

3. The method according to claim 2, wherein: The step of determining whether to perform the step of determining the characteristic information of the header file according to the operating system type includes: If the operating system type is a preset first operating system, the step of determining characteristic information of the header file is performed.

4. The method according to claim 2, wherein: The step of determining whether to perform the step of determining the characteristic information of the header file according to the operating system type includes: If the operating system type is a preset second operating system, obtaining the number of target parameters defined in the header file, the target parameters including variables and / or templates; According to the number of target parameters defined in the header file, it is determined whether to perform the step of determining the characteristic information of the header file.

5. The method according to claim 4, wherein: The step of determining whether to perform the step of determining the characteristic information of the header file according to the number of target parameters defined in the header file comprises: If the number of target parameters defined in the header file is less than or equal to the set threshold, executing the step of determining characteristic information of the header file; If the number of target parameters defined in the header file is greater than a set threshold, the step of determining the characteristic information of the header file is not performed.

6. The method according to any one of claims 1 to 5, wherein: The characteristic information of the header file includes at least one of the following: The number of times the header file is directly referenced in the source file, the type parameter of the header file, and the complexity parameter of the header file; The complexity parameter of the header file includes at least one of the following parameters: The number of macros defined in the header file, the number of other header files introduced in the header file, and the file size of the header file.

7. The method according to claim 6, wherein: The step of determining whether to add the header file to a precompiled header file corresponding to the target object according to the characteristic information of the header file and the number of the source files comprises: Determine the ratio of the number of times the header file is directly referenced in the source file to the number of the source files; Determine the product of the number of times the header file is directly referenced in the source file and the type parameter of the header file; Determining a sum of the ratio and the product; If the sum is greater than a set threshold, it is determined to add the header file to the precompiled header file corresponding to the target object.

8. The method according to claim 6, wherein: The step of determining whether to add the header file to a precompiled header file corresponding to the target object according to the characteristic information of the header file and the number of the source files comprises: Determine the ratio of the number of times the header file is directly referenced in the source file to the number of the source files; Determine the product of the number of times the header file is directly referenced in the source file and the type parameter of the header file; Determining a complexity coefficient of the header file according to a complexity parameter of the header file; Determining a sum of the ratio, the product, and the complexity coefficient; If the sum is greater than a set threshold, it is determined to add the header file to the precompiled header file corresponding to the target object.

9. An electronic device, comprising: A memory and a processor; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor executes the precompilation method according to any one of claims 1 to 8.

10. A computer program product comprising: A computer program, when executed by a processor of an electronic device, causes the processor to execute the pre-compilation method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Selective pre-compilation of virtual code to enhance emulator performance

    CN101238438A