Code processing method and device, equipment and readable storage medium

By obtaining the language type and conversion rules of the file to be processed, the compiler is used to convert different high-level programming languages ​​into hardware description languages, which solves the limitations of single language conversion tools in the existing technology and realizes multi-language shared compiler backend and parallel processing.

CN119883282BActive Publication Date: 2026-04-07BEIJING INSTITUTE OF OPEN SOURCE CHIP
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-24
Publication Date
2026-04-07

Smart Images

  • Figure CN119883282B_ABST
    Figure CN119883282B_ABST
Patent Text Reader

Abstract

This application provides a code processing method, apparatus, device, and readable storage medium, relating to the field of computer technology and applied to compilers. The method includes: obtaining a file to be processed and a first language type of the code in the file; obtaining a first code conversion rule corresponding to the first language type; the first code conversion rule includes: a code conversion rule for converting code of the first language type into code of a preset language type, wherein the preset language type is compatible with the compiler; based on the first code conversion rule, converting the code of the first language type in the file to be processed into code of the preset language type; performing syntax analysis on the converted code to the preset language type to obtain a syntax tree of the file to be processed, and obtaining the target code based on the syntax tree. This application can process the code of files with different first language types using the same compiler, and the method is simple and efficient.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, and particularly relates to a code processing method and device, equipment and a readable storage medium. BACKGROUND

[0002] Through a code conversion tool, a high-level programming language such as C or C++ can be converted into a hardware description language (HDL), so that hardware performance testing can be performed according to the HDL.

[0003] In the related art, a code conversion tool can only convert one high-level programming language into an HDL. For example, a My Hardware Description Language (MyHDL) code conversion tool based on Python can only support conversion from Python to HDL.

[0004] This method is inconvenient to operate and requires high programming ability of the user. For example, a user using the MyHDL code conversion tool needs to be familiar with the Python language. SUMMARY

[0005] Embodiments of the present application provide a code processing method, device, equipment and readable storage medium to solve the problem of inconvenient code compilation method in the prior art.

[0006] In a first aspect, the embodiments of the present application provide a code processing method applied to a compiler, and the method comprises the following steps.

[0007] Obtaining a to-be-processed file and a first language type of code in the to-be-processed file;

[0008] Obtaining a first code conversion rule corresponding to the first language type, wherein the first code conversion rule is used to convert code of the first language type into code of a preset language type;

[0009] Converting the code of the first language type in the to-be-processed file into code of the preset language type based on the first code conversion rule;

[0010] Performing syntax analysis on the code converted into the preset language type to obtain a syntax tree of the to-be-processed file, and obtaining target code according to the syntax tree.

[0011] Optionally, the step of obtaining the first code conversion rule corresponding to the first language type comprises the following steps.

[0012] Obtaining a preset corresponding relationship between a language type and a code conversion rule; the code conversion rule is used to convert a code of the language type corresponding to the code conversion rule into a code of the preset language type;

[0013] According to the preset corresponding relationship between the language type and the code conversion rule, a first code conversion rule corresponding to the first language type is obtained.

[0014] Optionally, the target code is a hardware description language code; the to-be-processed file comprises at least one main function; and the obtaining of the target code according to the syntax tree comprises:

[0015] According to the syntax tree, a code segment corresponding to each main function in the to-be-processed file is obtained;

[0016] Each code segment is converted into a program block meeting the syntax requirement of the hardware description language to obtain the target code; and in a subsequent execution process, each program block is executed in parallel.

[0017] Optionally, the first language type of the code in the to-be-processed file has multiple types; and the obtaining of the first code conversion rule corresponding to the first language type comprises:

[0018] A first code conversion rule corresponding to each first language type is obtained respectively;

[0019] The converting of the code of the first language type in the to-be-processed file into the code of the preset language type based on the first code conversion rule comprises:

[0020] The code of each first language type in the to-be-processed file is converted into the code of the preset language type based on the first code conversion rule corresponding to each first language type.

[0021] Optionally, the target code is a hardware description language code or a code of another language type other than the hardware description language; after the target code is obtained according to the syntax tree, the method further comprises:

[0022] If the second language type of the target code is the hardware description language, the target code is executed through a field programmable gate array;

[0023] If the second language type of the target code is another language type, the target code is executed through preset simulation software.

[0024] Optionally, the obtaining of the to-be-processed file comprises:

[0025] generating a parameter setting statement for parameter setting based on a parameter setting format matched with the compiler;

[0026] inserting the parameter setting statement into the to-be-processed file to obtain a to-be-processed file including the parameter setting statement.

[0027] Optionally, the target code has a corresponding second language type; and the obtaining the target code according to the syntax tree comprises:

[0028] setting a state counter value of a state machine for a statement in the syntax tree;

[0029] generating the state machine corresponding to the statement according to the state counter value to obtain the target code; wherein the state machine is a state machine in the form of a decision statement, and the decision statement is matched with the second language type.

[0030] Optionally, the first code conversion rule comprises a correspondence between a syntax of the first language type code and a syntax of the preset language type code.

[0031] The converting the first language type code in the to-be-processed file into the preset language type code based on the first code conversion rule comprises:

[0032] converting the first language type code in the to-be-processed file into code meeting syntax requirements of the preset language type according to the correspondence between the syntax of the first language type code and the syntax of the preset language type code.

[0033] Optionally, the obtaining the first language type of the code in the to-be-processed file comprises:

[0034] obtaining a file extension of the to-be-processed file;

[0035] obtaining the first language type of the code in the to-be-processed file according to the file extension.

[0036] Optionally, the obtaining the first language type of the code in the to-be-processed file comprises:

[0037] obtaining a code keyword in the to-be-processed file; the code keyword is used to represent the first language type of the code in the to-be-processed file;

[0038] obtaining the first language type of the code in the to-be-processed file according to the code keyword.

[0039] In a second aspect, an embodiment of the present application provides a code processing apparatus, which comprises:

[0040] The first acquisition module is used to acquire the file to be processed and the first language type of the code in the file to be processed;

