Code conversion system and method based on multiple agents

By using a multi-agent code conversion system, the problems of complexity and reliability in cross-language development are solved, achieving efficient and flexible code conversion that adapts to different coding styles and long code processing.

CN121832945APending Publication Date: 2026-04-10HEFEI SUXIN MICROELECTRONICS TECHNOLOGY CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-17
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Existing code conversion tools suffer from problems such as complexity, time consumption, and error-proneness in cross-language development. They are particularly difficult to adapt to complex structures and different coding styles. Furthermore, AI-based methods lack sufficient data and have limited model intelligence, making it difficult to guarantee the correctness and reliability of the conversion results.

Method used

A multi-agent-based code conversion system is adopted. By inserting block delimiters into the source code for preprocessing, creating code description files, and using multi-agents for module-by-module generation and debugging, the target code is ensured to meet hardware functional requirements and adapt to conversions of various code styles and no mapping relationships.

Benefits of technology

It improves the reliability and quality of code conversion, reduces the pressure of handling long contexts for large models, can handle thousands to tens of thousands of lines of code, adapts to diverse coding styles, and ensures conversion quality through multiple debugging sessions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121832945A_ABST
    Figure CN121832945A_ABST
Patent Text Reader

Abstract

The invention provides a multi-agent-based code conversion system and method. The method comprises the following steps: preprocessing an input source code; performing block processing on the source code to obtain source code blocks, obtaining variable information and array size information of the blocks corresponding to the source code, and integrating the variable information and the array size information into complete variable information; fusing the code description file, the code blocks of the source codes and the variable information of the blocks corresponding to the source codes to generate target code blocks; debugging and checking the target code blocks in combination with the source code blocks; the code description file is used for guiding the intelligent agent to establish a jumping type relation in the code conversion process, and it is ensured that the generated target code better meets the actual function requirement of hardware; a block identifier is inserted into a long code to divide the long code into a plurality of blocks, so that the limitation on long code conversion is relieved; codes of different styles can be output by simply adjusting the cue word of the intelligent agent; through multiple times of debugging verification, the conversion quality of the target code is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of software development, and particularly to a code conversion system and method based on multi-agent. BACKGROUND

[0002] In the development process of digital integrated circuits (ICs), cross-language development is a common requirement, that is, algorithm modeling is performed using a high-level programming language, and actual hardware implementation is completed using a hardware description language (HDL). Due to significant differences between the high-level programming language and the underlying hardware description language in terms of syntax structure, abstraction level, and execution model, the conversion process between the two languages is complex, time-consuming, and prone to errors, and therefore a code conversion tool is in great demand.

[0003] There are two existing code conversion methods. One is a script or rule-based conversion method. This method converts code based on scripts or specific functional configurations, and has strict requirements for the quality and structure of the code to be converted, including code format and coding style. The code conversion is performed through a fixed mode, which is difficult to adapt to diverse code styles brought by different code personnel and cannot meet the needs of the source code. Moreover, it can only handle syntax with explicit mapping structure and is difficult to handle complex structures such as classes, structures, and timing logic. These limitations actually sacrifice the advantages of high-level programming languages in expressiveness and flexibility, increasing the additional workload of source code developers. In addition, the underlying code is not open and is less maintained, making it difficult to respond promptly when bugs occur and lacking corresponding solutions, which makes the script or rule-based conversion method have obvious limitations in dealing with complex and large-scale engineering design.

[0004] The other is an artificial intelligence (AI)-based conversion method. This method has two branches. One is to build an intermediate representation and use a neural network model to complete the conversion from the source language to the target language. The other is to train an LLM model for code conversion, which is less common. The AI-based code conversion method has very high requirements for code data of the source language and the target language. Since there is little corpus for some code languages and very few related data sets, there is a lack of sufficient data to train a powerful neural network. Since the code in the IC field is generally long, the model is greatly limited in processing long code. The intelligence level of the small model obtained based on the current data resources and training methods is limited, and the correctness and reliability of the conversion result are still difficult to guarantee. Especially when facing complex language structures such as object-oriented features, composite data types, and precise timing behaviors, the quality and functional correctness of the generated code are often poor. It can only handle basic syntax units with explicit conversion rules and is difficult to handle the conversion between source languages and target languages without mapping relationships.

[0005] Therefore, there is an urgent need for a code conversion system and method that integrates processing long context, adapting to various code styles and ways, and converting source code and target code without mapping relationship, to meet the needs of multilingual development scenarios. SUMMARY

[0006] To solve the above problems, the application provides a code conversion system and method based on multiple agents, which can guide the agent to establish a jump connection in the code conversion process through the code description file, ensure that the generated target code is more in line with the actual functional requirements of the hardware, and through the insertion of block identifiers in long code to divide it into multiple blocks, the restriction on long code conversion is removed, and different styles of code can be output by simply adjusting the agent prompt words, and through multiple debugging and verification, the conversion quality of the target code is guaranteed.

[0007] To achieve the above purpose, the technical scheme adopted by the application is: The application provides a code conversion system based on multiple agents, comprising a pre-preparation module, a labeling auxiliary module, a code generation module and a debug module connected in communication; The pre-preparation module is used for preprocessing the source code, and the preprocessing includes inserting block symbols in the source code, labeling variable information according to requirements, and writing a code description file for the source code; The labeling auxiliary module is used for obtaining the source code blocks and the variable information corresponding to the blocks, the array size information of the variables, and integrating the variable information corresponding to the source code blocks and the array size information of the variables into complete variable information; The code generation module is used for fusing the code description file, the source code blocks and the variable information, generating target code blocks by calling code generation agents module by module, and outputting the target code blocks; The debug module is used for debugging and verifying the obtained target code blocks in combination with the source code blocks.

[0008] Preferably, the variable information includes core information and attribute information, the core information is the bit width and symbol of the variable, and the attribute information includes array attribute, storage type and interface attribute.

[0009] Preferably, the labeling auxiliary module comprises a code block unit, an information acquisition unit and an information integration unit; The code block unit is used for running a code block program to process the source code and obtain the source code blocks; The information acquisition unit is used for calling an information acquisition agent to acquire the variable information corresponding to the source code blocks, and running an array size acquisition program to acquire the array size information of the variables; The information integration unit is used for integrating the variable information corresponding to the source code block and the array size information of the variable into complete variable information.

[0010] Preferably, the calling information acquisition agent acquires the variable information corresponding to the source code block, including the following steps: The agent reads the number of the current block and the corresponding code segment, and establishes a unique mapping of block number-code content; The variable information corresponding to the source code block is obtained in combination with the annotation content of the code content.

[0011] Preferably, the array size acquisition program traverses the current source code block, identifies the definition statement of the array type variable, including static array and dynamic array, parses the array size, and integrates all array size information of the entire code according to the parsed array information, and outputs the array size information table.

[0012] Preferably, according to the block-level variable information table and the array size information table output by the information acquisition unit, the block-level variable information table and the array size information table are associated based on the variable name, the variable information table of the block code is completed, and the complete variable information table is obtained after integration.

[0013] Preferably, in the code generation module, a code generation agent is called to convert the source code block by block into target code blocks according to the code block, rule prompt word and complete variable information table.

[0014] Preferably, the debug module includes a code debugging unit, a code integration unit and a code verification unit. The code debugging unit is used for combining the source code block, and calling the debug agent to debug the obtained target code block; The code integration unit is used for calling the code integration agent to integrate and splice the target code block to obtain complete target code. The code verification unit is used for compiling and verifying and checking the target code after debugging or integration.

[0015] Preferably, the code debugging unit calls the debug agent to process the source code block and the corresponding target code block in order of block number, and each block is debugged from the rule compliance dimension.

[0016] On the other hand, the present application provides a code conversion method based on multiple agents, including the following steps: S1: preprocessing the input source code, the preprocessing including inserting block symbols in the source code, annotating variable information according to requirements, and writing a code description file for the source code; S2: Divide the source code into blocks to obtain source code blocks, obtain the variable information and array size information of the corresponding blocks, and integrate them into complete variable information; S3: Combine code description files, code blocks in the source code, and variable information of the corresponding blocks in the source code to generate the target code block; S4: Combine source code blocks with the target code blocks for debugging. After debugging, integrate and splice the target code blocks to obtain the integrated target code. Compile and verify the integrated target code, and then verify and accept the compiled target code.

[0017] The beneficial effects of this invention are as follows: This invention does not rely on a single model, but rather constructs a highly specialized and collaborative intelligent agent system, thereby systematically improving the reliability and quality of the converted code. The introduction of code documentation as a guiding mechanism effectively addresses the semantic gap between high-level programming languages ​​and hardware description languages. Through code documentation, the intelligent agent can establish leapfrog connections during the code conversion process, ensuring that the generated target code more closely matches the actual functional requirements of the hardware, and giving source code programmers greater freedom in writing code. Facing the challenges of long code or complex algorithms, this invention adopts a divide-and-conquer strategy. In the preprocessing stage, long code is divided into multiple blocks by inserting block identifiers. This approach not only reduces the pressure on large models to handle long contexts, making the code generation process more stable, but also lays the foundation for subsequent debugging. This invention can output code in different styles simply by adjusting the intelligent agent's prompts, demonstrating high flexibility and customizability.

[0018] Compared to script- or rule-based code conversion methods, this invention is based on multi-agent conversion, which essentially performs semantic conversion during the code conversion process. It can handle syntax conversions without direct mapping relationships or even without mapping relationships, and can adapt to different and diverse code styles (whether it is the input code style or the output code style).

[0019] Compared to AI-based code conversion methods, this invention has very low data requirements for source code and target code languages. It can achieve code conversion without training a model, only optimization, and the optimization effect is considerable, with very low usage cost. In addition, the code block approach can effectively reduce the pressure on large models to process context length, thus enabling the conversion of thousands to tens of thousands of lines of code. The intelligent agent performs multiple debugging on the converted target code, ensuring the quality of the converted code. Attached Figure Description

[0020] Figure 1 This is a flowchart of the operation of a code conversion system based on multiple agents according to the present invention.

[0021] Figure 2 This is a flowchart of the steps of a code conversion method based on multiple agents according to the present invention.

[0022] Figure 3 This is a flowchart of the intelligent agent optimization process of the present invention. Detailed Implementation

[0023] Please see Figure 1 As shown, the present invention provides a code conversion system based on multiple agents, including a communication connection preparation module, an annotation assistance module, a code generation module, and a debug module; Preliminary preparation module: used to preprocess the source code, including inserting block delimiters into the source code, annotating variable information according to requirements, and writing code description files for the source code; Specifically, long code snippets are split by inserting block delimiters into the source code, reducing the pressure on the large model's context processing while ensuring semantic coherence. By default, a block delimiter is inserted every 150 lines. If the code has strong semantic connections, this can be extended to 200 lines per snippet, taking care to avoid splitting that disrupts logical integrity. A uniformly formatted block delimiter (e.g., / / BLOCK_START_1 / / BLOCK_END_1) is inserted at logical breakpoints in the source code (such as function ends, loop terminations, and module boundaries). This delimiter must be unique and identifiable to facilitate automatic splitting by the subsequent block processing program.

[0024] The variable information includes core information and attribute information. The core information is the bit width and sign of the variable. The attribute information includes array attributes, storage type, and interface attributes.

[0025] In the source code, variables with special requirements should be annotated. When annotating, the core attributes of the variable in the target code must be clearly defined, namely, bit width (the data width of the variable in the target code) and sign (whether the variable is a signed type). These two types of information are the foundation of variable definition in hardware description languages. Furthermore, if the variable is an array, the array dimensions and the length of each dimension must be annotated, i.e., the array size. Add comments next to the variable declaration line or usage line for annotation. The annotation format should be consistent to facilitate automatic extraction of information by the intelligent agent later.

[0026] Writing code documentation aims to establish a direct link between the source code and the target code, bridging the semantic gap, especially for syntax or special requirements without direct mapping. It explains the implicit logic or functionality in the source code and how it's implemented in the target code. It clarifies the conversion requirements of complex structures (such as classes, structs, and built-in functions) in the source code to those in the target code (e.g., "In MATLAB source code, registers are represented by classes; in the target code, SystemVerilog, logic variables act as registers"). It also clarifies the coding style (such as naming conventions and indentation) or hardware constraints (such as timing requirements and resource limitations) of the target code. The documentation should be written in plain text or Markdown format, following a "code snippet + description" structure, facilitating rapid association of corresponding logic by the code generation agent.

[0027] Annotation assistance module: used to obtain source code blocks and corresponding variable information, variable array size information, and integrate the variable information of the corresponding source code blocks and variable array size information into complete variable information; The annotation assistance module includes a code segmentation unit, an information acquisition unit, and an information integration unit; Code partitioning unit: Used to run a code partitioning program to partition the source code into blocks, resulting in source code blocks; Specifically, the source code with inserted block identifiers is processed by running the code segmentation program in the annotation assistance module to identify the unique inserted block identifiers and automatically divide the source code into multiple independent source code blocks. Each block corresponds to a set of block identifiers to ensure the semantic integrity of the code after segmentation. Finally, multiple independent source code blocks are obtained, each block is accompanied by a corresponding block number to facilitate subsequent information matching.

[0028] Information Acquisition Unit: Used to call the information acquisition agent to obtain variable information of the corresponding block of the source code, and at the same time run the array size acquisition program to obtain the array size information of the variables; Furthermore, the process of calling the information-retrieving agent to obtain variable information for the corresponding block of the source code includes the following steps: The agent reads the current block number and its corresponding code snippet, and establishes a unique mapping between the block number and the code content; Combine the annotations in the code content to obtain the variable information of the corresponding block in the source code.

[0029] It should be noted that the agent identifies comments in the code block regarding variable symbols, bit widths, and sizes, and outputs a variable information table for the current block. In multi-block scenarios, the agent repeats the above steps until all source code blocks have been processed. The fields in the variable information table for each source code block vary slightly depending on the specific scenario.

[0030] The program obtains array sizes by traversing the current source code block, identifying the definition statements of array type variables, including static and dynamic arrays, parsing the array sizes, integrating the parsed array information to obtain the size information of all arrays in the entire code, and outputting an array size information table.

[0031] The program iterates through the current source code block to identify the definition statement of the array type variable, including static arrays, such as c = zeros(3,4) in MATLAB, which outputs <variable name c><array size [3 4]>, where [3 4] represents row 3 and column 4; dynamic arrays only record the maximum value, such as 'a' being 2 in the first iteration. 3, the second beat is 5. If the value is 5, then the maximum value will be 5. 5. Parse the array size to obtain an array size information table, which includes the array variable name, array dimensions, length of each dimension, and array type.

[0032] Information integration unit: Used to integrate the variable information of the corresponding block of source code with the array size information of the variables into complete variable information.

[0033] Based on the "block-level variable information table" (sorted by block number, including block number, variable name, source code type, target bit width / symbol, scope) and "array size information table" (including array variable name, array dimension, length of each dimension, array type) output by the information acquisition unit, the block-level variable information table and array size information table are associated with the variable name to complete the variable information table of the block code, and the integrated result is a complete variable information table.

[0034] For each group (within the same block) of variable information, determine the variable type and associate it with array information. Read each variable (e.g., variable A) from the variable information table of the current block; compare the variable name with the array variable name in the array size information table of the same group. If a match is found (e.g., variable A and array variable A have the same name), it is determined to be an "array variable," the corresponding array size is extracted from the array size information table, and the attribute information is completed to generate a complete variable information record.

[0035] Code generation module: It integrates code documentation, source code blocks, and variable information, and generates target code module by module by calling the code generation agent, outputting target code blocks; In the code generation module, a code generation agent is invoked to convert the source code into target code blocks one by one based on code blocks, rule prompts, and a complete variable information table.

[0036] The debug module combines source code blocks to debug and verify the resulting target code blocks.

[0037] The debug module includes a code debugging unit, a code integration unit, and a code verification unit; Code debugging unit: used to combine source code blocks and call the debug agent to debug the obtained target code blocks; The code debugging unit calls the debug agent to process the source code blocks and corresponding target code blocks one by one according to the block number order. Each block is debugged from the perspective of rule compliance. After the debugging is successful, qualified code is output to the code integration unit.

[0038] Rule compliance: Check whether the target code block meets specific rules, such as syntax transformation rules (e.g., if the source code block contains classes, does the target code convert class attributes to reg type), function implementation rules (e.g., if the source code uses the sum function, does the target code implement it using combinational logic), and hardware constraint rules (e.g., if a register is required to store one clock cycle of data, does the target code define the register and implement clock cycle storage in the always @(posedge clk) block)? If the rules are not executed, the debug agent corrects the target code according to the rules.

[0039] Code integration unit: used to call the code integration agent to integrate and splice the target code blocks to obtain the complete target code; Code verification unit: Used to perform compilation verification and validation on the target code that has passed debugging or integration.

[0040] Input the debugged (simple case) or integrated target code (complex case) into the simulator for compilation and verification. If the simulator reports an error, the error message and the target code are fed back to the debug agent for a second level of debugging. This second level of debugging will continue until the simulator stops reporting errors or the maximum number of debugging rounds is reached. Verify and accept the compiled target code. If the simulator reports an error, the target code data needs to be checked to verify whether its functionality is consistent with the source code; if the maximum number of debugging rounds using the debug agent is exceeded, manual debugging and subsequent verification are required.

[0041] On the other hand, the present invention provides a code conversion method based on multiple agents, comprising the following steps: S1: Preprocess the input source code, including inserting block delimiters into the source code, annotating variable information according to requirements, and writing code description files for the annotated source code; S2: Divide the source code into blocks to obtain source code blocks, obtain the variable information and array size information of the corresponding blocks, and integrate them into complete variable information; S3: Combine code description files, code blocks in the source code, and variable information of the corresponding blocks in the source code to generate the target code block; S4: Combine source code blocks with the target code blocks for debugging. After debugging, integrate and splice the target code blocks to obtain the integrated target code. Compile and verify the integrated target code, and then verify and accept the compiled target code.

[0042] Please see Figure 2 As shown below, the method of this invention will be described in detail using the conversion between high-level programming language MATLAB code and hardware description language SystemVerilog code as an example.

[0043] Example 1: Code conversion in a simple case, involving Figure 2 Core processes Brief description: The MATLAB source code is concise, 100 to 200 lines; the MATLAB source code uses a simple syntax structure and does not use classes, structures, or complex functions in MATLAB (such as sum, repmat, etc.); the Systemverilog target code has a simple syntax and only contains combinational logic; the Systemverilog target code has no special requirements for variable bit width and symbols.

[0044] In simple cases, the preliminary preparation module will be omitted because: the MATLAB source code is concise enough that it does not need to be divided into blocks; the MATLAB syntax structure is simple and does not require special explanation; and there are no strict requirements for variable storage space in the target code Systemverilog, so there is no need to annotate variable bit width and other information. After skipping the preliminary preparation module, we will directly proceed to the annotation assistance module. Since it is not necessary to divide the MATLAB source code into blocks and annotate information, the steps of running the code block division program and calling the information acquisition agent in the annotation assistance module will be omitted. Only the array size acquisition program needs to be run.

[0045] Specifically: A1: After placing the MATLAB source code in the specified path, the array size acquisition program of the annotation auxiliary module can automatically capture the array size information of all variables in the MATLAB source code.

[0046] A2: The captured array size information and the source code MATLAB are sent to the code generation module, which then generates the target code Systemverilog by calling the code generation agent.

[0047] A3: The MATLAB source code and the converted Systemverilog target code are sent together to the debug module. The debug agent performs syntax checks on the converted Systemverilog target code. Since block processing is not required, the code integration step is skipped, and the syntax-checked Systemverilog target code is directly sent to the simulator for compilation and verification. If the simulator reports an error, the error message and the Systemverilog target code are fed back to the debug agent for adjustment. The number of debugging rounds can be set here. If set to 10, the debug agent will terminate after 10 rounds of debugging.

[0048] A4: Verify and accept the compiled and verified Systemverilog target code. If the simulator no longer reports errors, then the Systemverilog target code data needs to be checked to verify whether its functionality is consistent with the MATLAB source code; if the number of debugging rounds of the debug agent exceeds the limit, manual debugging and subsequent verification are required.

[0049] Example 2: Code conversion in complex situations, involving Figure 2 The entire process Complex scenario description: The MATLAB source code is quite long, exceeding 1000 lines; the MATLAB source code uses classes and structures, and the target Systemverilog code is expected to handle classes specially, such as not converting classes and storing class attributes as registers; the MATLAB source code uses built-in functions, such as sum, repmat, floor, and any; the target Systemverilog code needs registers to store one to two clock cycles of data, i.e., it requires combinational and sequential logic; there are detailed requirements for the bit width and sign of variables in the target Systemverilog code.

[0050] Specifically: B1: Insert block delimiters in the MATLAB source code, approximately every 150 lines. Since the MATLAB source code is quite long, it may exceed the maximum length of the large model context, leading to information truncation and inability to complete the task. To ensure semantic coherence in the MATLAB source code, it can be extended to 200 lines per block. Then, annotate the variable information in the MATLAB source code according to requirements, i.e., annotate the bit width and sign of each variable in the MATLAB source code, specifying how it should be designed in the target Systemverilog code. Write a code description file for the annotated MATLAB source code, explaining how code requiring special handling should be expressed in the target Systemverilog code. Because there are many areas where high-level programming languages ​​and hardware description languages ​​lack mapping relationships, high-level programming languages ​​need to use more complex methods to represent content that is easily expressed in hardware description languages. To reduce the workload of programmers and ensure that the converted code matches the actual functional requirements of the source code, a simple code description file can be used to prompt the agent, thus establishing a leapfrog connection in the conversion process between source and target code, outputting a detailed annotated MATLAB source code and a code description file.

[0051] B2: Input the MATLAB source code processed in step B1 into the annotation auxiliary module. Divide the MATLAB source code into blocks by running the code block division program. Obtain the variable information of the corresponding block of the MATLAB source code by calling the information acquisition agent. At the same time, obtain the array size information of the variables by running the array size acquisition program. Integrate the variable information of the corresponding block of the MATLAB source code and the array size information of the variables to obtain the complete variable information. Output the variable information and the MATLAB source code block.

[0052] B3: Input the code description file from step B1, the MATLAB code block from step B2, and the variable information into the code generation module. By calling the code generation agent, the Systemverilog target code is generated module by module, and the Systemverilog target code block is output.

[0053] B4: Input the Systemverilog target code generated in step B3 and the corresponding MATLAB source code from step B2 into the debug module for debugging. After the first round of debugging by the debug agent, the code integration agent integrates and splices the Systemverilog target code into a single integrated Systemverilog target code, which is then input into the simulator for compilation and verification. If the simulator reports an error, the error message and the Systemverilog target code are fed back to the debug agent for a second layer of debugging. This second layer of debugging will continue until the simulator stops reporting errors or the maximum number of debugging rounds is reached.

[0054] B5: Verify and accept the compiled and verified Systemverilog target code. If the simulator no longer reports errors, then the Systemverilog target code data needs to be checked to verify whether its functionality is consistent with the MATLAB source code; if the number of debugging rounds of the debug agent exceeds the limit, manual debugging and subsequent verification are required.

[0055] Examples 1 and 2 illustrate the conversion process between MATLAB code (a high-level programming language) and SystemVerilog code (a hardware description language). For conversions between high-level programming languages ​​(such as MATLAB to Python), only running... Figure 2 The small modules in the blue box are sufficient; the process can be found in Example 1 and Example 2.

[0056] Example 3: Optimizing the agent; please refer to [link / reference]. Figure 3 The agents in this invention all adopt mainstream large models, such as GPT-5, Claude4-Sonnet, Genmini-Pro-2.5, etc., and assign suitable agent roles to them according to the advantages of different large models.

[0057] C1: Input data is input into the agent. The agent processes the input data or completes a specific task based on pre-designed prompts, thereby generating output data. Specifically, select typical source code samples, corresponding expected target code, and necessary auxiliary information (such as code documentation, complete variable information, and more for complex scenarios) as the basic input for the agent. Use the agent's built-in default prompts to ensure traceability of the optimization starting point. Input the basic input data and initial prompts into the agent to be optimized, triggering the agent to execute the corresponding task. Save the initial output results generated by the agent and label the initial version and generation time for easy comparison of optimization effects later. Compare the agent's initial output results with the "expected target code / correctly labeled information" one by one to locate deviation problems. Record them according to "problem type-problem location-impact degree" and prioritize them according to the severity of their impact on the optimization target. For high-priority problems, adjust the prompts based on the agent's working logic. Re-input the adjusted prompts and the original basic input data into the agent to generate new output results. Continue iterating until the stopping condition is reached.

[0058] C2: Verify whether the output data meets the requirements. If the output data does not meet the requirements, analyze the problematic part of the output data and adjust the prompt words of the agent accordingly. C3: Repeat steps C1 to C2 until the final output data meets or closely matches the requirements.

[0059] The above embodiments are merely descriptions of preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Various modifications and improvements made by those skilled in the art to the technical solutions of the present invention without departing from the spirit of the present invention should fall within the protection scope defined by the claims of the present invention.

