CN112835564A - Code generation method and device - Google Patents

Code generation method and device Download PDF

Info

Publication number
CN112835564A
CN112835564A CN202110111200.4A CN202110111200A CN112835564A CN 112835564 A CN112835564 A CN 112835564A CN 202110111200 A CN202110111200 A CN 202110111200A CN 112835564 A CN112835564 A CN 112835564A
Authority
CN
China
Prior art keywords
service
processed
code generation
code
parameters
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110111200.4A
Other languages
Chinese (zh)
Inventor
姜科
杨洸
林强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Hyperstrong Technology Co Ltd
Original Assignee
Beijing Hyperstrong Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Hyperstrong Technology Co Ltd filed Critical Beijing Hyperstrong Technology Co Ltd
Priority to CN202110111200.4A priority Critical patent/CN112835564A/en
Publication of CN112835564A publication Critical patent/CN112835564A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computing Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the application provides a code generation method and a code generation device, wherein when a code is generated, a code generation instruction is received firstly; the code generation instruction comprises an identifier of a service to be processed; abstracting 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; the description file comprises a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters; generating a target code corresponding to the service to be processed according to the plurality of abstract parameters and the parameter values corresponding to the abstract parameters; and outputting the target code corresponding to the service to be processed. Therefore, when the codes are generated, technicians do not need to manually write the codes, and the automatic generation of the codes is realized, so that the code generation efficiency is effectively improved.

Description