[0041] The second acquisition module is used to acquire a first code conversion rule corresponding to the first language type; the first code conversion rule is used to convert the code of the first language type into the code of a preset language type;

[0042] The conversion module is used to convert the code of the first language type in the file to be processed into the code of the preset language type based on the first code conversion rule;

[0043] The third acquisition module is used to perform syntax analysis on the code converted to the preset language type, obtain the syntax tree of the file to be processed, and obtain the target code based on the syntax tree.

[0044] Thirdly, embodiments of this application also provide an electronic device, including a processor;

[0045] Memory used to store processor-executable instructions;

[0046] The processor is configured to execute instructions to implement the method of the first aspect.

[0047] Fourthly, embodiments of this application also provide a computer-readable storage medium that, when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to perform the method of the first aspect.

[0048] In this embodiment, after obtaining the file to be processed, regardless of whether the first language type of the code in the file is compatible with the compiler, the code can be converted into code of a preset language type compatible with the compiler using the first code conversion rule corresponding to the first language type of the code in the file. Thus, the compiler can obtain the target code based on the code of the preset language type it is compatible with. This embodiment's method can compile code from files of different first language types using the same compiler, solving the problem in related technologies where a single code conversion tool can only process one type of file, leading to inconvenient and difficult code compilation methods. This embodiment has the advantages of being simple and intelligent.

[0049] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application. Attached Figure Description

[0050] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0051] Figure 1 This is a schematic diagram illustrating an application scenario of a code processing method provided in an embodiment of this application;

[0052] Figure 2 This is a flowchart of a code processing method provided in an embodiment of this application;

[0053] Figure 3 This is a flowchart of another code processing method provided in an embodiment of this application;

[0054] Figure 4 This is a flowchart of another code processing method provided in the embodiments of this application;

[0055] Figure 5 This is a block diagram of a code processing device provided in an embodiment of this application;

[0056] Figure 6 This is a block diagram of an electronic device provided in an embodiment of the present invention;

[0057] Figure 7 This is a block diagram of another electronic device according to another embodiment of the present invention. Detailed Implementation

[0058] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0059] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and are not limited in number; for example, a first object can be one or more. Furthermore, the term "and / or" in the specification and claims is used to describe the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. In the embodiments of this application, the term "multiple" refers to two or more, and other quantifiers are similar.

[0060] Figure 1 This is a schematic diagram illustrating an application scenario of a code processing method provided in an embodiment of this application. (Refer to...) Figure 1 Application scenarios include at least code conversion tools.

[0061] Algorithms described in high-level programming languages ​​(such as C / C++, SystemC) can be converted into HDL through a High-Level Synthesis (HLS) process. HDL includes Very-High-Speed ​​Integrated Circuit Hardware Description Language (VHDL) or hardware description languages ​​such as Verilog. Specifically, the file to be processed is input into a code conversion tool, which then converts the high-level programming language code in the file into HDL.

[0062] However, existing code conversion tools can only convert code in one corresponding high-level programming language. For example, MyHDL only supports converting Python to HDL. This means that files generated from different high-level programming languages ​​require a compatible code conversion tool to perform the HLS process. Furthermore, given a chosen code conversion tool, programmers are required to be familiar with the high-level programming language compatible with that tool, making the method complex to operate.

[0063] To address the aforementioned problems in related technologies, embodiments of this application provide a code processing method, which involves obtaining a file to be processed and a first language type of the code in the file to be processed; obtaining a first code conversion rule corresponding to the first language type; the first code conversion rule being used to convert the code of the first language type into code of a preset language type; based on the first code conversion rule, converting the code of the first language type in the file to be processed into code of the preset language type; performing syntax analysis on the converted code to the preset language type to obtain a syntax tree of the file to be processed, and obtaining target code based on the syntax tree. After obtaining the file to be processed, regardless of whether the first language type of the code in the file is compatible with the compiler backend, and regardless of the first language type of the file received by the compiler, the code in the file can be converted into code of a preset language type compatible with the compiler backend by using the first code conversion rule corresponding to the first language type of the code in the file. That is, based on this embodiment, multiple files of different first language types can share a single compiler backend. Thus, the compiler can obtain the target code based on the code of the preset language type that is compatible with it. The method of this embodiment can compile the code of files of different first language types using the same compiler, solving the problem in related technologies that a code conversion tool can only process one type of file. The method is simple, intelligent, and efficient.

[0064] The code processing method provided in this application will be described in detail below with reference to the accompanying drawings and specific embodiments.

[0065] Figure 2 This is a flowchart of the steps of a code processing method provided in an embodiment of this application, such as... Figure 2 As shown, the method may include:

[0066] Step 101: Obtain the file to be processed and the first language type of the code in the file to be processed.

[0067] The files to be processed include code generated according to the first language type. The first language type can be any high-level programming language, such as C, C++, Python, etc., without any limitation here.

[0068] For example, you can obtain the first language type of the code in the file to be processed based on the file extension of the file to be processed or the code keywords in the file to be processed.

[0069] Step 102: Obtain the first code conversion rule corresponding to the first language type.

[0070] The first code conversion rule is used to convert code of the first language type into code of the preset language type, which is compatible with the compiler.

[0071] The first code conversion rules are recorded in the syntax tree description file. For example, multiple syntax tree description files corresponding to different language types are obtained and stored in a folder accessible to the compiler. Each syntax tree description file records conversion rules for converting code of its corresponding language type to code of a preset language type. After receiving the file to be processed, the compiler obtains the first language type of the code in the file, then identifies the syntax tree description file corresponding to the first language type from the folder containing the syntax tree description files, and retrieves the first code conversion rules from that syntax tree description file.

[0072] Furthermore, based on the correspondence between language types and syntax tree description files, a syntax tree description file corresponding to the first language type is obtained. This syntax tree description file records the first code conversion rules. The first code conversion rules include at least the following: syntax code conversion rules for converting the code of the first language type into the code of a preset language type.

