Programming Assistance Method, Computer Device, and Storage Medium Based on Generative AI

By analyzing the hardware attributes, complexity and time sensitivity of the program code module output by generating AI, determining instruction priorities and optimizing it, the problem of generative AI code redundancy is solved, and the code operation efficiency and memory utilization are improved.

CN120010825BActive Publication Date: 2025-06-27CHANGCHUN ARCHITECTURE & CIVILENGEERING CO LLEGE
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510503311.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-22
Publication Date
2025-06-27
Estimated Expiration
2045-04-22

AI Technical Summary

Technical Problem

The program code output of generative AI has high redundancy, resulting in increased memory usage and reduced code operation efficiency.

Method used

Pre-generated code is generated through a generative AI model, the hardware attributes, program complexity and time sensitivity of each code module are analyzed, the instruction priority of each code module is determined, and optimization is carried out to remove redundant code.

Benefits of technology

It reduces the redundancy of program code obtained by generative AI-assisted programming, reduces memory usage, and improves code operation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120010825B_ABST
    Figure CN120010825B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of data processing, and specifically relates to a programming assistance method, a computer device, and a storage medium based on generative AI. A pre-generated code is obtained through a generative AI model according to programming requirement information; 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-sensitive situation of each code module is analyzed to obtain the time priority of each code module; according to the attribute priority, the program complexity priority, and the time priority, the instruction priority of each code module is determined; according to the instruction priority of each code module, the program code in each code module in the pre-generated code is optimized. Using this method can reduce the redundancy of the program code obtained by generative AI-assisted programming, reduce memory occupancy, and improve code running efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data processing, and in particular to a programming assistance method, a computer device, and a 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 Pretrained Transformer) series. The applications of generative AI in programming assistance are mainly reflected in the following aspects: 1. Generative AI can generate program code according to natural language descriptions; 2. When writing program code, generative AI can predict and complete code fragments in real time; 3. Generative AI can help identify errors in program code and provide repair suggestions; 4. Generative AI can suggest or automatically perform code refactoring to improve the readability, maintainability, and performance of the code. The AI model is trained with a large amount of code data to learn the syntax and common programming patterns of different programming languages, so as to achieve AI-assisted programming.

[0003] In traditional methods, in the process of the AI retrieving keywords based on user demand information and generating program code, especially in specific programming projects, such as the development of an automated control program, when programming and burning a hardware device, the reserved ROM of a single-chip microcomputer for program caching is usually small. The generated burning control program code usually has a high redundancy due to insufficient provision of user configuration requirements and other reasons, resulting in a large occupation of program memory. For example, there are invalid communication protocols or internal loops in the code, resulting in a high time complexity of the code when multiple module functions are combined. Summary of the Invention

[0004] In order to solve the technical problem of high redundancy of the program code output by generative AI, the purpose of the present invention is to provide a programming assistance method, a computer device, and a storage medium based on generative AI. The specific technical solutions adopted are as follows:

[0005] A programming assistance method based on generative AI, the method comprising:

[0006] Obtaining pre-generated code through a generative AI model according to programming requirement information;

[0007] Analyzing the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module;

[0008] Analyzing the complexity of the program code in each code module to obtain the program complexity priority of each code module;

[0009] Analyze the time-sensitive situations of each of the code modules to obtain the time priorities of each of the code modules;

[0010] Determine the instruction priorities of each of the code modules according to the attribute priorities, the program complexity priorities, and the time priorities;

[0011] Optimize the program codes in each of the code modules in the pre-generated code according to the instruction priorities of each of the code modules to obtain the final target program codes.

[0012] In one embodiment, analyzing the hardware involved in each code module in the pre-generated code to obtain the attribute priorities of each code module, including:

[0013] Extract the hardware-related keywords in each code module in the pre-generated code;

[0014] Determine the attribute categories of the hardware-related keywords in each of the code modules;

[0015] For each of the code modules, determine the attribute priorities of the code modules according to the number of occurrences of the hardware-related keywords in each attribute category in the code module.

