A program compiling method, a compiler, a computer device and a storage medium

CN115794060BActive Publication Date: 2026-08-07BEIJING ESWIN COMPUTING TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING ESWIN COMPUTING TECH CO LTD
Filing Date
2022-12-13
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

由于芯片尺寸的限制,芯片中电子元件数量减少,导致程序的存储空间有限,从而导致程序代码长度(code size)受限,因此如何在小尺寸芯片上,保证产品功能性完整或集成更多的产品功能(可以理解为不削减完整的可执行程序或提高更多可执行程序的存储)是一项开发难题

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115794060B_ABST
    Figure CN115794060B_ABST
Patent Text Reader

Abstract

The present disclosure provides a program compiling method, a compiler, a computer device and a storage medium, and belongs to the technical field of compiler development. The program compiling method comprises the following steps: obtaining a source program and generating stack data, wherein the stack data comprises a plurality of stack operation instructions, and at least part of the stack operation instructions comprises storage unit identification information; identifying the source program and determining at least one merging condition; determining the identification information of a target storage unit corresponding to each merging condition; and determining a group of stack operation instructions in the stack data according to the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data, merging the group of stack operation instructions, and generating assembly instructions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments disclosed herein belong to the field of compiler development technology, specifically relating to a program compilation method, a compiler, a computer device, and a storage medium. Background Technology

[0002] With the rapid development of smart electronic products, small smart electronic products have received widespread attention. However, the development of microcontroller units (MCUs) in small smart electronic products is usually limited by the corresponding chip size. Due to the limitation of chip size, the number of electronic components in the chip is reduced, resulting in limited program storage space, which in turn limits the code size. Therefore, how to ensure the complete functionality of the product or integrate more product functions on a small chip (which can be understood as not reducing the complete executable program or increasing the storage of more executable programs) is a development challenge. Summary of the Invention

[0003] This disclosure aims to at least solve one of the technical problems existing in the prior art, and to provide a program compilation method, compiler, computer device and storage medium.

[0004] Firstly, the technical solution adopted to solve the technical problem of this disclosure is a program compilation method, which includes: acquiring a source program and generating stack data; wherein the stack data includes multiple stack operation instructions, at least some of which include storage unit identification information; identifying the source program and determining at least one merging condition; determining the identification information of the corresponding target storage unit according to each merging condition; and determining a set of stack operation instructions in the stack data and merging them according to the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data to generate assembly instructions.

[0005] In some embodiments, identifying the source program and determining at least one merging condition includes:

[0006] Identify the source program, determine at least one calling function information in the source program, and determine the corresponding called function information based on the calling function information;

[0007] The merging conditions are determined based on the called function information and the corresponding called function information.

[0008] In some embodiments,

[0009] The step of determining the merging conditions based on the calling function information and the corresponding called function information includes:

[0010] Based on the identification information of the storage units occupied by each function in the source program, the first identification information of the storage unit corresponding to the calling function information and the second identification information of the storage unit corresponding to the called function information are determined respectively.

[0011] Based on the first identification information and the second identification information, the identification information of the target storage unit is determined, and the number of the target storage units is determined;

[0012] The step of determining and merging a set of stack operation instructions in the stack data based on the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data to generate assembly instructions includes:

[0013] When the number of target storage units meets the preset condition, a set of stack operation instructions in the stack data is determined and merged according to the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data to generate assembly instructions.

[0014] In some embodiments, determining the identification information of the target storage unit based on the first identification information and the second identification information includes:

[0015] Based on the first identification information and the second identification information, storage units with the same identification information are selected as the target storage units, and the identification information of the target storage units is determined.

[0016] In some embodiments, determining and merging a set of stack operation instructions in the stack data based on the storage unit identification information of the stack operation instructions in the stack data according to the identification information of each target storage unit to generate the assembly instructions includes: identifying each stack operation instruction in the stack data; when the stack operation instruction is a push instruction, selecting a set of push instructions that are identical to the identification information of the target storage unit from the stack data based on the storage unit identification information of the push instruction and merging them to generate the assembly instructions; and when the stack operation instruction is a pop instruction, selecting a set of pop instructions that are identical to the identification information of the target storage unit from the stack data based on the storage unit identification information of the pop instruction and merging them to generate the assembly instructions.