[0073] Specifically, the default language type that is compatible with the compiler is the language type that the compiler backend can process to convert the code into target code. Further, after receiving the file to be processed, the compiler frontend converts the code of the file's first language type into the default language type according to the first code conversion rule. The compiler backend then uses the converted default language type code to obtain the target code.

[0074] Step 103: Based on the first code conversion rule, convert the code of the first language type in the file to be processed into the code of the preset language type.

[0075] Specifically, based on the first code conversion rule in the syntax tree description file that converts the code of the first language type to the code of the preset language type, the code of the first language type in the file to be processed is converted to the code of the preset language type.

[0076] For example, the first code conversion rule includes syntax conversion rules for converting code in the first language type to code in the preset language type. For instance, the first language type is Python, and the preset language type is C. When generating code based on Python, lines of code do not need to end with a semicolon (;), while in C, lines of code must end with a semicolon (;). Therefore, the first code conversion rule for converting code in the first language type to code in the preset language type would at least include: adding a semicolon (;) to the end of each line of code in the file to be processed.

[0077] Step 104: Perform syntax analysis on the code converted to the preset language type to obtain the syntax tree of the file to be processed, and obtain the target code based on the syntax tree.

[0078] The compiler front-end performs syntax analysis on the code converted to a preset language type to obtain the syntax tree of the file to be processed. The compiler back-end optimizes the code based on the syntax tree and generates target code based on the optimized code.

[0079] In related technologies, domain-specific languages ​​(DSLs) can be built based on languages ​​such as Scala or Python, such as the Constructing Hardware in a Scala Embedded Language (Chisel) or the Python Multi-level Timing Library (PyMTL). This approach achieves syntax analysis through mechanisms such as custom classes and operator overloading, which is complex and involves cumbersome processing steps. In contrast, this embodiment can directly perform native syntax analysis on the user program, specifically by directly performing native syntax analysis on the code in the file to be processed, offering a more flexible approach.

[0080] The method of this application supports the conversion of various high-level programming languages ​​to HDL, especially the conversion of basic syntax and static data types. Furthermore, this embodiment can support dynamic memory and dynamic data types. For example, it can convert dynamic variable types such as Python dictionaries, sets, and lists to the hardware implementation of a Field Programmable Gate Array (FPGA).

[0081] In summary, in this embodiment, the following steps are taken: A file to be processed and a first language type of the code in the file are obtained; a first code conversion rule corresponding to the first language type is obtained; the first code conversion rule is used to convert the code of the first language type into code of a preset language type; based on the first code conversion rule, the code of the first language type in the file to be processed is converted into code of the preset language type; syntax analysis is performed on the converted code to obtain the syntax tree of the file to be processed, and the target code is obtained based on the syntax tree. After the compiler obtains the file to be processed, regardless of whether the first language type of the code in the file is compatible with the compiler, the code of the file to be processed can be converted into code of a preset language type compatible with the compiler through the first code conversion rule corresponding to the first language type of the code in the file. Thus, the compiler can obtain the target code based on the code of the preset language type compatible with it. The method of this embodiment can compile code for files of different first language types using the same compiler, solving the problem in related technologies where a code conversion tool can only process one type of file, resulting in inconvenient and difficult code compilation methods. This embodiment has the advantages of being simple and intelligent.

[0082] Figure 3 This is a flowchart of another code processing method provided in an embodiment of this application, referred to... Figure 3 The method may include the following steps:

[0083] Step 201: Obtain the file to be processed and the first language type of the code in the file to be processed.

[0084] The file to be processed is a file containing code to be compiled. The first language type of the code in the file to be processed can be any of the high-level programming languages.

[0085] The files to be processed can be written in a high-level programming language and are source files used for circuit verification.

[0086] For example, obtaining the file to be processed in step 201 may include sub-steps A1 to A2:

[0087] Sub-step A1 generates parameter setting statements for parameter setting based on the parameter setting format adapted to the compiler.

[0088] The parameter setting format adapted to the compiler is the standard parameter setting format applicable to the compiler. In one embodiment, the parameter setting format adapted to the compiler is a combination of "#param" and the parameter. The parameter setting statement is obtained by setting the parameters of the test case using this format.

[0089] For example, if the parameter includes the main function main 0, then the format of the parameter setting statement for setting the parameter of the main function main 0 is: #param entry=main0; if the parameter includes the reset parameter rst_n, then the format of the parameter setting statement for setting the parameter of the reset parameter rst_n is: #param rst=rst_n.

[0090] When compiling parameters, various parameters are set using a standard parameter setting format that is compatible with the compiler. This parameter setting format is a standard format applicable to the compiler and is independent of the actual high-level programming language syntax.

[0091] In this embodiment, the compilation parameters are set using a format independent of the syntax of each high-level programming language, thus ensuring universality. When files generated by different high-level programming languages ​​are compiled using the compiler, the compiler front-end converts the first language type corresponding to each high-level programming language into a preset language type. After the front-end performs the language type conversion, files from different high-level programming languages ​​can share the same compiler back-end during processing. Furthermore, after processing the code based on the shared compiler back-end, the format of the HDL code exported by the compiler can be freely configured, regardless of the language of the high-level programming language used by the front-end. For example, it can be configured to export HDL code as C language code, or it can be configured to export HDL code as Verilog code.

[0092] Specifically, after configuring the language type of the HDL code to be exported, the compiler converts the code of the file to be processed into code of the preset type and generates a syntax tree based on it. The compiler backend optimizes the code based on the syntax tree, and then converts the optimized code into HDL code of the user-defined language type according to the code conversion rules corresponding to the configured language type and exports it.

[0093] Sub-step A2 inserts the parameter setting statements into the file to be processed, resulting in a file to be processed that includes the parameter setting statements.

[0094] Based on the first language type, generate code to implement the preset function. Based on the parameter setting format adapted to the compiler, generate parameter setting statements to set parameters. Insert the parameter setting statements into the code written in the first language type to obtain a file to be processed that includes the parameter setting statements.