Claims

1. A code conversion system based on multi-agent technology, characterized in that, It includes a communication connection preparation module, a labeling assistance module, a code generation module, and a debug module; Preliminary preparation module: used to preprocess the source code, including inserting block delimiters into the source code, annotating variable information according to requirements, and writing code description files for the source code; Annotation assistance module: used to obtain source code blocks and corresponding variable information, variable array size information, and integrate the variable information of the corresponding source code blocks and variable array size information into complete variable information; Code generation module: It integrates code documentation, source code blocks, and variable information, and generates target code module by module by calling the code generation agent, outputting target code blocks; The debug module is used to debug and verify the target code blocks obtained by combining source code blocks.

2. The code conversion system based on multi-agent technology according to claim 1, characterized in that, The variable information includes core information and attribute information. The core information is the bit width and sign of the variable. The attribute information includes array attributes, storage type, and interface attributes.

3. The code conversion system based on multi-agent technology according to claim 1, characterized in that, The annotation assistance module includes a code segmentation unit, an information acquisition unit, and an information integration unit; Code partitioning unit: Used to run a code partitioning program to partition the source code into blocks, resulting in source code blocks; Information Acquisition Unit: Used to call the information acquisition agent to obtain variable information of the corresponding block of the source code, and at the same time run the array size acquisition program to obtain the array size information of the variables; Information integration unit: Used to integrate the variable information of the corresponding block of source code with the array size information of the variables into complete variable information.

4. The code conversion system based on multi-agent technology according to claim 3, characterized in that, The process of calling the information retrieval agent to obtain variable information for the corresponding block of source code includes the following steps: The agent reads the current block number and its corresponding code snippet, and establishes a unique mapping between the block number and the code content; Combine the annotations in the code content to obtain the variable information of the corresponding block in the source code.

5. A code conversion system based on multiple agents according to claim 3, characterized in that, The program obtains array sizes by traversing the current source code block, identifying the definition statements of array type variables, including static and dynamic arrays, parsing the array sizes, integrating the parsed array information to obtain the size information of all arrays in the entire code, and outputting an array size information table.

6. A code conversion system based on multiple agents according to claim 3, characterized in that, Based on the block-level variable information table and array size information table output by the information acquisition unit, the variable information table of the block code is completed by associating the block-level variable information table and array size information table with variable names, and then the complete variable information table is obtained after integration.

7. A code conversion system based on multiple agents according to claim 1, characterized in that, In the code generation module, a code generation agent is invoked to convert the source code into target code blocks one by one based on code blocks, rule prompts, and a complete variable information table.

8. A code conversion system based on multiple agents according to claim 1, characterized in that, The debug module includes a code debugging unit, a code integration unit, and a code verification unit; Code debugging unit: used to combine source code blocks and call the debug agent to debug the obtained target code blocks; Code integration unit: used to call the code integration agent to integrate and splice the target code blocks to obtain the complete target code; Code verification unit: Used to perform compilation verification and validation on the target code that has passed debugging or integration.

9. A code conversion system based on multiple agents according to claim 8, characterized in that, The code debugging unit calls the debug agent to process the source code blocks and corresponding target code blocks one by one according to the block number order. Each block is debugged from the perspective of rule compliance. After the debugging is successful, qualified code is output to the code integration unit.

10. A multi-agent-based code conversion method, employing the multi-agent-based code conversion system described in any one of claims 1-9, characterized in that, Includes the following steps: S1: Preprocess the input source code, including inserting block delimiters into the source code, annotating variable information according to requirements, and writing code description files for the source code; S2: Divide the source code into blocks to obtain source code blocks, obtain the variable information and array size information of the corresponding blocks, and integrate them into complete variable information; S3: Combine code description files, code blocks in the source code, and variable information of the corresponding blocks in the source code to generate the target code block; S4: Combine source code blocks with the target code blocks for debugging. After debugging, integrate and splice the target code blocks to obtain the integrated target code. Compile and verify the integrated target code, and then verify and accept the compiled target code.

Citation Information

Cited By

  • Customized content merging method and system in cross-language code conversion based on marks

    CN122044567A

  • Method and system for merging customized content in a tag-based cross-language code conversion

    CN122044567B