[0016] In one embodiment, the attribute categories include core hardware and peripheral devices; for each of the code modules, determining the attribute priorities of the code modules according to the number of occurrences of the hardware-related keywords in each attribute category in the code module includes:

[0017] For each of the code modules, perform a weighted sum of the number of occurrences of the hardware-related keywords in each attribute category in the code module to obtain the attribute priorities of the code module;

[0018] Among them, the first weight used in the weighted sum is greater than the second weight; the first weight is the weight corresponding to the number of occurrences of the hardware-related keywords with the attribute category of core hardware; the second weight is the weight corresponding to the number of occurrences of the hardware-related keywords with the attribute category of peripheral devices.

[0019] In one embodiment, analyzing the complexity of the program codes in each of the code modules to obtain the program complexity priorities of each of the code modules, including:

[0020] Parse the number of loop nesting levels of the program codes in each of the code modules;

[0021] Parse the call depth and call times of each function in each of the code modules;

[0022] For each of the code modules, 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 times of each function in the code module.

[0023] In one embodiment, analyzing the time-sensitive situation of each code module to obtain the time priority of each code module includes:

[0024] Determine the interrupt response time and task scheduling order according to the programming requirement information;

[0025] Determine the sequence value of each code module according to the task scheduling order;

[0026] Determine the time priority of each code module according to the interrupt response time and the sequence value of each code module.

[0027] 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:

[0028] Allocate memory for each code module according to the instruction priority of each code module to obtain the memory allocation amount of each code module;

[0029] Perform redundancy removal optimization on the program code in each code module according to the instruction priority of each code module to obtain the redundancy-removed program code;

[0030] Obtain the final target program code according to the memory allocation amount of each code module and the corresponding redundancy-removed program code.

[0031] In one embodiment, 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:

[0032] Determine the allocation ratio of each code module according to the instruction priority of each code module;

[0033] Determine the memory allocation amount of each code module according to the total available memory amount and the allocation ratio of each code module.

[0034] In one embodiment, performing redundancy removal optimization on the program code in each code module according to the instruction priority of each code module to obtain the redundancy-removed program code includes:

[0035] Determine the priority interval to which each code module belongs according to the instruction priority of each code module;

[0036] Perform redundant code simplification, loop nesting optimization, redundant function deletion, and logic compression processing on the program code in the code modules belonging to the first priority interval;

[0037] Perform logic reconstruction and delete unnecessary information and invalid code on the program code in the code modules belonging to the second priority interval;

[0038] Perform redundant instruction reduction on the program code in the code modules belonging to the third priority interval;

[0039] Among them, 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.

[0040] A computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the following steps are implemented:

[0041] Obtain pre-generated code through a generative AI model according to programming requirement information;

[0042] Analyze the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module;

[0043] Analyze the complexity of the program code in each code module to obtain the program complexity priority of each code module;

[0044] Analyze the time-sensitive situation of each code module to obtain the time priority of each code module;

[0045] Determine the instruction priority of each code module according to the attribute priority, the program complexity priority, and the time priority;

[0046] Optimize 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.

[0047] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the following steps are implemented:

[0048] Obtain pre-generated code through a generative AI model according to programming requirement information;

[0049] Analyze the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module;

[0050] Analyze the complexity of the program code in each code module to obtain the program complexity priority of each code module;

[0051] Analyze the time sensitivity of each code module to obtain the time priority of each code module;

[0052] According to the attribute priority, the program complexity priority, and the time priority, determine the instruction priority of each code module;

[0053] Optimize 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.

[0054] The present invention has the following beneficial effects:

[0055] According to the programming requirement information, obtain the pre-generated code through the generative AI model, then analyze the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module, analyze the complexity of the program code in each code module to obtain the program complexity priority of each code module, analyze the time sensitivity of each code module to obtain the time priority of each code module, and then determine the instruction priority of each code module according to the attribute priority, the program complexity priority, and the time priority. Finally, optimize 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, which can reduce the redundancy of the program code obtained by generative AI-assisted programming, reduce memory occupancy, and improve the code running efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0057] Figure 1 It is a schematic flowchart of a programming assistance method based on generative AI provided by an embodiment of the present invention;