[0095] For example, in one embodiment, the first language type of the file code to be processed is C language, and the parameters include the main function main0 and the main function main1. The code for the parameter setting statement for setting the parameters of the main function main0 is: #param cpu [entry=main0], and the code for the parameter setting statement for setting the parameters of the main function main1 is: #param cpu [entry=main1].

[0096] For example, step 201, obtaining the first language type of the code in the file to be processed, may include substeps B1 through B2:

[0097] Sub-step B1: Obtain the file extension of the file to be processed.

[0098] The file extension reflects the language type of the file to be processed. For example, if the name of the file to be processed is "Ac", then "A" is the file identifier and ".c" is the file extension.

[0099] Sub-step B2: Based on the file extension, obtain the first language type of the code in the file to be processed.

[0100] For example, if the file extension of the file to be processed is ".c", then it can be determined that the primary language type of the code in the file to be processed is C.

[0101] For example, the primary language type of the file to be processed can be C, Go, JavaScript, Python, Scala, Cangjie, or another language.

[0102] Furthermore, each language type has a corresponding syntax tree description file, with a one-to-one correspondence between the syntax tree description file and the language type. The syntax tree description file records the conversion rules for converting the code of its corresponding language type into code of the preset language type. The syntax tree description file is stored in a folder accessible to the compiler.

[0103] For example, the filenames of the syntax tree description files for C, Go, JavaScript, Python, Scala, and Cangjie are C.ast, go.ast, JavaScript.ast, Python.ast, Scala.ast, and Cangjie.ast, respectively.

[0104] For example, after the compiler obtains the file to be processed, if the first language type of the file to be processed is C, it will call the syntax tree description file C.ast from the folder where the syntax tree description files are stored, and convert the code of the file to be processed into the code of the preset language type according to the first code conversion rule in the syntax tree description file C.ast.

[0105] For example, step 201, obtaining the first language type of the code in the file to be processed, may include substeps C1 to C2:

[0106] Sub-step C1: Obtain the code keywords from the file to be processed.

[0107] Code keywords are used to identify the first language type of the code in the file to be processed.

[0108] For example, the code in the file to be processed can be compared with the pre-stored code used to represent the language type. If a piece of code in the file to be processed belongs to the pre-stored code used to represent the language type, then it is identified as the code keyword in this step.

[0109] Sub-step C2: Obtain the first language type of the code in the file to be processed based on the code keywords.

[0110] For example, the first language type of the code in the source code of the file to be processed can be obtained based on the pragma tag parameter in the source code of the file to be processed.

[0111] Step 202: Obtain the correspondence between preset language types and code conversion rules.

[0112] The code conversion rules are recorded in the syntax tree description file. The code conversion rules are used to convert the code of the language type corresponding to the code conversion rule into the code of the preset language type.

[0113] In order to achieve dynamic support for various high-level programming languages, in the design of the compiler in this embodiment, the syntax tree description files corresponding to each high-level programming language are written separately and stored in a designated folder that the compiler can access.

[0114] Step 203: Based on the preset correspondence between language types and code conversion rules, obtain the first code conversion rule corresponding to the first language type.

[0115] Specifically, by comparing the language type in the correspondence with the first language type, the syntax tree description file corresponding to the language type that is the same as the first language type is determined as the syntax tree description file corresponding to the first language type.

[0116] For example, after the compiler runs, it obtains the first language type of the code in the target file name of the file to be processed based on the file extension or file suffix in the input file name. It then dynamically reads the syntax tree file corresponding to the first language type of the code in the file to be processed from the folder where the syntax tree files are stored, and compiles the code based on the first code conversion rules in the syntax tree file.

[0117] Specifically, the syntax tree description file corresponding to the first language type includes: code conversion rules for converting code of the first language type into code of the preset language type, where the preset language type is compatible with the compiler. For example, the code conversion rules include the correspondence between the syntax of the first language type code and the syntax of the preset language type code. Following step 203, the method further includes the following steps:

[0118] Step 204: Based on the first code conversion rule, convert the code of the first language type in the file to be processed into the code of the preset language type.

[0119] In this embodiment, the first language type of the file to be processed can be C, Go, JavaScript, Python, Scala, Cangjie, or other high-level programming languages. This embodiment does not limit the type of the first language type, but regardless of the high-level programming language of the code in the file to be processed, based on this embodiment, the code of the file to be processed generated by the aforementioned high-level programming language can be converted into code of a preset language type adapted by the compiler. Then, through a compiler backend capable of processing the preset language type, it can be converted into Verilog code or other types of code.

[0120] For example, if the code in the file to be processed has multiple first language types, then step 203 may include sub-step D1:

[0121] Sub-step D1: Obtain the first code conversion rule corresponding to each first language type.

[0122] For example, if the file to be processed is a mixed language file written in C and Python, then in this step, the first code conversion rule corresponding to C and the first code conversion rule corresponding to Python are obtained respectively.

[0123] Based on sub-step D1, step 204 may include sub-step E1:

[0124] Sub-step E1 converts the code in the file to be processed for each first language type into the code of the preset language type based on the first code conversion rule corresponding to each first language type.

[0125] For example, when the compiler analyzes the code in the file to be processed, upon identifying the first language type of a line of code, it uses the first code conversion rule corresponding to the first language type of the line of code to convert that line of code into code of the preset language type. Based on this method, code of mixed language types in the file to be processed can be converted into code of the preset type.

[0126] For example, if the file to be processed is a mixed language file written in C and Python, when a line of code is identified as being in C, the first code conversion rule corresponding to C is used to convert that line of code into the preset language type; when a line of code is identified as being in Python, the first code conversion rule corresponding to Python is used to convert that line of code into the preset language type.

[0127] The method based on this embodiment can support mixed-language programming, that is, in a single file to be processed, any number of the following high-level programming languages ​​can be mixed: C, Go, JavaScript, Python, Scala, Cangjie, or other high-level programming languages. For a file to be processed that mixes multiple high-level programming languages, the method of this embodiment obtains a first code conversion rule corresponding to each first language type. Based on the first code conversion rule corresponding to each first language type, the code in the file to be processed corresponding to each first language type is converted to code in a preset language type, so that all code is converted to code in the preset language type. Based on the code in the preset language type, the target code is obtained, thereby completing the hardware design.