[0017] In some embodiments, after determining the number of target memory units, the method further includes: determining whether the number of target memory units meets the preset condition; and if the number of target memory units does not meet the preset condition, generating the assembly instructions based on the stack data.

[0018] In some embodiments, the source program is a floating-point program.

[0019] Secondly, embodiments of this disclosure also provide a compiler, comprising: an acquisition module configured to acquire a source program and generate stack data; wherein the stack data includes multiple stack operation instructions, at least some of which include storage unit identification information; a first information determination module configured to identify the source program and determine at least one merging condition; a second information determination module configured to determine the identification information of a corresponding target storage unit based on each merging condition; and an instruction generation module configured to determine a set of stack operation instructions in the stack data and merge them based on the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data to obtain generated assembly instructions.

[0020] Thirdly, this disclosure also provides a computer device, which includes: a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the computer device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, the steps of the program compilation method as described in any of the above embodiments are performed.

[0021] Fourthly, embodiments of this disclosure also provide a computer non-transient readable storage medium, wherein a computer program is stored on the computer non-transient readable storage medium, and the computer program is executed by a processor to perform the steps of the program compilation method as described in any of the above embodiments.

[0022] Fifthly, embodiments of this disclosure also provide an electronic product including a microcontroller unit; the microcontroller unit stores assembly instructions obtained using the program compilation method as described in any of the above embodiments. Attached Figure Description

[0023] Figure 1 A schematic diagram illustrating a program compilation method provided in an embodiment of this disclosure;

[0024] Figure 2 This is a schematic diagram showing a large number of stack operation instructions in an exemplary program;

[0025] Figure 3 A detailed flowchart of a program compilation method provided in this embodiment of the disclosure;

[0026] Figure 4 for Figure 2 A schematic diagram of the assembly program after the stack operation instructions have been merged;

[0027] Figure 5 A schematic flowchart illustrating the program compilation process provided in this embodiment of the disclosure;

[0028] Figure 6 A schematic diagram of a compiler provided for an embodiment of this disclosure;

[0029] Figure 7 This is a schematic diagram of the structure of a computer device provided in an embodiment of this disclosure. Detailed Implementation

[0030] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of the embodiments of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.

[0031] Unless otherwise defined, the technical or scientific terms used in this disclosure shall have the ordinary meaning understood by one of ordinary skill in the art to which this disclosure pertains. The terms “first,” “second,” and similar terms used in this disclosure do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, the terms “an,” “a,” or “the,” and similar terms do not indicate a quantity limitation, but rather indicate the presence of at least one. The terms “including,” “comprising,” or “containing,” and similar terms mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects. The terms “connected,” “linked,” or similar terms are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. The terms “upper,” “lower,” “left,” and “right,” etc., are used only to indicate relative positional relationships, and these relative positional relationships may change accordingly when the absolute position of the described objects changes.

[0032] In this disclosure, "multiple or several" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.

[0033] In related technologies, due to the limitations of chip size, the number of electronic components within a chip is reduced, resulting in a limited code size. To ensure complete product functionality or integrate more product functions on small-sized chips, traditional technologies utilize save-restore techniques to reduce the code length during compilation. However, save-restore techniques reduce code length by using program jumps, i.e., switching from the currently executing code to the next executing code within a complete program. It's important to note that program jumps are extremely time-consuming, requiring the process of retrieving the code to be jumped to and then executing the jump program. Therefore, while using save-restore techniques to reduce code length during compilation, it also leads to low program execution efficiency.

[0034] To address the issue of low program execution efficiency caused by reducing code length during program compilation in related technologies, this disclosure provides a program compilation method. This method reduces the code length during compilation while ensuring program execution efficiency by merging a large number of stack operation instructions into a single instruction.

[0035] Specifically, this method obtains the source program and generates stack data, which includes multiple stack operation instructions, at least some of which include memory location identification information. By identifying the source program, at least one merging condition is determined. Then, based on each merging condition, the identification information of the corresponding target memory location can be determined. Subsequently, based on the identification information of each target memory location and the memory location identification information of the stack operation instructions in the stack data, a set of stack operation instructions in the stack data is determined and merged to generate assembly instructions.

