Embedded code compilation method, device and computer-readable storage medium thereof

Through the compilation method of embedded code, the attribute header file of the variable is generated into the attribute table and written back to the module file, which solves the problem of lengthy target code in embedded program and generates concise target code.

CN116225446BActive Publication Date: 2025-09-19WEICHAI POWER CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211732686.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-30
Publication Date
2025-09-19
Estimated Expiration
2042-12-30

AI Technical Summary

Technical Problem

During the compilation of an embedded program, when variable definition header files and/or declaration header files are nested, the compiled target code becomes too lengthy.

Method used

By compiling the source code to generate the initial compilation file, determining the attributes of the variables, generating the header file into the attribute table, and traversing the attribute table to write the header file back to the corresponding usage module file, an updated usage module file is formed for compilation to generate concise target code.

Benefits of technology

The problem of lengthy target code during embedded code compilation is solved, and more concise target code is generated.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116225446B_ABST
    Figure CN116225446B_ABST
Patent Text Reader

Abstract

The present application provides a method, device and computer-readable storage medium for compiling embedded code. The compilation method includes: compiling the source code to generate an initial compilation file, wherein the initial compilation file is a file that can read the attributes of the variables; determining the attributes of each variable in the initial compilation file, generating a header file of at least one of the attributes into an attribute table; traversing the attribute table, writing the header file of at least one of the attributes back to the file of the corresponding variable usage module to form an updated file of the usage module, and compiling with the updated file of the usage module to obtain the target code. Through the present application, the problem that the target code compiled is too lengthy when the definition header file and / or declaration header file of the variable are nested is solved, and the purpose of making the embedded compiled code concise is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of embedded code compilation, and in particular to an embedded code compilation method, device, computer-readable storage medium, processor, and electronic device. Background Art

[0002] Existing software technology uses a top-down execution process: a variable is used in one .c file, and the variable's attributes exist in another folder. During the normal program compilation process, the compiler quickly finds the header files for definitions and declarations, and the compiled code is not lengthy.

[0003] However, during the compilation of an embedded program, when the header file for variable definition and / or declaration is nested, the compiled target code will become lengthy.

[0004] Therefore, there is an urgent need for a compilation method that can alleviate the relatively lengthy target code obtained by compiling an embedded-free program. Summary of the Invention

[0005] The main purpose of this application is to provide a method, device, computer-readable storage medium, processor and electronic device for compiling embedded code, so as to at least solve the problem in the prior art that when the definition header file and / or declaration header file of the variable is nested, the compiled target code becomes lengthy.

[0006] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a method for compiling an embedded code is provided, comprising: compiling the source code to generate an initial compiled file, wherein the initial compiled file is a file that can read the attributes of the variables; determining the attributes of each of the variables in the initial compiled file, and generating a header file of at least one of the attributes into an attribute table; traversing the attribute table, writing the header file of at least one of the attributes back to the file of the corresponding usage module of the variable to form an updated file of the usage module, and using the updated file of the usage module for compilation to obtain the target code.

[0007] Optionally, the attributes of each of the variables in the initial compiled file are determined, and a header file of at least one of the attributes is generated into an attribute table, including: determining the attributes of each of the variables, and when there are multiple attributes, generating a header file of the same attribute into an attribute table accordingly, to obtain multiple attribute tables corresponding to multiple attributes, wherein one attribute corresponds to one attribute table.

[0008] Optionally, traverse the attribute table and write the header file of at least one attribute back to the file of the corresponding module using the variable, including: when there are multiple attribute tables, traverse each attribute table and write the header file of each attribute corresponding to the variable back to the file of the module using the variable.

[0009] Optionally, the attributes of each variable in the initial compiled file are determined, and a header file of at least one of the attributes is generated into an attribute table, including: determining whether the attribute of each global variable is a definition attribute or a declaration attribute; when the attribute of the global variable is the definition attribute, generating the header file of the definition attribute of the global variable into the definition attribute table; when the attribute of the global variable is the declaration attribute, generating the header file of the declaration attribute of the global variable into the declaration attribute table.

[0010] Optionally, traversing the attribute table and writing the header file of at least one attribute back to the file of the corresponding module using the variable includes: traversing the definition attribute table and writing the header file of the definition attribute back to the file of the corresponding module using the global variable; traversing the declaration attribute table and writing the header file of the declaration attribute back to the file of the corresponding module using the global variable.

[0011] Optionally, compiling the source code to generate an initial compiled file includes: compiling the source code to generate an object file; and converting the object file into a text file to obtain the initial compiled file.

[0012] According to another aspect of the present application, a compilation device for embedded code is provided, comprising: an initial compilation unit, for compiling source code to generate an initial compilation file, wherein the initial compilation file is a file that can read the attributes of variables; a generation unit, for determining the attributes of each of the variables in the initial compilation file, and generating a header file of at least one of the attributes into an attribute table; a recompilation unit, for traversing the attribute table, writing the header file of at least one of the attributes back to the file of the corresponding usage module of the variable to form an updated file of the usage module, and using the updated file of the usage module for compilation to obtain the target code.

[0013] According to another aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute any one of the compilation methods described above.

[0014] According to another aspect of the present application, a processor is provided, which is used to run a program, wherein the program executes any one of the above-mentioned compilation methods when running.

[0015] According to another aspect of the present application, an electronic device is also provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include a method for executing any one of the compilation methods described above.

[0016] To apply the technical solution of the present application, first, the source code is compiled to generate an initial compiled file. Then, the attributes of each of the above variables in the above initial compiled file are determined, and a header file of at least one of the above attributes is generated into an attribute table. The above attribute table is traversed, and the header file of at least one of the above attributes is written back to the file of the corresponding usage module of the above variable to form an updated file of the above usage module, and the updated file of the above usage module is used for compilation to obtain the target code. Compared with the method in the prior art in which the target code compiled is too lengthy when the definition header file and / or declaration header file of the variable is nested during the compilation process of the embedded code, the present solution can make the compiled embedded code more concise when the definition header file and / or declaration header file of the variable is nested. The source code is compiled to generate an initial compilation file, and the header files corresponding to the attributes of each variable in the initial compilation file are generated into an attribute table. The attribute table is traversed and the header files of the corresponding attributes of the above-mentioned variables are written back to the use module of each variable to obtain the file of the updated use module, so that the target code compiled by compiling the file of the updated use module is more concise, thereby solving the problem that the target code compiled is too lengthy when the definition header file and / or declaration header file of the variable is nested during the compilation process of the embedded code. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The drawings that constitute part of this application are used to provide a further understanding of this application. The illustrative embodiments of this application and their descriptions are used to explain this application and do not constitute an improper limitation on this application. In the drawings:

[0018] Figure 1 A hardware structure block diagram of a mobile terminal for executing an embedded code compilation method provided in an embodiment of the present application is shown;

[0019] Figure 2 A schematic diagram of a process for compiling an embedded code provided in an embodiment of the present application is shown;

[0020] Figure 3A flowchart of a specific embedded code compiling method provided in an embodiment of the present application is shown;

[0021] Figure 4 A schematic diagram of an embedded code compiling device provided in an embodiment of the present application is shown;

[0022] Figure 5 A schematic diagram of an initial compiling unit of an embedded code compiling device provided in an embodiment of the present application is shown;

[0023] Figure 6 A schematic diagram of a generation unit of an embedded code compiling device provided in an embodiment of the present application is shown;

[0024] Figure 7 A schematic diagram of a recompiling unit of an embedded code compiling device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0025] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0026] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.

[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0028] In the prior art, when header files for attributes of variables in source code are nested, multiple intermediate header files are present. Consequently, the compiled target code also contains codes from multiple intermediate header files, making the target code relatively lengthy. To address the problem of lengthy compiled target code, embodiments of the present application provide a method for compiling embedded code.

[0029] The technical solutions in the embodiments of the present invention will be described clearly and completely below with reference to the accompanying drawings in the embodiments of the present invention.

[0030] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 FIG. 1 is a hardware structure diagram of a mobile terminal of an embedded code compilation method according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.

[0031] The memory 104 can be used to store computer programs, such as software programs and modules of application software, such as the computer program corresponding to the device information display method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implementing the above-mentioned method. The memory 104 may include a high-speed random access memory and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the above-mentioned networks include but are not limited to the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the above-mentioned network may include a wireless network provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, abbreviated as NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0032] In this embodiment, a method for compiling embedded code running on a mobile terminal, a computer terminal, or a similar computing device is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0033] Figure 2 FIG. 1 is a flow chart of a method for compiling embedded code according to an embodiment of the present application. Figure 2 As shown, the method includes the following steps:

[0034] Step S201 : compile the source code to generate an initial compiled file. The initial compiled file is a file that can read the attributes of variables.