[0128] For example, if the first code conversion rule includes the correspondence between the syntax of the first language type code and the syntax of the preset language type code, then step 204 may include: converting the first language type code in the file to be processed into code that meets the syntax requirements of the preset language type according to the correspondence between the syntax of the first language type code and the syntax of the preset language type code.

[0129] For example, if the first language type is Python and the default language type is C, Python syntax does not require lines of code to end with a semicolon (;), while C syntax requires lines of code to end with a semicolon (;). Therefore, the first code conversion rule for converting code from the first language type to code in the default language type would at least include: adding a semicolon (;) to the end of each line of code in the file to be processed, so that the converted code meets the syntax requirements of C.

[0130] Step 205: Perform syntax analysis on the code converted to the preset language type to obtain the syntax tree of the file to be processed, and obtain the target code based on the syntax tree.

[0131] For example, the target code has a corresponding second language type. Step 205 may include substeps F1 to F2:

[0132] Sub-step F1 sets the state counter values ​​for the statements in the syntax tree.

[0133] A state counter is a programmable element used to accumulate the number of input pulses. The value of the state counter records the number of transitions between different states of the system or device.

[0134] Sub-step F2 generates a state machine corresponding to the statement based on the state counter value, thus obtaining the target code.

[0135] Among them, the state machine is a state machine in the form of decision statements, and the decision statements are compatible with the second language type.

[0136] For example, if the second language is C, the state machine is in switch form; if the second language is Verilog, the state machine is in case form.

[0137] In one embodiment, the second language type of the target code is Verilog, and the state counter values ​​of the state machine can be set using PC0 to generate a case-type state machine.

[0138] The target code is code in a hardware description language, or code in a language other than a hardware description language. For example, the target code can be Verilog code or C code.

[0139] In this embodiment, the compiler internally defines a generic syntax tree data structure. This generic syntax tree data structure is a syntax tree data structure for a preset language type. According to the method of this embodiment, regardless of the first language type of the code in the file to be processed, which is a high-level programming language, the compiler will compile all types of high-level programming languages ​​in the file to this data structure after receiving it. After compiling the high-level programming languages ​​into this generic syntax tree data structure, a state machine can be created based on this data structure, assigning a state to each syntax statement to achieve the conversion from high-level language to HDL.

[0140] For example, the target code is hardware description language code; the file to be processed includes at least one main function. Step 205 may also include sub-steps G1 to G2:

[0141] Sub-step G1: Based on the syntax tree, obtain the code segments corresponding to each main function in the file to be processed.

[0142] The code segment corresponding to the main function includes at least one line of code that is executed sequentially, with the main function as the entry point.

[0143] Sub-step G2 converts each code segment into a program block that conforms to the syntax requirements of the hardware description language, thus obtaining the target code.

[0144] During subsequent execution, the target code executes its various blocks in parallel.

[0145] The program block can be a Verilog program block (always block). During execution, the various always blocks are executed in parallel. One always block corresponds to a code segment of the main function; the lines of code in the main function's code segment are executed sequentially, and correspondingly, the lines of code in an always block are executed sequentially.

[0146] This embodiment supports the definition of multiple main functions. The compilation system will compile each main function into an always block, realizing parallel execution on hardware. This makes up for the low efficiency of sequential execution in high-level programming languages ​​and achieves parallel use independent of various high-level programming languages.

[0147] Furthermore, the compiler used to execute the method of this embodiment supports hardware-level multitasking parallelism. Specifically, it allows users to write multiple main functions, and the compiler will compile each main function into an independent always block to achieve hardware multithreading and thus fully utilize hardware parallelism.

[0148] The following example uses C language as the first language and two main functions defined in the file to be processed as an example to illustrate the method of this embodiment: through sub-steps A1 to A2, parameter setting statements for setting parameters of the main function main0 are generated respectively: #param cpu [entry=main0;] and #param cpu [entry=main1;].

[0149] Based on the method of this embodiment, the target code (e.g., Verilog code) obtained after compiling and transforming the file containing the main functions main0 and main1 includes two always blocks. One always block is used to execute the code segment corresponding to the main function main0, and the other always block is used to execute the code segment corresponding to the main function main1. Furthermore, the always blocks corresponding to the two main functions are executed simultaneously on the hardware to achieve parallel processing of the hardware.

[0150] It should be noted that sub-steps F1 to F2 can generate a state machine corresponding to the code statements, and sub-steps G1 to G2 can convert each code segment into a program block that conforms to the syntax requirements of the hardware description language, thus obtaining target code with a state machine and multiple program blocks.

[0151] Step 206: If the second language type of the target code is a hardware description language, then the target code is executed through a field-programmable gate array.

[0152] For example, if the target code is Verilog code, it is burned into the FPGA and executed.

[0153] Step 207: If the second language type of the target code is another language type, then execute the target code through the preset simulation software.

[0154] For example, if the target code is in C language, it can be executed by simulation software to simulate the hardware circuit.

[0155] Based on the method of this embodiment, regardless of the high-level programming language of the first language type of the file to be processed, and regardless of whether the file contains code of one or more first language types, after receiving the file, the compiler can convert it into code of a preset language type adapted by the compiler by obtaining the first code conversion rule corresponding to the first language type. Thus, the compiler backend can convert the converted code into target code based on the code of the preset language type. Furthermore, based on the method of this embodiment, not only can Verilog code that needs to be programmed into the FPGA for testing be obtained, but also target code of other language types capable of circuit hardware simulation can be obtained, such as C language code. Specifically, by setting a state machine, target code of other language types can be equipped with the function of hardware simulation of the circuit.

[0156] In addition to converting high-level programming languages ​​into HDL, this application also supports direct hardware simulation of high-level programming languages. Specifically, based on the method of this embodiment, the high-level programming language is compiled into a C program with a state machine, and further compiled into an executable program. During execution, the sequential execution of statements is achieved through state machine progression to simulate the operation of hardware.

[0157] This embodiment realizes the development of a flexibly configurable compiler framework. The compiler front end supports compiling syntax trees for various configurable high-level programming languages, and the compiler back end uniformly generates HDL code.

[0158] HLS technology in related technologies typically only supports the conversion of a single high-level programming language to HDL. This application, by introducing a multi-frontend support mechanism, enables dynamic loading of the syntax tree of the corresponding language type during compilation based on tags, thus achieving multi-frontend language syntax support. Specifically, through the code conversion rules in the syntax tree description file corresponding to the language type, the code in the file to be processed received by the compiler is converted into code of a unified language type, thereby achieving multi-frontend language syntax support. HLS tools in related technologies typically only support the definition of a single main function, focusing on statement-level parallelization optimization. This application allows users to write multiple main functions to execute code simultaneously, achieving hardware parallelization. Specifically, each main function is converted into a corresponding always block, and hardware parallelization is achieved based on the always blocks corresponding to each main function.

[0159] Since this application does not limit the primary language type of the file to be processed, as long as it is converted into code of a preset type, it can be compiled into target code by the compiler backend. This allows programmers with only a software IT background to design and develop hardware circuits or FPGAs, without requiring them to be familiar with Verilog or any specific high-level programming language. Programmers generate the file to be processed according to their familiar language type, and the compiler frontend automatically converts it into code of the preset language type, which is then converted into Verilog code or a C program with a state machine by the backend, thereby enabling agile circuit design and development. In addition, based on the method of this embodiment, the HDL generated by the high-level programming language can be used for digital circuit verification. This allows programmers to write stimulus code using their preferred high-level programming language without having to write code using HDL, reducing the difficulty of digital circuit verification and saving manpower costs for digital circuit verification.

[0160] Existing code conversion methods suffer from incompatibility issues related to semantics, compilation parameters, and exported formats, and also exhibit code fragmentation. This embodiment proposes a standard framework to support the compilation of various high-level programming languages ​​into HDL, offering advantages such as semantic uniformity, universal compilation parameters, and support for parallelization.

[0161] Reference Figure 4 The method in this embodiment may include the following steps:

[0162] Step S1: Obtain the file to be processed; the language type of the code in the file to be processed is the first language type.

[0163] The first language type can be C, Go, JavaScript, Python, Scala, Cangjie, or other high-level programming languages.

[0164] Step S2: The compiler converts the code in the file to be processed into code of a preset type according to the syntax tree description file, and generates target code based on the preset type code.

[0165] The syntax tree description file includes first code conversion rules for converting code of a first language type into code of a preset language type.

[0166] Specifically, syntax tree description files corresponding to multiple language types are pre-built and stored in a folder accessible to the compiler. These syntax tree description files record code conversion rules used to convert code of their corresponding language type into code of the preset type. In other words, the folder records the correspondence between language types and code conversion rules.

[0167] After the compiler obtains the file to be processed, it identifies the first language type of the code in the file. Then, it retrieves the syntax tree description file corresponding to the first language type from the folder used to store syntax tree description files, and obtains the first code conversion rule corresponding to the first language type from the syntax tree description file. Based on the first code conversion rule, it converts the code of the first language type in the file to code of the preset language type. Syntax analysis is then performed on the converted code to obtain the syntax tree of the file to be processed, and the target code is obtained from the syntax tree.

[0168] The target code is the code exported by the compiler. The language type of the target code can be set according to user needs. For example, it can be set to Verilog code or C language code.

[0169] Step S3: If the target code is C language code with a state machine, then obtain the C program based on the target code and proceed to step S4.

[0170] The C language code obtained by the method in this embodiment has a state machine. Based on the state machine, the sequential execution of the C language code can be realized, and hardware circuit simulation can be performed.

[0171] Step S4: Simulate the C program containing the target code.

[0172] A state machine can simulate the pulse signals that trigger circuits in hardware circuits to perform corresponding operations. Based on a C program with a state machine, hardware circuits can be simulated.

[0173] Step S5: If the target code is Verilog code, then burn the target code into the field programmable gate array.

[0174] For example, the compiler can be configured to export target code in either C or Verilog.

[0175] Furthermore, by burning the target code into a thread-programmable gate array (FPGA), hardware circuit simulation can be achieved.

[0176] In this embodiment, the compiler front-end supports compiling syntax trees for various configurable high-level programming languages, while the compiler back-end uniformly generates HDL code.

[0177] In this embodiment, when the compiler reads a file to be processed, it can obtain the first language type of the file by its file extension, load the syntax tree description file corresponding to the first language type, and compile the file to be processed, which is the source file, based on the first code conversion rules in the syntax tree description file. Alternatively, this embodiment can obtain the first language type of the code to be compiled later based on the pragma flag parameter in the source code of the file to be processed, and the compiler can dynamically switch the syntax tree description file and compile according to the flag parameter.

[0178] In this embodiment, after generating the intermediate syntax tree, a state machine is constructed. Each line of statement is assigned a state number, and a state machine in the form of decision statements is generated to match the second language type of the exported target code. For example, if the target code to be exported is Verilog code, a Verilog case statement-style state machine is generated to complete the generation of the Verilog code. If the target code to be exported is C language code, a C language switch statement-style state machine is generated to complete the generation of the C language code.

[0179] refer to Figure 5 This illustrates a code processing apparatus provided in an embodiment of this application. The code processing apparatus 30 includes:

[0180] The first acquisition module 301 is used to acquire the file to be processed and the first language type of the code in the file to be processed;

[0181] The second acquisition module 302 is used to acquire the first code conversion rule corresponding to the first language type; the first code conversion rule is used to convert the code of the first language type into the code of the preset language type;

[0182] The conversion module 303 is used to convert the code of the first language type in the file to be processed into the code of the preset language type based on the first code conversion rule;