[0058] Figure 2 It is a schematic flowchart of determining the attribute priority provided by an embodiment of the present invention;

[0059] Figure 3 Flow chart showing the process of determining the complexity priority of a program provided by an embodiment of the present invention;

[0060] Figure 4 Flow chart showing the process of determining the time priority provided by an embodiment of the present invention;

[0061] Figure 5 Internal structure diagram of a computer device provided by an embodiment of the present invention;

[0062] Figure 6 Internal structure diagram of a computer-readable storage medium provided by an embodiment of the present invention. Detailed implementation manners

[0063] In order to further elaborate on the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following, in combination with the accompanying drawings and preferred embodiments, details the specific implementation manners, structures, features and effects of a programming assistance method, a computer device and a storage medium based on generative AI according to the present invention. In the following description, different "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. In addition, the specific features, structures or characteristics in one or more embodiments can be combined in any suitable form.

[0064] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field to which the present invention belongs.

[0065] The following specifically describes the specific solutions of a programming assistance method, a computer device and a storage medium based on generative AI provided by the present invention with reference to the accompanying drawings.

[0066] Please refer to Figure 1 , which shows a flowchart of a programming assistance method based on generative AI provided by an embodiment of the present invention, including the following steps:

[0067] Step 102, obtaining pre-generated code through a generative AI model according to programming requirement information.

[0068] Among them, the generative AI model is an artificial intelligence model that can automatically generate contents such as text and program code. The pre-generated code is the initial code generated by the generative AI model according to the programming requirement information, which has not been optimized and is not shown to the user. The pre-generated code has the following characteristics: 1. It contains the code logic of all possible relevant modules; 2. There is code redundancy, and the code structure is complete but complex.

[0069] In one embodiment, the computer device can obtain the programming requirement information input by the user, and generate pre-generated code through the generative AI model according to the programming requirement information.

[0070] In one embodiment, the programming requirement information input by the user can be preprocessed first, and then steps 102 to 112 can be executed based on the preprocessed programming requirement information. In one embodiment, the preprocessing may include removing irrelevant content such as stop words and punctuation marks.

[0071] In one embodiment, the computer device can extract key function words from the programming requirement information, then convert the key function words into semantic vectors, match the semantic vectors with template vectors through a generative AI model, and generate pre-generated code according to the matching result in combination with the context in the programming requirement information.

[0072] Among them, the key function words may include at least one of hardware-related instructions and operation instructions. For example, the hardware-related instructions may include GPIO (General Purpose Input Output) and / or ADC (analog to digital converter), etc. The operation instructions may include reading and / or initializing, etc.

[0073] In one embodiment, the step of extracting key function words from the programming requirement information may include: the programming requirement information can be segmented, and then the segmentation results are matched with the words in the pre-constructed keyword library, and the key function words are determined according to the obtained matching rate.

[0074] In one embodiment, word embedding technology can be used to convert the key function words into semantic vectors. In one embodiment, the word embedding technology may adopt the one-hot encoding method and use the context semantic model. One-hot encoding belongs to simple encoding and is suitable for small instruction sets. The context semantic model may include deep learning models such as BERT and / or GPT. Model parameters of BERT: 12-layer Transformer, parameter scale 110M, hidden layer dimension 768. Model parameters of GPT-4: model parameter scale exceeds 1700B, suitable for complex generation tasks.

[0075] In one embodiment, the steps of generating pre-generated code by matching semantic vectors with template vectors through a generative AI model and combining the context in the programming requirement information according to the matching result may include: inputting the semantic vectors and the context in the programming requirement information into the generative AI model, calculating the semantic similarity between the semantic vectors and the template vectors through the generative AI model to obtain the semantic proximity, determining the matched vectors according to the semantic proximity, and generating pre-generated code according to the matched vectors in combination with the context and predefined modules in the programming requirement information. In one embodiment, the generative AI model may be a GPT series model or other similar large-scale generative models. The predefined modules may include GPIO initialization code templates, etc. The semantic similarity calculation may adopt methods such as cosine similarity calculation, and the threshold may be set above 0.8. The temperature parameter may be set to 0.7 to control the randomness and diversity of the generated code. The maximum generation length may be set to 500 - 2000 characters to ensure the integrity of the code.