[0036] The embodiments of this disclosure identify the source program through the compiler, utilize the program identification function built into the compiler, and determine at least one merging condition according to predefined strategy information. The merging condition represents the prerequisite for merging subsequent stack operation instructions. The merging condition can be used to determine the target storage unit that needs to be saved.

[0037] It should be noted that the embodiments of this disclosure pertain to the program compilation stage, specifically determining the target storage unit, i.e., determining the identification information of the target storage unit. Based on the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data, a set of stack operation instructions in the stack data can be identified and merged, thereby generating assembly instructions with a shortened program code length. Compiling a program using the program compilation method provided in these embodiments can shorten the program code length, expanding its application range on small-size chips, and saving more chip storage space for integrating more product functions. Furthermore, compared to integrating the same function on a chip in conventional technologies, the shortened program code length in these embodiments reduces the chip's storage capacity, thereby improving chip performance and computational efficiency.

[0038] The following provides a detailed description of a program compilation method provided by an embodiment of this disclosure. The execution subject of this program compilation method is a compiler, which can be applied to the program compilation stage. This stage can be the process of compiling and testing on a terminal using compilation software, or it can be the actual compilation and application process, such as the process of writing the compiled assembly program into the chip after the program compilation is completed. This disclosure does not specifically limit this aspect.

[0039] Figure 1 This is a schematic diagram of a program compilation method provided in an embodiment of the present disclosure, as shown below. Figure 1 As shown, steps S11 to S14 are included, wherein:

[0040] S11. Obtain the source program and generate stack data.

[0041] Stack data includes multiple stack operation instructions, at least some of which include memory location identification information. Memory locations may include, for example, registers or memory.

[0042] The source program in this step can be user-written program code. For example, the source program can be a floating-point program.

[0043] After obtaining the source program, it is compiled. It should be noted that steps S11 through S14 are all part of the compilation process. The stack data generated in this step is the stack data containing multiple stack operation instructions generated during the compilation process. These stack operation instructions can be either the push instruction (store) or the pop instruction (load) from the stack.

[0044] For example, in large source programs, the push instruction `store` and the pop instruction `load` can sometimes have dozens of generic instructions, leading to a large code size. Figure 2The diagram shown illustrates a series of stack operation instructions in an exemplary program. Here, addi represents an addition instruction; sw represents a push instruction; dl represents a pop instruction; sp represents the starting address of the stack; "number" + (sp) represents the address information of the stack operation instruction stored in the stack space; fs represents a register; fs + "number" represents a specific register; and ra represents memory.

[0045] It should be noted that the stack data includes multiple stack operation instructions, including at least push and pop instructions, but not necessarily only push and pop instructions. Both push and pop instructions include memory location identifier information, such as fs + "number", ra, or ra + "number".

[0046] S12. Identify the source program and determine at least one merging condition.

[0047] In practice, the compiler's built-in program identification function is used to identify program instructions eligible for merging according to predefined strategy information, and at least one merging condition is determined. This merging condition can be a prerequisite for merging subsequent stack operation instructions.

[0048] For example, predefined strategy information could be used to identify certain calling functions and certain called functions. Based on this strategy information, certain calling functions and certain called functions in the source program are identified, and the identified calling and called functions are determined as a merging condition; that is, the merging condition includes at least one set of calling function information and called function information. Alternatively, predefined strategy information could also be user-defined push or pop instructions corresponding to certain memory locations that can be merged. Based on the identification strategy, the source program is identified, and the merging condition is determined to include the specified memory locations.

[0049] It should be noted that the calling function can be a caller function, and the called function can be a callee function. The caller function passes parameters to the callee function, and the callee function returns the result. During this process, the callee function needs to use the storage unit occupied by the caller function. Due to the calling relationship (i.e., the caller function calls the callee function), the data in the storage unit occupied by the caller function needs to be saved. The storage unit occupied by the caller function is the storage unit that the callee function needs to save.

[0050] S13. Based on each merging condition, determine the identification information of the corresponding target storage unit.

[0051] In practice, if the merging conditions include information about the calling function and the called function, the storage unit that the called function needs to save, i.e., the identification information of the target storage unit, can be determined based on the identifier information of the storage units occupied by each function in the source program, the calling function information, and the called function information. If the merging conditions include certain specified storage units, then those specified storage units are used as the target storage units, and the identification information of the target storage units is obtained.

[0052] S14. Based on the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data, determine a set of stack operation instructions in the stack data and merge them to generate assembly instructions.