[0183] The third acquisition module 304 is used to perform syntax analysis on the code converted to a preset language type, obtain the syntax tree of the file to be processed, and obtain the target code based on the syntax tree.

[0184] Optionally, the second acquisition module 302 includes:

[0185] The first acquisition submodule is used to acquire the correspondence between preset language types and code conversion rules; the code conversion rules are used to convert the code of the language type corresponding to the code conversion rules into the code of the preset language type;

[0186] The second acquisition submodule is used to acquire the first code conversion rule corresponding to the first language type based on the preset correspondence between language type and code conversion rule.

[0187] Optionally, the target code is hardware description language code; the file to be processed includes at least one main function; the third acquisition module 304 includes:

[0188] The third submodule is used to obtain the code segments corresponding to each main function in the file to be processed based on the syntax tree.

[0189] The fourth acquisition submodule is used to convert each code segment into a program block that conforms to the syntax requirements of the hardware description language, thereby obtaining the target code; the target code is executed in parallel during subsequent execution.

[0190] Optionally, the first language type of the code in the file to be processed may be multiple, and the second acquisition module 302 may include:

[0191] The fifth submodule is used to obtain the first code conversion rule corresponding to each first language type;

[0192] Conversion module 303 includes:

[0193] The first conversion submodule is used to convert the code in the file to be processed into the code of the preset language type based on the first code conversion rules corresponding to each first language type.

[0194] Optionally, the target code is code in a hardware description language, or code in a language other than a hardware description language; the device 30 also includes:

[0195] The first processing module is used to execute the target code through a field-programmable gate array if the second language type of the target code is a hardware description language after obtaining the target code from the syntax tree.

[0196] The second processing module is used to execute the target code through preset simulation software if the second language type of the target code is another language type.

[0197] Optionally, the first acquisition module 301 includes:

[0198] Generate submodules to generate parameter setting statements for setting parameters based on parameter setting formats adapted to the compiler;

[0199] The sixth submodule is used to insert parameter setting statements into the file to be processed, thus obtaining a file to be processed that includes parameter setting statements.

[0200] Optionally, the target code has a corresponding second language type; the third acquisition module 304 includes:

[0201] The settings submodule is used to set the state machine state counter values ​​for statements in the syntax tree;

[0202] The seventh acquisition submodule is used to generate a state machine corresponding to the statement based on the state counter value, and obtain the target code; wherein, the state machine is a state machine in the form of decision statements, and the decision statements are adapted to the second language type.

[0203] Optionally, the first code conversion rule includes: the correspondence between the syntax of the first language type code and the syntax of the preset language type code; the conversion module 303 includes:

[0204] The second conversion submodule is used to convert the first language type code in the file to be processed into code that meets the syntax requirements of the preset language type, based on the correspondence between the syntax of the first language type code and the syntax of the preset language type code.

[0205] Optionally, the first acquisition module 301 includes:

[0206] The eighth submodule is used to obtain the file extension of the file to be processed;

[0207] The ninth submodule is used to obtain the first language type of the code in the file to be processed based on the file extension.

[0208] Optionally, the first acquisition module 301 may include:

[0209] The tenth submodule is used to obtain code keywords from the file to be processed; code keywords are used to identify the first language type of the code in the file to be processed.

[0210] The eleventh submodule is used to obtain the first language type of the code in the file to be processed based on the code keywords.

[0211] In this embodiment, after obtaining the file to be processed, regardless of whether the first language type of the code in the file is compatible with the compiler, the compiler can convert the code in the file into code of a preset language type compatible with the compiler by using the first code conversion rule corresponding to the first language type of the code in the file. Thus, the compiler can obtain the target code based on the code of the preset language type that is compatible with it. The method of this embodiment can compile code from files with different first language types using the same compiler, solving the problem in related technologies where a single code conversion tool can only process one type of file, leading to inconvenient and difficult code compilation methods. This embodiment has the advantages of being simple and intelligent.

[0212] Figure 6 This is a block diagram illustrating an electronic device 400 according to an exemplary embodiment. For example, the electronic device 400 may be a mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, medical device, fitness equipment, personal digital assistant, etc.

[0213] Reference Figure 6 The electronic device 400 may include one or more of the following components: processing component 402, memory 404, power supply component 406, multimedia component 408, audio component 410, input / output (I / O) interface 412, sensor component 414, and communication component 416.

[0214] Processing component 402 typically controls the overall operation of electronic device 400, such as operations associated with display, telephone calls, data communication, camera operation, and recording. Processing component 402 may include one or more processors 420 to execute instructions to perform all or part of the steps of the methods described above. Furthermore, processing component 402 may include one or more modules to facilitate interaction between processing component 402 and other components. For example, processing component 402 may include a multimedia module to facilitate interaction between multimedia component 408 and processing component 402.

[0215] Memory 404 is used to store various types of data to support the operation of electronic device 400. Examples of such data include instructions for any application or method operating on electronic device 400, contact data, phonebook data, messages, pictures, multimedia, etc. Memory 404 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.

[0216] Power supply component 406 provides power to various components of electronic device 400. Power supply component 406 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to electronic device 400.

[0217] Multimedia component 408 includes a screen that provides an output interface between electronic device 400 and a user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors may not only sense the boundaries of touch or swipe actions but also detect the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 408 includes a front-facing camera and / or a rear-facing camera. When electronic device 400 is in an operating mode, such as a shooting mode or a multimedia mode, the front-facing camera and / or rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.

[0218] Audio component 410 is used to output and / or input audio signals. For example, audio component 410 includes a microphone (MIC) used to receive external audio signals when electronic device 400 is in an operating mode, such as call mode, recording mode, and voice acquisition mode. The received audio signals may be further stored in memory 404 or transmitted via communication component 416. In some embodiments, audio component 410 also includes a speaker for outputting audio signals.

[0219] I / O interface 412 provides an interface between processing component 402 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.