[0076] Step 104: Analyze the hardware involved in each code module in the pre-generated code to obtain the attribute priority of each code module.

[0077] Among them, the attribute priority is the priority of the code module measured from the attribute level.

[0078] In one embodiment, the computer device may extract the hardware-related keywords in each code module of the pre-generated code, and then determine the attribute priority of each code module according to the hardware-related keywords in each code module.

[0079] Among them, the hardware-related keywords are important keywords involved in the automated hardware burning programming process. In one embodiment, the hardware-related keywords may include at least one of important pin definitions, real-time communication, analog-to-digital conversion and digital-to-analog conversion of signals, etc. in the automated hardware burning programming process. For example: the hardware-related keywords may include words related to hardware interfaces such as GPIO, UART (Universal Asynchronous Receiver and Transmitter), and ADC.

[0080] In one embodiment, natural language processing (NLP) technology may be used to extract the hardware-related keywords in each code module of the pre-generated code through semantic parsing.

[0081] In one embodiment, the computer device can 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.

[0082] In one embodiment, based on the key instruction library provided in the programming requirement information, the extracted hardware-related keywords can be semantically vectorized. Semantic vectorization can employ one-hot encoding or more advanced word embedding techniques, etc.

[0083] In one embodiment, a mapping table can be established between the code modules and the hardware keyword vectors, and then the attribute priority of each code module can be determined according to the semantic results of the hardware keyword vectors corresponding to each code module.

[0084] Step 106: Analyze the complexity of the program code in each code module to obtain the program complexity priority of each code module.

[0085] Among them, the program complexity priority is the priority of the code module measured from the level of program complexity.

[0086] 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 for each code module, determine the program complexity priority of the code module according to the loop nesting complexity and function call complexity of the code module.

[0087] In one embodiment, the loop nesting complexity can be determined according to the number of loop nesting levels. Among them, the number of loop nesting levels is the number of nested layers formed by the loop logic in the program code. For example: the number of nested layers of loop logics such as for and while.

[0088] In one embodiment, the function call complexity can be determined according to at least one of the call depth and call frequency of each function in the code module.

[0089] Step 108: Analyze the time-sensitive situation of each code module to obtain the time priority of each code module.

[0090] Among them, the time priority is the priority of the code module measured from the level of time sensitivity.

[0091] In one embodiment, the time-sensitive situation can include at least one of the length of the interrupt response time and the periodic task scheduling situation, etc.

[0092] Step 110: Determine the instruction priority of each code module according to the attribute priority, program complexity priority, and time priority.

[0093] Among them, the instruction priority is the overall priority of the code module measured from multiple aspects.

[0094] In one embodiment, the instruction priority of each code module can be determined according to the product of the attribute priority, program complexity priority, and time priority.

[0095] In one embodiment, the instruction priority of the code module can be determined according to the following formula:

[0096]

[0097] Among them, n represents any code module. represents the instruction priority of code module n. represents the attribute priority of code module n. represents the program complexity priority of code module n. represents the time priority of code module n. represents the normalization function.

[0098] In one embodiment, the complexity priority of the code module can be determined first according to the product of the attribute priority and program complexity priority of the code module, and then the instruction priority of the code module can be determined according to the product of the complexity priority and time priority of the code module. The complexity priority of the code module can be determined according to the following formula:

[0099]

[0100] Among them, n represents any code module. represents the complexity priority of code module n. represents the attribute priority of code module n. represents the program complexity priority of code module n.

[0101] Then the instruction priority of the code module is determined according to the following formula:

[0102]

[0103] Among them, n represents any code module. represents the instruction priority of code module n. represents the time priority of code module n. represents the complexity priority of code module n. represents the normalization function.

[0104] Step 112, optimize the program code in each code module of the pre-generated code according to the instruction priority of each code module to obtain the final target program code.

[0105] In one embodiment, the optimization may include at least one of memory allocation and redundancy removal optimization for each code module.