[0053] In practice, based on the storage unit identification information of the stack operation instructions in the stack data, such as fs + "number" in the example above, a set of stack operation instructions with the same identification information as the target storage unit are selected from the stack data and merged according to a pre-set merging strategy. For example, when multiple stack operation instructions include push instructions, a set of push instructions can be merged to generate assembly instructions; as another example, when multiple stack operation instructions include pop instructions, a set of pop instructions can be merged to generate assembly instructions.

[0054] For the entire source program, in addition to generating stack operation instructions, various other instructions are also generated. After compilation, these other assembly instructions are obtained, which, together with the merged assembly instructions generated in this step, form the compiled assembly program. Here, the assembly program can be a RISC-V program. RISC-V is an open-source instruction set architecture (ISA) based on the Reduced Instruction Set Computer (RISC) principle.

[0055] Steps S11 to S14 above identify the source program through the compiler. Utilizing the compiler's built-in program identification function, at least one merging condition is determined according to predefined strategy information. This merging condition represents a prerequisite for merging subsequent stack operation instructions. The merging condition allows for the identification of the corresponding target storage units that need to be saved. Based on the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data, a set of stack operation instructions in the stack data can be identified and merged, thereby generating assembly instructions that shorten the program code length. Compiling a program using the program compilation method provided in this embodiment can shorten the program code length, save chip storage space, and the saved space can be used to integrate more functions, which is beneficial for product function expansion and increases the application range of small-size chips. Alternatively, when integrating the same functions, chips with lower storage capacity are better at improving data processing efficiency and product performance.

[0056] In some embodiments, for step S12, specifically, at least one calling function information in the source program can be determined by identifying the source program, and the corresponding called function information can be determined based on the calling function information; then, the merging conditions are determined based on the calling function information and the corresponding called function information.

[0057] In practice, the compiler's built-in program identification function can be used to identify the calling function and its corresponding called function in the source program, determining the calling function information and the corresponding called function information. The calling function information can be information that identifies the calling function, and the called function information can be information that identifies the called function, such as its name, identifier, or symbol. Then, the identified calling and called functions can be used as a merging condition; that is, the merging condition includes at least one set of calling and called function information.

[0058] In some embodiments, merging conditions are determined based on the calling function information and the corresponding called function information. Specifically, firstly, the first identifier information of the storage unit corresponding to the calling function information and the second identifier information of the storage unit corresponding to the called function information can be determined based on the identifier information of the storage unit occupied by each function in the source program in a pre-set manner. Then, the identifier information of the target storage unit is determined based on the first identifier information and the second identifier information, and the number of target storage units is determined.

[0059] Here, the identification information of the storage units occupied by each function in the source program is set in advance. For example, it can be the identification information of the storage units occupied by each function in the source program that is pre-stored in the compiler.

[0060] After determining the calling function information and the called function information, the first identifier information corresponding to the calling function information and the second identifier information corresponding to the called function information are determined from the identifier information of the storage units occupied by each function in the pre-set source program.

[0061] The first identifier information corresponding to the called function information is also the identifier information of the target storage unit occupied by the caller function indicated by the called function information. The second identifier information corresponding to the called function information is also the identifier information of the target storage unit occupied by the callee function indicated by the called function information.

[0062] Taking the `callee` function as an example, the storage unit that the `callee` function needs to save is the target storage unit, which is also the storage unit occupied by the `caller` function. At least part of the storage unit occupied by the `callee` function belongs to the storage unit that the `callee` function needs to save (that is, the storage unit occupied by the `caller` function). Therefore, based on the first identification information, the target storage unit is determined and counted from the storage units with the second identification information, and the identification information of the target storage unit and the number of target storage units are determined.

[0063] In practice, based on the first identification information and the second identification information, the storage unit with the same identification information is selected as the target storage unit, and the identification information of the target storage unit is determined.

[0064] In some embodiments, taking the merging conditions including calling function information and called function information as an example, assembly instructions are generated. Specifically, Figure 3 A detailed flowchart of a program compilation method provided in this disclosure embodiment is shown below. Figure 3 As shown, steps S21 to S25 are included, wherein:

[0065] S21. Obtain the source program and generate stack data.