Code generation method and device
Technical Field
The present application relates to the field of software engineering technologies, and in particular, to a code generation method and apparatus.
Background
The development and operation of software are not independent of the writing of code. During the development of software, a technician is usually required to manually write different codes to realize various functions of the software.
However, when a technician writes the code manually, a lot of time is consumed, so that the efficiency of code generation is low.
Disclosure of Invention
The embodiment of the application provides a code generation method and a code generation device, when a code is generated, technical personnel do not need to manually write, automatic code generation is achieved, and therefore code generation efficiency is effectively improved.
In a first aspect, an embodiment of the present application provides a code generation method, where the code generation method includes:
receiving a code generation instruction; wherein, the code generation instruction comprises the identification of the service to be processed.
Abstracting 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; the description file comprises a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters.
And generating a target code corresponding to the service to be processed according to the plurality of abstract parameters and the parameter values corresponding to the abstract parameters.
And outputting the target code corresponding to the service to be processed.
In a possible implementation manner, the generating, according to the plurality of abstraction parameters and the parameter value corresponding to each abstraction parameter, a code corresponding to the service to be processed includes:
and generating a code generation rule corresponding to the service to be processed according to the plurality of abstract parameters.
Generating a code generation tool corresponding to the code generation rule according to the code generation rule;
and generating a target code corresponding to the service to be processed according to the description file and the code generation tool.
In a possible implementation manner, the generating an object code corresponding to the service to be processed according to the description file and the code generation tool includes:
and importing the description file into the code generation tool to generate a target code corresponding to the service to be processed.
In a possible implementation manner, the generating a code generation tool corresponding to the code generation rule according to the code generation rule includes:
and determining the architecture of the target code corresponding to the service to be processed according to the code generation rule.
And generating a code generation tool corresponding to the code generation rule according to the architecture of the target code corresponding to the service to be processed.
In a possible implementation manner, the generating a code generation rule corresponding to the to-be-processed service according to the plurality of abstraction parameters includes:
and determining the abstraction parameter at the head position of the table in the plurality of abstraction parameters as a plurality of target abstraction parameters.
And generating a code generation rule corresponding to the service to be processed according to the target abstraction parameters.
In one possible implementation, the method further includes:
determining the type of the service to be processed, the function type of the target code corresponding to the service to be processed, the file type of the target code and the implementation mode of the target code.
And updating the code generation rule according to the type of the service 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 to obtain a new code generation rule.
In a possible implementation manner, the abstracting the to-be-processed service indicated by the identifier of the to-be-processed service includes:
analyzing the service to be processed to obtain state information, condition information and execution action information corresponding to the service to be processed.
And abstracting the service to be processed based on the state information, the condition information and the execution action information.
In a second aspect, an embodiment of the present application provides a code generation apparatus, where the code generation apparatus includes:
a receiving unit for receiving a code generation instruction; wherein, the code generation instruction comprises the identification of the service to be processed.
The processing unit is used for abstracting 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; the description file comprises a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters.
And the generating unit is used for generating the target code corresponding to the service to be processed according to the plurality of abstract parameters and the parameter values corresponding to the abstract parameters.
And the output unit is used for outputting the target code corresponding to the service to be processed.
In a possible implementation manner, the generating unit is specifically configured to generate a code generation rule corresponding to the service to be processed according to the plurality of abstraction parameters; generating a code generation tool corresponding to the code generation rule according to the code generation rule; and generating a target code corresponding to the service to be processed according to the description file and the code generation tool.
In a possible implementation manner, the generating unit is specifically configured to import the description file into the code generating tool, and generate an object code corresponding to the service to be processed.
In a possible implementation manner, the generating unit is specifically configured to determine, according to the code generation rule, an architecture of a target code corresponding to the service to be processed; and generating a code generation tool corresponding to the code generation rule according to the architecture of the target code corresponding to the service to be processed.
In a possible implementation manner, the generating unit is specifically configured to determine, as a plurality of target abstraction parameters, an abstraction parameter in a header position of the table from among the plurality of abstraction parameters; and generating a code generation rule corresponding to the service to be processed according to the target abstraction parameters.
In a possible implementation manner, the generating unit is specifically configured to determine the type of the service to be processed, a function type of an object code corresponding to the service to be processed, a file type of the object code, and an implementation manner of the object code; and updating the code generation rule according to the type of the service 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 to obtain a new code generation rule.
In a possible implementation manner, the processing unit is specifically configured to analyze the service to be processed to obtain state information, condition information, and execution action information corresponding to the service to be processed; and abstracting the service to be processed based on the state information, the condition information and the execution action information.
In a third aspect, an embodiment of the present application further provides a code generation apparatus, where the code generation apparatus may include a memory and a processor; wherein,
the memory is used for storing the computer program.
The processor is configured to read the computer program stored in the memory, and execute the code generation method in any one of the foregoing possible implementation manners according to the computer program in the memory.
In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, where a computer-executable instruction is stored in the computer-readable storage medium, and when a processor executes the computer-executable instruction, the code generation method described in any one of the foregoing possible implementation manners of the first aspect is implemented.
In a fifth aspect, an embodiment of the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the computer program implements the code generation method described in any one of the possible implementation manners of the first aspect.
Therefore, according to the code generation method and the code generation device provided by the embodiment of the application, when a code is generated, a code generation instruction is received firstly; the code generation instruction comprises an identifier of a service to be processed; abstracting 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; the description file comprises a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters; generating a target code corresponding to the service to be processed according to the plurality of abstract parameters and the parameter values corresponding to the abstract parameters; and outputting the target code corresponding to the service to be processed. Therefore, when the codes are generated, technicians do not need to manually write the codes, and the automatic generation of the codes is realized, so that the code generation efficiency is effectively improved.
Drawings
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 disclosure.
Fig. 1 is a schematic flowchart of a code generation method according to an embodiment of the present application;
fig. 2 is a schematic flowchart of generating a target code corresponding to a service to be processed according to an embodiment of the present application;
FIG. 3 is a schematic flowchart of another method for generating code according to an embodiment of the present disclosure;
FIG. 4 is a flowchart illustrating a code operation according to an embodiment of the present disclosure;
fig. 5 is a schematic structural diagram of a code generation apparatus according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of another code generation apparatus according to an embodiment of the present application.
With the foregoing drawings in mind, certain embodiments of the disclosure have been shown and described in more detail below. These drawings and written description are not intended to limit the scope of the disclosed concepts in any way, but rather to illustrate the concepts of the disclosure to those skilled in the art by reference to specific embodiments.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.
In the embodiments of the present application, "at least one" means one or more, "a plurality" means two or more. "and/or" describes the association relationship of the associated objects, meaning that there may be three relationships, e.g., a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone, wherein A and B can be singular or plural. In the description of the text of the present application, the character "/" generally indicates that the former and latter associated objects are in an "or" relationship.
The technical scheme provided by the embodiment of the application can be applied to a code generation scene. The implementation of the software function is not independent of the code, for example, because of different manufacturers and vehicle types, the control method of the electric vehicle for the contactor is different, and the control can be performed through a Battery Management System (BMS for short) or through other electric control devices of the whole vehicle. For the electric automobile controlled by the BMS software, different technical schemes are required to be adopted for the whole automobile, so software developers often need to compile different codes to realize different overall scheduling and control time sequences of the BMS software, and the aim of adapting to different requirements of the whole automobile is fulfilled.
In the prior art, a technician determines a function to be implemented by software to be developed according to a received instruction, and manually writes a corresponding code according to the function to be implemented by the software to be developed, so that the software can implement various different functions. However, it takes a lot of time to write the code manually, and in the process of writing the code, a writing error may occur, which reduces the efficiency of generating the code.
To solve the problem of inefficient code generation, automated code generation may be considered. The embodiment of the application provides a code generation method, which comprises the steps of firstly receiving a code generation instruction; the code generation instruction comprises an identifier of a service to be processed; abstracting 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; the description file comprises a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters; generating a target code corresponding to the service to be processed according to the plurality of abstract parameters and the parameter values corresponding to the abstract parameters; and outputting the target code corresponding to the service to be processed.
Therefore, in the embodiment of the application, when the code is generated, the code generation instruction is received firstly; the code generation instruction comprises an identifier of a service to be processed; abstracting 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; the description file comprises a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters; and generating a target code corresponding to the service to be processed according to the plurality of abstract parameters and the parameter values corresponding to the abstract parameters. Therefore, when the codes are generated, technicians do not need to manually write the codes, and the automatic generation of the codes is realized, so that the code generation efficiency is effectively improved.
Hereinafter, the code generation method provided in the present application will be described in detail by specific embodiments. It is to be understood that the following detailed description may be combined with other embodiments, and that the same or similar concepts or processes may not be repeated in some embodiments.
Fig. 1 is a schematic flowchart of a code generation method according to an embodiment of the present application. The code generation method may be performed by software and/or hardware means, for example, the hardware means may be a code generation means, which may be a terminal or a processing chip in the terminal. For example, referring to fig. 1, the code generation method may include:
s101, receiving a code generation instruction.
Wherein, the code generation instruction comprises the identification of the service to be processed.
For example, the code generation instruction has various forms, which may be a text form, or a symbol of a feature, and is mainly used for identifying a service to be processed. The embodiment of the application does not limit the form of the code generation instruction and the form of the service identifier to be processed.
S102, abstracting the service to be processed indicated by the identification of the service to be processed to obtain a description file corresponding to the service to be processed.
For example, when the to-be-processed service indicated by the identifier of the to-be-processed service is abstracted, the to-be-processed service may be analyzed first to obtain state information, condition information, and execution action information corresponding to the to-be-processed service; and abstracting the service to be processed based on the state information, the condition information and the execution action information.
The state information may include a plurality of different states, the condition information may include a plurality of different conditions, the execution action information may include a plurality of different execution actions, and the state information corresponding to the service to be processed may include a plurality of sub-states. For example, the state information may include 3 sub-states, an initialize sub-state, a run sub-state, and an exit sub-state. The condition information may be jump information between different states, and the execution action information may be an action to be executed for each sub-state. It is understood that the status information, the condition information and the execution role information can be represented by special characters, and the embodiment of the present application is not limited to any specific representation manner.
In the embodiment of the application, the to-be-processed service can be converted into the language which can be identified by the computer by analyzing the to-be-processed service into the state information, the condition information and the execution action and performing the abstraction processing, so that the success rate of code generation can be effectively improved.
When the service to be processed indicated by the identifier of the service to be processed is abstracted, a description file corresponding to the service to be processed can be obtained, and the description file comprises a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters. The abstract parameters may be state information, condition information, and execution action information obtained by analyzing the service to be processed, and corresponding specific information and number, and the parameters corresponding to the abstract parameters may be specific numerical values corresponding to the state information, the condition information, and the execution action information, respectively. The abstract parameters and the specific contents of the parameter values corresponding to the abstract parameters are not limited in any way in the embodiments of the present application. The description file may be in various types, for example, the description file may be an EXCEL table, and the embodiment of the present application does not limit any specific type of the description file.
After the to-be-processed service indicated by the identifier of the to-be-processed service is abstracted to obtain the description file corresponding to the to-be-processed service, the target code corresponding to the to-be-processed service may be generated according to the plurality of abstraction parameters and the parameter values corresponding to the abstraction parameters, that is, the following S103 is executed:
s103, generating a target code corresponding to the service to be processed according to the plurality of abstract parameters and the parameter values corresponding to the abstract parameters.
When generating the object code corresponding to the service to be processed according to the plurality of abstraction parameters and the parameter values corresponding to the parameters, the abstraction parameters and the parameter values corresponding to the abstraction parameters may be directly obtained, or the abstraction parameters in the description and the parameter values corresponding to the abstraction parameters may be read by obtaining the description file.
After the plurality of abstraction parameters and the parameter values corresponding to the abstraction parameters are respectively obtained, the target code corresponding to the service to be processed can be generated according to the plurality of abstraction parameters and the parameter values corresponding to the abstraction parameters, and the target code is output.
And S104, outputting the target code corresponding to the service to be processed.
Illustratively, when an object code corresponding to a service to be processed is output, if a file storage type of the object code is set, the object code corresponding to the service to be processed is stored in a file of the corresponding file storage type, and a file containing the object code is output; and if the file storage type of the object code is not set, storing the object code corresponding to the service to be processed in the file of the default file storage type, and outputting the file of the default file storage type, wherein the default file storage type is the file storage type set by the user last time, and the default file storage type can be specifically set according to actual requirements.
Therefore, in the code generation method provided by the embodiment of the application, when a code is generated, a code generation instruction is received firstly; the code generation instruction comprises an identifier of a service to be processed; abstracting 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; the description file comprises a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters; and generating a target code corresponding to the service to be processed according to the plurality of abstract parameters and the parameter values corresponding to the abstract parameters. Therefore, when the codes are generated, technicians do not need to manually write the codes, and the automatic generation of the codes is realized, so that the code generation efficiency is effectively improved.
Based on the above embodiment shown in fig. 1, in order to facilitate understanding how to generate the target code corresponding to the service to be processed according to the plurality of abstraction parameters and the parameter values corresponding to the abstraction parameters in the embodiment of the present application, in the following, how to generate the target code corresponding to the service to be processed according to the plurality of abstraction parameters and the parameter values corresponding to the abstraction parameters in the embodiment of the present application will be described in detail through the embodiment shown in fig. 2.
Fig. 2 is a schematic flowchart of generating an object code corresponding to a service to be processed according to an embodiment of the present application. The method for generating the object code corresponding to the service to be processed can also be executed by software and/or hardware devices. For example, please refer to fig. 2, the method for generating a target code corresponding to a service to be processed may include:
s201, generating a code generation rule corresponding to the service to be processed according to the plurality of abstract parameters.
For example, when a code generation rule corresponding to a service to be processed is generated according to a plurality of abstraction parameters, the plurality of abstraction parameters may be processed first, and abstraction parameters required by the code generation rule, that is, target abstraction parameters, are determined. For example, if the description file is a table, determining an abstraction parameter at a header position of the table among the plurality of abstraction parameters as a target abstraction parameter; and generating a code generation rule corresponding to the service to be processed according to the plurality of target abstract parameters. For example, if the description file is a text, a plurality of target abstraction parameters may be obtained by reading an initial position of the text, and the setting may be specifically performed according to actual needs.
According to the embodiment, when the abstraction parameter is the specific information and the number of the state information, the condition information and the execution action information included in the code corresponding to the service to be processed, the code generation rule is the number information of the state information, the condition information and the 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 needs to include 2 states, 4 jump conditions, and 5 execution actions in the generated code.
In the embodiment of the application, by determining a plurality of target abstraction parameters and generating corresponding code generation rules, the target code can be prevented from being affected by other abstraction parameters except the target abstraction parameters, and the generation rules can be used for assisting in generating the corresponding target code.
In addition, in order to further improve the generation rule, the type of the service to be processed, the function type of the target code corresponding to the service to be processed, the file type of the target code and the implementation mode of the target code can be determined; and updating the code generation rule according to the type of the service 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 to obtain a new code generation rule, so that the integrity of the generation rule can be further improved, and the generation of the corresponding target code is better assisted.
The type of the service to be processed, the function type of the target code corresponding to the service to be processed, the file type of the target code, and the implementation manner of the target code may be determined according to the specific service. For example, the function type of the target code corresponding to the service to be processed may be in the form of void xxx _ step (void), the file type of the target code may be in the forms of xxx.c and xxx.h, and the implementation manner of the target code may be in the form of switch … … case … …, which is not limited in this embodiment of the present application.
It can be seen that, in the embodiment of the present application, by generating a new code generation rule, the purpose is to: the style of the generated target code can be unified, the problems of non-unified code style and logic errors caused by the fact that a plurality of technicians write the code in different labor are solved, and the code generation efficiency is improved.
And S202, generating a code generation tool corresponding to the code generation rule according to the code generation rule.
For example, when a code generation tool corresponding to a code generation rule is generated according to the code generation rule, the architecture of a target code corresponding to a service to be processed may be determined according to the code generation rule; and generating a code generation tool corresponding to the code generation rule according to the architecture of the target code corresponding to the service to be processed. The architecture of the object code corresponding to the service to be processed may include a repeated portion of the generated object code, or may include other portions.
Further, when the code generation tool corresponding to the code generation rule is generated according to the architecture of the target code corresponding to the service to be processed, the corresponding code generation tool may be written according to the architecture of the target code, or may be generated in other manners, which is not limited in this embodiment of the present application.
In the embodiment of the application, the architecture of the target code corresponding to the service to be processed is determined through the code generation rule, and the corresponding code generation tool is generated, so that the corresponding target code can be generated through the code generation tool, and the accuracy and the efficiency of code generation are improved.
And S203, generating a target code corresponding to the service to be processed according to the description file and the code generation tool.
For example, when the object code corresponding to the service to be processed is generated according to the description file and the code generation tool, the description file may be imported into the code generation tool, and the object code corresponding to the service to be processed is generated.
The code generation tool may first determine a plurality of target abstraction parameter values required by the target code according to parameter values corresponding to a plurality of abstraction drawing parameters in the description file, and spell the plurality of target abstraction parameter values with an architecture of the target code corresponding to the service to be processed, or supplement the plurality of target abstraction parameter values into the architecture of the target code, thereby generating the target code corresponding to the service to be processed. The specific generation mode can be set according to the actual situation. By importing the description file into the code generation tool, the code generation tool generates the target code corresponding to the service to be processed according to the parameter value corresponding to the abstract parameter in the description file, so that the problem of errors in manual code writing is avoided, and the code generation efficiency is improved.
To sum up, in the code generation method provided in the embodiment of the present application, when generating a target code corresponding to a service to be processed according to a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters, a code generation rule corresponding to the service to be processed is generated according to the plurality of abstraction parameters; generating a corresponding code generation tool according to the code generation rule; and generating the target code corresponding to the service to be processed according to the description file and the code generation tool, so that the problems of long time consumption and high error rate caused by manually writing the code can be avoided, and the code generation efficiency is improved.
In order to facilitate understanding of the code generation method provided in the embodiment of the present application, the following will describe in detail the technical solution provided in the embodiment of the present application, taking a specific application of the method in practice as an example. Referring to fig. 3, fig. 3 is a schematic flowchart of another method for generating a code according to an embodiment of the present application.
The generation of the code can be carried out by adopting a scheduler, and the division of labor of each software and/or hardware device in the generation process of the code can be ensured to be clear, so that the generation efficiency of the code is improved. The scheduling definition in fig. 3 is that when the code generation instruction is received, the type of the service to be processed and the identifier of the service to be processed may be determined, and the state information, the condition information, and the execution action information corresponding to the service to be processed are determined by analyzing the service to be processed. It is assumed that the corresponding state of the service to be processed is represented by S, the condition is represented by C, and the execution action is represented by a.
For example, the states S may include an initialization state S0 and a plurality of running states S1 Sn, the condition C may be a state jump condition between each state S, Cx _ y represents a jump condition from the state Sx to the state Sy, e.g., C1_2 represents a jump condition from the state S1 to the state S2. Each state S includes 3 substates, namely an initialization substate en, an operation substate du, and an exit substate ex. The execution action A is an action executed by each sub-state, wherein the action for executing the initialization sub-state en can be Aen _1 to Aen _ n, which means that the actions of initializing the sub-state 1 to the sub-state n are executed in sequence; the actions for executing the run sub-state du may be Adu _ 1-Adu _ n, which represents the sequential execution of the actions running sub-state 1-sub-state n; the actions for exiting the sub-state ex may be Aex _1 to Aex _ n, which indicate that the actions for exiting the sub-state 1 to the sub-state n are performed sequentially.
It is understood that the above state jump condition is a corresponding condition in the actual code, and the execution action is a function interface provided by the basic software layer. The relationship between states, conditions and execution actions can be seen in fig. 4, where fig. 4 is a flowchart illustrating a code operation provided in an embodiment of the present application.
According to fig. 4, during the code running process, the actions of the initialization sub-state en in the initialization state S0, that is, the actions of the initialization sub-state 1 to the initialization sub-state n, are executed sequentially. After the initialization of the sub-state is completed, the actions of the run sub-state du in the initialization state S0, that is, the actions of the run sub-state 1 to the run sub-state n are sequentially executed, and the actions of the run sub-state n are performed in a loop until the jump condition C is received as C0_ x. Upon receiving the jump condition, the sequential execution of the operation sub-states in the initialization state S0 is stopped, and the sequential execution of the operation of the exit sub-state ex in the initialization state S0, that is, the sequential execution of the operations of the exit sub-state 1 to the exit sub-state n is changed. The jump condition may jump from the initialized state S0 to the state S1, or may jump from the initialized state S0 to the state S1, and the embodiment of the present application does not limit the specific jump condition.
After the exit operations of the plurality of sub-states in the initialization state S0 are executed, the state jump is performed according to a specific jump condition. If the jump condition is C-C0 _1, the initialization state S0 jumps to the state S1, the code operation mode in the state S1 is executed, and the state S1 jumps to the state S2 according to the received jump condition C-C1 _2, and the code operation mode in the state S2 is executed. If the jump condition is C-C0 _2, the initialization state S0 jumps to the state S2, the code operation mode in the state S2 is executed, and the state S2 jumps to the state S1 according to the received jump condition C-C2 _1, and the code operation mode in the state S1 is executed. As shown in fig. 3, the code operation manners in the state S1 and the state S2 are the same as the code operation manner in the initialization state S0, and are not described again in this embodiment of the present application.
The jump condition shown in fig. 4 may jump simultaneously or jump according to a certain time sequence, which is not limited in this embodiment of the present application.
As shown in fig. 3, after the scheduling definition is performed, a scheduling description file may be established, that is, a description file corresponding to the service to be processed is obtained according to the analysis result of the service to be processed. The schedule description file can be referred to the following table 1. Table 1 is a scheduler state table that includes the number of states that generate code, the number of initialization state actions and their corresponding, and the number of execution state actions and their corresponding.
TABLE 1
Figure BDA0002919416130000121
Table 1 includes a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters, where the header part in table 1 is a plurality of abstraction parameters, that is, a state identifier, a state number, an initialization action identifier, an initialization action 1, an initialization action 2, an execution action identifier, an execution action 1, and an execution action 2. Each parameter value corresponding to an abstraction parameter is a numerical value of the column where each abstraction parameter is located, for example, the parameter values corresponding to the state numbers are 0, 1 and 2.
In addition, the schedule description file also includes a scheduler state transition table, which can be seen in table 2 below.
TABLE 2
Figure BDA0002919416130000131
Table 2 also includes a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters, where the abstraction parameters are header portions of table 2, that is, the abstraction parameters are a state skip identifier, a current state, a target state, a skip condition, an exit state action identifier, an exit state action 1, and an exit state action 2. The parameter values are the values listed in the respective abstractions, and for example, the parameter values corresponding to the abstract parameter jump conditions are C ═ C0_1, C ═ C0_2, C ═ C1_2, C ═ C1_0, C ═ C2_0, and C ═ C2_ 1.
And determining target abstraction parameters according to the table 1 and the table 2, wherein the target abstraction parameters are a state number, an initialization action 1, an initialization action 2, an execution action 1, an execution action 2, a current state, a target state, a jump condition, an exit state action 1 and an exit state action 2, and generating a corresponding code generation rule according to the target abstraction parameters.
For example, to further refine the generated code generation rule, in addition to the abstract parameters and the parameter values corresponding to the abstract parameters shown in tables 1 and 2, the parameters of the scheduler also need to be set, and the parameters of the scheduler can be set through the parameters in the following table 3, where table 3 is a scheduler design table.
TABLE 3
Scheduler name Number of states Status variable name
APPSc 3 APPScStep
As can be seen from the parameters in table 3, the code generation method according to the embodiment of the present application may be implemented by using state machines, the number of the state machines is consistent with the number of the states in table 3, and the state jump, the state jump condition, and the execution action of each state of the state machines in the running process are consistent with the parameter values corresponding to the abstract parameters in tables 1 and 2. As can be seen from the state variable names in table 3, the state machine in the embodiment of the present application is in the form of switch … … case … ….
It can be understood that the generated code generation rule can be updated and perfected according to the parameters of the scheduler shown in table 3, so as to obtain a new code generation rule. For example, when the code generation rule is updated, other parameters of the generated code may also be set, for example, the generated target code includes one.c and one.h files, and the file names of the generated files are xxx.c and xxx.h, respectively, where xxx is a scheduling name; and type.h and util.h header file references are required to be added in xxx.h, so that the data type corresponding to the embedded chip is consistent with the system definition; the object code may be a separate function whose name may be in the form of void xxx step (void), and the function needs to be marked in xxx. The embodiments of the present application only take the above parameters as examples to update the generated code generation rule, but do not represent that the embodiments of the present application are only limited thereto.
According to fig. 3, after a new code generation rule is generated, a corresponding code generation tool is written according to the new code generation rule, and the scheduling description file shown in table 1 and table 2 is imported into the code generation tool, and the code generation tool can automatically generate a code, that is, a target code corresponding to a service to be processed is generated by reading a parameter value corresponding to a target abstraction parameter.
The object code generated according to the method is as follows:
Figure BDA0002919416130000141
Figure BDA0002919416130000151
Figure BDA0002919416130000161
Figure BDA0002919416130000171
Figure BDA0002919416130000181
Figure BDA0002919416130000191
fig. 5 is a schematic structural diagram of a code generation apparatus 50 according to an embodiment of the present application, and for example, please refer to fig. 5, the code generation apparatus 50 may include:
a receiving unit 501 for receiving a code generation instruction; wherein, the code generation instruction comprises the identification of the service to be processed.
A processing unit 502, configured to perform abstraction processing 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; the description file comprises a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters.
The generating unit 503 is configured to generate a target code corresponding to the to-be-processed service according to the plurality of abstraction parameters and the parameter value corresponding to each abstraction parameter.
An output unit 504, configured to output a target code corresponding to the service to be processed.
Optionally, the generating unit 503 is specifically configured to generate a code generation rule corresponding to the service to be processed according to the plurality of abstraction parameters; generating a code generation tool corresponding to the code generation rule according to the code generation rule; and generating a target code corresponding to the service to be processed according to the description file and the code generation tool.
Optionally, the generating unit 503 is specifically configured to import the description file into a code generation tool, and generate a target code corresponding to the service to be processed.
Optionally, the generating unit 503 is specifically configured to determine, according to the code generation rule, an architecture of a target code corresponding to the service to be processed; and generating a code generation tool corresponding to the code generation rule according to the architecture of the target code corresponding to the service to be processed.
Optionally, the generating unit 503 is specifically configured to determine, as the plurality of target abstraction parameters, abstraction parameters in a header position of the table from the plurality of abstraction parameters; and generating a code generation rule corresponding to the service to be processed according to the plurality of target abstract parameters.
Optionally, the generating unit 503 is specifically configured to determine the type of the service to be processed, a function type of a target code corresponding to the service to be processed, a file type of the target code, and an implementation manner of the target code; and updating the code generation rule according to the type of the service 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 to obtain a new code generation rule.
Optionally, the processing unit 502 is specifically configured to analyze the service to be processed to obtain state information, condition information, and execution action information corresponding to the service to be processed; and abstracting the service to be processed based on the state information, the condition information and the execution action information.
The code generation apparatus 50 provided in this embodiment of the present application may implement the technical solution of the code generation method in any embodiment, and its implementation principle and beneficial effect are similar to those of the code generation method, and reference may be made to the implementation principle and beneficial effect of the code generation method, which are not described herein again.
Fig. 6 is a schematic structural diagram of another code generation apparatus 60 provided in the embodiment of the present application, and for example, please refer to fig. 6, the code generation apparatus 60 may include a processor 601 and a memory 602;
wherein,
the memory 602 is used for storing computer programs.
The processor 601 is configured to read the computer program stored in the memory 602, and execute the technical solution of the code generation method in any of the embodiments according to the computer program in the memory 602.
Alternatively, the memory 602 may be separate or integrated with the processor 601. When the memory 602 is a device independent of the processor 601, the code generation apparatus 60 may further include: a bus for connecting the memory 602 and the processor 601.
Optionally, this embodiment further includes: a communication interface, which may be connected to the processor 601 through a bus. The processor 601 may control the communication interface to implement the functions of receiving and transmitting of the code generation apparatus 60 described above.
The code generation apparatus 60 shown in the embodiment of the present application can execute the technical solution of the code generation method in any one of the above embodiments, and its implementation principle and beneficial effect are similar to those of the code generation method, and reference may be made to the implementation principle and beneficial effect of the code generation method, which are not described herein again.
An embodiment of the present application further provides a computer-readable storage medium, where a computer execution instruction is stored in the computer-readable storage medium, and when a processor executes the computer execution instruction, the technical solution of the code generation method in any of the above embodiments is implemented, and implementation principles and advantageous effects of the computer-readable storage medium are similar to those of the code generation method, and reference may be made to the implementation principles and advantageous effects of the code generation method, which are not described herein again.
The embodiment of the present application further provides a computer program product, which includes a computer program, and 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, and the implementation principle and the beneficial effect of the computer program are similar to those of the code generation method, which can be referred to as the implementation principle and the beneficial effect of the code generation method, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts shown as units may or may not be physical units, may be located in one position, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment. In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional unit.
The integrated module implemented in the form of a software functional module may be stored in a computer-readable storage medium. The software functional module is stored in a storage medium and includes several instructions to enable a computer device (which may be a personal computer, a server, or a network device) or a processor (processor) to execute some steps of the methods according to the embodiments of the present application.
It should be understood that the Processor may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of a method disclosed in connection with the present invention may be embodied directly in a hardware processor, or in a combination of the hardware and software modules within the processor.
The memory may comprise a high-speed RAM memory, and may further comprise a non-volatile storage NVM, such as at least one disk memory, and may also be a usb disk, a removable hard disk, a read-only memory, a magnetic or optical disk, etc.
The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended ISA (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, the buses in the figures of the present application are not limited to only one bus or one type of bus.
The computer-readable storage medium may be implemented by any type or combination of volatile or non-volatile memory devices, 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 or optical disks. A storage media may be any available media that can be accessed by a general purpose or special purpose computer.
Finally, it should be noted that: the above embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present application.

Claims (11)

1. A code generation method, comprising:
receiving a code generation instruction; the code generation instruction comprises an identifier of a service to be processed;
abstracting 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; the description file comprises a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters;
generating a target code corresponding to the service to be processed according to the plurality of abstract parameters and the parameter values corresponding to the abstract parameters;
and outputting the target code corresponding to the service to be processed.
2. The method according to claim 1, wherein the generating, according to the plurality of abstraction parameters and the parameter values corresponding to the abstraction parameters, the object code corresponding to the service to be processed includes:
generating a code generation rule corresponding to the service to be processed according to the plurality of abstract parameters;
generating a code generation tool corresponding to the code generation rule according to the code generation rule;
and generating a target code corresponding to the service to be processed according to the description file and the code generation tool.
3. The method according to claim 2, wherein the generating an object code corresponding to the service to be processed according to the description file and the code generation tool comprises:
and importing the description file into the code generation tool to generate a target code corresponding to the service to be processed.
4. The method of claim 2, wherein generating the code generation tool corresponding to the code generation rule according to the code generation rule comprises:
determining the architecture of a target code corresponding to the service to be processed according to the code generation rule;
and generating a code generation tool corresponding to the code generation rule according to the architecture of the target code corresponding to the service to be processed.
5. The method according to claim 2, wherein the description file is a table, and the generating a code generation rule corresponding to the to-be-processed service according to the plurality of abstraction parameters includes:
determining an abstraction parameter at a header position of the table among the plurality of abstraction parameters as a plurality of target abstraction parameters;
and generating a code generation rule corresponding to the service to be processed according to the target abstraction parameters.
6. The method of claim 5, further comprising:
determining the type of the service to be processed, the function type of a target code corresponding to the service to be processed, the file type of the target code and the implementation mode of the target code;
and updating the code generation rule according to the type of the service 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 to obtain a new code generation rule.
7. The method according to any one of claims 1 to 6, wherein the abstracting the to-be-processed service indicated by the identifier of the to-be-processed service includes:
analyzing the service to be processed to obtain state information, condition information and execution action information corresponding to the service to be processed;
and abstracting the service to be processed based on the state information, the condition information and the execution action information.
8. A code generation apparatus, comprising:
a receiving unit for receiving a code generation instruction; the code generation instruction comprises an identifier of a service to be processed;
the processing unit is used for abstracting 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; the description file comprises a plurality of abstraction parameters and parameter values corresponding to the abstraction parameters;
a generating unit, configured to generate a target code corresponding to the to-be-processed service according to the plurality of abstraction parameters and the parameter values corresponding to the abstraction parameters;
and the output unit is used for outputting the target code corresponding to the service to be processed.
9. A code generation apparatus comprising a memory and a processor; wherein,
the memory for storing a computer program;
the processor is configured to read the computer program stored in the memory and execute a code generation method according to any one of the preceding claims 1 to 7 according to the computer program in the memory.
10. A computer-readable storage medium having computer-executable instructions stored thereon, which when executed by a processor, implement a code generation method as claimed in any one of claims 1 to 7.
11. A computer program product comprising a computer program, characterized in that the computer program, when executed by a processor, implements a code generation method as claimed in any one of the preceding claims 1 to 7.
CN202110111200.4A 2021-01-27 2021-01-27 Code generation method and device Pending CN112835564A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110111200.4A CN112835564A (en) 2021-01-27 2021-01-27 Code generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110111200.4A CN112835564A (en) 2021-01-27 2021-01-27 Code generation method and device

Publications (1)

Publication Number Publication Date
CN112835564A true CN112835564A (en) 2021-05-25

Family

ID=75931883

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110111200.4A Pending CN112835564A (en) 2021-01-27 2021-01-27 Code generation method and device

Country Status (1)

Country Link
CN (1) CN112835564A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113296789A (en) * 2021-06-16 2021-08-24 北京有竹居网络技术有限公司 Code generation method, device, equipment and storage medium
CN115686676A (en) * 2022-11-04 2023-02-03 北京远舢智能科技有限公司 Dynamic calling method and device of object and electronic equipment

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7761848B1 (en) * 2005-03-15 2010-07-20 Open Invention Network, Llc Code generator tool for building software applications with reusable components
US20110265061A1 (en) * 2010-04-27 2011-10-27 Verizon Patent And Licensing Inc. Code generation
CN103473108A (en) * 2013-08-12 2013-12-25 福建富士通信息软件有限公司 Java code generating method
CN106874019A (en) * 2017-03-17 2017-06-20 微梦创科网络科技(中国)有限公司 The generation method and skeletal code maker of a kind of skeletal code
CN106919434A (en) * 2017-03-22 2017-07-04 恒生电子股份有限公司 A kind of code generating method and device
CN110297632A (en) * 2019-06-12 2019-10-01 百度在线网络技术(北京)有限公司 Code generating method and device
CN110955410A (en) * 2019-10-23 2020-04-03 山东中创软件工程股份有限公司 Automatic code generation method, device, equipment and medium
CN111722839A (en) * 2020-06-24 2020-09-29 北京航天数据股份有限公司 Code generation method and device, electronic equipment and storage medium

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7761848B1 (en) * 2005-03-15 2010-07-20 Open Invention Network, Llc Code generator tool for building software applications with reusable components
US20110265061A1 (en) * 2010-04-27 2011-10-27 Verizon Patent And Licensing Inc. Code generation
CN103473108A (en) * 2013-08-12 2013-12-25 福建富士通信息软件有限公司 Java code generating method
CN106874019A (en) * 2017-03-17 2017-06-20 微梦创科网络科技(中国)有限公司 The generation method and skeletal code maker of a kind of skeletal code
CN106919434A (en) * 2017-03-22 2017-07-04 恒生电子股份有限公司 A kind of code generating method and device
CN110297632A (en) * 2019-06-12 2019-10-01 百度在线网络技术(北京)有限公司 Code generating method and device
CN110955410A (en) * 2019-10-23 2020-04-03 山东中创软件工程股份有限公司 Automatic code generation method, device, equipment and medium
CN111722839A (en) * 2020-06-24 2020-09-29 北京航天数据股份有限公司 Code generation method and device, electronic equipment and storage medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113296789A (en) * 2021-06-16 2021-08-24 北京有竹居网络技术有限公司 Code generation method, device, equipment and storage medium
CN115686676A (en) * 2022-11-04 2023-02-03 北京远舢智能科技有限公司 Dynamic calling method and device of object and electronic equipment
CN115686676B (en) * 2022-11-04 2023-07-28 北京远舢智能科技有限公司 Dynamic calling method and device for object and electronic equipment

Similar Documents

Publication Publication Date Title
CN101520737B (en) Compiling method and processor using the same
CN112835564A (en) Code generation method and device
CN103399775A (en) Hot patching method and hot patching equipment
EP4231138A1 (en) Method and apparatus for fixing weak memory ordering problem
CN107480327A (en) A kind of emulation verification method, device and electronic equipment
CN109857642B (en) Blocking type debugging method and debugging tool for UI automation script
US20190286544A1 (en) Method, device and server for checking a defective function
CN117743145A (en) Test script generation method and device based on coding template and processing equipment
CN109324838B (en) Execution method and execution device of single chip microcomputer program and terminal
CN102750167B (en) Application program launching method, device and computer system
CN114780154B (en) Method compatible with hardware states of master control boards of different manufacturers
CN111857785A (en) MCU starting method and device and terminal equipment
CN113703753B (en) Method and device for product development and product development system
CN112130765B (en) EEPROM data reading and writing method and device
CN115878141A (en) Embedded equipment and method for repairing ROM (read only memory) program
CN114063982A (en) Method for automatically constructing functional components based on multi-scenario application
CN112508526A (en) Data auditing method and device
CN111027196A (en) Simulation analysis task processing method and device for power equipment and storage medium
CN112364580A (en) Method and device for automatically inserting specific code into register transmission level design file
CN112487738B (en) Signal control method, system, terminal and storage medium in board design stage
CN111078714B (en) Data processing method and device
CN113094071B (en) Micro control unit, control method thereof and firmware upgrading method thereof
CN115878272B (en) Graph task scheduling method, execution end device, storage medium and program product
CN111984320B (en) PDO data read-write method, device, equipment and storage medium
CN117992059A (en) Singlechip software development method, singlechip, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination