Code generation method and device
By receiving code generation instructions, abstracting the processing of pending services and generating description files, the problem of low code generation efficiency in software development is solved, and automated code generation is realized, and efficiency is improved.
Patent Information
- Application Number
- CN202110111200.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-27
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2041-01-27
AI Technical Summary
During software development, technicians need to spend a lot of time writing code manually, resulting in low code generation efficiency.
By receiving code generation instructions, abstracting the pending services, generating description files, and generating object codes based on the description files, realizing automated code generation.
Without the need for technicians to write code manually, the automatic code generation is realized, which significantly improves the efficiency of code generation.
Smart Images

Figure CN112835564B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software engineering technology, and in particular to a code generation method and device. Background Art
[0002] The development and operation of software cannot be separated from the writing of codes. In the process of software development, technicians are usually required to manually write different codes to realize various functions of the software.
[0003] However, when technical personnel manually write the code, it takes a lot of time, resulting in low efficiency of code generation. Summary of the invention
[0004] The embodiments of the present application provide a code generation method and device, which, when generating code, eliminates the need for manual writing by technical personnel, realizes automatic code generation, and effectively improves the efficiency of code generation.
[0005] In a first aspect, an embodiment of the present application provides a code generation method, the code generation method comprising:
[0006] A code generation instruction is received; wherein the code generation instruction includes an identifier of the service to be processed.
[0007] Abstract processing is performed on the to-be-processed service indicated by the identifier of the to-be-processed service to obtain a description file corresponding to the to-be-processed service; wherein the description file includes a plurality of abstract parameters and parameter values corresponding to each abstract parameter.
[0008] According to the multiple abstraction parameters and the parameter values corresponding to the abstraction parameters, a target code corresponding to the service to be processed is generated.
[0009] Output the target code corresponding to the business to be processed.
[0010] In a possible implementation, the step of generating a code corresponding to the service to be processed according to the multiple abstraction parameters and parameter values corresponding to the abstraction parameters includes:
[0011] According to the multiple abstract parameters, a code generation rule corresponding to the business to be processed is generated.
[0012] Generate a code generation tool corresponding to the code generation rule according to the code generation rule;
[0013] Generate target code corresponding to the service to be processed according to the description file and the code generation tool.
[0014] In a possible implementation, the generating the target code corresponding to the service to be processed according to the description file and the code generation tool includes:
[0015] The description file is imported into the code generation tool to generate the target code corresponding to the business to be processed.
[0016] In a possible implementation, generating a code generation tool corresponding to the code generation rule according to the code generation rule includes:
[0017] According to the code generation rule, the architecture of the target code corresponding to the business to be processed is determined.
[0018] A code generation tool corresponding to the code generation rule is generated according to the architecture of the target code corresponding to the business to be processed.
[0019] In a possible implementation, the description file is a table, and generating the code generation rules corresponding to the to-be-processed business according to the multiple abstraction parameters includes:
[0020] The abstraction parameters at the header position of the table among the multiple abstraction parameters are determined as multiple target abstraction parameters.
[0021] According to the multiple target abstraction parameters, a code generation rule corresponding to the business to be processed is generated.
[0022] In a possible implementation, the method further includes:
[0023] Determine the type of the business to be processed, the function type of the target code corresponding to the business to be processed, the file type of the target code, and the implementation method of the target code.
[0024] According to the type of the business to be processed, the function type of the target code, the file type of the target code and the operation rule of the target code, the code generation rule is updated to obtain a new code generation rule.
[0025] In a possible implementation manner, the abstracting the service to be processed indicated by the identifier of the service to be processed includes:
[0026] The pending business is parsed to obtain state information, condition information, and execution action information corresponding to the pending business.
[0027] Based on the state information, the condition information and the execution action information, the business to be processed is abstracted.
[0028] In a second aspect, an embodiment of the present application provides a code generation device, the code generation device comprising:
[0029] The receiving unit is used to receive a code generation instruction; wherein the code generation instruction includes an identifier of the service to be processed.
[0030] The processing unit is used to perform abstract processing on the pending business indicated by the identifier of the pending business to obtain a description file corresponding to the pending business; wherein the description file includes multiple abstract parameters and parameter values corresponding to each abstract parameter.
[0031] A generating unit is used to generate a target code corresponding to the service to be processed according to the multiple abstract parameters and parameter values corresponding to the abstract parameters.
[0032] The output unit is used to output the target code corresponding to the business to be processed.
[0033] In a possible implementation, the generation unit is specifically used to generate code generation rules corresponding to the business to be processed according to the multiple abstract parameters; generate a code generation tool corresponding to the code generation rules according to the code generation rules; and generate a target code corresponding to the business to be processed according to the description file and the code generation tool.
[0034] In a possible implementation, the generating unit is specifically configured to import the description file into the code generating tool to generate a target code corresponding to the service to be processed.
[0035] In a possible implementation, the generation unit is specifically used to determine the architecture of the target code corresponding to the business to be processed according to the code generation rule; and generate a code generation tool corresponding to the code generation rule according to the architecture of the target code corresponding to the business to be processed.
[0036] In a possible implementation, the generation unit is specifically used to determine the abstraction parameters at the header position of the table among the multiple abstraction parameters as multiple target abstraction parameters; and generate code generation rules corresponding to the business to be processed based on the multiple target abstraction parameters.
[0037] In one possible implementation, the generation unit is specifically used to determine the type of the business to be processed, the function type of the target code corresponding to the business to be processed, the file type of the target code, and the implementation method of the target code; according to the type of the business to be processed, the function type of the target code, the file type of the target code, and the operation rules of the target code, the code generation rules are updated to obtain new code generation rules.
[0038] In a possible implementation, the processing unit is specifically used to parse the business to be processed to obtain status information, condition information and execution action information corresponding to the business to be processed; based on the status information, the condition information and the execution action information, the business to be processed is abstracted.
[0039] In a third aspect, an embodiment of the present application further provides a code generation device, which may include a memory and a processor; wherein:
[0040] The memory is used to store computer programs.
[0041] The processor is used to read the computer program stored in the memory and execute the code generation method described in any possible implementation manner of the first aspect according to the computer program in the memory.
[0042] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the code generation method described in any possible implementation of the first aspect above is implemented.
[0043] In a fifth aspect, an embodiment of the present application further provides a computer program product, including a computer program, which, when executed by a processor, implements the code generation method described in any possible implementation of the first aspect above.
[0044] It can be seen that the code generation method and device provided by the embodiment of the present application, when generating code, first receive a code generation instruction; wherein the code generation instruction includes an identifier of the business to be processed; abstract the business to be processed indicated by the identifier of the business to be processed to obtain a description file corresponding to the business to be processed; wherein the description file includes multiple abstraction parameters and parameter values corresponding to each abstraction parameter; and according to the multiple abstraction parameters and the parameter values corresponding to each abstraction parameter, generate the target code corresponding to the business to be processed; and output the target code corresponding to the business to be processed. It can be seen that when generating code, there is no need for technicians to manually write it, and automatic code generation is achieved, thereby effectively improving the efficiency of code generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0046] Figure 1 A flowchart of a code generation method provided in an embodiment of the present application;
[0047] Figure 2 A schematic diagram of a process for generating a target code corresponding to a business to be processed provided in an embodiment of the present application;
[0048] Figure 3 A flowchart of another method for generating code provided in an embodiment of the present application;
[0049] Figure 4 A schematic diagram of a code operation flow provided in an embodiment of the present application;
[0050] Figure 5 A schematic diagram of the structure of a code generation device provided in an embodiment of the present application;
[0051] Figure 6 A schematic diagram of the structure of another code generation device provided in an embodiment of the present application.
[0052] The above drawings show clear embodiments of the present disclosure, which will be described in more detail below. These drawings and text descriptions are not intended to limit the scope of the present disclosure in any way, but to illustrate the concepts of the present disclosure to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0053] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0054] In the embodiments of the present application, "at least one" means one or more, and "more" means two or more. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. In the text description of the present application, the character " / " generally indicates that the associated objects before and after are in an "or" relationship.
[0055] The technical solution provided in the embodiment of the present application can be applied to the code generation scenario. The realization of software functions is inseparable from the code. For example, due to different manufacturers and models, electric vehicles have different control methods for contactors. They can be controlled by the battery management system (Battery Management System, referred to as BMS), or by other electronic control devices of the vehicle. For electric vehicles controlled by BMS software, due to the different technical solutions that need to be adopted by the whole vehicle, software developers often need to write different codes to realize different overall scheduling and control timing of the BMS software, so as to achieve the purpose of adapting to the different needs of the whole vehicle.
[0056] In the prior art, technicians determine the functions that the software to be developed needs to implement based on the received instructions, and manually write corresponding codes according to the functions that the software to be developed needs to implement, so that the software can implement various functions. However, manual code writing takes a lot of time, and in the process of code writing, writing errors may occur, which reduces the efficiency of code generation.
[0057] In order to solve the problem of low efficiency in code generation, automatic code generation can be considered. The embodiment of the present application provides a code generation method, which first receives a code generation instruction; wherein the code generation instruction includes an identifier of a pending business; abstracts the pending business indicated by the identifier of the pending business to obtain a description file corresponding to the pending business; wherein the description file includes multiple abstraction parameters and parameter values corresponding to each abstraction parameter; and generates a target code corresponding to the pending business according to the multiple abstraction parameters and the parameter values corresponding to each abstraction parameter; and outputs the target code corresponding to the pending business.
[0058] It can be seen that in the embodiment of the present application, when generating code, a code generation instruction is first received; wherein the code generation instruction includes the identifier of the business to be processed; the business to be processed indicated by the identifier of the business to be processed is abstracted to obtain a description file corresponding to the business to be processed; wherein the description file includes multiple abstraction parameters and parameter values corresponding to each abstraction parameter; and according to the multiple abstraction parameters and the parameter values corresponding to each abstraction parameter, a target code corresponding to the business to be processed is generated. It can be seen that when generating code, there is no need for technicians to manually write it, and automatic code generation is achieved, thereby effectively improving the efficiency of code generation.
[0059] The code generation method provided by the present application will be described in detail below through specific embodiments. It is understandable that the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0060] Figure 1 The following is a flowchart of a code generation method provided by an embodiment of the present application. The code generation method can be executed by software and / or hardware devices. For example, the hardware device can be a code generation device, and the code generation device can be a terminal or a processing chip in the terminal. For example, see Figure 1 As shown, the code generation method may include:
[0061] S101, receiving a code generation instruction.
[0062] The code generation instruction includes an identifier of the business to be processed.
[0063] For example, the code generation instruction has multiple forms, which can be in text form or in characteristic symbols, and is mainly used to identify the pending business. The embodiment of the present application does not impose any restrictions on the form of the code generation instruction and the form of the pending business identification.
[0064] S102: Perform abstract processing on the pending business indicated by the identifier of the pending business to obtain a description file corresponding to the pending business.
[0065] For example, when abstracting the pending business indicated by its identifier, the pending business can be parsed first to obtain the status information, condition information and execution action information corresponding to the pending business; and based on the status information, condition information and execution action information, the pending business can be abstracted.
[0066] Among them, the state information may include multiple different states, the condition information may include multiple different conditions, the execution action information may include multiple different execution actions, and the state information corresponding to the pending business may include multiple sub-states. For example, the state information may include 3 sub-states, namely, the initialization sub-state, the running sub-state, and the exit sub-state. The condition information may be the jump information between the different states, and the execution action information may be the action to be performed for each sub-state. It is understandable that the state information, condition information, and execution action information can all be represented by special characters, and the embodiments of the present application do not impose any restrictions on the specific representation method.
[0067] In the embodiment of the present application, by parsing the business to be processed into status information, condition information and execution actions and performing abstract processing, it is possible to convert the business to be processed into a language that can be recognized by a computer, which can effectively improve the success rate of code generation.
[0068] When the pending business indicated by the identifier of the pending business is abstracted, a description file corresponding to the pending business can be obtained, and the description file includes multiple abstraction parameters and parameter values corresponding to each abstraction parameter. Among them, the abstraction parameters can be the state information, condition information, execution action information obtained by parsing the pending business, and the corresponding specific information and quantity, and the parameters corresponding to the abstraction parameters can be the specific numerical values corresponding to the state information, condition information, and execution action information, respectively. The embodiment of the present application does not impose any limitation on the specific content of the abstraction parameters and the parameter values corresponding to each abstraction parameter. Among them, the description file can be in a variety of types. For example, the description file can be an EXCEL table. The embodiment of the present application does not impose any limitation on the specific type of the description file.
[0069] After abstracting the pending business indicated by the identifier of the pending business and obtaining the description file corresponding to the pending business, the target code corresponding to the pending business can be generated according to the multiple abstraction parameters and the parameter values corresponding to the abstraction parameters, that is, the following S103 is executed:
[0070] S103: Generate a target code corresponding to the service to be processed according to a plurality of abstract parameters and parameter values corresponding to each abstract parameter.
[0071] When generating the target code corresponding to the business to be processed based on multiple abstract parameters and the parameter values corresponding to each parameter, the abstract parameters and the parameter values corresponding to each abstract parameter can be directly obtained, or the abstract parameters and the parameter values corresponding to each abstract parameter in the description can be read by obtaining the description file. Specifically, the embodiments of the present application do not impose any restrictions.
[0072] After obtaining a plurality of abstract parameters and parameter values corresponding to the abstract parameters respectively, a target code corresponding to the service to be processed can be generated according to the plurality of abstract parameters and parameter values corresponding to the abstract parameters, and the target code can be output.
[0073] S104: Output the target code corresponding to the business to be processed.
[0074] For example, when outputting the target code corresponding to the business to be processed, if the file storage type of the target code is set, the target code corresponding to the business to be processed is stored in a file of the corresponding file storage type, and the file containing the target code is output; if the file storage type of the target code is not set, the target code corresponding to the business to be processed is stored in a file of a default file storage type, and the file of the default file storage type is output, wherein the default file storage type is the file storage type set by the user last time, and can be set according to actual needs.
[0075] It can be seen that the code generation method provided in the embodiment of the present application, when generating code, first receives a code generation instruction; wherein the code generation instruction includes the identifier of the business to be processed; abstracts the business to be processed indicated by the identifier of the business to be processed to obtain a description file corresponding to the business to be processed; wherein the description file includes multiple abstraction parameters and parameter values corresponding to each abstraction parameter; and generates the target code corresponding to the business to be processed according to the multiple abstraction parameters and the parameter values corresponding to each abstraction parameter. It can be seen that when generating code, there is no need for technicians to manually write it, and automatic code generation is achieved, thereby effectively improving the efficiency of code generation.
[0076] Based on the above Figure 1 In order to facilitate understanding of the embodiment of the present application, how to generate the target code corresponding to the service to be processed according to multiple abstract parameters and the parameter values corresponding to each abstract parameter, the following will be described. Figure 2 The illustrated embodiment describes in detail how to generate target code corresponding to the service to be processed based on multiple abstract parameters and parameter values corresponding to each abstract parameter in the embodiment of the present application.
[0077] Figure 2 A flow chart of generating a target code corresponding to a pending service provided in an embodiment of the present application. The method of generating a target code corresponding to a pending service can also be executed by software and / or hardware devices. For example, see Figure 2 As shown, the method for generating the target code corresponding to the service to be processed may include:
[0078] S201. Generate code generation rules corresponding to the business to be processed according to multiple abstract parameters.
[0079] For example, when generating code generation rules corresponding to the business to be processed based on multiple abstraction parameters, the multiple abstraction parameters can be processed first to determine the abstraction parameters required for the code generation rules, that is, the target abstraction parameters. For example, if the description file is a table, the abstraction parameters at the header position of the table among the multiple abstraction parameters are determined as the target abstraction parameters; and the code generation rules corresponding to the business to be processed are generated based on the multiple target abstraction parameters. For example, if the description file is a text, the multiple target abstraction parameters can be obtained by reading the initial position of the text, and can be set according to actual needs.
[0080] According to the above embodiment, when the abstraction parameter is the specific information and quantity of the state information, condition information and execution action information contained in the code corresponding to the business to be processed, the corresponding code generation rule is the quantity information of the state information, condition information and execution action information. For example, if the abstraction parameter is 2 state information, 4 condition information and 5 execution action information, the corresponding code generation rule is that the generated code needs to include 2 states, 4 jump conditions and 5 execution actions.
[0081] In the embodiment of the present application, by determining multiple target abstraction parameters and generating corresponding code generation rules, it is possible to avoid the influence of other abstraction parameters except the target abstraction parameters on the target code. The generation rules can be used to assist in generating the corresponding target code.
[0082] In addition, in order to further improve the generation rules, it is also possible to determine the type of business to be processed, the function type of the target code corresponding to the business to be processed, the file type of the target code, and the implementation method of the target code; and according to the type of business to be processed, the function type of the target code, the file type of the target code, and the operation rules of the target code, update the code generation rules to obtain new code generation rules, which can further improve the integrity of the generation rules and better assist in generating the corresponding target code.
[0083] Among them, the type of the business to be processed, the function type of the target code corresponding to the business to be processed, the file type of the target code, and the implementation method of the target code can be determined according to the specific business. For example, the function type of the target code corresponding to the business to be processed can be in the form of void xxx_step (void), the file type of the target code can be in the form of xxx.c and xxx.h, and the implementation method of the target code can be in the form of switch...case..., and the embodiment of the present application does not make any limitation on this.
[0084] It can be seen that in the embodiment of the present application, by generating new code generation rules, its purpose is to: make the style of generated target code unified, avoid the problems of inconsistent code style and logical errors caused by multiple technicians dividing the work of writing code, and improve the efficiency of code generation.
[0085] S202: Generate a code generation tool corresponding to the code generation rule according to the code generation rule.
[0086] For example, when a code generation tool corresponding to a code generation rule is generated according to a code generation rule, the architecture of the target code corresponding to the business to be processed can be determined according to the code generation rule; and the code generation tool corresponding to the code generation rule can be generated according to the architecture of the target code corresponding to the business to be processed. The architecture of the target code corresponding to the business to be processed may include a repeated part of the generated target code, or may include other parts, and the embodiments of the present application do not impose any limitation on this.
[0087] Furthermore, when generating a code generation tool corresponding to the code generation rule according to the architecture of the target code corresponding to the business to be processed, the corresponding code generation tool can be written according to the architecture of the target code, or the corresponding code generation tool can be generated by other means. The embodiments of the present application do not impose any limitations on this.
[0088] In an embodiment of the present application, the architecture of the target code corresponding to the business to be processed is determined by code generation rules, and a corresponding code generation tool is generated, so that the corresponding target code can be generated by the code generation tool, thereby improving the accuracy and efficiency of the generated code.
[0089] S203: Generate target code corresponding to the service to be processed according to the description file and the code generation tool.
[0090] For example, when generating the target code corresponding to the service to be processed according to the description file and the code generation tool, the description file can be imported into the code generation tool to generate the target code corresponding to the service to be processed.
[0091] Among them, the code generation tool can first determine the multiple target abstraction parameter values required by the target code according to the parameter values corresponding to the multiple abstraction parameters in the description file, and piece together the multiple target abstraction parameter values with the architecture of the target code corresponding to the business to be processed, or add the multiple target abstraction parameter values to the architecture of the target code, so as to generate the target code corresponding to the business to be processed. The specific generation method can be set according to the actual situation. By importing the description file into the code generation tool, the code tool generates the target code corresponding to the business to be processed according to the parameter values corresponding to the abstraction parameters in the description file, avoiding the problem of errors in manually written code and improving the efficiency of code generation.
[0092] To summarize, the code generation method provided in the embodiment of the present application, when generating the target code corresponding to the business to be processed according to multiple abstract parameters and the parameter values corresponding to each abstract parameter, first generates the code generation rules corresponding to the business to be processed according to the multiple abstract parameters; and generates the corresponding code generation tool according to the code generation rules; and generates the target code corresponding to the business to be processed according to the description file and the code generation tool, which can avoid the time-consuming and high error rate problems caused by manual code writing, and improve the efficiency of code generation.
[0093] In order to facilitate understanding of the code generation method provided in the embodiment of the present application, the following will take the specific application of the method in practice as an example to describe in detail the technical solution provided in the embodiment of the present application. Figure 3 As shown, Figure 3 A flowchart of another method for generating code provided in an embodiment of the present application.
[0094] A scheduler may be used in the code generation to ensure that the division of labor among various software and / or hardware devices in the code generation process is clear, thereby improving the efficiency of code generation. Figure 3 The scheduling definition in , that is, when receiving the code generation instruction, the type of the pending business and the identifier of the pending business can be determined, and the state information, condition information and execution action information corresponding to the pending business can be determined by parsing the pending business. Assume that the state corresponding to the pending business is represented by S, the condition is represented by C, and the execution action is represented by A.
[0095] For example, state S may include initialization state S0 and multiple running states S1 to Sn, condition C may be a state jump condition between each state S, Cx_y represents the jump condition from state Sx to state Sy, for example, C1_2 represents the jump condition from state S1 to state S2. Each state S includes three sub-states, namely initialization sub-state en, running sub-state du, and exit sub-state ex. The execution action A is the action performed for each sub-state, wherein the action of executing initialization sub-state en may be Aen_1 to Aen_n, indicating that the actions of initialization sub-state 1 to sub-state n are executed in sequence; the action of executing running sub-state du may be Adu_1 to Adu_n, indicating that the actions of running sub-state 1 to sub-state n are executed in sequence; the action of executing exit sub-state ex may be Aex_1 to Aex_n, indicating that the actions of exiting sub-state 1 to sub-state n are executed in sequence.
[0096] It can be understood that the above state jump conditions are the corresponding conditions in the actual code, and the execution action is the function interface provided by the basic software layer. The relationship between the state, condition and execution action can be seen in Figure 4 As shown, Figure 4 A schematic diagram of a code execution flow provided in an embodiment of the present application.
[0097] according to Figure 4 As shown, during the code running process, the actions of the initialization substate en in the initialization state S0 are first executed in sequence, that is, the actions of the initialization substate 1 to the initialization substate n are executed in sequence. After completing the initialization of the substates, the actions of the running substate du in the initialization state S0 are executed in sequence, that is, the actions of the running substate 1 to the running substate n are executed in sequence, and the actions of running n substates in sequence are performed in a loop until the jump condition C=C0_x is received. After receiving the jump condition, the actions of the running substate in the initialization state S0 are stopped in sequence, and the actions of the exit substate ex in the initialization state S0 are executed in sequence, that is, the actions of the exit substate 1 to the exit substate n are executed in sequence. Among them, the jump condition can be to jump from the initialization state S0 to the state S1, or it can be to jump from the initialization state S0 to the state S1. The embodiment of the present application does not impose any limitation on the specific jump condition.
[0098] After executing the exit actions of multiple sub-states in the initialization state S0, the state jumps according to the specific jump condition. If the jump condition is C=C0_1, the initialization state S0 jumps to state S1, and runs according to the code running mode in state S1, and according to the received jump condition C=C1_2, jumps from state S1 to state S2, and runs according to the code running mode in state S2. If the jump condition is C=C0_2, the initialization state S0 jumps to state S2, and runs according to the code running mode in state S2, and according to the received jump condition C=C2_1, jumps from state S2 to state S1, and runs according to the code running mode in state S1. According to Figure 3 As shown, the code operation mode in state S1 and state S2 is the same as the code operation mode in the above-mentioned initialization state S0, and the embodiment of the present application will not be repeated here.
[0099] in, Figure 4 The jump conditions shown can be jumped simultaneously or in a certain time sequence, and the embodiments of the present application do not impose any limitations on this.
[0100] according to Figure 3 As shown, after the scheduling definition is performed, a scheduling description file can be established, that is, according to the above analysis results of the pending business, a description file corresponding to the pending business is obtained. Among them, the scheduling description file can be shown in the following Table 1. Table 1 is a scheduler state table, which includes the number of states of generating code, initialization state actions and their corresponding numbers, and execution state actions and their corresponding numbers.
[0101] Table 1
[0102]
[0103] Table 1 includes multiple abstract parameters and parameter values corresponding to each abstract parameter, wherein the table header in Table 1 is divided into multiple abstract parameters, namely, state identifier, state number, initialization action identifier, initialization action 1, initialization action 2, execution action identifier, execution action 1, and execution action 2. Each parameter value corresponding to the abstract parameter is the value of the column where each abstract parameter is located, for example, the parameter value corresponding to the state number is 0, 1, and 2.
[0104] In addition, the scheduling description file also includes a scheduler state migration table, as shown in Table 2 below.
[0105] Table 2
[0106]
[0107] Table 2 also includes multiple abstract parameters and parameter values corresponding to each abstract parameter, wherein the abstract parameter is the header part of Table 2, that is, the abstract parameters are state jump identifier, current state, target state, jump condition, exit state action identifier, exit state action 1, and exit state action 2. The parameter value is the value of each abstract column, for example, the parameter value corresponding to the abstract parameter jump condition is C==C0_1, C==C0_2, C==C1_2, C==C1_0, C==C2_0, and C==C2_1.
[0108] Determine the target abstraction parameters according to Table 1 and Table 2, where the target abstraction parameters are state number, initialization action 1, initialization action 2, execution action 1, execution action 2, current state, target state, jump condition, exit state action 1, and exit state action 2, and generate corresponding code generation rules according to the target abstraction parameters.
[0109] For example, to further improve the generated code generation rules, in addition to the abstraction parameters shown in Table 1 and Table 2 and the parameter values corresponding to each abstraction parameter, the parameters of the scheduler need to be set. The parameters of the scheduler can be set through the parameters in the following Table 3, which is a scheduler design table.
[0110] Table 3
[0111] Scheduler Name Number of states Status variable name APPSc 3 APPScStep
[0112] According to the parameters in Table 3, the code generation method of the embodiment of the present application can be implemented by a state machine, and the number of state machines is consistent with the number of states in Table 3. The state jumps, state jump conditions, and execution actions of each state of the state machine during operation are consistent with the parameter values corresponding to the abstract parameters in Tables 1 and 2. Among them, according to the state variable names in Table 3, the state machine in the embodiment of the present application is in the form of switch...case...
[0113] It is understandable that the generated code generation rules can be updated and improved according to the parameters of the scheduler shown in Table 3 to obtain new code generation rules. For example, when updating the code generation rules, other parameters of the generated code can also be set. For example, the generated target code contains a .c and a .h file, and the generated file names are xxx.c and xxx.h, respectively, where xxx is the scheduling name; and type.h and util.h header file references need to be added to xxx.h so that the data type corresponding to the embedded chip is consistent with the system definition; the target code can be an independent function, and the function name can be in the form of void xxx_step (void), and the function needs to be marked in xxx.h. The embodiment of the present application only updates the generated code generation rules using the above parameters as an example, but it does not mean that the embodiment of the present application is limited to this.
[0114] according to Figure 3 As shown, after generating new code generation rules, write the corresponding code generation tool according to the new code generation rules, and import the scheduling description files shown in Tables 1 and 2 into the code generation tool. The code generation tool can automatically generate code by reading the parameter values corresponding to the target abstraction parameters, that is, generate the target code corresponding to the business to be processed.
[0115] The target code generated according to the above method is:
[0116]
[0117]
[0118]
[0119]
[0120]
[0121]
[0122] Figure 5 A schematic diagram of the structure of a code generating device 50 provided in an embodiment of the present application, for example, see Figure 5As shown, the code generating device 50 may include:
[0123] The receiving unit 501 is used to receive a code generation instruction; wherein the code generation instruction includes an identifier of a service to be processed.
[0124] The processing unit 502 is used to perform abstract processing on the service to be processed indicated by the identifier of the service to be processed to obtain a description file corresponding to the service to be processed; wherein the description file includes multiple abstract parameters and parameter values corresponding to each abstract parameter.
[0125] The generating unit 503 is used to generate a target code corresponding to the service to be processed according to a plurality of abstract parameters and parameter values corresponding to each abstract parameter.
[0126] The output unit 504 is used to output the target code corresponding to the service to be processed.
[0127] Optionally, the generation unit 503 is specifically used to generate code generation rules corresponding to the business to be processed according to multiple abstract parameters; generate a code generation tool corresponding to the code generation rules according to the code generation rules; and generate a target code corresponding to the business to be processed according to the description file and the code generation tool.
[0128] Optionally, the generating unit 503 is specifically configured to import the description file into a code generating tool to generate a target code corresponding to the service to be processed.
[0129] Optionally, the generation unit 503 is specifically used to determine the architecture of the target code corresponding to the business to be processed according to the code generation rules; and generate a code generation tool corresponding to the code generation rules according to the architecture of the target code corresponding to the business to be processed.
[0130] Optionally, the generating unit 503 is specifically configured to determine the abstraction parameters at the header position of the table among the multiple abstraction parameters as multiple target abstraction parameters; and generate code generation rules corresponding to the business to be processed according to the multiple target abstraction parameters.
[0131] Optionally, the generation unit 503 is specifically used to determine the type of business to be processed, the function type of the target code corresponding to the business to be processed, the file type of the target code and the implementation method of the target code; according to the type of business to be processed, the function type of the target code, the file type of the target code and the operation rules of the target code, the code generation rules are updated to obtain new code generation rules.
[0132] Optionally, the processing unit 502 is specifically used to parse the business to be processed to obtain state information, condition information and execution action information corresponding to the business to be processed; based on the state information, condition information and execution action information, perform abstract processing on the business to be processed.
[0133] The code generation device 50 provided in the embodiment of the present application can execute the technical solution of the code generation method in any of the above-mentioned embodiments. Its implementation principle and beneficial effects are similar to the implementation principle and beneficial effects of the code generation method. Please refer to the implementation principle and beneficial effects of the code generation method, and no further details will be given here.
[0134] Figure 6 A schematic diagram of the structure of another code generating device 60 provided in an embodiment of the present application, for example, see Figure 6 As shown, the code generating device 60 may include a processor 601 and a memory 602;
[0135] in,
[0136] The memory 602 is used to store computer programs.
[0137] The processor 601 is used to read the computer program stored in the memory 602 and execute the technical solution of the code generation method in any of the above embodiments according to the computer program in the memory 602.
[0138] Optionally, the memory 602 may be independent or integrated with the processor 601. When the memory 602 is a device independent of the processor 601, the code generating device 60 may further include: a bus for connecting the memory 602 and the processor 601.
[0139] Optionally, this embodiment further includes: a communication interface, which can be connected to the processor 601 through a bus. The processor 601 can control the communication interface to implement the receiving and sending functions of the above-mentioned code generating device 60.
[0140] The code generation device 60 shown in the embodiment of the present application can execute the technical solution of the code generation method in any of the above-mentioned embodiments. Its implementation principle and beneficial effects are similar to the implementation principle and beneficial effects of the code generation method. Please refer to the implementation principle and beneficial effects of the code generation method, and no further details will be given here.
[0141] An embodiment of the present application also provides a computer-readable storage medium, which stores computer-executable instructions. When a processor executes the computer-executable instructions, the technical solution of the code generation method in any of the above embodiments is implemented. The implementation principle and beneficial effects are similar to those of the code generation method. Please refer to the implementation principle and beneficial effects of the code generation method, which will not be repeated here.
[0142] An embodiment of the present application also provides a computer program product, including a computer program. When the computer program is executed by a processor, the technical solution of the code generation method in any of the above embodiments is implemented. The implementation principle and beneficial effects of the computer program are similar to those of the code generation method. Please refer to the implementation principle and beneficial effects of the code generation method, which will not be repeated here.
[0143] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0144] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, each functional unit in each embodiment of the present application may be integrated into a processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0145] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to perform some steps of the methods of various embodiments of the present application.
[0146] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0147] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.
[0148] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0149] The computer-readable storage medium may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The storage medium may be any available medium that can be accessed by a general or special purpose computer.
[0150] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A code generation method, characterized in that: include: Receiving a code generation instruction; wherein the code generation instruction includes an identifier of the service to be processed; Parsing the pending business to obtain state information, condition information and execution action information corresponding to the pending business; the state information includes multiple sub-states, which are initialization sub-state, running sub-state and exit sub-state; the condition information is jump information between different states; Based on the state information, the condition information and the execution action information, the service to be processed is abstracted to obtain a description file corresponding to the service to be processed; wherein the description file includes a plurality of abstraction parameters and parameter values corresponding to each abstraction parameter; the abstraction parameters are the information and quantity of the state information, condition information and execution action information contained in the code corresponding to the service to be processed; Generate code generation rules corresponding to the business to be processed according to the multiple abstract parameters, and determine the architecture of the target code corresponding to the business to be processed according to the code generation rules; generate a code generation tool corresponding to the code generation rules according to the architecture of the target code corresponding to the business to be processed; import the description file into the code generation tool, so that the code generation tool generates the target code corresponding to the business to be processed according to the parameter values corresponding to the abstract parameters in the description file; Output the target code corresponding to the business to be processed.
2. The method according to claim 1, characterized in that The generating the target code corresponding to the service to be processed according to the description file and the code generation tool comprises: The description file is imported into the code generation tool to generate the target code corresponding to the business to be processed.
3. The method according to claim 1, characterized in that The description file is a table, and the code generation rules corresponding to the service to be processed are generated according to the multiple abstract parameters, including: Determine the abstraction parameters at the header position of the table among the multiple abstraction parameters as multiple target abstraction parameters; According to the multiple target abstraction parameters, a code generation rule corresponding to the business to be processed is generated.
4. The method according to claim 3, characterized in that The method further comprises: Determine the type of the business to be processed, the function type of the target code corresponding to the business to be processed, the file type of the target code, and the implementation method of the target code; According to the type of the business to be processed, the function type of the target code, the file type of the target code and the operation rule of the target code, the code generation rule is updated to obtain a new code generation rule.
5. A code generating device, characterized in that: include: A receiving unit, configured to receive a code generation instruction; wherein the code generation instruction includes an identifier of a service to be processed; A processing unit is used to parse the business to be processed to obtain state information, condition information and execution action information corresponding to the business to be processed; the state information includes multiple sub-states, and the multiple sub-states are initialization sub-state, operation sub-state and exit sub-state; the condition information is the jump information between different states; the processing unit is also used to perform abstract processing on the business to be processed based on the state information, the condition information and the execution action information to obtain a description file corresponding to the business to be processed; wherein the description file includes multiple abstract parameters and parameter values corresponding to each abstract parameter; the abstract parameter is the information and quantity of state information, condition information and execution action information contained in the code corresponding to the business to be processed; A generating unit, configured to generate a code generation rule corresponding to the business to be processed according to the multiple abstract parameters, determine the architecture of the target code corresponding to the business to be processed according to the code generation rule; generate a code generation tool corresponding to the code generation rule according to the architecture of the target code corresponding to the business to be processed; import the description file into the code generation tool, so that the code generation tool generates the target code corresponding to the business to be processed according to the parameter values corresponding to the abstract parameters in the description file; The output unit is used to output the target code corresponding to the business to be processed.
6. A code generating device, characterized in that: comprising a memory and a processor; wherein, The memory is used to store computer programs; The processor is used to read the computer program stored in the memory and execute the code generation method described in any one of claims 1 to 5 according to the computer program in the memory.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the processor executes the computer-executable instructions, a code generation method as described in any one of claims 1 to 5 is implemented.
8. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, a code generation method as described in any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Code automatic generation method and device, equipment and medium
CN110955410A
C++ code generation method for unmanned aerial vehicle flight mode based on state machine diagram
CN111596915A