[0106] In the above programming assistance method based on generative AI, according to the programming requirement information, obtain the pre-generated code through the generative AI model, then analyze the hardware involved in each code module of the pre-generated code to obtain the attribute priority of each code module, analyze the complexity of the program code in each code module to obtain the program complexity priority of each code module, analyze the time-sensitive situation of each code module to obtain the time priority of each code module, and then determine the instruction priority of each code module according to the attribute priority, program complexity priority and time priority. Finally, optimize the program code in each code module of the pre-generated code according to the instruction priority of each code module to obtain the final target program code, which can reduce the redundancy of the program code obtained by generative AI-assisted programming, reduce memory occupancy, and improve code running efficiency.

[0107] In one embodiment, refer to Figure 2 , step 104 analyzes the hardware involved in each code module of the pre-generated code to obtain the attribute priority of each code module, including the following steps:

[0108] Step 202, extract the hardware-related keywords in each code module of the pre-generated code.

[0109] Step 204, determine the attribute category of the hardware-related keywords in each code module.

[0110] In one embodiment, in the context of automated hardware burning, the attribute category may include core hardware and peripheral devices.

[0111] Among them, the core hardware represents the keywords of the communication interface in the hardware. For example, the hardware-related keywords belonging to the attribute category of core hardware may include GPIO, I2C (a bus), and SPI (Serial Peripheral Interface), etc. The peripheral device represents the keywords of the interaction device in the hardware. The hardware-related keywords belonging to the attribute category of peripheral devices may include LED display and button control, etc.

[0112] In one embodiment, the computer device may semantically vectorize the extracted hardware-related keywords to obtain hardware keyword vectors, and then determine the attribute categories of the hardware-related keywords in each code module according to the semantic results of the hardware keyword vectors corresponding to each code module.

[0113] 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 in each attribute category in the code module.

[0114] In one embodiment, the computer device may, for each code module, perform a weighted sum of the number of occurrences of the hardware-related keywords in each attribute category in the code module to obtain the attribute priority of the code module.

[0115] In one embodiment, the weights used in the weighted sum process may be set according to the following rules: The weight corresponding to the number of occurrences of the hardware-related keywords in the first attribute category is greater than the weight corresponding to the number of occurrences of the hardware-related keywords in the second attribute category. The hardware-related keywords in the first attribute category are more important than the hardware-related keywords in the second attribute category.

[0116] In the above embodiment, by extracting the hardware-related keywords in each code module of the pre-generated code, determining the attribute categories of the hardware-related keywords in each code module, and for each code module, according to the number of occurrences of the hardware-related keywords in each attribute category in the code module, the attribute priority of the code module can be accurately determined.

[0117] In one embodiment, the attribute categories include core hardware and peripheral devices; for each code module, determining the attribute priority of the code module according to the number of occurrences of the hardware-related keywords in each attribute category in the code module includes: for each code module, performing a weighted sum of the number of occurrences of the hardware-related keywords in each attribute category in the code module to obtain the attribute priority of the code module; wherein, the first weight used in the weighted sum is greater than the second weight; the first weight is the weight corresponding to the number of occurrences of the hardware-related keywords with the attribute category of core hardware; the second weight is the weight corresponding to the number of occurrences of the hardware-related keywords with the attribute category of peripheral devices.

[0118] In one embodiment, the step of obtaining the attribute priority of a code module by performing a weighted sum of the occurrences of hardware-related keywords under each attribute category in the code module may include: determining a first product between a first weight and the number of occurrences of hardware-related keywords with the 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 the attribute category of peripheral devices in the code module, and determining the attribute priority of the code module according to the sum of the first product and the second product.

[0119] In one embodiment, the sum of the first weight and the second weight may be equal to 1.

[0120] In one embodiment, the attribute priority of a code module may be determined according to the following formula:

[0121]

[0122] where n represents any code module. represents the attribute priority of code module n. represents the number of occurrences of hardware-related keywords with the attribute category of core hardware in code module n. represents the number of occurrences of hardware-related keywords with the attribute category of peripheral devices in code module n. represents the first weight. represents the second weight. represents the normalization function.