[0066] The stack data includes multiple stack operation instructions, at least some of which include memory unit identification information. The specific execution process of this step can be found in step S11 above; repeated parts will not be described again.

[0067] S22. Identify the source program, determine at least one calling function information in the source program, and determine the corresponding called function information based on the calling function information.

[0068] In practice, the compiler's built-in program identification function can be used to identify the calling function (caller function) and its corresponding called function (callee function) in the source program, and to determine the calling function information and its corresponding called function information.

[0069] The calling function information can be information used to identify the calling function, and the called function information can be information used to identify the called function, such as name, identifier, symbol, etc.

[0070] S23. Based on the identification information of the storage units occupied by each function in the pre-set source program, determine the first identification information of the storage unit corresponding to the calling function information and the second identification information of the storage unit corresponding to the called function information.

[0071] The pre-defined identifiers of the storage units occupied by each function in the source program, such as the identifiers of the storage units occupied by each function in the source program that are pre-stored in the compiler.

[0072] After determining the calling function information and the called function information in S22, the first identifier information corresponding to the calling function information and the second identifier information corresponding to the called function information are determined from the identifier information of the storage units occupied by each function in the pre-set source program.

[0073] The first identifier information corresponding to the called function information is also the identifier information of the target storage unit occupied by the caller function indicated by the called function information. The second identifier information corresponding to the called function information is also the identifier information of the target storage unit occupied by the callee function indicated by the called function information.

[0074] S24. Based on the first identification information and the second identification information, determine the identification information of the target storage unit and determine the number of target storage units.

[0075] Taking the `callee` function as an example, the storage unit that the `callee` function needs to save is the target storage unit, which is also the storage unit occupied by the `caller` function. At least part of the storage unit occupied by the `callee` function belongs to the storage unit that the `callee` function needs to save (that is, the storage unit occupied by the `caller` function). Therefore, based on the first identification information, the target storage unit is determined and counted from the storage units with the second identification information, and the identification information of the target storage unit and the number of target storage units are determined.

[0076] In practice, based on the first identification information and the second identification information, the storage unit with the same identification information is selected as the target storage unit, and the identification information of the target storage unit is determined.

[0077] S25. When the number of target storage units meets the preset conditions, based on the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data, a set of stack operation instructions in the stack data is determined and merged to generate assembly instructions.

[0078] The preset condition here can be that the number of target storage units is greater than 1.

[0079] In practice, each stack operation instruction in the stack data can be identified. When the stack operation instruction is a push instruction, a set of push instructions with the same identification information as the target storage unit is selected from the stack data according to the storage unit identification information of the push instruction and merged to generate assembly instructions.

[0080] For example, given that the memory location identifiers of the push instruction `sw` are fs0~fs11 and `ra`, and the identifiers of the target memory location are fs0~fs5 and `ra`, a set of push instructions with the same identifiers as the target memory location is selected from the stack data. These are: `sw fs0,88(sp)`, `sw fs1,84(sp)`, `sw fs2,80(sp)`, `sw fs3,76(sp)`, `sw fs4,72(sp)`, `sw fs5,68(sp)`, and `sw ra,92(sp)`. These are then combined into a single assembly instruction `push.f`, denoted as `push.f{ra,fs0~fs5},-64`. Here, -64 represents the address information of the assembly instruction `push.f` stored in the stack space.

[0081] When a stack operation instruction is a pop instruction, based on the memory location identifier of the pop instruction, a set of pop instructions with the same identifier as the target memory location are selected from the stack data and merged to generate assembly instructions.

[0082] For example, given that the memory location identifiers of the pop instruction `dl` are fs0~fs11 and ra, and the identifiers of the target memory location are fs0~fs5 and ra, a set of pop instructions with the same identifiers as the target memory location is selected from the stack data. These are `dl fs0,88(sp)`, `dl fs1,84(sp)`, `dl fs2,80(sp)`, `dl fs3,76(sp)`, `dl fs4,72(sp)`, `dl fs5,68(sp)`, and `dl ra,92(sp)`, which are then combined into a single assembly instruction `pop.f`, denoted as `pop.f{ra,fs0~fs5},-64`. Here, -64 represents the address information of the assembly instruction `pop.f` stored in the stack space.

[0083] Continuing with the example above, after merging, the resulting assembly program is as follows: Figure 4 As shown, Figure 4 for Figure 2 A schematic diagram of the assembler after the stack operation instructions are merged.