[0035] Specifically, source code (also known as source program) refers to an uncompiled text file written in accordance with a specific programming language specification. It is a series of human-readable computer language instructions. In modern programming languages, source code can be in the form of books or tapes, but the most common format is a text file. This typical format is used to compile computer programs. The ultimate goal of computer source code is to translate human-readable text into binary instructions that a computer can execute. This process is called compilation and is accomplished by a compiler. By compiling the source code, an initial compiled file can be obtained. From this initial compiled file, the properties of variables can be read.

[0036] Step S202 : determining the attributes of each of the variables in the initial compiled file, and generating a header file of at least one of the attributes into an attribute table.

[0037] Specifically, in embedded software development, each C++ / C program usually consists of a header file and a definition file. The header file is a carrier file containing function and data interface declarations, mainly used to store program declarations, while the definition file is used to store program implementation in existing technologies.

[0038] Specifically, in the prior art, variable attributes can be divided into defined attributes and declared attributes. Defined attributes are used to allocate addresses and storage space for variables, while declared attributes only allocate storage space for variables, not addresses. The above-mentioned attribute table is generated by the header file corresponding to the variable attributes. When the variable in the above-mentioned initial compiled file has only one attribute, one attribute table is generated; when the variable in the above-mentioned initial compiled file has multiple attributes, multiple attribute tables are generated. That is, this application does not specifically limit the number of the above-mentioned attribute tables.

[0039] Step S203, traverse the above attribute table, write the header file of at least one of the above attributes back to the file of the corresponding module using the variable to form an updated file of the module using the variable, and use the updated file of the module using the module to compile and obtain the target code.

[0040] Specifically, in the development of embedded systems, in order to save memory space, developers adopt a module reuse design. The system is usually divided into different usage modules, that is, the program will be divided into several small segments. After traversing the attribute table, at least one header file of the above attributes will be written back to the file of the usage module of the corresponding variable, so that the updated file of the usage module is used for compilation to obtain the target code.

[0041] According to this embodiment, first, the source code is compiled to generate an initial compiled file, and then the attributes of each of the above variables in the initial compiled file are determined, and a header file of at least one of the above attributes is generated into an attribute table, and the attribute table is traversed, and the header file of at least one of the above attributes is written back to the file of the corresponding use module of the above variable to form an updated file of the use module, and the updated file of the use module is used for compilation to obtain the target code. Compared with the relatively lengthy scheme of the compilation method to obtain the target code in the prior art, in the scheme of the present application, the header file corresponding to the attributes of each variable in the initial compiled file is generated into an attribute table, and the header file of the attribute of the variable is directly found through the intermediate header file, and only the header file of the attribute of the variable (the intermediate header file is not written back) is written back to the use module of each variable to obtain the file of the updated use module, so that the target code obtained by compiling the file of the updated use module is more concise because the target code does not include the code of the intermediate header file, thereby solving the problem that the target code obtained by compilation in the prior art is too lengthy.

[0042] The execution subject of the method may be any compiler in the prior art, specifically, the WindRiver compiler.

[0043] In a specific implementation, step S201 can be implemented by: compiling the source code to generate an object file; and converting the object file into a text file to obtain the initial compiled file. This method compiles the source code to generate an object file, i.e., an executable file; and converts the object file into a text file to obtain the initial compiled file. Since text files are readable, converting the executable file into a text file ensures that the attributes of the variables in the text file, i.e., the initial compiled file, can be read and identified, thereby achieving the purpose of classifying the attributes of different variables. This ensures that the identification of variable attributes is more convenient and efficient.

[0044] In order to generate variables into an attribute table according to their respective different attributes, the above-mentioned step S202 of the present application can be implemented by the following steps: determine the attributes of each of the above-mentioned variables, and when there are multiple attributes, generate the header files of the same attribute into the above-mentioned attribute table accordingly, and obtain multiple attribute tables corresponding to multiple attributes, wherein one attribute corresponds to one attribute table. When the variables in the above-mentioned initial compiled file have multiple attributes, this method generates the header files of the variables with the same attribute into the same attribute table, that is, there are as many corresponding attribute tables as there are attributes, so that the header files of the variables with the same attributes can be placed into one attribute table, that is, the header files of the variables with different attributes can be classified and placed into corresponding attribute tables respectively, so that the header files are more organized and the subsequent traversal process can be ensured to be more efficient.

[0045] Specifically, when there is only one variable with the same attribute in the initial compiled file, the attribute table contains only one header file for that variable. When there are multiple variables with the same attribute in the initial compiled file, the header files for those variables can be stored simultaneously in the same attribute table for the corresponding attribute. That is, the attribute table can store the header file corresponding to one variable or multiple variables, but the multiple variables must meet the condition of the same attribute. This application does not impose any specific restrictions on the number of header files in the attribute table.

[0046] The above step S202 can also be implemented in other ways, for example: determining whether the attributes of each global variable are defined attributes or declared attributes; if the attributes of the above global variables are defined attributes, generating the header file of the defined attributes of the above global variables into the defined attribute table; if the attributes of the above global variables are declared attributes, generating the header file of the declared attributes of the above global variables into the declared attribute table. This method determines whether the attributes of each global variable are defined attributes or declared attributes, and generates the header file of the global variables whose attributes are defined attributes into the defined attribute table, and generates the header file of the global variables whose attributes are declared attributes into the declared attribute table. In this way, the header files of the global variables with defined attributes and the global variables with declared attributes are generated into their respective corresponding attribute tables, making the classification clear, so as to ensure that the subsequent compiler traverses the attribute table according to the attributes corresponding to each global variable in the initial compiled file.

[0047] Specifically, after the attributes of global variables are classified in the initial compilation file, the attributes of global variables are divided into definition attributes and declaration attributes. Therefore, it is first determined whether the attributes of each global variable are definition attributes or declaration attributes. After that, the header files of variables with OBJECT attributes (definition attributes) of global variables are generated into the definition attribute table. At the same time, the header files of variables with NOTYPE attributes (declaration attributes) of global variables are generated into the declaration attribute table.

[0048] Of course, the attributes of the above-mentioned global variables can also be attributes inherent to other variables, such as storage type, scope and link attributes, etc., that is, this application does not specifically limit the types of the above-mentioned global variable attributes.

[0049] In some embodiments, the above step S203 can be specifically implemented by the following steps: when there are multiple attribute tables, traverse each of the attribute tables, and write the header files of each of the attributes corresponding to the variables back to the files of the module using the variables. When multiple attribute tables are generated, that is, when there are multiple attributes of the variable, the method traverses each of the attribute tables, obtains the header files of the attributes corresponding to each variable, and writes the obtained header files back to the files of the module using the variables, so as to ensure that the traversal is performed according to the attributes of each variable, and the header files of the attributes corresponding to the variables are written back to the module using the variables in sequence. For such an attribute, it is only necessary to traverse the header files in the corresponding attribute table, and there is no need to traverse the header files of other attributes, so that the compilation efficiency is higher.

[0050] Specifically, when the header files of the attributes corresponding to the variables are written back to the files of the modules that use the variables, all the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables, or some of the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables. That is, this application does not impose any specific restrictions on the number of header files written back to the files of the modules that use the variables. In actual applications, in order to make the compiled target code more concise, it is a better solution to write all the header files of the attributes corresponding to the variables back to the files of the modules that use the variables.

[0051] The above step S203 can also be implemented in other ways, for example: traversing the above definition attribute table, writing the header file of the above definition attribute back to the file of the corresponding module using the above global variable; traversing the above declaration attribute table, writing the header file of the above declaration attribute back to the file of the corresponding module using the above global variable. After generating the above definition attribute table and the declaration attribute table, the method traverses the above definition attribute table, writes the header file of the above definition attribute back to the file of the corresponding module using the above global variable, and traverses the above declaration attribute table, writes the header file of the above declaration attribute back to the file of the corresponding module using the above global variable, thereby placing the header file corresponding to each global variable in the file of the using module, which can further make the code more concise.

[0052] For example, as shown in Table 1 and Table 2, when the global variable Com_stTxEngConfTrg is used in the ComTxVehSys2 module, first, traverse the definition attribute table to find the definition header file ComTxVehSys2_MData.c of the above variable, traverse the declaration attribute table to find the above variable declaration header file ComTxVehSys2.c, and then rewrite the definition header file and declaration header file of the global variable Com_stTxEngConfTrg back to the ComTxVehSys2.c file of the using module, so that the code is more concise.

[0053] Table 1

[0054]

[0055] Table 2

[0056]

[0057] In order to enable those skilled in the art to more clearly understand the technical solution of the present application, the implementation process of the embedded code compiling method of the present application will be described in detail below with reference to specific embodiments.

[0058] This embodiment relates to a specific method for compiling embedded code, such as Figure 3 As shown, the following steps are included:

[0059] Step S1: Read the compiled .o file (object file) and convert it into a .txt file (initial compiled file);

[0060] Step S2: Determine whether the attribute of each global variable is an OBJECT attribute (definition attribute) or a NOTYPE attribute (declaration attribute);

[0061] Step S3: When the attribute of the global variable is the OBJECT attribute (definition attribute), the header file of the definition attribute of the global variable is stored in the definition attribute table; when the attribute of the global variable is the NOTYPE attribute (declaration attribute), the header file of the declaration attribute of the global variable is stored in the declaration attribute table;

[0062] Step S4: rewrite the header file of the definition and declaration back into the .c file (the file that uses the module);

[0063] Step S5: The updated .c file (the file using the module) is recompiled.

[0064] The embodiment of the present application also provides a compilation device for an embedded code. It should be noted that the compilation device for the embedded code of the embodiment of the present application can be used to execute the compilation method for embedded code provided by the embodiment of the present application. The device is used to implement the above-mentioned embodiment and preferred embodiment, and the description thereof will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.

[0065] The following introduces the embedded code compilation device provided in the embodiment of the present application.

[0066] Figure 4 Schematic diagram of the embedded code compiling device according to the embodiment of the present application. Figure 4 As shown, the device includes:

[0067] The initial compilation unit 10 is used to compile the source code to generate an initial compilation file. The initial compilation file is a file that can read the attributes of variables.

[0068] Specifically, source code (also known as source program) refers to an uncompiled text file written in accordance with a specific programming language specification. It is a series of human-readable computer language instructions. In modern programming languages, source code can be in the form of books or tapes, but the most common format is a text file. This typical format is used to compile computer programs. The ultimate goal of computer source code is to translate human-readable text into binary instructions that a computer can execute. This process is called compilation and is accomplished by a compiler. By compiling the source code, an initial compiled file can be obtained. From this initial compiled file, the properties of variables can be read.

[0069] The generating unit 20 is configured to determine the attributes of each of the variables in the initial compiled file, and generate a header file of at least one of the attributes into an attribute table.

[0070] Specifically, in embedded software development, each C++ / C program usually consists of a header file and a definition file. The header file is a carrier file containing function and data interface declarations, mainly used to store program declarations, while the definition file is used to store program implementation in existing technologies.

[0071] Specifically, in the prior art, variable attributes can be divided into defined attributes and declared attributes. Defined attributes are used to allocate addresses and storage space for variables, while declared attributes only allocate storage space for variables, not addresses. The above-mentioned attribute table is generated by the header file corresponding to the variable attributes. When the variable in the above-mentioned initial compiled file has only one attribute, one attribute table is generated; when the variable in the above-mentioned initial compiled file has multiple attributes, multiple attribute tables are generated. That is, this application does not specifically limit the number of the above-mentioned attribute tables.

[0072] The recompilation unit 30 is used to traverse the above-mentioned attribute table, write the header file of at least one of the above-mentioned attributes back to the file of the corresponding above-mentioned variable using module to form an updated file of the above-mentioned using module, and use the above-mentioned updated file of the above-mentioned using module to compile and obtain the target code.

[0073] Specifically, in the development of embedded systems, in order to save memory space, developers adopt a module reuse design. The system is usually divided into different usage modules, that is, the program will be divided into several small segments. After traversing the attribute table, at least one header file of the above attributes will be written back to the file of the usage module of the corresponding variable, so that the updated file of the usage module is used for compilation to obtain the target code.

[0074] According to the present embodiment, the initial compilation unit compiles the source code to generate an initial compilation file, the generation unit determines the attributes of each of the above variables in the above initial compilation file, generates a header file of at least one of the above attributes into an attribute table, and the recompilation unit traverses the above attribute table and writes the header file of at least one of the above attributes back to the file of the corresponding use module of the above variable to form an updated file of the use module, and compiles the updated file of the use module to obtain the target code. Compared with the relatively lengthy scheme of the compilation method to obtain the target code in the prior art, in the scheme of the present application, the header file corresponding to the attributes of each variable in the initial compilation file is generated into an attribute table, the header file of the attribute of the variable is directly found through the intermediate header file, and only the header file of the attribute of the variable (the intermediate header file is not written back) is written back to the use module of each variable to obtain the file of the updated use module, so that the target code obtained by compiling the file of the updated use module is more concise because the target code does not include the code of the intermediate header file, thereby solving the problem of the target code obtained by compilation in the prior art being too lengthy.

[0075] In the specific implementation process, the above initial compilation unit, such as Figure 5 As shown, the apparatus comprises: a compilation module 11 and a conversion module 12, wherein the compilation module 11 is used to compile the source code to generate an object file; and the conversion module 12 is used to convert the object file into a text file to obtain the initial compiled file. The apparatus compiles the source code to generate an object file, i.e., an executable file, and converts the object file into a text file to obtain the initial compiled file. Since text files are readable, converting the executable file into a text file ensures that the attributes of the variables in the text file, i.e., the initial compiled file, can be read and identified, thereby achieving the purpose of classifying the attributes of different variables, which ensures that the identification of variable attributes is more convenient and efficient.

[0076] In order to generate variables into an attribute table according to their respective different attributes, the generation unit includes: a first determination module, which is used to determine the attributes of each of the above variables. When there are multiple attributes, the header files of the same attribute are correspondingly generated into the above attribute table, so as to obtain multiple attribute tables corresponding to the multiple attributes, wherein one attribute corresponds to one attribute table. When the variables in the above initial compiled file have multiple attributes, the device generates the header files of the variables with the same attribute into the same attribute table, that is, there are as many corresponding attribute tables as there are attributes. In this way, the header files of variables with the same attributes can be placed into one attribute table, that is, the header files of variables with different attributes can be classified and placed into corresponding attribute tables respectively, so that the header files are more organized and the subsequent traversal process is more efficient.

[0077] Specifically, when there is only one variable with the same attribute in the initial compiled file, the attribute table contains only one header file for that variable. When there are multiple variables with the same attribute in the initial compiled file, the header files for those variables can be stored simultaneously in the same attribute table for the corresponding attribute. That is, the attribute table can store the header file corresponding to one variable or multiple variables, but the multiple variables must meet the condition of the same attribute. This application does not impose any specific restrictions on the number of header files in the attribute table.

[0078] The above generation unit, such as Figure 6 As shown, it also includes: a second determination module 21, a first generation module 22 and a second generation module 23, wherein the second determination module 21 is used to determine whether the attributes of each global variable are definition attributes or declaration attributes; the first generation module 22 is used to generate the header file of the definition attributes of the above-mentioned global variable into the definition attribute table when the attributes of the above-mentioned global variable are the above-mentioned definition attributes; the second generation module 23 is used to generate the header file of the declaration attributes of the above-mentioned global variable into the declaration attribute table when the attributes of the above-mentioned global variable are the above-mentioned declaration attributes. The device determines whether the attributes of each global variable are definition attributes or declaration attributes, and generates the header file of the global variable with the definition attribute into the definition attribute table, and generates the header file of the global variable with the declaration attribute into the declaration attribute table, so that the header files of the global variables with the definition attribute and the global variables with the declaration attribute are generated into their respective corresponding attribute tables, so that the classification is clear, so as to ensure that the subsequent compiler traverses the attribute table according to the attributes corresponding to each global variable in the initial compilation file.

[0079] Specifically, after the attributes of global variables are classified in the initial compilation file, the attributes of global variables are divided into definition attributes and declaration attributes. Therefore, it is first determined whether the attributes of each global variable are definition attributes or declaration attributes. After that, the header files of variables with OBJECT attributes (definition attributes) of global variables are generated into the definition attribute table. At the same time, the header files of variables with NOTYPE attributes (declaration attributes) of global variables are generated into the declaration attribute table.

[0080] Of course, the attributes of the above-mentioned global variables can also be attributes inherent to other variables, such as storage type, scope and link attributes, etc., that is, this application does not specifically limit the types of the above-mentioned global variable attributes.

[0081] In some embodiments, the recompilation unit includes: a first traversal module, which is used to traverse each of the above-mentioned attribute tables when there are multiple attribute tables, and write the header files of each of the above-mentioned attributes corresponding to the above-mentioned variables back to the files of the modules using the above-mentioned variables. When the device generates multiple attribute tables, that is, when there are multiple attributes of a variable, it traverses each of the above-mentioned attribute tables, obtains the header files of the attributes corresponding to each variable, and writes the obtained header files back to the files of the modules using the above-mentioned variables, so as to ensure that the traversal is performed according to the attributes of each variable, and the header files of the attributes corresponding to the variables are sequentially written back to the modules using the variables, thereby avoiding the problem of low compilation efficiency caused by repeated traversal.

[0082] Specifically, when the header files of the attributes corresponding to the variables are written back to the files of the modules that use the variables, all the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables, or some of the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables. That is, this application does not impose any specific restrictions on the number of header files written back to the files of the modules that use the variables. In actual applications, in order to make the compiled target code more concise, it is a better solution to write all the header files of the attributes corresponding to the variables back to the files of the modules that use the variables.

[0083] Optionally, the above recompilation unit, such as Figure 7 As shown, it also includes: a second traversal module 31 and a third traversal module 32, wherein the second traversal module is used to traverse the above-mentioned definition attribute table and write the header file of the above-mentioned definition attribute back to the file of the corresponding module using the above-mentioned global variable; the third traversal module is used to traverse the above-mentioned declaration attribute table and write the header file of the above-mentioned declaration attribute back to the file of the above-mentioned module using the above-mentioned global variable. After the device generates the above-mentioned definition attribute table and the declaration attribute table, it traverses the above-mentioned definition attribute table and writes the header file of the above-mentioned definition attribute back to the file of the corresponding module using the above-mentioned global variable, and traverses the above-mentioned declaration attribute table and writes the header file of the above-mentioned declaration attribute back to the file of the above-mentioned module using the above-mentioned global variable, thereby putting the header file corresponding to each global variable into the file of the using module, which can make the code more concise.

[0084] For example, as shown in Table 1 and Table 2, when the global variable Com_stTxEngConfTrg is used in the ComTxVehSys2 module, first, traverse the definition attribute table to find the definition header file ComTxVehSys2_MData.c of the above variable, traverse the declaration attribute table to find the above variable declaration header file ComTxVehSys2.c, and then rewrite the definition header file and declaration header file of the global variable Com_stTxEngConfTrg back to the ComTxVehSys2.c file of the using module, so that the code is more concise.

[0085] The embedded code compilation device includes a processor and a memory. The initial compilation unit 10, generation unit 20, and recompilation unit 30 are all stored as program units in the memory. The processor executes the program units stored in the memory to implement the corresponding functions. The above modules are all located in the same processor; alternatively, the above modules can be located in different processors in any combination.

[0086] The processor includes a kernel, which retrieves the corresponding program unit from memory. One or more kernels can be configured. By adjusting kernel parameters, the compiled target code can be overly lengthy when variable definition and / or declaration header files are nested, thus simplifying the embedded compiled code.

[0087] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0088] An embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored program, wherein when the program is running, a device where the computer-readable storage medium is located is controlled to execute a method for compiling the embedded code.

[0089] Specifically, the compilation method of the embedded code includes:

[0090] Step S201 : compile the source code to generate an initial compiled file. The initial compiled file is a file that can read the attributes of variables.

[0091] Specifically, source code (also known as source program) refers to an uncompiled text file written in accordance with a specific programming language specification. It is a series of human-readable computer language instructions. In modern programming languages, source code can be in the form of books or tapes, but the most common format is a text file. This typical format is used to compile computer programs. The ultimate goal of computer source code is to translate human-readable text into binary instructions that a computer can execute. This process is called compilation and is accomplished by a compiler. By compiling the source code, an initial compiled file can be obtained. From this initial compiled file, the properties of variables can be read.

[0092] Step S202 : determining the attributes of each of the variables in the initial compiled file, and generating a header file of at least one of the attributes into an attribute table.

[0093] Specifically, in embedded software development, each C++ / C program usually consists of a header file and a definition file. The header file is a carrier file containing function and data interface declarations, mainly used to store program declarations, while the definition file is used to store program implementation in existing technologies.

[0094] Specifically, in the prior art, variable attributes can be divided into defined attributes and declared attributes. Defined attributes are used to allocate addresses and storage space for variables, while declared attributes only allocate storage space for variables, not addresses. The above-mentioned attribute table is generated by the header file corresponding to the variable attributes. When the variable in the above-mentioned initial compiled file has only one attribute, one attribute table is generated; when the variable in the above-mentioned initial compiled file has multiple attributes, multiple attribute tables are generated. That is, this application does not specifically limit the number of the above-mentioned attribute tables.

[0095] Step S203, traverse the above attribute table, write the header file of at least one of the above attributes back to the file of the corresponding module using the variable to form an updated file of the module using the variable, and use the updated file of the module using the module to compile and obtain the target code.

[0096] Specifically, in the development of embedded systems, in order to save memory space, developers adopt a module reuse design. The system is usually divided into different usage modules, that is, the program will be divided into several small segments. After traversing the attribute table, at least one header file of the above attributes will be written back to the file of the usage module of the corresponding variable, so that the updated file of the usage module is used for compilation to obtain the target code.

[0097] According to this embodiment, first, the source code is compiled to generate an initial compiled file, and then the attributes of each of the above variables in the initial compiled file are determined, and a header file of at least one of the above attributes is generated into an attribute table, and the attribute table is traversed, and the header file of at least one of the above attributes is written back to the file of the corresponding use module of the above variable to form an updated file of the use module, and the updated file of the use module is used for compilation to obtain the target code. Compared with the relatively lengthy scheme of the compilation method to obtain the target code in the prior art, in the scheme of the present application, the header file corresponding to the attributes of each variable in the initial compiled file is generated into an attribute table, and the header file of the attribute of the variable is directly found through the intermediate header file, and only the header file of the attribute of the variable (the intermediate header file is not written back) is written back to the use module of each variable to obtain the file of the updated use module, so that the target code obtained by compiling the file of the updated use module is more concise because the target code does not include the code of the intermediate header file, thereby solving the problem that the target code obtained by compilation in the prior art is too lengthy.

[0098] The execution subject of the method may be any compiler in the prior art, specifically, the WindRiver compiler.

[0099] In a specific implementation, step S201 can be implemented by: compiling the source code to generate an object file; and converting the object file into a text file to obtain the initial compiled file. This method compiles the source code to generate an object file, i.e., an executable file; and converts the object file into a text file to obtain the initial compiled file. Since text files are readable, converting the executable file into a text file ensures that the attributes of the variables in the text file, i.e., the initial compiled file, can be read and identified, thereby achieving the purpose of classifying the attributes of different variables. This ensures that the identification of variable attributes is more convenient and efficient.

[0100] In order to generate variables into an attribute table according to their respective different attributes, the above-mentioned step S202 of the present application can be implemented by the following steps: determine the attributes of each of the above-mentioned variables, and when there are multiple attributes, generate the header files of the same attribute into the above-mentioned attribute table accordingly, and obtain multiple attribute tables corresponding to multiple attributes, wherein one attribute corresponds to one attribute table. When the variables in the above-mentioned initial compiled file have multiple attributes, this method generates the header files of the variables with the same attribute into the same attribute table, that is, there are as many corresponding attribute tables as there are attributes, so that the header files of the variables with the same attributes can be placed into one attribute table, that is, the header files of the variables with different attributes can be classified and placed into corresponding attribute tables respectively, so that the header files are more organized and the subsequent traversal process can be ensured to be more efficient.

[0101] Specifically, when there is only one variable with the same attribute in the initial compiled file, the attribute table contains only one header file for that variable. When there are multiple variables with the same attribute in the initial compiled file, the header files for those variables can be stored simultaneously in the same attribute table for the corresponding attribute. That is, the attribute table can store the header file corresponding to one variable or multiple variables, but the multiple variables must meet the condition of the same attribute. This application does not impose any specific restrictions on the number of header files in the attribute table.

[0102] The above step S202 can also be implemented in other ways, for example: determining whether the attributes of each global variable are defined attributes or declared attributes; if the attributes of the above global variables are defined attributes, generating the header file of the defined attributes of the above global variables into the defined attribute table; if the attributes of the above global variables are declared attributes, generating the header file of the declared attributes of the above global variables into the declared attribute table. This method determines whether the attributes of each global variable are defined attributes or declared attributes, and generates the header file of the global variables whose attributes are defined attributes into the defined attribute table, and generates the header file of the global variables whose attributes are declared attributes into the declared attribute table. In this way, the header files of the global variables with defined attributes and the global variables with declared attributes are generated into their respective corresponding attribute tables, making the classification clear, so as to ensure that the subsequent compiler traverses the attribute table according to the attributes corresponding to each global variable in the initial compiled file.

[0103] Specifically, after the attributes of global variables are classified in the initial compilation file, the attributes of global variables are divided into definition attributes and declaration attributes. Therefore, it is first determined whether the attributes of each global variable are definition attributes or declaration attributes. After that, the header files of variables with OBJECT attributes (definition attributes) of global variables are generated into the definition attribute table. At the same time, the header files of variables with NOTYPE attributes (declaration attributes) of global variables are generated into the declaration attribute table.

[0104] Of course, the attributes of the above-mentioned global variables can also be attributes inherent to other variables, such as storage type, scope and link attributes, etc., that is, this application does not specifically limit the types of the above-mentioned global variable attributes.

[0105] In some embodiments, the above-mentioned step S203 can be specifically implemented by the following steps: when there are multiple attribute tables, traverse each of the above-mentioned attribute tables, and write the header files of each of the above-mentioned attributes corresponding to the above-mentioned variables back to the files of the modules using the above-mentioned variables. When multiple attribute tables are generated, that is, when there are multiple attributes of a variable, this method traverses each of the above-mentioned attribute tables, obtains the header files of the attributes corresponding to each variable, and writes the obtained header files back to the files of the modules using the above-mentioned variables, so as to ensure that the traversal is performed according to the attributes of each variable, and the header files of the attributes corresponding to the variables are written back to the modules using the variables in sequence, thereby avoiding the problem of low compilation efficiency caused by repeated traversal.

[0106] Specifically, when the header files of the attributes corresponding to the variables are written back to the files of the modules that use the variables, all the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables, or some of the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables. That is, this application does not impose any specific restrictions on the number of header files written back to the files of the modules that use the variables. In actual applications, in order to make the compiled target code more concise, it is a better solution to write all the header files of the attributes corresponding to the variables back to the files of the modules that use the variables.

[0107] The above step S203 can also be implemented in other ways, for example: traversing the above definition attribute table, writing the header file of the above definition attribute back to the file of the corresponding module using the above global variable; traversing the above declaration attribute table, writing the header file of the above declaration attribute back to the file of the corresponding module using the above global variable. After generating the above definition attribute table and the declaration attribute table, the method traverses the above definition attribute table, writes the header file of the above definition attribute back to the file of the corresponding module using the above global variable, and traverses the above declaration attribute table, writes the header file of the above declaration attribute back to the file of the corresponding module using the above global variable, thereby placing the header file corresponding to each global variable into the file of the using module, which can make the code more concise.

[0108] For example, as shown in Table 1 and Table 2, when the global variable Com_stTxEngConfTrg is used in the ComTxVehSys2 module, first, traverse the definition attribute table to find the definition header file ComTxVehSys2_MData.c of the above variable, traverse the declaration attribute table to find the above variable declaration header file ComTxVehSys2.c, and then rewrite the definition header file and declaration header file of the global variable Com_stTxEngConfTrg back to the ComTxVehSys2.c file of the using module, so that the code is more concise.

[0109] An embodiment of the present invention provides a processor, which is used to run a program, wherein the program executes the compiling method of the embedded code when it is running.

[0110] Specifically, the compilation method of the embedded code includes:

[0111] Step S201 : compile the source code to generate an initial compiled file. The initial compiled file is a file that can read the attributes of variables.

[0112] Specifically, source code (also known as source program) refers to an uncompiled text file written in accordance with a specific programming language specification. It is a series of human-readable computer language instructions. In modern programming languages, source code can be in the form of books or tapes, but the most common format is a text file. This typical format is used to compile computer programs. The ultimate goal of computer source code is to translate human-readable text into binary instructions that a computer can execute. This process is called compilation and is accomplished by a compiler. By compiling the source code, an initial compiled file can be obtained. From this initial compiled file, the properties of variables can be read.

[0113] Step S202 : determining the attributes of each of the variables in the initial compiled file, and generating a header file of at least one of the attributes into an attribute table.

[0114] Specifically, in embedded software development, each C++ / C program usually consists of a header file and a definition file. The header file is a carrier file containing function and data interface declarations, mainly used to store program declarations, while the definition file is used to store program implementation in existing technologies.

[0115] Specifically, in the prior art, variable attributes can be divided into defined attributes and declared attributes. Defined attributes are used to allocate addresses and storage space for variables, while declared attributes only allocate storage space for variables, not addresses. The above-mentioned attribute table is generated by the header file corresponding to the variable attributes. When the variable in the above-mentioned initial compiled file has only one attribute, one attribute table is generated; when the variable in the above-mentioned initial compiled file has multiple attributes, multiple attribute tables are generated. That is, this application does not specifically limit the number of the above-mentioned attribute tables.

[0116] Step S203, traverse the above attribute table, write the header file of at least one of the above attributes back to the file of the corresponding module using the variable to form an updated file of the module using the variable, and use the updated file of the module using the module to compile and obtain the target code.

[0117] Specifically, in the development of embedded systems, in order to save memory space, developers adopt a module reuse design. The system is usually divided into different usage modules, that is, the program will be divided into several small segments. After traversing the attribute table, at least one header file of the above attributes will be written back to the file of the usage module of the corresponding variable, so that the updated file of the usage module is used for compilation to obtain the target code.

[0118] According to this embodiment, first, the source code is compiled to generate an initial compiled file, and then the attributes of each of the above variables in the initial compiled file are determined, and a header file of at least one of the above attributes is generated into an attribute table, and the attribute table is traversed, and the header file of at least one of the above attributes is written back to the file of the corresponding use module of the above variable to form an updated file of the use module, and the updated file of the use module is used for compilation to obtain the target code. Compared with the relatively lengthy scheme of the compilation method to obtain the target code in the prior art, in the scheme of the present application, the header file corresponding to the attributes of each variable in the initial compiled file is generated into an attribute table, and the header file of the attribute of the variable is directly found through the intermediate header file, and only the header file of the attribute of the variable (the intermediate header file is not written back) is written back to the use module of each variable to obtain the file of the updated use module, so that the target code obtained by compiling the file of the updated use module is more concise because the target code does not include the code of the intermediate header file, thereby solving the problem that the target code obtained by compilation in the prior art is too lengthy.

[0119] The execution subject of the method may be any compiler in the prior art, specifically, the WindRiver compiler.

[0120] In a specific implementation, step S201 can be implemented by: compiling the source code to generate an object file; and converting the object file into a text file to obtain the initial compiled file. This method compiles the source code to generate an object file, i.e., an executable file; and converts the object file into a text file to obtain the initial compiled file. Since text files are readable, converting the executable file into a text file ensures that the attributes of the variables in the text file, i.e., the initial compiled file, can be read and identified, thereby achieving the purpose of classifying the attributes of different variables. This ensures that the identification of variable attributes is more convenient and efficient.

[0121] In order to generate variables into an attribute table according to their respective different attributes, the above-mentioned step S202 of the present application can be implemented by the following steps: determine the attributes of each of the above-mentioned variables, and when there are multiple attributes, generate the header files of the same attribute into the above-mentioned attribute table accordingly, and obtain multiple attribute tables corresponding to multiple attributes, wherein one attribute corresponds to one attribute table. When the variables in the above-mentioned initial compiled file have multiple attributes, this method generates the header files of the variables with the same attribute into the same attribute table, that is, there are as many corresponding attribute tables as there are attributes, so that the header files of the variables with the same attributes can be placed into one attribute table, that is, the header files of the variables with different attributes can be classified and placed into corresponding attribute tables respectively, so that the header files are more organized and the subsequent traversal process can be ensured to be more efficient.

[0122] Specifically, when there is only one variable with the same attribute in the initial compiled file, the attribute table contains only one header file for that variable. When there are multiple variables with the same attribute in the initial compiled file, the header files for those variables can be stored simultaneously in the same attribute table for the corresponding attribute. That is, the attribute table can store the header file corresponding to one variable or multiple variables, but the multiple variables must meet the condition of the same attribute. This application does not impose any specific restrictions on the number of header files in the attribute table.

[0123] The above step S202 can also be implemented in other ways, for example: determining whether the attributes of each global variable are defined attributes or declared attributes; if the attributes of the above global variables are defined attributes, generating the header file of the defined attributes of the above global variables into the defined attribute table; if the attributes of the above global variables are declared attributes, generating the header file of the declared attributes of the above global variables into the declared attribute table. This method determines whether the attributes of each global variable are defined attributes or declared attributes, and generates the header file of the global variables whose attributes are defined attributes into the defined attribute table, and generates the header file of the global variables whose attributes are declared attributes into the declared attribute table. In this way, the header files of the global variables with defined attributes and the global variables with declared attributes are generated into their respective corresponding attribute tables, making the classification clear, so as to ensure that the subsequent compiler traverses the attribute table according to the attributes corresponding to each global variable in the initial compiled file.

[0124] Specifically, after the attributes of global variables are classified in the initial compilation file, the attributes of global variables are divided into definition attributes and declaration attributes. Therefore, it is first determined whether the attributes of each global variable are definition attributes or declaration attributes. After that, the header files of variables with OBJECT attributes (definition attributes) of global variables are generated into the definition attribute table. At the same time, the header files of variables with NOTYPE attributes (declaration attributes) of global variables are generated into the declaration attribute table.

[0125] Of course, the attributes of the above-mentioned global variables can also be attributes inherent to other variables, such as storage type, scope and link attributes, etc., that is, this application does not specifically limit the types of the above-mentioned global variable attributes.

[0126] In some embodiments, the above-mentioned step S203 can be specifically implemented by the following steps: when there are multiple attribute tables, traverse each of the above-mentioned attribute tables, and write the header files of each of the above-mentioned attributes corresponding to the above-mentioned variables back to the files of the modules using the above-mentioned variables. When multiple attribute tables are generated, that is, when there are multiple attributes of a variable, this method traverses each of the above-mentioned attribute tables, obtains the header files of the attributes corresponding to each variable, and writes the obtained header files back to the files of the modules using the above-mentioned variables, so as to ensure that the traversal is performed according to the attributes of each variable, and the header files of the attributes corresponding to the variables are written back to the modules using the variables in sequence, thereby avoiding the problem of low compilation efficiency caused by repeated traversal.

[0127] Specifically, when the header files of the attributes corresponding to the variables are written back to the files of the modules that use the variables, all the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables, or some of the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables. That is, this application does not impose any specific restrictions on the number of header files written back to the files of the modules that use the variables. In actual applications, in order to make the compiled target code more concise, it is a better solution to write all the header files of the attributes corresponding to the variables back to the files of the modules that use the variables.

[0128] The above step S203 can also be implemented in other ways, for example: traversing the above definition attribute table, writing the header file of the above definition attribute back to the file of the corresponding module using the above global variable; traversing the above declaration attribute table, writing the header file of the above declaration attribute back to the file of the corresponding module using the above global variable. After generating the above definition attribute table and the declaration attribute table, the method traverses the above definition attribute table, writes the header file of the above definition attribute back to the file of the corresponding module using the above global variable, and traverses the above declaration attribute table, writes the header file of the above declaration attribute back to the file of the corresponding module using the above global variable, thereby placing the header file corresponding to each global variable into the file of the using module, which can make the code more concise.

[0129] For example, as shown in Table 1 and Table 2, when the global variable Com_stTxEngConfTrg is used in the ComTxVehSys2 module, first, traverse the definition attribute table to find the definition header file ComTxVehSys2_MData.c of the above variable, traverse the declaration attribute table to find the above variable declaration header file ComTxVehSys2.c, and then rewrite the definition header file and declaration header file of the global variable Com_stTxEngConfTrg back to the ComTxVehSys2.c file of the using module, so that the code is more concise.

[0130] An embodiment of the present invention provides a device, comprising a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, at least the following steps are performed:

[0131] Step S201, compile the source code to generate an initial compiled file, where the initial compiled file is a file that can read the attributes of the variables;

[0132] Step S202, determining the attributes of each of the variables in the initial compiled file, and generating a header file of at least one of the attributes into an attribute table;

[0133] Step S203, traverse the above attribute table, write the header file of at least one of the above attributes back to the file of the corresponding module using the variable to form an updated file of the module using the variable, and use the updated file of the module using the module to compile and obtain the target code.

[0134] The devices in this article can be servers, PCs, PADs, mobile phones, etc.

[0135] Specifically, source code (also known as source program) refers to an uncompiled text file written in accordance with a specific programming language specification. It is a series of human-readable computer language instructions. In modern programming languages, source code can be in the form of books or tapes, but the most common format is a text file. This typical format is used to compile computer programs. The ultimate goal of computer source code is to translate human-readable text into binary instructions that a computer can execute. This process is called compilation and is accomplished by a compiler. By compiling the source code, an initial compiled file can be obtained. From this initial compiled file, the properties of variables can be read.

[0136] Specifically, in embedded software development, each C++ / C program usually consists of a header file and a definition file. The header file is a carrier file containing function and data interface declarations, mainly used to store program declarations, while the definition file is used to store program implementation in existing technologies.

[0137] Specifically, in the prior art, variable attributes can be divided into defined attributes and declared attributes. Defined attributes are used to allocate addresses and storage space for variables, while declared attributes only allocate storage space for variables, not addresses. The above-mentioned attribute table is generated by the header file corresponding to the variable attributes. When the variable in the above-mentioned initial compiled file has only one attribute, one attribute table is generated; when the variable in the above-mentioned initial compiled file has multiple attributes, multiple attribute tables are generated. That is, this application does not specifically limit the number of the above-mentioned attribute tables.

[0138] Specifically, in the development of embedded systems, in order to save memory space, developers adopt a module reuse design. The system is usually divided into different usage modules, that is, the program will be divided into several small segments. After traversing the attribute table, at least one header file of the above attributes will be written back to the file of the usage module of the corresponding variable, so that the updated file of the usage module is used for compilation to obtain the target code.

[0139] According to this embodiment, first, the source code is compiled to generate an initial compiled file, and then the attributes of each of the above variables in the initial compiled file are determined, and a header file of at least one of the above attributes is generated into an attribute table, and the attribute table is traversed, and the header file of at least one of the above attributes is written back to the file of the corresponding use module of the above variable to form an updated file of the use module, and the updated file of the use module is used for compilation to obtain the target code. Compared with the relatively lengthy scheme of the compilation method to obtain the target code in the prior art, in the scheme of the present application, the header file corresponding to the attributes of each variable in the initial compiled file is generated into an attribute table, and the header file of the attribute of the variable is directly found through the intermediate header file, and only the header file of the attribute of the variable (the intermediate header file is not written back) is written back to the use module of each variable to obtain the file of the updated use module, so that the target code obtained by compiling the file of the updated use module is more concise because the target code does not include the code of the intermediate header file, thereby solving the problem that the target code obtained by compilation in the prior art is too lengthy.

[0140] The execution subject of the method may be any compiler in the prior art, specifically, the WindRiver compiler.

[0141] In a specific implementation, step S201 can be implemented by: compiling the source code to generate an object file; and converting the object file into a text file to obtain the initial compiled file. This method compiles the source code to generate an object file, i.e., an executable file; and converts the object file into a text file to obtain the initial compiled file. Since text files are readable, converting the executable file into a text file ensures that the attributes of the variables in the text file, i.e., the initial compiled file, can be read and identified, thereby achieving the purpose of classifying the attributes of different variables. This ensures that the identification of variable attributes is more convenient and efficient.

[0142] In order to generate variables into an attribute table according to their respective different attributes, the above-mentioned step S202 of the present application can be implemented by the following steps: determine the attributes of each of the above-mentioned variables, and when there are multiple attributes, generate the header files of the same attribute into the above-mentioned attribute table accordingly, and obtain multiple attribute tables corresponding to multiple attributes, wherein one attribute corresponds to one attribute table. When the variables in the above-mentioned initial compiled file have multiple attributes, this method generates the header files of the variables with the same attribute into the same attribute table, that is, there are as many corresponding attribute tables as there are attributes, so that the header files of the variables with the same attributes can be placed into one attribute table, that is, the header files of the variables with different attributes can be classified and placed into corresponding attribute tables respectively, so that the header files are more organized and the subsequent traversal process can be ensured to be more efficient.

[0143] Specifically, when there is only one variable with the same attribute in the initial compiled file, the attribute table contains only one header file for that variable. When there are multiple variables with the same attribute in the initial compiled file, the header files for those variables can be stored simultaneously in the same attribute table for the corresponding attribute. That is, the attribute table can store the header file corresponding to one variable or multiple variables, but the multiple variables must meet the condition of the same attribute. This application does not impose any specific restrictions on the number of header files in the attribute table.

[0144] The above step S202 can also be implemented in other ways, for example: determining whether the attributes of each global variable are defined attributes or declared attributes; if the attributes of the above global variables are defined attributes, generating the header file of the defined attributes of the above global variables into the defined attribute table; if the attributes of the above global variables are declared attributes, generating the header file of the declared attributes of the above global variables into the declared attribute table. This method determines whether the attributes of each global variable are defined attributes or declared attributes, and generates the header file of the global variables whose attributes are defined attributes into the defined attribute table, and generates the header file of the global variables whose attributes are declared attributes into the declared attribute table. In this way, the header files of the global variables with defined attributes and the global variables with declared attributes are generated into their respective corresponding attribute tables, making the classification clear, so as to ensure that the subsequent compiler traverses the attribute table according to the attributes corresponding to each global variable in the initial compiled file.

[0145] Specifically, after the attributes of global variables are classified in the initial compilation file, the attributes of global variables are divided into definition attributes and declaration attributes. Therefore, it is first determined whether the attributes of each global variable are definition attributes or declaration attributes. After that, the header files of variables with OBJECT attributes (definition attributes) of global variables are generated into the definition attribute table. At the same time, the header files of variables with NOTYPE attributes (declaration attributes) of global variables are generated into the declaration attribute table.

[0146] Of course, the attributes of the above-mentioned global variables can also be attributes inherent to other variables, such as storage type, scope and link attributes, etc., that is, this application does not specifically limit the types of the above-mentioned global variable attributes.

[0147] In some embodiments, the above-mentioned step S203 can be specifically implemented by the following steps: when there are multiple attribute tables, traverse each of the above-mentioned attribute tables, and write the header files of each of the above-mentioned attributes corresponding to the above-mentioned variables back to the files of the modules using the above-mentioned variables. When multiple attribute tables are generated, that is, when there are multiple attributes of a variable, this method traverses each of the above-mentioned attribute tables, obtains the header files of the attributes corresponding to each variable, and writes the obtained header files back to the files of the modules using the above-mentioned variables, so as to ensure that the traversal is performed according to the attributes of each variable, and the header files of the attributes corresponding to the variables are written back to the modules using the variables in sequence, thereby avoiding the problem of low compilation efficiency caused by repeated traversal.

[0148] Specifically, when the header files of the attributes corresponding to the variables are written back to the files of the modules that use the variables, all the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables, or some of the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables. That is, this application does not impose any specific restrictions on the number of header files written back to the files of the modules that use the variables. In actual applications, in order to make the compiled target code more concise, it is a better solution to write all the header files of the attributes corresponding to the variables back to the files of the modules that use the variables.

[0149] The above step S203 can also be implemented in other ways, for example: traversing the above definition attribute table, writing the header file of the above definition attribute back to the file of the corresponding module using the above global variable; traversing the above declaration attribute table, writing the header file of the above declaration attribute back to the file of the corresponding module using the above global variable. After generating the above definition attribute table and the declaration attribute table, the method traverses the above definition attribute table, writes the header file of the above definition attribute back to the file of the corresponding module using the above global variable, and traverses the above declaration attribute table, writes the header file of the above declaration attribute back to the file of the corresponding module using the above global variable, thereby placing the header file corresponding to each global variable into the file of the using module, which can make the code more concise.

[0150] For example, as shown in Table 1 and Table 2, when the global variable Com_stTxEngConfTrg is used in the ComTxVehSys2 module, first, traverse the definition attribute table to find the definition header file ComTxVehSys2_MData.c of the above variable, traverse the declaration attribute table to find the above variable declaration header file ComTxVehSys2.c, and then rewrite the definition header file and declaration header file of the global variable Com_stTxEngConfTrg back to the ComTxVehSys2.c file of the using module, so that the code is more concise.

[0151] The present application also provides a computer program product, which, when executed on a data processing device, is adapted to execute a program for initializing at least the following method steps:

[0152] Step S201, compile the source code to generate an initial compiled file, where the initial compiled file is a file that can read the attributes of the variables;

[0153] Step S202, determining the attributes of each of the variables in the initial compiled file, and generating a header file of at least one of the attributes into an attribute table;

[0154] Step S203, traverse the above attribute table, write the header file of at least one of the above attributes back to the file of the corresponding module using the variable to form an updated file of the module using the variable, and use the updated file of the module using the module to compile and obtain the target code.

[0155] Specifically, source code (also known as source program) refers to an uncompiled text file written in accordance with a specific programming language specification. It is a series of human-readable computer language instructions. In modern programming languages, source code can be in the form of books or tapes, but the most common format is a text file. This typical format is used to compile computer programs. The ultimate goal of computer source code is to translate human-readable text into binary instructions that a computer can execute. This process is called compilation and is accomplished by a compiler. By compiling the source code, an initial compiled file can be obtained. From this initial compiled file, the properties of variables can be read.

[0156] Specifically, in embedded software development, each C++ / C program usually consists of a header file and a definition file. The header file is a carrier file containing function and data interface declarations, mainly used to store program declarations, while the definition file is used to store program implementation in existing technologies.

[0157] Specifically, in the prior art, variable attributes can be divided into defined attributes and declared attributes. Defined attributes are used to allocate addresses and storage space for variables, while declared attributes only allocate storage space for variables, not addresses. The above-mentioned attribute table is generated by the header file corresponding to the variable attributes. When the variable in the above-mentioned initial compiled file has only one attribute, one attribute table is generated; when the variable in the above-mentioned initial compiled file has multiple attributes, multiple attribute tables are generated. That is, this application does not specifically limit the number of the above-mentioned attribute tables.

[0158] Specifically, in the development of embedded systems, in order to save memory space, developers adopt a module reuse design. The system is usually divided into different usage modules, that is, the program will be divided into several small segments. After traversing the attribute table, at least one header file of the above attributes will be written back to the file of the usage module of the corresponding variable, so that the updated file of the usage module is used for compilation to obtain the target code.

[0159] According to this embodiment, first, the source code is compiled to generate an initial compiled file, and then the attributes of each of the above variables in the initial compiled file are determined, and a header file of at least one of the above attributes is generated into an attribute table, and the attribute table is traversed, and the header file of at least one of the above attributes is written back to the file of the corresponding use module of the above variable to form an updated file of the use module, and the updated file of the use module is used for compilation to obtain the target code. Compared with the relatively lengthy scheme of the compilation method to obtain the target code in the prior art, in the scheme of the present application, the header file corresponding to the attributes of each variable in the initial compiled file is generated into an attribute table, and the header file of the attribute of the variable is directly found through the intermediate header file, and only the header file of the attribute of the variable (the intermediate header file is not written back) is written back to the use module of each variable to obtain the file of the updated use module, so that the target code obtained by compiling the file of the updated use module is more concise because the target code does not include the code of the intermediate header file, thereby solving the problem that the target code obtained by compilation in the prior art is too lengthy.

[0160] The execution subject of the method may be any compiler in the prior art, specifically, the WindRiver compiler.

[0161] In a specific implementation, step S201 can be implemented by: compiling the source code to generate an object file; and converting the object file into a text file to obtain the initial compiled file. This method compiles the source code to generate an object file, i.e., an executable file; and converts the object file into a text file to obtain the initial compiled file. Since text files are readable, converting the executable file into a text file ensures that the attributes of the variables in the text file, i.e., the initial compiled file, can be read and identified, thereby achieving the purpose of classifying the attributes of different variables. This ensures that the identification of variable attributes is more convenient and efficient.

[0162] In order to generate variables into an attribute table according to their respective different attributes, the above-mentioned step S202 of the present application can be implemented by the following steps: determine the attributes of each of the above-mentioned variables, and when there are multiple attributes, generate the header files of the same attribute into the above-mentioned attribute table accordingly, and obtain multiple attribute tables corresponding to multiple attributes, wherein one attribute corresponds to one attribute table. When the variables in the above-mentioned initial compiled file have multiple attributes, this method generates the header files of the variables with the same attribute into the same attribute table, that is, there are as many corresponding attribute tables as there are attributes, so that the header files of the variables with the same attributes can be placed into one attribute table, that is, the header files of the variables with different attributes can be classified and placed into corresponding attribute tables respectively, so that the header files are more organized and the subsequent traversal process can be ensured to be more efficient.

[0163] Specifically, when there is only one variable with the same attribute in the initial compiled file, the attribute table contains only one header file for that variable. When there are multiple variables with the same attribute in the initial compiled file, the header files for those variables can be stored simultaneously in the same attribute table for the corresponding attribute. That is, the attribute table can store the header file corresponding to one variable or multiple variables, but the multiple variables must meet the condition of the same attribute. This application does not impose any specific restrictions on the number of header files in the attribute table.

[0164] The above step S202 can also be implemented in other ways, for example: determining whether the attributes of each global variable are defined attributes or declared attributes; if the attributes of the above global variables are defined attributes, generating the header file of the defined attributes of the above global variables into the defined attribute table; if the attributes of the above global variables are declared attributes, generating the header file of the declared attributes of the above global variables into the declared attribute table. This method determines whether the attributes of each global variable are defined attributes or declared attributes, and generates the header file of the global variables whose attributes are defined attributes into the defined attribute table, and generates the header file of the global variables whose attributes are declared attributes into the declared attribute table. In this way, the header files of the global variables with defined attributes and the global variables with declared attributes are generated into their respective corresponding attribute tables, making the classification clear, so as to ensure that the subsequent compiler traverses the attribute table according to the attributes corresponding to each global variable in the initial compiled file.

[0165] Specifically, after the attributes of global variables are classified in the initial compilation file, the attributes of global variables are divided into definition attributes and declaration attributes. Therefore, it is first determined whether the attributes of each global variable are definition attributes or declaration attributes. After that, the header files of variables with OBJECT attributes (definition attributes) of global variables are generated into the definition attribute table. At the same time, the header files of variables with NOTYPE attributes (declaration attributes) of global variables are generated into the declaration attribute table.

[0166] Of course, the attributes of the above-mentioned global variables can also be attributes inherent to other variables, such as storage type, scope and link attributes, etc., that is, this application does not specifically limit the types of the above-mentioned global variable attributes.

[0167] In some embodiments, the above-mentioned step S203 can be specifically implemented by the following steps: when there are multiple attribute tables, traverse each of the above-mentioned attribute tables, and write the header files of each of the above-mentioned attributes corresponding to the above-mentioned variables back to the files of the modules using the above-mentioned variables. When multiple attribute tables are generated, that is, when there are multiple attributes of a variable, this method traverses each of the above-mentioned attribute tables, obtains the header files of the attributes corresponding to each variable, and writes the obtained header files back to the files of the modules using the above-mentioned variables, so as to ensure that the traversal is performed according to the attributes of each variable, and the header files of the attributes corresponding to the variables are written back to the modules using the variables in sequence, thereby avoiding the problem of low compilation efficiency caused by repeated traversal.

[0168] Specifically, when the header files of the attributes corresponding to the variables are written back to the files of the modules that use the variables, all the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables, or some of the header files of the attributes corresponding to the variables can be written back to the files of the modules that use the variables. That is, this application does not impose any specific restrictions on the number of header files written back to the files of the modules that use the variables. In actual applications, in order to make the compiled target code more concise, it is a better solution to write all the header files of the attributes corresponding to the variables back to the files of the modules that use the variables.

[0169] The above step S203 can also be implemented in other ways, for example: traversing the above definition attribute table, writing the header file of the above definition attribute back to the file of the corresponding module using the above global variable; traversing the above declaration attribute table, writing the header file of the above declaration attribute back to the file of the corresponding module using the above global variable. After generating the above definition attribute table and the declaration attribute table, the method traverses the above definition attribute table, writes the header file of the above definition attribute back to the file of the corresponding module using the above global variable, and traverses the above declaration attribute table, writes the header file of the above declaration attribute back to the file of the corresponding module using the above global variable, thereby placing the header file corresponding to each global variable into the file of the using module, which can make the code more concise.

[0170] For example, as shown in Table 1 and Table 2, when the global variable Com_stTxEngConfTrg is used in the ComTxVehSys2 module, first, traverse the definition attribute table to find the definition header file ComTxVehSys2_MData.c of the above variable, traverse the declaration attribute table to find the above variable declaration header file ComTxVehSys2.c, and then rewrite the definition header file and declaration header file of the global variable Com_stTxEngConfTrg back to the ComTxVehSys2.c file of the using module, so that the code is more concise.

[0171] Obviously, those skilled in the art will appreciate that the various modules or steps of the present invention described above can be implemented using a general-purpose computing device, can be centralized on a single computing device, or can be distributed across a network of multiple computing devices. They can be implemented using program code executable by the computing device, and thus, can be stored in a storage device and executed by the computing device. In some cases, the steps shown or described herein can be performed in a different order than that shown, or can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.

[0172] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0173] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0174] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0175] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0176] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0177] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0178] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0179] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0180] From the above description, it can be seen that the above embodiments of the present application achieve the following technical effects:

[0181] 1) In the compilation method of the embedded code of the present application, first, the source code is compiled to generate an initial compiled file, and then the attributes of each of the above variables in the above initial compiled file are determined, and the header file of at least one of the above attributes is generated into an attribute table, and the above attribute table is traversed, and the header file of at least one of the above attributes is written back to the file of the corresponding use module of the above variable to form an updated file of the use module, and the file of the updated use module is compiled to obtain the target code. Compared with the relatively lengthy scheme of the compilation method to obtain the target code in the prior art, in the scheme of the present application, the header file corresponding to the attributes of each variable in the initial compiled file is generated into an attribute table, and the header file of the attribute of the variable is directly found through the intermediate header file, and only the header file of the attribute of the variable (the intermediate header file is not written back) is written back to the use module of each variable to obtain the file of the updated use module, so that the file of the updated use module is compiled, and the target code obtained is more concise because the target code does not include the code of the intermediate header file, thereby solving the problem that the target code obtained by compilation in the prior art is too lengthy.

[0182] 2) in the compilation method of the embedded code of the present application, source code is compiled to generate object file; Above-mentioned object file is converted into text file, obtain above-mentioned initial compilation file, can ensure that the identification for variable attribute is more convenient and efficient like this. Determine the attribute of each above-mentioned variable, when above-mentioned attribute has multiple, the header file of same above-mentioned attribute is correspondingly generated into one above-mentioned attribute table, obtain multiple above-mentioned attribute tables corresponding to multiple above-mentioned attributes, wherein, one above-mentioned attribute corresponds to one above-mentioned attribute table, so that the header file of the variable with the same attribute can be put into an attribute table, the header file of the variable with different attributes is classified, and is respectively put into corresponding attribute table, makes header file more organized, ensures that subsequent traversal process is more efficient. When above-mentioned attribute table has multiple, traverse each above-mentioned attribute table, the header file of each above-mentioned attribute corresponding to above-mentioned variable is respectively written back to the file of the use module of above-mentioned variable, to ensure that traverse according to the attribute of each variable, the header file of variable corresponding attribute is written back in the use module of variable in sequence, avoids the problem of low compilation efficiency brought by repeated traversal. Determine whether the attributes of each global variable are defined attributes or declared attributes; if the attributes of the above global variables are defined attributes, generate the header file of the definition attributes of the above global variables into the definition attribute table; if the attributes of the above global variables are declared attributes, generate the header file of the declaration attributes of the above global variables into the declaration attribute table, so that the header files of global variables with defined attributes and global variables with declared attributes are generated into their respective corresponding attribute tables, making the classification clear, so as to ensure that the subsequent compiler traverses the attribute table according to the attributes corresponding to each global variable in the initial compilation file. Traverse the above definition attribute table, write the header file of the definition attribute back to the file of the corresponding module using the above global variables; traverse the above declaration attribute table, write the header file of the declaration attribute back to the file of the corresponding module using the above global variables, so that the header file corresponding to each global variable is placed in the file of the using module, which can further make the code more concise.

[0183] The above description is merely a preferred embodiment of the present application and is not intended to limit the present application. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present application shall be included within the scope of protection of the present application.

Claims

1. A method for compiling an embedded code, characterized in that: include: Compile the source code to generate an initial compiled file, where the initial compiled file is a file that can read the attributes of the variables; Determining the attributes of each of the variables in the initial compiled file, and generating a header file of at least one of the attributes into an attribute table; Traversing the attribute table, writing the header file of at least one attribute back to the file of the corresponding module using the variable to form an updated file of the module using the variable, and compiling with the updated file of the module using the module to obtain the target code; Determining the attributes of each of the variables in the initial compiled file and generating a header file of at least one of the attributes into an attribute table includes: Determine whether the attributes of each global variable are defined attributes or declared attributes; In a case where the attribute of the global variable is the definition attribute, generating a header file of the definition attribute of the global variable into a definition attribute table; In a case where the attribute of the global variable is the declaration attribute, generating a header file of the declaration attribute of the global variable into a declaration attribute table; Compile the source code to generate the initial compilation files, including: Compile the source code to generate object files; The object file is converted into a text file to obtain the initial compiled file.

2. The compiling method according to claim 1, wherein: Determining the attributes of each of the variables in the initial compiled file and generating a header file of at least one of the attributes into an attribute table includes: Determine the attributes of each variable. If there are multiple attributes, generate a header file of the same attribute into an attribute table to obtain multiple attribute tables corresponding to multiple attributes, wherein one attribute corresponds to one attribute table.

3. The compiling method according to claim 2, wherein: Traversing the attribute table and writing the header file of at least one attribute back to the file of the corresponding module using the variable, including: In the case that there are multiple attribute tables, each attribute table is traversed, and the header file of each attribute corresponding to the variable is written back to the file of the module using the variable.

4. The compiling method according to claim 1, wherein: Traversing the attribute table and writing the header file of at least one attribute back to the file of the corresponding module using the variable, including: Traversing the attribute definition table, writing the header file of the attribute definition back to the file of the corresponding module using the global variable; The declaration attribute table is traversed, and the header file of the declaration attribute is written back to the file of the corresponding module using the global variable.

5. A compiling device for embedded code, characterized in that: include: An initial compilation unit, used to compile the source code to generate an initial compilation file, wherein the initial compilation file is a file capable of reading the attributes of variables; a generating unit, configured to determine the attributes of each of the variables in the initial compiled file, and generate a header file of at least one of the attributes into an attribute table; a recompiling unit, configured to traverse the attribute table, write the header file of at least one attribute back to the file of the corresponding module using the variable to form an updated file of the module using the variable, and compile using the updated file of the module using the variable to obtain a target code; The generating unit includes: A first determining module is used to determine whether the attribute of each global variable is a defined attribute or a declared attribute; a first generating module, configured to generate a header file of the definition attribute of the global variable into a definition attribute table when the attribute of the global variable is the definition attribute; a second generating module, configured to generate a header file of the declaration attribute of the global variable into a declaration attribute table when the attribute of the global variable is the declaration attribute; The initial compilation unit consists of: The third generation module is used to compile the source code and generate an object file; The conversion module is used to convert the object file into a text file to obtain the initial compiled file.

6. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the compilation method according to any one of claims 1 to 4.

7. A processor, characterized in that: The processor is configured to run a program, wherein the program executes the compilation method according to any one of claims 1 to 4 when the program is run.

8. An electronic device, characterized in that: include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include instructions for executing the compilation method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Dynamic library delay loading method and device, equipment and storage medium

    CN111596970A

  • Project engineering file analysis method, device and equipment and storage medium

    CN112231278A