[0123] In one embodiment, the first weight may be set to 0.8. Thus, the weight proportion of the core hardware part in the attribute priority of the code module is amplified.

[0124] In the above embodiment, since the keywords of the core hardware category can determine whether the programming result is available, a higher weight is given to the core hardware. By performing a weighted sum of the occurrences of hardware-related keywords under each attribute category in the code module, the attribute priority of the code module can be accurately obtained. The higher the attribute priority, the higher the proportion of the core code of automated programming in the code module, and the higher the priority needs to be given during the code optimization process, so as to protect important pin assignments and communications.

[0125] In one embodiment, referring to 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:

[0126] Step 302, parsing the number of loop nesting levels of the program code in each code module.

[0127] In one embodiment, a code parser can be used to parse the number of levels of loop nesting in the program code of each code module.

[0128] Step 304, parse the call depth and call count of each function in each code module.

[0129] In one embodiment, the function call tree of each code module can be parsed to determine the call depth and call count of each function in the code module.

[0130] Step 306, for each code module respectively, determine the program complexity priority of the code module according to the number of levels of loop nesting in the code module and the call depth and call count of each function in the code module.

[0131] In one embodiment, the program complexity priority of a code module is negatively correlated with the number of levels of loop nesting in the code module. The program complexity priority of a code module is negatively correlated with the call depth and call count of each function in the code module.

[0132] In one embodiment, the function call complexity of a code module can be determined according to the sum of the call depth and call count of each function in the code module, and the program complexity priority of the code module can be determined according to the product of the number of levels of loop nesting in the code module and the function call complexity.

[0133] In one embodiment, the program complexity priority of a code module is negatively correlated with the product of the number of levels of loop nesting in the code module and the function call complexity. In one embodiment, the program complexity priority of a code module can be determined according to the reciprocal of the product of the number of levels of loop nesting in the code module and the function call complexity.

[0134] In one embodiment, the program complexity priority of a code module can be determined according to the following formula:

[0135]

[0136] Where n represents any code module. represents the program complexity priority of code module n. represents the number of levels of loop nesting in code module n. represents the call depth of code module n, which includes the call depths corresponding to each function in code module n respectively. represents the call count of code module n, which includes the call counts corresponding to each function in code module n respectively. i represents the order of the functions in code module n. r represents the total number of functions in code module n.

[0137] It can be understood that the higher the level of loop nesting, the higher the implementation time complexity within 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 a higher attribute priority executes memory tasks first, then implement the functions of the code module with a higher level of loop nesting, and keep the code module with a higher level of loop nesting in an unawakened state until the control pin performs an awakening operation, it is necessary to assign a lower program complexity priority to the code module with a higher level of loop nesting. Therefore, the program complexity priority is negatively correlated with the level of loop nesting. The call depth and call times of a function can quantify the complexity of function calls in the implementation of a code module. The higher the complexity of function calls, the more complex the implemented 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 a higher complexity of function calls. Therefore, the program complexity priority is negatively correlated with the call depth and call times of the function.

[0138] In one embodiment, the complexity priority of a code module can be determined according to the following formula:

[0139]

[0140] Where n represents any code module. represents the complexity priority of code module n. represents the attribute priority of code module n. represents the level of loop nesting of code module n. represents the call depth of code module n, which includes the call depths corresponding to each function in code module n. represents the call times of code module n, which includes the call times corresponding to each function in code module n. i represents the order of the functions in code module n. r represents the total number of functions in code module n.

[0141] In the above embodiment, for each code module, according to the level of loop nesting of the code module and the call depth and call times of each function in the code module, the program complexity priority of the code module can be accurately determined, and the occupancy of memory and execution time by the code module with a higher program logic complexity can be accurately reduced, such as a jump module or a menu module, etc.

[0142] In one embodiment, refer to 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:

[0143] Step 402, determine the interrupt response time and task scheduling order according to the programming requirement information.

[0144] In one embodiment, the interrupt response time and the task scheduling order required by the user can be extracted from the programming requirement information.

