Programming assistance method based on generative AI, computer equipment and storage medium
By analyzing the attributes, complexity and sensitivity of each code module in the pre-generated code generated by the generative AI model, determining instruction priorities and optimizing it, the problem of high redundancy of the generative AI output code is solved, and more efficient memory usage and code operation are achieved.
Patent Information
- Application Number
- CN202510503311.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-22
- Publication Date
- 2025-05-16
- Estimated Expiration
- 2045-04-22
AI Technical Summary
The program code output of generative AI has high redundancy, resulting in increased memory usage and reduced code operation efficiency.
Pre-generated code is generated through a generative AI model, and the hardware attributes, program complexity and time sensitivity of each code module are analyzed, the instruction priority of each code module is determined, and the redundant code is optimized.
It reduces the redundancy of program code obtained by generative AI-assisted programming, reduces memory usage, and improves code operation efficiency.
Smart Images

Figure CN120010825A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a programming assistance method, computer device and storage medium based on generative AI. Background Art
[0002] Generative AI refers to artificial intelligence technology that can automatically generate text, code, or other types of content, usually based on deep learning models, such as the GPT (Generative Pre-trained Transformer) series. The application of generative AI in programming assistance is mainly reflected in the following aspects: 1. Generative AI can generate program code based on natural language descriptions; 2. When writing program code, generative AI can predict and complete code snippets in real time; 3. Generative AI can help identify errors in program code and make repair suggestions; 4. Generative AI can suggest or automatically perform code refactoring to improve code readability, maintainability, and performance. AI models are trained with a large amount of code data to learn the syntax and common programming patterns of different programming languages, thereby realizing AI-assisted programming.
[0003] In the traditional method, in the process of AI performing keyword retrieval and generating program code based on user demand information, especially in specific programming projects, such as the development of automatic control programs, when programming and burning hardware devices, the microcontroller's usual ROM, that is, the reserved support for program cache, is relatively small. The generated burning control program code will usually have high redundancy due to insufficient provision of user configuration requirements, resulting in a large degree of program memory occupation. For example, there are invalid communication protocols or internal loops in the code, which results in a high complexity of code running time after the functions of multiple modules are combined. Summary of the invention
[0004] In order to solve the technical problem of high redundancy of program code output by generative AI, the purpose of the present invention is to provide a programming assistance method, computer device and storage medium based on generative AI. The technical solutions adopted are as follows: A programming assistance method based on generative AI, the method comprising: According to the programming requirement information, the pre-generated code is obtained through the generative AI model; Analyze the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module; Analyzing the complexity of the program code in each of the code modules to obtain a program complexity priority of each of the code modules; Analyze the time sensitivity of each of the code modules to obtain the time priority of each of the code modules; Determining the instruction priority of each of the code modules according to the attribute priority, the program complexity priority and the time priority; According to the instruction priority of each code module, the program code in each code module in the pre-generated code is optimized to obtain a final target program code.
[0005] In one embodiment, analyzing the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module includes: Extracting hardware-related keywords from each code module in the pre-generated code; Determining the attribute category of the hardware-related keywords in each of the code modules; For each of the code modules, the attribute priority of the code module is determined according to the number of occurrences of the hardware-related keywords under each attribute category in the code module.
[0006] In one embodiment, the attribute categories include core hardware and peripheral devices; and determining the attribute priority of each code module according to the number of occurrences of hardware-related keywords under each attribute category in the code module, respectively, includes: For each of the code modules, weighted sum of the number of occurrences of hardware-related keywords under each attribute category in the code module is performed to obtain the attribute priority of the code module; Among them, the first weight used in the weighted summation is greater than the second weight; the first weight is the weight corresponding to the number of times hardware-related keywords with the attribute category of core hardware appear; the second weight is the weight corresponding to the number of times hardware-related keywords with the attribute category of peripheral devices appear.
[0007] In one embodiment, analyzing the complexity of the program code in each of the code modules to obtain the program complexity priority of each of the code modules includes: Analyze the number of loop nesting levels of the program code in each of the code modules; Analyze the call depth and call count of each function in each of the code modules; For each of the code modules, the program complexity priority of the code module is determined according to the number of loop nesting levels of the code module and the call depth and the call count of each function in the code module.
[0008] In one embodiment, analyzing the time sensitivity of each of the code modules to obtain the time priority of each of the code modules includes: Determine the interrupt response time and task scheduling order according to the programming requirement information; Determining the order value of each of the code modules according to the task scheduling order; The time priority of each of the code modules is determined according to the interrupt response time and the sequence value of each of the code modules.
[0009] In one embodiment, optimizing the program code in each code module in the pre-generated code according to the instruction priority of each code module to obtain the final target program code includes: Allocate memory for each code module according to the instruction priority of each code module to obtain a memory allocation amount for each code module; According to the instruction priority of each code module, performing redundancy optimization on the program code in each code module to obtain a redundancy-free program code; The final target program code is obtained according to the memory allocation amount of each code module and the corresponding de-redundant program code.
[0010] In one embodiment, allocating memory to each code module according to the instruction priority of each code module to obtain the memory allocation amount of each code module includes: Determining the allocation ratio of each of the code modules according to the instruction priority of each of the code modules; The memory allocation amount of each code module is determined according to the total available memory amount and the allocation ratio of each code module.
[0011] In one embodiment, performing redundancy optimization on the program code in each of the code modules according to the instruction priority of each of the code modules to obtain the redundancy-free program code includes: Determining the priority interval to which each of the code modules belongs according to the instruction priority of each of the code modules; For the program codes in the code modules belonging to the first priority interval, redundant code simplification, loop nesting optimization, redundant function deletion and logic compression are performed; Performing logic reconstruction on the program code in the code module belonging to the second priority interval, and deleting unnecessary information and invalid code; Performing redundant instruction reduction processing on program codes in code modules belonging to the third priority interval; The instruction priority corresponding to the second priority interval is smaller than the instruction priority corresponding to the third priority interval, and larger than the instruction priority corresponding to the first priority interval.
[0012] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented: According to the programming requirement information, the pre-generated code is obtained through the generative AI model; Analyze the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module; Analyzing the complexity of the program code in each of the code modules to obtain a program complexity priority of each of the code modules; Analyze the time sensitivity of each of the code modules to obtain the time priority of each of the code modules; Determining the instruction priority of each of the code modules according to the attribute priority, the program complexity priority and the time priority; According to the instruction priority of each code module, the program code in each code module in the pre-generated code is optimized to obtain a final target program code.
[0013] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps: According to the programming requirement information, the pre-generated code is obtained through the generative AI model; Analyze the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module; Analyzing the complexity of the program code in each of the code modules to obtain a program complexity priority of each of the code modules; Analyze the time sensitivity of each of the code modules to obtain the time priority of each of the code modules; Determining the instruction priority of each of the code modules according to the attribute priority, the program complexity priority and the time priority; According to the instruction priority of each code module, the program code in each code module in the pre-generated code is optimized to obtain a final target program code.
[0014] The present invention has the following beneficial effects: According to the programming requirement information, the pre-generated code is obtained through the generative AI model, and then the hardware involved in each code module in the pre-generated code is analyzed to obtain the attribute priority of each code module, the complexity of the program code in each code module is analyzed to obtain the program complexity priority of each code module, the time sensitivity of each code module is analyzed to obtain the time priority of each code module, and then the instruction priority of each code module is determined according to the attribute priority, program complexity priority and time priority. Finally, according to the instruction priority of each code module, the program code in each code module in the pre-generated code is optimized to obtain the final target program code, which can reduce the redundancy of the program code obtained by generative AI-assisted programming, reduce memory usage, and improve code running efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0016] Figure 1 A flowchart of a programming assistance method based on generative AI provided by one embodiment of the present invention; Figure 2 A schematic diagram of a process for determining attribute priority provided by an embodiment of the present invention; Figure 3 A schematic diagram of a flow chart for determining a program complexity priority according to an embodiment of the present invention; Figure 4 A schematic diagram of a process for determining time priority provided by an embodiment of the present invention; Figure 5 An internal structural diagram of a computer device provided by one embodiment of the present invention; Figure 6 An internal structure diagram of a computer-readable storage medium provided for one embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of the programming assistance method based on generative AI, computer equipment and storage medium proposed by the present invention, its specific implementation method, structure, features and effects, in combination with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[0018] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0019] The following is a detailed description of a specific solution of a generative AI-based programming assistance method, a computer device, and a storage medium provided by the present invention in conjunction with the accompanying drawings.
[0020] See also Figure 1 , which shows a method flow chart of a programming assistance method based on generative AI provided by an embodiment of the present invention, comprising the following steps: Step 102, obtaining pre-generated code through a generative AI model according to programming requirement information.
[0021] Among them, the generative AI model is an artificial intelligence model that can automatically generate text, program code and other content. Pre-generated code is the initial code generated by the generative AI model based on programming requirements information, which is not optimized and not displayed to the user. The pre-generated code has the following characteristics: 1. It contains the code logic of all possible related modules; 2. The code is redundant and the code structure is complete but complex.
[0022] In one embodiment, a computer device may obtain programming requirement information input by a user, and generate pre-generated code through a generative AI model based on the programming requirement information.
[0023] In one embodiment, the programming requirement information input by the user may be preprocessed first, and then steps 102 to 112 are performed based on the preprocessed programming requirement information. In one embodiment, the preprocessing may include removing irrelevant content such as stop words and punctuation marks.
[0024] In one embodiment, a computer device may extract key functional vocabulary from programming requirement information, and then convert the key functional vocabulary into a semantic vector, match the semantic vector with a template vector through a generative AI model, and generate pre-generated code based on the matching result and the context in the programming requirement information.
[0025] Among them, the key functional vocabulary may include at least one of hardware-related instructions and operation instructions. For example, hardware-related instructions may include GPIO (General Purpose Input Output) and / or ADC (analog to digital converter). Operation instructions may include reading and / or initialization.
[0026] In one embodiment, the step of extracting key functional vocabulary from programming requirement information may include: segmenting the programming requirement information, then matching the segmentation result with words in a pre-built keyword library, and determining the key functional vocabulary according to a matching rate obtained by matching.
[0027] In one embodiment, word embedding technology can be used to convert key functional vocabulary into semantic vectors. In one embodiment, word embedding technology can use a one-hot encoding method and use a contextual semantic model. One-hot encoding is a simple encoding and is suitable for small instruction sets. The contextual semantic model may include deep learning models such as BERT and / or GPT. BERT model parameters: 12-layer Transformer, parameter scale 110M, hidden layer dimension 768. GPT-4 model parameters: model parameter scale exceeds 1700B, suitable for complex generation tasks.
[0028] In one embodiment, the semantic vector is matched with the template vector by a generative AI model, and the step of generating the pre-generated code according to the matching result combined with the context in the programming requirement information may include: inputting the semantic vector and the context in the programming requirement information into the generative AI model, calculating the semantic similarity between the semantic vector and the template vector by the generative AI model to obtain the semantic proximity, determining the matched vector according to the semantic proximity, and generating the pre-generated code according to the matched vector combined with the context in the programming requirement information and the predefined module. In one embodiment, the generative AI model may be a GPT series model or other similar large-scale generation model. The predefined module may include a GPIO initialization code template, etc. The semantic similarity calculation may adopt methods such as cosine similarity calculation, and the threshold may be set to be above 0.8. The temperature parameter may be set to 0.7 to control the randomness and diversity of the generated code. The maximum generated length may be set to 500~2000 characters to ensure the integrity of the code.
[0029] Step 104: Analyze the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module.
[0030] Among them, the attribute priority is the priority of the code module measured at the attribute level.
[0031] In one embodiment, the computer device may extract hardware-related keywords from each code module in the pre-generated code, and then determine the attribute priority of each code module according to the hardware-related keywords in each code module.
[0032] Among them, the hardware-related keywords are important keywords involved in the process of automated hardware burning and programming. In one embodiment, the hardware-related keywords may include at least one of the keywords such as important pin definition, real-time communication, analog-to-digital conversion and digital-to-analog conversion of signals in the process of automated hardware burning and programming. For example, the hardware-related keywords may include words related to hardware interfaces such as GPIO, UART (Universal Asynchronous Receiver and Transmitter) and ADC.
[0033] In one embodiment, natural language processing (NLP) technology may be used to extract hardware-related keywords from each code module in the pre-generated code through semantic parsing.
[0034] In one embodiment, the computer device may semantically vectorize the extracted hardware-related keywords to obtain hardware keyword vectors, and then determine the attribute priority of each code module according to the semantic results of the hardware keyword vectors corresponding to each code module.
[0035] In one embodiment, the extracted hardware-related keywords may be semantically vectorized based on the key instruction library provided in the programming requirement information. The semantic vectorization may adopt one-hot encoding or more advanced word embedding technology.
[0036] In one embodiment, a mapping table between code modules and hardware keyword vectors may be established, and then the attribute priority of each code module may be determined according to the semantic result of the hardware keyword vector corresponding to each code module.
[0037] Step 106: Analyze the complexity of the program code in each code module to obtain the program complexity priority of each code module.
[0038] Among them, the program complexity priority is the priority of the code module measured from the level of program complexity.
[0039] In one embodiment, the computer device can parse the loop nesting complexity of the program code in each code module and parse the function call complexity in each code module, and then determine the program complexity priority of each code module based on the loop nesting complexity and function call complexity of the code module.
[0040] In one embodiment, the loop nesting complexity can be determined according to the number of loop nesting levels, where the number of loop nesting levels is the number of nesting levels formed by loop logic in the program code, such as the number of nesting levels of loop logic such as for and while.
[0041] In one embodiment, the function call complexity may be determined based on at least one of the call depth and the number of calls of each function in the code module.
[0042] Step 108: Analyze the time sensitivity of each code module to obtain the time priority of each code module.
[0043] Among them, time priority is the priority of the code module measured from the perspective of time sensitivity.
[0044] In one embodiment, the time-sensitive situation may include at least one of the length of the interrupt response time and the periodic task scheduling situation.
[0045] Step 110, determining the instruction priority of each code module according to the attribute priority, program complexity priority and time priority.
[0046] Among them, the instruction priority is the overall priority of the code module obtained by measuring from multiple aspects.
[0047] In one embodiment, the instruction priority of each code module may be determined according to the product of the attribute priority, the program complexity priority, and the time priority.
[0048] In one embodiment, the instruction priority of a code module may be determined according to the following formula: Where n represents any code module. Indicates the instruction priority of code module n. Indicates the attribute priority of code module n. Indicates the program complexity priority of code module n. Indicates the time priority of code module n. Represents the normalization function.
[0049] In one embodiment, the complexity priority of the code module can be determined based on the product of the attribute priority of the code module and the program complexity priority, and then the instruction priority of the code module can be determined based on the product of the complexity priority of the code module and the time priority. The complexity priority of the code module can be determined according to the following formula: Where n represents any code module. Indicates the complex priority of code module n. Indicates the attribute priority of code module n. Indicates the program complexity priority of code module n.
[0050] Then determine the instruction priority of the code module according to the following formula: Where n represents any code module. Indicates the instruction priority of code module n. Indicates the time priority of code module n. Indicates the complex priority of code module n. Represents the normalization function.
[0051] Step 112, optimizing the program code in each code module in the pre-generated code according to the instruction priority of each code module to obtain the final target program code.
[0052] In one embodiment, the optimization may include performing at least one of memory allocation and redundancy elimination optimization on each code module.
[0053] In the above-mentioned programming assistance method based on generative AI, pre-generated code is obtained through a generative AI model according to programming requirement information, and then the hardware involved in each code module in the pre-generated code is analyzed to obtain the attribute priority of each code module, the complexity of the program code in each code module is analyzed to obtain the program complexity priority of each code module, the time sensitivity of each code module is analyzed to obtain the time priority of each code module, and then the instruction priority of each code module is determined according to the attribute priority, program complexity priority and time priority. Finally, according to the instruction priority of each code module, the program code in each code module in the pre-generated code is optimized to obtain the final target program code, which can reduce the redundancy of the program code obtained by generative AI-assisted programming, reduce memory usage, and improve code running efficiency.
[0054] In one embodiment, see Figure 2 Step 104 analyzes the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module, including the following steps: Step 202: extract hardware-related keywords from each code module in the pre-generated code.
[0055] Step 204: determine the attribute category of the hardware-related keywords in each code module.
[0056] In one embodiment, in the context of automated hardware flashing, the attribute categories may include core hardware and peripherals.
[0057] Among them, core hardware represents the keywords of the communication interface in the hardware. For example, the hardware-related keywords belonging to the core hardware attribute category may include GPIO, I2C (a bus) and SPI (Serial Peripheral Interface). Peripheral devices represent the keywords of the interactive devices in the hardware. The hardware-related keywords belonging to the peripheral device attribute category may include LED display and key control.
[0058] In one embodiment, the computer device may semantically vectorize the extracted hardware-related keywords to obtain hardware keyword vectors, and then determine the attribute category of the hardware-related keywords in each code module based on the semantic results of the hardware keyword vectors corresponding to each code module.
[0059] Step 206 , for each code module, determine the attribute priority of the code module according to the number of occurrences of the hardware-related keywords under each attribute category in the code module.
[0060] In one embodiment, the computer device may perform weighted summation on the number of occurrences of hardware-related keywords under each attribute category in each code module to obtain the attribute priority of the code module.
[0061] In one embodiment, the weights used in the weighted summation process can be set according to the following rule: the weight corresponding to the number of occurrences of the hardware-related keywords under the first attribute category is greater than the weight corresponding to the number of occurrences of the hardware-related keywords under the second attribute category. The hardware-related keywords under the first attribute category are more important than the hardware-related keywords under the second attribute category.
[0062] In the above embodiment, hardware-related keywords are extracted from each code module in the pre-generated code, and the attribute categories of the hardware-related keywords in each code module are determined. For each code module, the attribute priority of the code module can be accurately determined according to the number of occurrences of the hardware-related keywords under each attribute category in the code module.
[0063] In one embodiment, the attribute categories include core hardware and peripheral devices; for each code module, the attribute priority of the code module is determined according to the number of times hardware-related keywords under each attribute category in the code module appear, including: for each code module, the number of times hardware-related keywords under each attribute category in the code module appear is weighted summed to obtain the attribute priority of the code module; wherein the first weight used in the weighted summation is greater than the second weight; the first weight is the weight corresponding to the number of times hardware-related keywords with the attribute category of core hardware appear; the second weight is the weight corresponding to the number of times hardware-related keywords with the attribute category of peripheral devices appear.
[0064] In one embodiment, the step of performing weighted summation on the number of occurrences of hardware-related keywords under each attribute category in the code module to obtain the attribute priority of the code module may include: determining a first product between a first weight and the number of occurrences of hardware-related keywords with an attribute category of core hardware in the code module, and a second product between a second weight and the number of occurrences of hardware-related keywords with an attribute category of peripheral devices in the code module, and determining the attribute priority of the code module based on the sum of the first product and the second product.
[0065] In one embodiment, the sum of the first weight and the second weight may be equal to 1.
[0066] In one embodiment, the attribute priority of the code module may be determined according to the following formula: Where n represents any code module. Indicates the attribute priority of code module n. Indicates the number of occurrences of hardware-related keywords with the attribute category of core hardware in code module n. Indicates the number of occurrences of hardware-related keywords with the attribute category of peripherals in code module n. Represents the first weight. Represents the second weight. Represents the normalization function.
[0067] In one embodiment, the first weight It can be set to 0.8, thereby increasing the weight of the core hardware part in the attribute priority of the code module.
[0068] In the above embodiment, since the keywords of the core hardware category can determine whether the programming results are available or not, a higher weight is given to the core hardware. The weighted sum of the number of occurrences of the hardware-related keywords under each attribute category in the code module can accurately obtain the attribute priority of the code module. The higher the attribute priority, the higher the proportion of automated programming core code in the code module, and the more it needs to be given a higher priority in the code optimization process, so as to protect important pin allocation and communication.
[0069] In one embodiment, see Figure 3 Step 106 analyzes the complexity of the program code in each code module to obtain the program complexity priority of each code module, including the following steps: Step 302: parse the number of loop nesting levels of the program code in each code module.
[0070] In one embodiment, a code parser may be used to parse the number of loop nesting levels of program codes in each code module.
[0071] Step 304: parse the call depth and call count of each function in each code module.
[0072] In one embodiment, the function call tree of each code module may be parsed to determine the call depth and call count of each function in the code module.
[0073] Step 306 , for each code module, determine the program complexity priority of the code module according to the number of loop nesting levels of the code module and the call depth and call count of each function in the code module.
[0074] In one embodiment, the program complexity priority of a code module is negatively correlated with the number of loop nesting levels of the code module. The program complexity priority of a code module is negatively correlated with the call depth and call times of each function in the code module.
[0075] In one embodiment, the function call complexity of the code module can be determined based on the sum of the call depth and the number of calls of each function in the code module, and the program complexity priority of the code module can be determined based on the product of the number of loop nesting levels of the code module and the function call complexity.
[0076] In one embodiment, the program complexity priority of a code module is negatively correlated with the product of the number of loop nesting levels of the code module and the complexity of function calls. In one embodiment, the program complexity priority of a code module can be determined according to the inverse of the product of the number of loop nesting levels of the code module and the complexity of function calls.
[0077] In one embodiment, the program complexity priority of a code module may be determined according to the following formula: Where n represents any code module. Indicates the program complexity priority of code module n. Indicates the number of loop nesting levels of code module n. Indicates the call depth of code module n, including the call depth of each function in code module n. Indicates the number of calls to code module n, including the number of calls to each function in code module n. i indicates the order of functions in code module n. r indicates the total number of functions in code module n.
[0078] It can be understood that the higher the number of loop nesting levels, the higher the implementation time complexity in the code module, and the higher the memory occupancy rate of the code module. Therefore, in order to reduce its memory occupancy rate, ensure that the code module with high attribute priority executes the memory task first, and then implements the function of the code module with high loop nesting levels, and keep the code module with high loop nesting levels in an unawakened state until the control pin performs a wake-up operation, it is necessary to assign a lower program complexity priority to the code module with higher loop nesting levels. Therefore, the program complexity priority is negatively correlated with the number of loop nesting levels. The function call depth and call count can quantify the complexity of the function call in the implementation of the function of the code module. The higher the complexity of the function call, the more complex the implementation function of the program code, and the higher the memory allocation ratio. In order to reduce its memory occupancy rate, it is necessary to assign a lower program complexity priority to the code module with higher function call complexity. Therefore, the program complexity priority is negatively correlated with the function call depth and call count.
[0079] In one embodiment, the complex priority of a code module may be determined according to the following formula: Where n represents any code module. Indicates the complex priority of code module n. Indicates the attribute priority of code module n. Indicates the number of loop nesting levels of code module n. Indicates the call depth of code module n, including the call depth of each function in code module n. Indicates the number of calls to code module n, including the number of calls to each function in code module n. i indicates the order of functions in code module n. r indicates the total number of functions in code module n.
[0080] In the above embodiments, for each code module respectively, the program complexity priority of the code module can be accurately determined according to the number of loop nesting levels of the code module and the calling depth and calling number of each function in the code module, and the memory and execution time occupied by code modules with higher program logic complexity, such as jump modules or menu modules, can be accurately reduced.
[0081] In one embodiment, see Figure 4 Step 108 analyzes the time sensitivity of each code module to obtain the time priority of each code module, including the following steps: Step 402: determine the interrupt response time and task scheduling order according to the programming requirement information.
[0082] In one embodiment, the interrupt response time and task scheduling order required by the user may be extracted from the programming requirement information.
[0083] Step 404, determining the sequence value of each code module according to the task scheduling sequence.
[0084] Among them, the earlier the execution order of the code module in the task scheduling order, the smaller the order value; the later the execution order, the larger the order value.
[0085] In one embodiment, a scheduling analysis algorithm may be used to identify the order value of the code module. The scheduling analysis algorithm may include a fixed priority scheduling algorithm.
[0086] Step 406: Determine the time priority of each code module according to the interrupt response time and the order value of each code module.
[0087] In one embodiment, the time priority of the code module is positively correlated with the interrupt response time, and the time priority of the code module is negatively correlated with the order value of the code module.
[0088] In one embodiment, for each code module, the time priority of the code module is determined according to the ratio between the interrupt response time and the order value of the code module.
[0089] In one embodiment, the time priority of a code module may be determined according to the following formula: Where n represents any code module. Indicates the time priority of code module n. Indicates the interrupt response time. An ordinal value representing code module n.
[0090] It can be understood that, under the automated programming logic, the interrupt response time has the first priority treatment, the purpose is to prevent problems such as freezing during program operation, so the longer the interrupt response time, the higher the time priority of the code module, that is, the time priority of the code module is positively correlated with the interrupt response time. Since the smaller the order value of the code module, the earlier the execution order of the code module, that is, the higher the priority of execution, the higher the time priority should be, so the time priority of the code module is negatively correlated with the order value of the code module.
[0091] In the above embodiment, the time priority of each code module can be accurately determined according to the interrupt response time and the order value of each code module, so that time-sensitive code modules can be given a relatively high priority to cope with mechanisms such as interrupt restart when a program fails.
[0092] In one embodiment, according to the instruction priority of each code module, the program code in each code module in the pre-generated code is optimized to obtain the final target program code, including: according to the instruction priority of each code module, memory is allocated for each code module to obtain the memory allocation amount of each code module; according to the instruction priority of each code module, the program code in each code module is de-redundantly optimized to obtain the de-redundant program code; according to the memory allocation amount of each code module and the corresponding de-redundant program code, the final target program code is obtained.
[0093] In one embodiment, the memory allocation amount of the code module is positively correlated with the instruction priority of the code module.
[0094] In one embodiment, the priority interval to which each code module belongs can be determined according to the instruction priority of each code module, and then de-redundancy optimization is performed on each code module according to the priority interval to which each code module belongs to obtain de-redundant program code.
[0095] In the above embodiment, memory is allocated for each code module according to the instruction priority of each code module to obtain the memory allocation amount of each code module, and the program code in each code module is de-redundantly optimized according to the instruction priority of each code module to obtain de-redundant program code, and finally, the final target program code is obtained according to the memory allocation amount of each code module and the corresponding de-redundant program code, thereby increasing the proportion of key code modules in the memory, reducing the proportion of code modules with secondary functions, and reducing the redundancy of the code.
[0096] In one embodiment, memory is allocated to each code module according to the instruction priority of each code module to obtain the memory allocation amount of each code module, including: determining the allocation ratio of each code module according to the instruction priority of each code module; determining the memory allocation amount of each code module according to the total available memory and the allocation ratio of each code module.
[0097] In one embodiment, the priority sum can be obtained according to the sum of the instruction priorities of each code module, and the allocation ratio of the code module can be determined according to the ratio of the instruction priority of the code module to the priority sum.
[0098] In one embodiment, the memory allocation amount of the code module may be determined according to the product of the total available memory amount and the allocation ratio of the code module.
[0099] In one embodiment, the memory allocation of a code module may be determined according to the following formula: Where n represents any code module. Indicates the memory allocation for code module n. Indicates the instruction priority of code module n. Represents the sum of the instruction priorities of each code module. Indicates the total amount of available memory.
[0100] In the above embodiment, the allocation ratio of each code module is determined according to the instruction priority of each code module, and the memory allocation amount of each code module is determined according to the total available memory and the allocation ratio of each code module. Memory can be accurately allocated to each code module according to priority. A code module with a higher instruction priority is allocated a larger amount of memory, thereby increasing the proportion of key code modules in the memory to ensure functional integrity and reducing the proportion of code modules with secondary functions in the memory to reduce memory usage.
[0101] In one embodiment, according to the instruction priority of each code module, the program code in each code module is de-redundantly optimized to obtain de-redundant program code, including: determining the priority interval to which each code module belongs according to the instruction priority of each code module; performing redundant code simplification, loop nesting optimization, redundant function deletion and logic compression processing on the program code in the code module belonging to the first priority interval; performing logic reconstruction, and non-essential information and invalid code deletion processing on the program code in the code module belonging to the second priority interval; and performing redundant instruction reduction processing on the program code in the code module belonging to the third priority interval; wherein the instruction priority corresponding to the second priority interval is less than the instruction priority corresponding to the third priority interval, and greater than the instruction priority corresponding to the first priority interval.
[0102] In one embodiment, the first priority interval may be a low priority interval, the second priority interval may be a medium priority interval, and the third priority interval may be a high priority interval.
[0103] In one embodiment, the interval range of the instruction priority corresponding to each priority interval can be set according to actual needs. For example, the interval range of the instruction priority corresponding to the first priority interval can be 0 to 0.33. The interval range of the instruction priority corresponding to the second priority interval can be 0.33 to 0.66. The interval range of the instruction priority corresponding to the third priority interval can be 0.66 to 1.
[0104] In one embodiment, redundant code simplification may include simplifying and deleting redundant codes.
[0105] In one embodiment, loop nest optimization may include loop optimization and nest reduction.
[0106] In one embodiment, redundant function removal may include removing uncalled functions.
[0107] In one embodiment, a logic compression algorithm may be used to perform logic compression processing. For example, the logic compression algorithm may be a lookup table instead of complex calculations.
[0108] In one embodiment, the non-essential information may include non-essential debugging information.
[0109] In the above embodiment, the code modules in the third priority interval with high priority are only lightly optimized without affecting the functions, that is, redundant instructions are reduced, so as to ensure the functional integrity of the key code modules. The code modules in the first priority interval with low priority are slimmed down in multiple dimensions, and the code modules in the second priority interval with medium priority are appropriately slimmed down, so as to reduce the code redundancy.
[0110] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0111] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 5 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a programming assistance method based on generative AI is implemented.
[0112] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0113] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps of the generative AI-based programming assistance method in each embodiment of the present application are implemented.
[0114] In one embodiment, Figure 6 As shown, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the generative AI-based programming assistance method in each embodiment of the present application are implemented.
[0115] It should be noted that the data involved in this application (including but not limited to data used for analysis, stored data, displayed data, etc.) are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0116] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0117] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0118] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application.
[0119] It should be noted that the sequence of the above embodiments of the present invention is only for description and does not represent the advantages and disadvantages of the embodiments. The processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0120] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.
Claims
1. A programming assistance method based on generative AI, characterized in that: The method comprises: According to the programming requirement information, the pre-generated code is obtained through the generative AI model; Analyze the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module; Analyzing the complexity of the program code in each of the code modules to obtain the program complexity priority of each of the code modules; Analyze the time sensitivity of each of the code modules to obtain the time priority of each of the code modules; Determining the instruction priority of each of the code modules according to the attribute priority, the program complexity priority and the time priority; According to the instruction priority of each code module, the program code in each code module in the pre-generated code is optimized to obtain a final target program code.
2. A programming assistance method based on generative AI according to claim 1, characterized in that: The analyzing the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module includes: Extracting hardware-related keywords from each code module in the pre-generated code; Determining the attribute category of the hardware-related keywords in each of the code modules; For each of the code modules, the attribute priority of the code module is determined according to the number of occurrences of the hardware-related keywords under each attribute category in the code module.
3. A programming assistance method based on generative AI according to claim 2, characterized in that: The attribute categories include core hardware and peripheral devices; and for each of the code modules, determining the attribute priority of the code module according to the number of occurrences of hardware-related keywords under each attribute category in the code module, includes: For each of the code modules, weighted sum of the number of occurrences of hardware-related keywords under each attribute category in the code module is performed to obtain the attribute priority of the code module; Among them, the first weight used in the weighted summation is greater than the second weight; the first weight is the weight corresponding to the number of times hardware-related keywords with the attribute category of core hardware appear; the second weight is the weight corresponding to the number of times hardware-related keywords with the attribute category of peripheral devices appear.
4. A programming assistance method based on generative AI according to claim 1, characterized in that: The analyzing the complexity of the program code in each of the code modules to obtain the program complexity priority of each of the code modules includes: Analyze the number of loop nesting levels of the program code in each of the code modules; Analyze the call depth and call count of each function in each of the code modules; For each of the code modules, the program complexity priority of the code module is determined according to the number of loop nesting levels of the code module and the call depth and the call count of each function in the code module.
5. The programming assistance method based on generative AI according to claim 1, characterized in that: The analyzing the time sensitivity of each of the code modules to obtain the time priority of each of the code modules includes: Determine the interrupt response time and task scheduling order according to the programming requirement information; Determining the order value of each of the code modules according to the task scheduling order; The time priority of each of the code modules is determined according to the interrupt response time and the sequence value of each of the code modules.
6. A programming assistance method based on generative AI according to any one of claims 1 to 5, characterized in that: The step of optimizing the program code in each of the code modules in the pre-generated code according to the instruction priority of each of the code modules to obtain a final target program code includes: Allocate memory for each code module according to the instruction priority of each code module to obtain a memory allocation amount for each code module; According to the instruction priority of each code module, performing redundancy optimization on the program code in each code module to obtain a redundancy-free program code; The final target program code is obtained according to the memory allocation amount of each code module and the corresponding de-redundant program code.
7. A programming assistance method based on generative AI according to claim 6, characterized in that: The allocating memory for each code module according to the instruction priority of each code module to obtain the memory allocation amount of each code module includes: Determining the allocation ratio of each of the code modules according to the instruction priority of each of the code modules; The memory allocation amount of each code module is determined according to the total available memory amount and the allocation ratio of each code module.
8. The programming assistance method based on generative AI according to claim 6, characterized in that: The step of performing redundancy optimization on the program code in each of the code modules according to the instruction priority of each of the code modules to obtain the redundancy-free program code comprises: Determining the priority interval to which each of the code modules belongs according to the instruction priority of each of the code modules; For the program codes in the code modules belonging to the first priority interval, redundant code simplification, loop nesting optimization, redundant function deletion and logic compression are performed; Performing logic reconstruction on the program code in the code module belonging to the second priority interval, and deleting unnecessary information and invalid code; Performing redundant instruction reduction processing on program codes in code modules belonging to the third priority interval; The instruction priority corresponding to the second priority interval is smaller than the instruction priority corresponding to the third priority interval, and larger than the instruction priority corresponding to the first priority interval.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of a programming assistance method based on generative AI described in any one of claims 1 to 8 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of a programming assistance method based on generative AI described in any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Model compiling method and device, computer equipment and computer readable storage medium
CN116126341A
Code text generation method and device, equipment, storage medium and product
CN117453192A
Redundant code identification method and device, computer equipment and readable storage medium
CN119536739A
Code conversion method and device, computer equipment and storage medium
CN119621074A
Software code optimization method, system and equipment based on big data and medium
CN119645416A