[0084] Based on this, compiling a program using the program compilation method provided in the embodiments of this disclosure can shorten the program code length, save chip storage space, and improve the performance of electronic products.

[0085] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.

[0086] In some embodiments, for step S24, after determining the number of target memory units, it is determined whether the number of target memory units meets a preset condition. For example, whether the number of target memory units is greater than 1. If the number of target memory units does not meet the preset condition, assembly instructions are generated based on the stack data. That is, if the number of target memory units does not meet the preset condition, the original compilation flow is maintained, compilation continues, the stack pointer is adjusted, and assembly instructions are generated.

[0087] In other embodiments, taking the example of merging conditions including both the calling function information and the called function information, assembly instructions are generated. Specifically, Figure 5 A flowchart illustrating the program compilation process provided in this embodiment of the disclosure is shown below. Figure 5 As shown, steps S31 to S36 are included, wherein:

[0088] S31. Identify the called functions in the source program and determine the number of memory units that the called functions need to save.

[0089] Here, the compiler's built-in program identification function can be used to directly identify the called function. Based on the pre-stored identifier information specifying the memory units that the called function needs to save, the number of memory units that the called function needs to save is determined.

[0090] S32. Determine if the number of storage units is greater than 1. If yes, proceed to step S33; otherwise, proceed to step S36.

[0091] S33. Combine multiple push instructions in the stack operation instructions into one assembly instruction; combine multiple pop instructions in the stack operation instructions into one assembly instruction.

[0092] S34. Adjust the stack pointer.

[0093] Here, the stack pointer needs to be adjusted for both push and pop instructions.

[0094] S35. Generate the assembler.

[0095] S36. Maintain the original compilation process and continue with step S34.

[0096] This disclosure also provides a compiler corresponding to the program compilation method. Since the principle of the compiler in solving the problem is similar to the program compilation method described above, the implementation process of the compiler can be referred to the implementation of the program compilation method, and the repeated parts will not be described again.

[0097] Figure 6 A schematic diagram of a compiler provided for an embodiment of this disclosure, such as... Figure 6As shown, the compiler includes an acquisition module 41, a first information determination module 42, a second information determination module 43, and an instruction generation module 44. The acquisition module 41 is configured to acquire the source program and generate stack data; the stack data includes multiple stack operation instructions, at least some of which include storage unit identification information.

[0098] It should be noted that the acquisition module 41 in this embodiment is configured to execute step S11 in the above program compilation method.

[0099] The first information determination module 42 is configured to identify the source program and determine at least one merging condition.

[0100] It should be noted that the first information determination module 42 in this embodiment is configured to execute step S12 in the above-described program compilation method.

[0101] The second information determination module 43 is configured to determine the identification information of the corresponding target storage unit based on each merging condition.

[0102] It should be noted that the second information determination module 43 in this embodiment is configured to execute step S13 in the above-described program compilation method.

[0103] The instruction generation module 44 is configured to determine a set of stack operation instructions in the stack data and merge them based on the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data to obtain generated assembly instructions.

[0104] It should be noted that the instruction generation module 44 in this embodiment is configured to execute step S14 in the above-described program compilation method.

[0105] In some embodiments, the first information determination module 42 includes a function information determination unit and a condition determination unit; wherein, the function information determination unit is configured to identify the source program, determine at least one calling function information in the source program, and determine the corresponding called function information based on the calling function information; the condition determination unit is configured to determine the merging condition based on the calling function information and the corresponding called function information.

[0106] It should be noted that the first information determination module 42 in this embodiment is configured to execute the specific implementation process of step S12 in the above program compilation method, and see step S22.

[0107] In some embodiments, the condition determination unit is specifically configured to determine, based on the identification information of the storage units occupied by each function in the source program in a pre-set manner, the first identification information of the storage unit corresponding to the called function information and the second identification information of the storage unit corresponding to the called function information; and to determine the identification information of the target storage unit based on the first identification information and the second identification information, and to determine the number of target storage units.

[0108] It should be noted that the condition determination unit in this embodiment is configured to execute steps S23 and S24 in the above-described program compilation method.