[0220] Sensor assembly 414 includes one or more sensors for providing state assessments of various aspects of electronic device 400. For example, sensor assembly 414 may detect the on / off state of electronic device 400, the relative positioning of components such as the display and keypad of electronic device 400, changes in position of electronic device 400 or a component of electronic device 400, the presence or absence of user contact with electronic device 400, orientation or acceleration / deceleration of electronic device 400, and temperature changes of electronic device 400. Sensor assembly 414 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 414 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 414 may also include an accelerometer, gyroscope, magnetometer, pressure sensor, or temperature sensor.

[0221] Communication component 416 facilitates wired or wireless communication between electronic device 400 and other devices. Electronic device 400 can access wireless networks based on communication standards, such as WiFi, carrier networks (such as 2G, 3G, 4G, or 5G), or combinations thereof. In one exemplary embodiment, communication component 416 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 416 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency acquisition (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.

[0222] In an exemplary embodiment, the electronic device 400 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to implement a code processing method provided in the embodiments of this application.

[0223] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 404 including instructions, which can be executed by a processor 420 of an electronic device 400 to perform the above-described method. For example, the non-transitory storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.

[0224] Figure 7This is a block diagram illustrating an electronic device 500 according to an exemplary embodiment. For example, the electronic device 500 may be provided as a server. (Refer to...) Figure 7 The electronic device 500 includes a processing component 522, which further includes one or more processors, and memory resources represented by memory 532 for storing instructions, such as application programs, that can be executed by the processing component 522. The application programs stored in memory 532 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 522 is configured to execute instructions to perform a code processing method provided in embodiments of this application.

[0225] Electronic device 500 may also include a power supply component 526 configured to perform power management of electronic device 500, a wired or wireless network interface 550 configured to connect electronic device 500 to a network, and an input / output (I / O) interface 558. Electronic device 500 may operate on an operating system stored in memory 532, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or similar.

[0226] This application also provides a computer program product, including a computer program and a code processing method implemented when the computer program is executed by a processor.

[0227] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the application disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.

[0228] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

[0229] The above are merely preferred embodiments of this application and are not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

[0230] The foregoing has provided a detailed description of a code processing method, apparatus, electronic device, and computer-readable storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A code processing method, characterized in that, Applied to compilers, the methods include: Obtain the file to be processed, and the first language type of the code in the file to be processed; Obtain the first code conversion rule corresponding to the first language type; the first code conversion rule is used to convert the code of the first language type into the code of a preset language type; Based on the first code conversion rule, the code of the first language type in the file to be processed is converted into the code of the preset language type; Perform syntax analysis on the code converted to the preset language type to obtain the syntax tree of the file to be processed, and obtain the target code based on the syntax tree, including: Based on the syntax tree, code segments corresponding to each main function in the file to be processed are obtained; the target code is code in a hardware description language; the file to be processed includes at least one main function; each code segment is converted into a program block that conforms to the syntax requirements of the hardware description language to obtain the target code; the target code is executed in parallel during subsequent execution. The target code has a corresponding second language type; obtaining the target code based on the syntax tree includes: setting a state counter value for a state machine for a statement in the syntax tree; generating a state machine corresponding to the statement based on the state counter value to obtain the target code; wherein the state machine is a state machine in the form of a decision statement, and the decision statement is adapted to the second language type.

2. The method according to claim 1, characterized in that, The acquisition of the first code conversion rule corresponding to the first language type includes: Obtain the correspondence between preset language types and code conversion rules; the code conversion rules are used to convert the code of the language type corresponding to the code conversion rules into the code of the preset language type; Based on the preset correspondence between the language type and the code conversion rule, obtain the first code conversion rule corresponding to the first language type.

3. The method according to claim 1, characterized in that, The first language type of the code in the file to be processed can be multiple, and the first code conversion rule corresponding to the first language type includes: Obtain the first code conversion rule corresponding to each of the first language types; The step of converting the code of the first language type in the file to be processed into the code of the preset language type based on the first code conversion rule includes: Based on the first code conversion rules corresponding to each of the first language types, the code in the file to be processed for each of the first language types is converted into the code of the preset language type.

4. The method according to claim 1, characterized in that, The target code is code in a hardware description language, or code in a language other than the hardware description language; after obtaining the target code from the syntax tree, the method further includes: If the second language type of the target code is a hardware description language, then the target code is executed through a field-programmable gate array; If the second language type of the target code is another language type, the target code is executed by preset simulation software.

5. The method according to claim 1, characterized in that, The process of obtaining the file to be processed includes: Based on the parameter setting format adapted to the compiler, a parameter setting statement for setting parameters is generated; Insert the parameter setting statement into the file to be processed to obtain a file to be processed that includes the parameter setting statement.

6. A code processing device, characterized in that, The device includes: The first acquisition module is used to acquire the file to be processed and the first language type of the code in the file to be processed; The second acquisition module is used to acquire a first code conversion rule corresponding to the first language type; the first code conversion rule is used to convert the code of the first language type into the code of a preset language type; The conversion module is used to convert the code of the first language type in the file to be processed into the code of the preset language type based on the first code conversion rule; The third acquisition module is used to perform syntax analysis on the code converted to the preset language type, obtain the syntax tree of the file to be processed, and obtain the target code based on the syntax tree; The third acquisition module includes: a third acquisition submodule, used to acquire the code segments corresponding to each main function in the file to be processed according to the syntax tree; the target code is code in a hardware description language; the file to be processed includes at least one main function; a fourth acquisition submodule, used to convert each code segment into a program block that conforms to the syntax requirements of the hardware description language to obtain the target code; the target code is executed in parallel during subsequent execution. The target code has a corresponding second language type; the third acquisition module is further configured to set the state counter value of the state machine for the statements in the syntax tree; generate a state machine corresponding to the statement based on the state counter value, and obtain the target code; wherein, the state machine is a state machine in the form of a decision statement, and the decision statement is adapted to the second language type.

7. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the method as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, When the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is enabled to perform the method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Programming language integration method, programming software system and electronic device

    CN111651165A

  • Code compiling method and device and compiler

    CN117519715A