[0145] Step 404: Determine the sequence value of each code module according to the task scheduling order.

[0146] Among them, the earlier the execution order of the code module in the task scheduling order, the smaller the sequence value; the later the execution order, the larger the sequence value.

[0147] In one embodiment, a scheduling analysis algorithm can be used to identify the sequence value of the code module. The scheduling analysis algorithm can include a fixed-priority scheduling algorithm.

[0148] Step 406: Determine the time priority of each code module according to the interrupt response time and the sequence value of each code module.

[0149] In one embodiment, the time priority of the code module is positively correlated with the interrupt response time. The time priority of the code module is negatively correlated with the sequence value of the code module.

[0150] In one embodiment, for each code module respectively, according to the ratio between the interrupt response time and the sequence value of the code module, the time priority of the code module is determined.

[0151] In one embodiment, the time priority of the code module can be determined according to the following formula:

[0152]

[0153] Among them, n represents any code module. represents the time priority of code module n. represents the interrupt response time. represents the sequence value of code module n.

[0154] It can be understood that since under the automated programming logic, the interrupt response time has the first-priority processing, the purpose is to prevent problems such as the program getting stuck during operation. Therefore, 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 sequence value of the code module, the earlier the execution order of the code module, that is, the more priority it has for execution, then the time priority should be higher. Therefore, the time priority of the code module is negatively correlated with the sequence value of the code module.

[0155] In the above embodiment, according to the interrupt response time and the sequence value of each code module, the time priority of each code module can be accurately determined, so that a relatively high priority can be given to the time-sensitive code module to cope with mechanisms such as interrupt restart when the program goes wrong.

[0156] In one embodiment, according to the instruction priorities 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: allocating memory for each code module according to the instruction priorities of each code module to obtain the memory allocation amount of each code module; performing redundancy removal optimization on the program code in each code module according to the instruction priorities of each code module to obtain the redundancy-removed program code; and obtaining the final target program code according to the memory allocation amount of each code module and the corresponding redundancy-removed program code.

[0157] In one embodiment, the memory allocation amount of a code module is positively correlated with the instruction priority of the code module.

[0158] 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 redundancy removal optimization is performed on each code module according to the priority interval to which each code module belongs to obtain the redundancy-removed program code.

[0159] 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, the program code in each code module is subjected to redundancy removal optimization according to the instruction priority of each code module to obtain the redundancy-removed program code, and finally the final target program code is obtained according to the memory allocation amount of each code module and the corresponding redundancy-removed program code, thereby increasing the proportion of critical code modules in memory, reducing the proportion of code modules with secondary functions, and reducing the redundancy of the code.

[0160] In one embodiment, 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 code module according to the instruction priority of each code module; and determining the memory allocation amount of each code module according to the total available memory amount and the allocation ratio of each code module.

[0161] In one embodiment, the total priority can be obtained according to the sum of the instruction priorities of each code module. The allocation ratio of the code module is determined according to the ratio of the instruction priority of the code module to the total priority.

[0162] In one embodiment, the memory allocation amount of the code module can be determined according to the product of the total available memory amount and the allocation ratio of the code module.

[0163] In one embodiment, the memory allocation amount of the code module can be determined according to the following formula:

[0164]

[0165] Among them, n represents any code module. Represents the memory allocation amount of code module n. Represents the instruction priority of code module n. Represents the sum of the instruction priorities of each code module. Represents the total available memory amount.

[0166] In the above embodiments, according to the instruction priorities of each code module, the allocation ratio of each code module is determined. According to the total available memory amount and the allocation ratio of each code module, the memory allocation amount of each code module is determined, which can accurately allocate memory for each code module according to the priority. The higher the instruction priority of the code module, the larger the allocated memory, so as to increase the proportion of critical code modules in the memory, ensure functional integrity, and reduce the proportion of code modules of secondary functions in the memory to reduce memory occupancy.

[0167] In one embodiment, according to the instruction priorities of each code module, the program code in each code module is optimized for redundancy removal, and the redundant program code is obtained, 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 modules belonging to the first priority interval; performing logic reconstruction, as well as non-essential information and invalid code deletion processing on the program code in the code modules belonging to the second priority interval; performing redundant instruction reduction processing on the program code in the code modules 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.