[0109] The instruction generation module 44 is configured to, when the number of target memory units meets a preset condition, determine a set of stack operation instructions in the stack data based on the identification information of each target memory unit and the memory unit identification information of the stack operation instructions in the stack data, and merge them to generate assembly instructions.

[0110] It should be noted that the instruction generation module 44 in this embodiment is configured to execute step S25 in the above-described program compilation method.

[0111] In some embodiments, the second information determination module 43 is configured to select a storage unit with the same identification information as the target storage unit based on the first identification information and the second identification information, and determine the identification information of the target storage unit.

[0112] It should be noted that the second information determination module 43 in this embodiment is configured to execute the specific implementation steps of determining the identification information of the target storage unit in step S24 of the above-described program compilation method.

[0113] In some embodiments, the instruction generation module 44 is configured to identify each stack operation instruction in the stack data; when the stack operation instruction is a push instruction, it selects a set of push instructions that are identical to the target storage unit identifier information from the stack data according to the storage unit identifier information of the push instruction and merges them to generate assembly instructions; and when the stack operation instruction is a pop instruction, it selects a set of pop instructions that are identical to the target storage unit identifier information from the stack data according to the storage unit identifier information of the pop instruction and merges them to generate assembly instructions.

[0114] It should be noted that the instruction generation module 44 in this embodiment is configured to execute the specific step of generating assembly instructions in step S25 of the above-described program compilation method.

[0115] In some embodiments, the program compilation method includes, in addition to the above-mentioned functional modules, a judgment module and a hold compilation module; the judgment module is configured to determine whether the number of target memory units meets a preset condition; the hold compilation module is configured to generate assembly instructions based on stack data if the number of target memory units does not meet the preset condition.

[0116] In some embodiments, the source program is a floating-point program.

[0117] This disclosure also provides a computer device. Figure 7 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present disclosure, such as... Figure 7 As shown, this disclosure provides a computer device including: one or more processors 501, a memory 502, and one or more I / O interfaces 503. The memory 502 stores one or more programs, which, when executed by the one or more processors, cause the one or more processors to implement any of the program compilation methods described in the above embodiments; the one or more I / O interfaces 503 are connected between the processor and the memory, configured to enable information interaction between the processor and the memory.

[0118] Among them, processor 501 is a device with data processing capabilities, including but not limited to a central processing unit (CPU); memory 502 is a device with data storage capabilities, including but not limited to random access memory (RAM), more specifically such as read-only memory (ROM), electrically erasable programmable read-only memory (EPROM), and flash memory; I / O interface (read / write interface) 503 is connected between processor 501 and memory 502, enabling information exchange between processor 501 and memory 502, including but not limited to a data bus.

[0119] In some embodiments, the processor 501, memory 502, and I / O interface 503 are interconnected via bus 504, and thus connected to other components of the computing device.

[0120] According to embodiments of this disclosure, a computer non-transient readable storage medium is also provided. This computer non-transient readable storage medium stores a computer program, wherein when executed by a processor, the program implements the steps of any of the program compilation methods described in the above embodiments.

[0121] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a machine-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication component, and / or installed from a removable medium. When the computer program is executed by a central processing unit (CPU), it performs the functions defined above in the system of this disclosure.

[0122] It should be noted that the computer-readable non-transient readable medium disclosed herein may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. Computer-readable storage media may be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. The transmitted data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The computer-readable signal medium can also be any non-transient readable computer storage medium other than a computer-readable storage medium, which can transmit, propagate, or transfer a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the non-transient readable computer storage medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0123] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two adjacent blocks may actually represent substantially parallel execution, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0124] According to embodiments of this disclosure, an electronic product is also provided, which includes a microcontroller unit, such as a microcontroller unit (MCU). The MCU stores assembly instructions obtained using the program compilation method described in any of the above embodiments. The electronic product can be a small intelligent electronic product, such as a smartwatch, wearable device, virtual reality device, augmented reality device, in-vehicle display, mobile phone, etc. Other essential components of this electronic product are those that should be understood by those skilled in the art, and will not be described in detail here, nor should they be construed as limiting the present disclosure.

[0125] It is understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of this disclosure, and this disclosure is not limited thereto. For those skilled in the art, various modifications and improvements can be made without departing from the spirit and substance of this disclosure, and these modifications and improvements are also considered to be within the scope of protection of this disclosure.

Claims