[0168] In one embodiment, the first priority interval can be a low priority interval, the second priority interval can be a medium priority interval, and the third priority interval can be a high priority interval.

[0169] In one embodiment, the range of the instruction priority corresponding to each priority interval can be set according to actual needs. For example: the range of the instruction priority corresponding to the first priority interval can be from 0 to 0.33. The range of the instruction priority corresponding to the second priority interval can be from 0.33 to 0.66. The range of the instruction priority corresponding to the third priority interval can be from 0.66 to 1.

[0170] In one embodiment, redundant code simplification may include simplifying and deleting redundant code.

[0171] In one embodiment, loop nest optimization may include optimization of loops and reduction of nesting.

[0172] In one embodiment, dead function elimination may include deleting functions that are not called.

[0173] In one embodiment, a logic compression algorithm may be employed for logic compression processing. For example, the logic compression algorithm may be using a lookup table to replace complex calculations.

[0174] In one embodiment, non-essential information may include non-essential debugging information.

[0175] In the above embodiments, for the code modules in the third priority interval with high priority, lightweight optimization is performed only on the premise of not affecting the function, that is, redundant instruction reduction processing, so as to ensure the functional integrity of the key code modules. For the code modules in the first priority interval with low priority, multi-dimensional slimming is performed, and for the code modules in the second priority interval with medium priority, appropriate slimming is performed, thereby reducing the code redundancy.

[0176] It should be understood that although the steps in the flowcharts involved in the above-described embodiments are sequentially shown according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this document, the execution of these steps has no strict order restriction, and these steps can be executed in other orders. Moreover, at least some of the steps in the flowcharts involved in the above-described embodiments may 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 sequential, but can be executed alternately or alternately with at least a part of other steps or steps or stages in other steps.

[0177] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as Figure 5As shown in the figure. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated 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 external devices. The communication interface of the computer device is used to communicate with external terminals through a network connection. When the computer program is executed by the processor, it implements a programming assistance method based on generative AI.

[0178] Those skilled in the art can understand that Figure 5 the structure shown in the figure is only a block diagram of some structures 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 different component arrangements.

[0179] In an exemplary embodiment, a computer device is provided, including a memory and a processor. A computer program is stored in the memory. When the processor executes the computer program, it implements the steps in the programming assistance method based on generative AI in various embodiments of the present application.

[0180] In one embodiment, as Figure 6 shown, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by the processor, it implements the steps in the programming assistance method based on generative AI in various embodiments of the present application.

[0181] It should be noted that the data involved in the present application (including but not limited to data for analysis, stored data, displayed data, etc.) are all information and data authorized by users or fully authorized by all parties, and the collection, use, and processing of relevant data need to comply with relevant regulations.

[0182] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. 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 methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. 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. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in the present application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., and are not limited thereto. The processors involved in the embodiments provided in the present application can be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, data processing logics based on quantum computing, etc., and are not limited thereto.

[0183] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, 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, it should be considered to be within the scope described in this specification.

[0184] The above-described embodiments merely represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application.

[0185] It should be noted that the above order of the embodiments of the present invention is only for description and does not represent the superiority or inferiority of the embodiments. The processes depicted in the accompanying drawings do not necessarily require the particular order or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0186] Each embodiment in this specification is described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other. The key point of each embodiment is to illustrate 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 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; 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; 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, determining 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; 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.

2. 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.

3. A 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.

4. A programming assistance method based on generative AI according to any one of claims 1 to 3, 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.

5. A programming assistance method based on generative AI according to claim 4, 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.

6. A programming assistance method based on generative AI according to claim 4, 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.

7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: 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 6 are implemented.

8. 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 6 are implemented.

Citation Information

Patent Citations

  • Code text generation method and device, equipment, storage medium and product

    CN117453192A

  • Software code optimization method, system and equipment based on big data and medium

    CN119645416A

  • Method and device for detecting code quality

    CN119782174A