1. A program compilation method, comprising: Obtain the source program and generate stack data; wherein, the stack data includes multiple stack operation instructions, and at least some of the stack operation instructions include storage unit identification information; Identify the source program and determine at least one merging condition; Based on each of the aforementioned merging conditions, the identification information of the corresponding target storage unit is determined; Based on the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data, a set of stack operation instructions in the stack data is determined and merged to generate assembly instructions; The process of identifying the source program and determining at least one merging condition includes: Identify the source program, determine at least one calling function information in the source program, and determine the corresponding called function information based on the calling function information; The merging conditions are determined based on the called function information and the corresponding called function information; The step of determining the identification information of the corresponding target storage unit based on each of the merging conditions includes: Based on the identification information of the storage units occupied by each function in the source program, the first identification information of the storage unit corresponding to the calling function information and the second identification information of the storage unit corresponding to the called function information are determined respectively. Based on the first identification information and the second identification information, the identification information of the target storage unit is determined, and the number of the target storage units is determined; The step of determining and merging a set of stack operation instructions in the stack data based on the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data to generate assembly instructions includes: When the number of target storage units meets the preset condition, a set of stack operation instructions in the stack data is determined and merged according to the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data to generate assembly instructions.

2. The program compilation method according to claim 1, wherein, Determining the identification information of the target storage unit based on the first identification information and the second identification information includes: Based on the first identification information and the second identification information, storage units with the same identification information are selected as the target storage units, and the identification information of the target storage units is determined.

3. The program compilation method according to claim 1, wherein, The step of determining and merging a set of stack operation instructions in the stack data based on the storage unit identification information of the stack operation instructions in the stack data according to the identification information of each target storage unit, and generating the assembly instructions, includes: Each stack operation instruction in the stack data is identified. When the stack operation instruction is a push instruction, based on the storage unit identifier information of the push instruction, a group of push instructions with the same identifier information as the target storage unit are selected from the stack data and merged to generate the assembly instruction; and, When the stack operation instruction is a pop instruction, according to the storage unit identification information of the pop instruction, a group of pop instructions with the same identification information as the target storage unit are selected from the stack data and merged to generate the assembly instruction.

4. The program compilation method according to claim 1, wherein, After determining the number of target storage units, the method further includes: Determine whether the number of the target storage units meets the preset condition; If the number of target storage units does not meet the preset condition, the assembly instructions are generated based on the stack data.

5. The program compilation method according to claim 1, wherein, The source program is a floating-point program.

6. A compiler, wherein, include: The acquisition module is configured to acquire the source program and generate stack data; wherein, the stack data includes multiple stack operation instructions, and at least some of the stack operation instructions include storage unit identification information; The first information determination module is configured to identify the source program and determine at least one merging condition. The second information determination module is configured to determine the identification information of the target storage unit corresponding to each of the merging conditions. The instruction generation module is configured to determine a set of stack operation instructions in the stack data and merge them based on the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data to obtain generated assembly instructions. The first information determining module is specifically configured to identify the source program, determine at least one calling function information in the source program, and determine the corresponding called function information based on the calling function information; and determine the merging condition based on the calling function information and the corresponding called function information. The second information determination module is specifically configured to determine, based on the identification information of the storage units occupied by each function in the source program, the first identification information of the storage unit corresponding to the called function information and the second identification information of the storage unit corresponding to the called function information; and to determine the identification information of the target storage unit based on the first identification information and the second identification information, and to determine the number of target storage units. The instruction generation module is specifically configured to, when the number of target storage units meets a preset condition, determine a set of stack operation instructions in the stack data and merge them to generate assembly instructions based on the identification information of each target storage unit and the storage unit identification information of the stack operation instructions in the stack data.

7. A computer device, wherein, include: The computer device includes a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the computer device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, the steps of the program compilation method as described in any one of claims 1 to 5 are performed.

8. A computer-readable non-transient storage medium, wherein, The computer program is stored on a non-transient readable storage medium, and the computer program is executed by a processor to perform the steps of the program compilation method as described in any one of claims 1 to 5.

9. An electronic product comprising a microcontroller unit; said microcontroller unit storing assembly instructions obtained using the program compilation method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Improving emulation and tracing performance using compiler-generated emulation optimization metadata

    CN113196243A

  • Code compiling method and device, equipment and medium

    CN115454437A