Code processing method, device and equipment and readable storage medium
By obtaining the language type of the pending file and the corresponding code conversion rules and converting them into preset language type code, the problem of a single code conversion tool in the existing technology dealing with a single language type is solved, and multilingual type code compilation and target code generation are realized.
Patent Information
- Application Number
- CN202510350491.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-24
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2045-03-24
AI Technical Summary
In the prior art, code conversion tools can only handle one high-level programming language, which leads to inconvenient operation and requires high programming capabilities of users.
Provides a code processing method, by obtaining the language type of the pending file and the corresponding code conversion rules, converting the code in the pending file into code of the preset language type, and performing syntax analysis to generate the target code.
It realizes code compilation in different high-level programming languages, solves the problem of a single code conversion tool dealing with a single language type, and improves the flexibility and user experience of the compilation process.
Smart Images

Figure CN119883282A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a code processing method, device, equipment and readable storage medium. Background Art
[0002] Through code conversion tools, high-level programming languages such as C and C++ can be converted into hardware description languages (HDL), so that hardware performance testing can be performed based on HDL.
[0003] In the related art, a code conversion tool can only convert one high-level programming language into HDL. For example, a Python-based HDL code conversion tool (My Hardware Description Language, MyHDL) only supports the conversion of Python into HDL.
[0004] This method is inconvenient to operate and requires high programming skills from the user. For example, users of the code conversion tool MyHDL need to be familiar with the Python language. Summary of the invention
[0005] The embodiments of the present application provide a code processing method, apparatus, device and readable storage medium to solve the problem of inconvenient and difficult code compilation methods in the prior art.
[0006] In a first aspect, an embodiment of the present application provides a code processing method, which is applied to a compiler, and the method includes: Obtaining a file to be processed and a first language type of a code in the file to be processed; 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 a code of a preset language type; Based on the first code conversion rule, converting the code of the first language type in the to-be-processed file into a code of a preset language type; The code converted into the preset language type is subjected to grammatical analysis to obtain a grammatical tree of the file to be processed, and a target code is obtained according to the grammatical tree.
[0007] Optionally, the acquiring a first code conversion rule corresponding to the first language type includes: Acquire a correspondence between a preset language type and a code conversion rule; the code conversion rule is used to convert a code of a language type corresponding to the code conversion rule into a code of the preset language type; According to the preset correspondence between the language type and the code conversion rule, a first code conversion rule corresponding to the first language type is acquired.
[0008] Optionally, the target code is a code of a hardware description language; the file to be processed includes at least one main function; and obtaining the target code according to the syntax tree includes: According to the syntax tree, obtain the code segments corresponding to the to-be-processed file and each of the main functions respectively; Each of the code segments is converted into a program block that meets the grammatical requirements of the hardware description language to obtain a target code; during the subsequent execution of the target code, each of the program blocks is executed in parallel.
[0009] Optionally, there are multiple first language types of the code in the to-be-processed file, and the acquiring a first code conversion rule corresponding to the first language type includes: Respectively obtaining first code conversion rules corresponding to each of the first language types; The converting the code of the first language type in the to-be-processed file into a code of a preset language type based on the first code conversion rule includes: Based on the first code conversion rule corresponding to each first language type, the code corresponding to each first language type in the to-be-processed file is converted into the code of the preset language type.
[0010] Optionally, the target code is a code of a hardware description language, or a code of a language type other than the hardware description language; after obtaining the target code according to the syntax tree, the method further includes: If the second language type of the target code is a hardware description language, executing the target code 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 using preset simulation software.
[0011] Optionally, obtaining the file to be processed includes: Based on a parameter setting format adapted to the compiler, generating a parameter setting statement for performing parameter setting; Inserting a parameter setting statement into the file to be processed to obtain the file to be processed including the parameter setting statement.
[0012] Optionally, the target code has a corresponding second language type; and obtaining the target code according to the syntax tree includes: Setting a state counter value of a state machine for a statement in the syntax tree; According to the state counter value, a state machine corresponding to the statement is generated 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 compatible with the second language type.
[0013] Optionally, the first code conversion rule includes: a correspondence between a syntax of the first language type code and a syntax of the preset language type code; The converting the code of the first language type in the to-be-processed file into a code of a preset language type based on the first code conversion rule includes: According to the correspondence between the syntax of the first language type code and the syntax of the preset language type code, the code of the first language type in the to-be-processed file is converted into a code that meets the syntax requirement of the preset language type.
[0014] Optionally, obtaining the first language type of the code in the file to be processed includes: Obtain the file extension of the file to be processed; According to the file extension, a first language type of the code in the file to be processed is obtained.
[0015] Optionally, obtaining the first language type of the code in the file to be processed includes: Obtain code keywords in the file to be processed; the code keywords are used to characterize the first language type of the code in the file to be processed; The first language type of the code in the file to be processed is obtained according to the code keyword.
[0016] In a second aspect, an embodiment of the present application provides a code processing device, the device comprising: A first acquisition module, used to acquire a file to be processed and a first language type of a code in the file to be processed; A 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 a code of a preset language type; A conversion module, configured to convert the code of the first language type in the to-be-processed file into a code of a preset language type based on the first code conversion rule; The third acquisition module is used to perform syntax analysis on the code converted into the preset language type to obtain a syntax tree of the file to be processed, and obtain the target code according to the syntax tree.
[0017] In a third aspect, an embodiment of the present application further provides an electronic device, including a processor; a memory for storing processor-executable instructions; The processor is configured to execute instructions to implement the method of the first aspect.
[0018] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, which, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to execute the method of the first aspect.
[0019] In an embodiment of the present application, after obtaining the file to be processed, regardless of whether the first language type of the code in the file to be processed is compatible with the compiler, the code therein can be converted into a code of a preset language type that is compatible with the compiler through a first code conversion rule corresponding to the first language type of the code in the file to be processed, thereby 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 the files to be processed of different first language types by the same compiler, solving the problem in the related art that one code conversion tool can only process one file to be processed, resulting in an inconvenient and difficult code compilation method. This embodiment has the advantages of being simple and intelligent.
[0020] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 This is a schematic diagram of an application scenario of a code processing method provided in an embodiment of the present application; Figure 2 It is a flowchart of a code processing method provided by an embodiment of the present application; Figure 3 It is a flowchart of another code processing method provided in an embodiment of the present application; Figure 4 This is a flowchart of another code processing method provided by an embodiment of the present application; Figure 5 is a block diagram of a code processing device provided in an embodiment of the present application; Figure 6 is a block diagram of an electronic device provided by an embodiment of the present invention; Figure 7 is a block diagram of another electronic device according to another embodiment of the present invention. DETAILED DESCRIPTION
[0023] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0024] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally a class, and the number of objects is not limited. For example, the first object can be one or more. In addition, the term "and / or" in the specification and claims is used to describe the association relationship of associated objects, indicating that three kinds of relationships can exist, for example, A and / or B can be represented: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the front and back associated objects are a kind of "or" relationship. In the embodiment of the present application, the term "multiple" refers to two or more, and other quantifiers are similar.
[0025] Figure 1 This is a schematic diagram of an application scenario of a code processing method provided in an embodiment of the present application, referring to Figure 1 ,The application scenarios at least include code conversion tools.
[0026] The algorithm described in a high-level programming language (such as C / C++, SystemC) can be converted into HDL through the High-Level Synthesis (HLS) process. HDL includes a general hardware description language (Very-High-Speed Integrated Circuit Hardware Description Language, VHDL) or a hardware description language Verilog. Specifically, the file to be processed is input into a code conversion tool, and the high-level programming language code in the file to be processed is converted into HDL through the code conversion tool.
[0027] However, the code conversion tools in the related art can only convert the code of a corresponding high-level programming language. For example, MyHDL only supports the conversion of Python to HDL. This results in that the to-be-processed files generated by different high-level programming language codes need to use a code conversion tool adapted to them to implement the HLS process. And when the code conversion tool is determined, the programmer is required to be familiar with the high-level programming language suitable for the code conversion tool, resulting in high difficulty in operating the method.
[0028] To solve the above-mentioned problems in the related art, an embodiment of the present application provides a code processing method, which comprises 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 is used to convert the code of the first language type into a 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 a code of a preset language type; performing syntax analysis on the code converted into the preset language type to obtain a syntax tree of the file to be processed, and obtaining a target code according to the syntax tree. After obtaining the file to be processed, no matter whether the first language type of the code in the file to be processed is compatible with the compiler backend, and no matter what the first language type of the file to be processed received by the compiler is, the code therein can be converted into a code of a preset language type that is compatible with the compiler backend through a first code conversion rule corresponding to the first language type of the code in the file to be processed. That is, based on this embodiment, multiple first language types of files to be processed can share a compiler backend, so that 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 for files to be processed of different first language types through the same compiler, thereby solving the problem in the related art that one code conversion tool can only process one file to be processed. The method is simple, intelligent and efficient.
[0029] The code processing method provided in the embodiment of the present application is described in detail below through specific embodiments in conjunction with the accompanying drawings.
[0030] Figure 2 is a flowchart of a code processing method provided by an embodiment of the present application, such as Figure 2 As shown, the method may include: Step 101: Obtain a file to be processed and a first language type of a code in the file to be processed.
[0031] The file to be processed includes codes generated according to a first language type. The first language type may be any high-level programming language. For example, the first language type may be C language, C++ language, Python language, etc., which is not limited here.
[0032] For example, the first language type of the code in the to-be-processed file may be obtained according to the file extension of the to-be-processed file or a code keyword in the to-be-processed file.
[0033] Step 102: Obtain a first code conversion rule corresponding to the first language type.
[0034] The first code conversion rule is used to convert the code of the first language type into the code of the preset language type, and the preset language type is compatible with the compiler.
[0035] The first code conversion rule is recorded in a syntax tree description file. For example, multiple syntax tree description files corresponding to language types are obtained and stored in a folder accessible to the compiler, wherein each syntax tree description file records a conversion rule for converting the code of the language type corresponding to it into the 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 to be processed, and then determines the syntax tree description file corresponding to the first language type from the folder where the syntax tree description files are stored, and obtains the first code conversion rule in the syntax tree description file.
[0036] Further, according to the correspondence between the language type and the syntax tree description file, a syntax tree description file corresponding to the first language type is obtained, and the syntax tree description file records a first code conversion rule. The first code conversion rule at least includes: a syntax code conversion rule for converting the code of the first language type into the code of the preset language type.
[0037] Specifically, the preset language type adapted to the compiler is a language type that can be processed by the compiler backend to convert the code into the target code. Further, after receiving the file to be processed, the compiler frontend converts the code of the first language type of the file to be processed into the code of the preset language type according to the first code conversion rule, and the compiler backend obtains the target code based on the converted code of the preset language type.
[0038] Step 103: based on the first code conversion rule, convert the code of the first language type in the to-be-processed file into a code of a preset language type.
[0039] Specifically, according to a first code conversion rule for converting a code of a first language type into a code of a preset language type in a syntax tree description file, the code of the first language type in the to-be-processed file is converted into a code of the preset language type.
[0040] For example, the first code conversion rule includes a syntax conversion rule for converting a code of the first language type into a code of a preset language type. For example, the first language type is Python, and the preset language type is C. When generating code based on Python, the code line does not need to end with the symbol ";", while in C, the code line needs to end with the symbol ";". Then the first code conversion rule for converting the code of the first language type into the code of the preset language type includes at least: adding the symbol ";" at the end of the code line in the file to be processed.
[0041] Step 104, performing syntax analysis on the code converted into the preset language type to obtain a syntax tree of the file to be processed, and obtaining the target code according to the syntax tree.
[0042] The compiler front end performs syntax analysis on the code converted into the preset language type to obtain a syntax tree of the file to be processed. The compiler back end performs code optimization based on the syntax tree and generates target code based on the optimized code.
[0043] In the related art, a domain-specific language (DSL) can be constructed based on Scala or Python, such as Chisel (Constructing Hardware in a ScalaEmbedded Language) or PyMTL (Python Multi-level Timing Library). This method implements syntax analysis through mechanisms such as custom classes and operator overloading, and the method is complex and the processing steps are cumbersome. However, 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, which is more flexible.
[0044] The method of the present application supports the conversion of various high-level programming languages into HDL, especially supports the conversion of basic syntax and static data types. Further, the present embodiment can support dynamic memory and dynamic data types. For example, dynamic variable types such as Python dictionaries, sets, lists, etc. can be converted to the hardware implementation of Field Programmable Gate Array (FPGA).
[0045] In summary, in the embodiment of the present application, a file to be processed and a first language type of the code in the file to be processed 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 a 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 a code of a preset language type; the code converted into the preset language type is subjected to grammatical analysis to obtain a syntax tree of the file to be processed, and the target code is obtained according to 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 to be processed is compatible with the compiler, the code of the file to be processed can be converted into a 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 to be processed, thereby 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 the code of the files to be processed of different first language types by the same compiler, which solves the problem that a code conversion tool in the related art can only process one file to be processed, resulting in an inconvenient and difficult code compilation method. This embodiment has the advantages of simple and intelligent methods.
[0046] Figure 3 is a flowchart of another code processing method provided in an embodiment of the present application, referring to Figure 3 , the method may include the following steps: Step 201: Obtain a file to be processed and a first language type of a code in the file to be processed.
[0047] The file to be processed is a file including codes to be compiled, and the first language type of the codes in the file to be processed may be any high-level programming language.
[0048] The file to be processed may be written in a high-level programming language and used as a source file for circuit verification.
[0049] For example, obtaining the to-be-processed file in step 201 may include sub-steps A1 to A2: Sub-step A1, generating a parameter setting statement for parameter setting based on a parameter setting format adapted to the compiler.
[0050] The parameter setting format adapted to the compiler is a standard parameter setting format suitable for the compiler. In one embodiment, the parameter setting format adapted to the compiler is a combination of "#param" and a parameter, and the test case is parameterized using this format to obtain a parameter setting statement.
[0051] For example, if the parameters include the main function main 0, the format of the parameter setting statement for setting the parameters of the main function main 0 is: #param entry=main0; if the parameters include the reset parameter rst_n, the format of the parameter setting statement for setting the parameters of the reset parameter rst_n is: #param rst=rst_n.
[0052] When compiling parameters, various parameter settings are performed using a standard parameter setting format that is compatible with the compiler. The parameter setting format is a standard format that is suitable for the compiler and has nothing to do with the actual high-level programming language syntax.
[0053] In this embodiment, the compilation parameters are set in a format that is independent of the syntax of each high-level programming language, so they are universal. When the to-be-processed files generated by different high-level programming languages are compiled using a compiler, the first language type corresponding to each high-level programming language is converted into a preset language type through the compiler front end. After the language type conversion of the code is performed by the front end, the to-be-processed files of different high-level programming languages can share the same compiler back end during the processing. In addition, after code processing based on the same shared compiler back end, the format of the HDL code exported by the compiler can be freely configured, which has nothing to do with the language type of the high-level programming language used by the front end. For example, the exported HDL code can be configured as a C language code, or it can be configured as a Verilog code.
[0054] Specifically, after the language type of the HDL code to be exported is configured, the compiler converts the code of the file to be processed into a preset type of code 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 language type set by the user according to the code conversion rules corresponding to the configured language type and exports it.
[0055] Sub-step A2: inserting the parameter setting statement into the file to be processed to obtain the file to be processed including the parameter setting statement.
[0056] According to the first language type, code for realizing a preset function is generated, and based on a parameter setting format compatible with the compiler, a parameter setting statement for parameter setting is generated, and the parameter setting statement is inserted into a code written in the language of the first language type to obtain a file to be processed including the parameter setting statement.
[0057] For example, in one embodiment, the first language type of the file code to be processed is C language, the parameters include main function main0 and main function main1, the code of the parameter setting statement for setting parameters for main function main 0 is: #param cpu [entry=main0], and the code of the parameter setting statement for setting parameters for main function main1 is: #param cpu [entry=main1].
[0058] For example, obtaining the first language type of the code in the file to be processed in step 201 may include sub-steps B1 and B2: Sub-step B1, obtaining the file extension of the file to be processed.
[0059] The file extension reflects the language type of the file to be processed. For example, the name of the file to be processed is "Ac", where A is the identifier of the file to be processed and ".c" is the file extension of the file to be processed.
[0060] Sub-step B2, obtaining the first language type of the code in the file to be processed according to the file extension.
[0061] For example, if the file extension of the file to be processed is ".c", it can be determined that the first language type of the code in the file to be processed is C language.
[0062] For example, the first language type of the file to be processed may be C language, Go language, JavaScript language, Python language, Scala language, Cangjie language, or other languages.
[0063] Furthermore, each language type has a corresponding syntax tree description file, which corresponds to the language type one by one, and records the conversion rules for converting the code of the corresponding language type into the code of the preset language type. The syntax tree description file is stored in a folder accessible to the compiler.
[0064] For example, the file names of the syntax tree description files of C language, go language, JavaScript language, Python language, Scala language, and Cangjie language are: C.ast, go.ast, JavaScript.ast, Python.ast, Scala.ast, Cangjie.ast.
[0065] For example, after the compiler obtains the file to be processed, if the first language type of the file to be processed is C language, the syntax tree description file C.ast is called from the folder storing the syntax tree description file, and the code of the file to be processed is converted into the code of the preset language type according to the first code conversion rule in the syntax tree description file C.ast.
[0066] For example, obtaining the first language type of the code in the file to be processed in step 201 may include sub-steps C1 to C2: Sub-step C1, obtaining code keywords in the file to be processed.
[0067] The code keyword is used to represent the first language type of the code in the file to be processed.
[0068] For example, the code in the file to be processed may be compared with the pre-stored code for representing the language type. If a code in the file to be processed belongs to the pre-stored code for representing the language type, it is determined as the code keyword in this step.
[0069] Sub-step C2, obtaining the first language type of the code in the file to be processed according to the code keyword.
[0070] For example, the first language type of the code in the file to be processed may be obtained according to the pragma tag parameter in the source code of the file to be processed.
[0071] Step 202: Obtain the correspondence between the preset language type and the code conversion rule.
[0072] The code conversion rule is recorded in the syntax tree description file, and the code conversion rule is used to convert the code of the language type corresponding to the code conversion rule into the code of the preset language type.
[0073] In order to dynamically support various high-level programming languages, in the design of the compiler of this embodiment, the syntax tree description files corresponding to each high-level programming language are written separately and stored in a designated folder accessible to the compiler.
[0074] Step 203: acquiring a first code conversion rule corresponding to the first language type according to a preset correspondence relationship between language types and code conversion rules.
[0075] Specifically, the language type in the corresponding relationship is compared with the first language type, and 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.
[0076] For example, after the compiler runs, the first language type of the code of the file to be processed is obtained according to the file extension or file suffix in the target file name of the file to be processed that is passed in, the syntax tree file corresponding to the first language type of the code of the file to be processed is dynamically read from the folder where the syntax tree file is stored, and compilation is performed based on the first code conversion rule in the syntax tree file.
[0077] Specifically, the syntax tree description file corresponding to the first language type includes: a code conversion rule for converting the code of the first language type into the code of the preset language type, and the preset language type is compatible with the compiler. For example, the code conversion rule includes the corresponding relationship between the syntax of the first language type code and the syntax of the preset language type code. Following step 203, the method also includes the following steps: Step 204: based on the first code conversion rule, convert the code of the first language type in the to-be-processed file into a code of a preset language type.
[0078] In this embodiment, the first language type of the file to be processed may be C language, go language, JavaScript language, Python language, Scala language, Cangjie language, or other high-level programming languages. This embodiment does not limit the type of the first language type, but no matter which high-level programming language the first language type of the code in the file to be processed is, based on this embodiment, the code of the file to be processed generated by the aforementioned high-level programming language can be converted into a code of a preset language type adapted by the compiler, and then converted into Verilog code or other types of code through a compiler backend capable of processing the preset language type.
[0079] For example, there are multiple first language types of the codes in the to-be-processed file. Accordingly, step 203 may include sub-step D1: Sub-step D1, obtaining first code conversion rules corresponding to each first language type.
[0080] For example, if the file to be processed is a mixed language file written in C language and Python language, in this step, a first code conversion rule corresponding to the C language and a first code conversion rule corresponding to the Python language are respectively obtained.
[0081] Based on sub-step D1, step 204 may include sub-step E1: Sub-step E1, based on the first code conversion rules corresponding to each first language type, converting the codes corresponding to each first language type in the to-be-processed file into codes of a preset language type.
[0082] For example, when analyzing the code in the to-be-processed file, the compiler, when identifying the first language type to which the code line belongs, uses the first code conversion rule corresponding to the first language type of the code line to convert the code line into a code of a preset language type. Based on this method, the mixed language type codes in the to-be-processed file can all be converted into codes of the preset type.
[0083] For example, the file to be processed is a mixed language type file written in C language and Python language. When a code line is identified as C language code, the first code conversion rule corresponding to the C language is used to convert the code line into a preset language type code; when a code line is identified as Python language code, the first code conversion rule corresponding to the Python language is used to convert the code into a preset language type code.
[0084] Based on the method of this embodiment, mixed language programming can be supported, that is, in a single to-be-processed file, any number of the following high-level programming languages can be mixed: C language, go language, JavaScript language, Python language, Scala language, Cangjie language, or other high-level programming languages. For the to-be-processed file that mixes multiple high-level programming languages, the method of this embodiment is used to obtain the first code conversion rules corresponding to each first language type, and based on the first code conversion rules corresponding to each first language type, the codes of each first language type in the to-be-processed file are converted into codes of a preset language type, so that all codes are converted into codes of the preset language type, and the target code is obtained based on the code of the preset language type, thereby completing the hardware design.
[0085] For example, the first code conversion rule includes: a correspondence between the syntax of the first language type code and the syntax of the preset language type code, then step 204 may include: according to the correspondence between the syntax of the first language type code and the syntax of the preset language type code, converting the first language type code in the to-be-processed file into a code that meets the syntax requirements of the preset language type.
[0086] For example, the first language type is Python, and the preset language type is C. The syntax code line of Python does not need to end with the symbol ";", while the syntax of C requires that the code line needs to end with the symbol ";". The first code conversion rule for converting the code of the first language type into the code of the preset language type at least includes: adding the symbol ";" at the end of the code line in the to-be-processed file, so that the converted code meets the syntax requirements of the C language.
[0087] Step 205, perform syntax analysis on the code converted into the preset language type to obtain a syntax tree of the file to be processed, and obtain the target code according to the syntax tree.
[0088] For example, the target code has a corresponding second language type. Step 205 may include sub-steps F1 to F2: Sub-step F1, setting the state counter value of the state machine for the statement in the syntax tree.
[0089] Among them, the state counter is a programming 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.
[0090] Sub-step F2, generating a state machine corresponding to the statement according to the state counter value, and obtaining the target code.
[0091] The state machine is a state machine in the form of a decision statement, and the decision statement is compatible with the second language type.
[0092] For example, if the second language type is C language, the state machine is in switch form; if the second language type is Verilog language, the state machine is in case form.
[0093] In one embodiment, the second language type of the target code is Verilog language, and PC0 can be used to set the state counter value of the state machine and generate a state machine in a case form.
[0094] The target code is a code of a hardware description language, or a code of a language other than a hardware description language. For example, the target code can be a code of the Verilog language, or a code of the C language.
[0095] In this embodiment, a general syntax tree data structure is defined inside the compiler. This general syntax tree data structure is a syntax tree data structure of a preset language type. According to the method of this embodiment, no matter what high-level programming language is the first language type of the file code to be processed, after the compiler receives the file to be processed, all kinds of high-level programming languages therein will be compiled into this data structure. After the high-level programming language is compiled into the general syntax tree data structure, a state machine can be created based on this data structure, and a state can be assigned to each syntax statement to realize the conversion from high-level language to HDL.
[0096] For example, the target code is a code of a hardware description language; the file to be processed includes at least one main function. Step 205 may also include sub-steps G1 to G2: Sub-step G1, according to the syntax tree, obtain the code segments corresponding to each main function in the file to be processed.
[0097] The code segment corresponding to the main function includes at least one code line that takes the main function as the entry and is executed sequentially.
[0098] Sub-step G2, converting each code segment into a program block that complies with the syntax requirements of the hardware description language to obtain the target code.
[0099] When the target code is subsequently executed, each program block is executed in parallel.
[0100] The program block may be a program block (always block) in the Verilog language. During the execution process, each always block is executed in parallel. An always block corresponds to a code segment of a main function, and the code lines in the code segment of the main function are executed in sequence. Correspondingly, the code lines in an always block are executed in sequence.
[0101] This embodiment supports the definition of multiple main functions. The compilation system will compile each main function into an always block to achieve parallel execution on hardware, making up for the low efficiency of sequential execution of high-level programming languages and achieving parallel use independent of various high-level programming languages.
[0102] Furthermore, the compiler used to execute the method of this embodiment supports multi-task parallelization at the hardware level. Specifically, the user is allowed to write multiple main functions, and the compiler will compile each main function into an independent always statement block to achieve hardware multi-threading, thereby making full use of hardware parallelization.
[0103] The following takes the case where the first language type is C language and two main functions are defined in the file to be processed as an example to illustrate the method of this embodiment: through sub-steps A1 to A2, a parameter setting statement for setting parameters for the main function main0 is generated: #param cpu [entry=main0;], and a parameter setting statement for setting parameters for the main function main0 is generated: #param cpu [entry=main1;].
[0104] Based on the method of this embodiment, the target code (for example, Verilog code) obtained after compiling and converting the to-be-processed file containing the main functions main0 and main1 includes two always blocks, one of which is used to execute the code segment corresponding to the main function main0, and the other 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 realize hardware parallel processing.
[0105] It should be noted that, through sub-steps F1 to F2, a state machine corresponding to the code statement can be generated, and through sub-steps G1 to G2, each code segment can be converted into a program block that meets the grammatical requirements of the hardware description language, thereby generating a target code with a state machine and multiple program blocks.
[0106] Step 206: If the second language type of the target code is a hardware description language, the target code is executed through a field programmable gate array.
[0107] For example, if the target code is Verilog code, it is burned into the FPGA and executed.
[0108] Step 207: If the second language type of the target code is another language type, the target code is executed by the preset simulation software.
[0109] For example, if the target code is a C language code, the target code can be executed by simulation software to realize the simulation of the hardware circuit.
[0110] Based on the method of this embodiment, no matter what high-level programming language the first language type of the file code to be processed is, no matter whether the file to be processed includes one or more codes of the first language type, after receiving the file to be processed, the compiler can convert it into a code of a preset language type adapted by the compiler by obtaining the first code conversion rule corresponding to the first language type, thereby, the compiler backend can convert it into a target code based on the code converted into the preset language type. In addition, based on the method of this embodiment, not only can the Verilog code that needs to be burned into the FPGA for testing be obtained, but also the target code of other language types that can perform circuit hardware simulation can be obtained, for example, the code of the C language can be obtained. Specifically, by setting a state machine, the target code of other language types has the function of hardware simulation of the circuit.
[0111] In addition to converting high-level programming languages into HDL, the present 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 the execution process, the state machine is used to promote the sequential execution of implementation statements to simulate the operation of the hardware.
[0112] This embodiment realizes the development of a flexibly configurable compiler framework, wherein the compiler front end supports compiling syntax trees of various configurable high-level programming languages, and the compiler back end is implemented in a unified manner to generate HDL codes.
[0113] The HLS technology in the related art usually only supports the conversion of a single high-level programming language to HDL. This application introduces a multi-front-end support mechanism to support dynamic loading of syntax trees of corresponding language types according to tags during compilation, thereby realizing multi-front-end language syntax support; specifically, through the code conversion rules in the syntax tree description file corresponding to the language type, the code in the to-be-processed file received by the compiler is converted into code of a unified language type, thereby realizing multi-front-end language syntax support. The HLS tool in the related art usually only supports the definition of one main function, focusing on parallel optimization at the statement level. This application allows users to write multiple main functions to execute code simultaneously, realizing hardware parallelization; specifically, each main function is converted into a corresponding always block, and hardware parallelization is realized based on the always blocks corresponding to each main function.
[0114] Since the present application does not limit the first language type of the file to be processed, as long as it is converted into a preset type of code, it can be compiled into a target code through the compiler backend, which enables programmers with only software IT background to design and develop hardware circuits or FPGAs. It does not require programmers to be familiar with Verilog language or a specific high-level programming language. Programmers generate files to be processed according to the language type they are familiar with, and the compiler front end will automatically convert it into a preset language type code, and then convert it into Verilog language code or C program with a state machine through the backend, thereby realizing agile development of circuit design. In addition, based on the method of this embodiment, the HDL generated by the high-level programming language can be used for the verification of digital circuits. Therefore, it can support programmers to write incentive codes in the high-level programming language they are good at, without the need to use HDL to write codes, which reduces the difficulty of digital circuit verification and saves the manpower cost of digital circuit verification.
[0115] The code conversion methods in related technologies have problems such as incompatibility in semantics, compilation parameters, and export formats, and have the defect of code fragmentation. This embodiment proposes a standard framework to support the compilation of various high-level programming languages into HDL, which has the advantages of unified semantics, universal compilation parameters, and support for parallelization. Reference Figure 4 The method of this embodiment may include the following steps: Step S1, obtaining a file to be processed; the language type of the code in the file to be processed is a first language type.
[0116] The first language type may be C language, Go language, JavaScript language, Python language, Scala language, Cangjie language, or other high-level programming languages.
[0117] Step S2, converting the code in the file to be processed into a preset type of code according to the syntax tree description file through a compiler, and generating a target code according to the preset type of code.
[0118] The syntax tree description file includes a first code conversion rule for converting a code of a first language type into a code of a preset language type.
[0119] Specifically, syntax tree description files corresponding to multiple language types are pre-built and stored in a folder accessible to the compiler. The syntax tree description file records code conversion rules for converting the code of the language type corresponding to the syntax tree description file into a code of a preset type. In other words, the folder records the correspondence between the language type and the code conversion rules.
[0120] After the compiler obtains the file to be processed, it identifies the first language type of the code in the file to be processed, and then obtains the syntax tree description file corresponding to the first language type from the folder for storing syntax tree description files, and obtains the first code conversion rule corresponding to the first language type in the syntax tree description file. Then, 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. The code converted into the preset language type is subjected to syntax analysis to obtain the syntax tree of the file to be processed, and the target code is obtained according to the syntax tree.
[0121] The target code is the code exported by the compiler, and the language type of the target code can be set according to user requirements, for example, it can be set to Verilog code or C language code.
[0122] Step S3: if the target code is a C language code with a state machine, a C program is obtained according to the target code, and the process goes to step S4.
[0123] The C language code obtained by the method of 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.
[0124] Step S4, simulating the C program including the target code.
[0125] The state machine can simulate the pulse signal in the hardware circuit that triggers the circuit to perform the corresponding operation. Based on the C program with the state machine, the hardware circuit can be simulated.
[0126] Step S5: If the target code is Verilog code, the target code is burned into the field programmable gate array.
[0127] For example, the language type of the exported target code can be set for the compiler to output C language code or Verilog code.
[0128] Furthermore, burning the target code into a thread programmable gate array can realize hardware circuit simulation.
[0129] The compiler front end of this embodiment supports compiling syntax trees of various configurable high-level programming languages, and the compiler back end is implemented in a unified manner of generating HDL codes.
[0130] In this embodiment, when the compiler reads a file to be processed, it can obtain the first language type of the file to be processed through the file suffix of the file to be processed, load the syntax tree description file corresponding to the first language type, and compile the file to be processed as a source file based on the first code conversion rule in the syntax tree description file; this embodiment can also obtain the first language type of the code that needs to be compiled subsequently according to the pragma tag parameter in the source code of the file to be processed, and the compiler dynamically switches the syntax tree description file according to the tag parameter and compiles it.
[0131] In this embodiment, after the intermediate syntax tree is generated, a state machine is constructed, wherein each line of statement is assigned a state number, and a state machine in the form of a decision statement that is compatible with the second language type of the exported target code is generated. For example, if the target code to be exported is Verilog code, a state machine in the form of a Verilog case statement is generated to complete the generation of the Verilog code. If the C language code to be exported is C language code, a state machine in the form of a C language switch statement is generated to complete the generation of the C language code.
[0132] refer to Figure 5 , which shows a code processing device provided in an embodiment of the present application, the code processing device 30 includes: A first acquisition module 301 is used to acquire a file to be processed and a first language type of a code in the file to be processed; The second acquisition module 302 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 a code of a preset language type; A conversion module 303, configured to convert the code of the first language type in the to-be-processed file into a code of a preset language type based on a first code conversion rule; The third acquisition module 304 is used to perform syntax analysis on the code converted into the preset language type, obtain a syntax tree of the file to be processed, and obtain the target code according to the syntax tree.
[0133] Optionally, the second acquisition module 302 includes: The first acquisition submodule is used to acquire the correspondence between the preset language type and the code conversion rule; the code conversion rule is used to convert the code of the language type corresponding to the code conversion rule into the code of the preset language type; The second acquisition submodule is used to acquire a first code conversion rule corresponding to the first language type according to a preset correspondence relationship between the language type and the code conversion rule.
[0134] Optionally, the target code is a code of a hardware description language; the file to be processed includes at least one main function; the third acquisition module 304 includes: The third acquisition submodule is used to obtain the code segments corresponding to each main function in the to-be-processed file according to the syntax tree; The fourth acquisition submodule is used to convert each code segment into a program block that meets the syntax requirements of the hardware description language to obtain the target code; when the target code is subsequently executed, each program block is executed in parallel.
[0135] Optionally, there are multiple first language types of the code in the file to be processed, and the second acquisition module 302 may include: A fifth acquisition submodule, used to respectively acquire a first code conversion rule corresponding to each first language type; The conversion module 303 includes: The first conversion submodule is used to convert the codes of each first language type in the to-be-processed file into codes of a preset language type based on the first code conversion rules corresponding to each first language type.
[0136] Optionally, the target code is a code of a hardware description language, or a code of a language other than the hardware description language; the apparatus 30 further includes: A first processing module is used for, after obtaining the target code according to the syntax tree, executing the target code through a field programmable gate array if the second language type of the target code is a hardware description language; The second processing module is used to execute the target code through the preset simulation software if the second language type of the target code is other language types.
[0137] Optionally, the first acquisition module 301 includes: A generation submodule, for generating a parameter setting statement for performing parameter setting based on a parameter setting format adapted to the compiler; The sixth acquisition submodule is used to insert the parameter setting statement into the file to be processed to obtain the file to be processed including the parameter setting statement.
[0138] Optionally, the target code has a corresponding second language type; the third acquisition module 304 includes: The setting submodule is used to set the state counter value of the state machine for the statements in the syntax tree; The seventh acquisition submodule is used to generate a 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 compatible with the second language type.
[0139] Optionally, the first code conversion rule includes: a correspondence between the syntax of the first language type code and the syntax of the preset language type code; the conversion module 303 includes: The second conversion submodule is used to convert the code of the first language type in the to-be-processed file into a code that meets the grammatical requirements of the preset language type according to the correspondence between the grammar of the first language type code and the grammar of the preset language type code.
[0140] Optionally, the first acquisition module 301 includes: An eighth acquisition submodule is used to obtain the file extension of the file to be processed; The ninth acquisition submodule is used to acquire the first language type of the code in the file to be processed according to the file extension.
[0141] Optionally, the first acquisition module 301 may include: A tenth acquisition submodule is used to acquire code keywords in the file to be processed; the code keywords are used to represent the first language type of the code in the file to be processed; The eleventh obtaining submodule is used to obtain the first language type of the code in the file to be processed according to the code keyword.
[0142] In this embodiment, after the compiler obtains the file to be processed, regardless of whether the first language type of the code in the file to be processed is compatible with the compiler, the code therein can be converted into a code of a preset language type that is compatible with the compiler through a first code conversion rule corresponding to the first language type of the code in the file to be processed, thereby 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 the files to be processed of different first language types by the same compiler, solving the problem in the related art that one code conversion tool can only process one file to be processed, resulting in an inconvenient and difficult code compilation method. This embodiment has the advantages of being simple and intelligent.
[0143] Figure 6 4 is a block diagram of an electronic device 400 according to an exemplary embodiment. For example, the electronic device 400 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0144] Reference Figure 6 , the electronic device 400 may include one or more of the following components: a processing component 402 , a memory 404 , a power component 406 , a multimedia component 408 , an audio component 410 , an input / output (I / O) interface 412 , a sensor component 414 , and a communication component 416 .
[0145] The processing component 402 generally controls the overall operation of the electronic device 400, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 402 may include one or more processors 420 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 402 may include one or more modules to facilitate the interaction between the processing component 402 and other components. For example, the processing component 402 may include a multimedia module to facilitate the interaction between the multimedia component 408 and the processing component 402.
[0146] The memory 404 is used to store various types of data to support the operation of the electronic device 400. Examples of such data include instructions for any application or method operating on the electronic device 400, contact data, phone book data, messages, pictures, multimedia, etc. The 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 memory, flash memory, magnetic disk or optical disk.
[0147] The power supply component 406 provides power to the various components of the electronic device 400. The 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 the electronic device 400.
[0148] The multimedia component 408 includes a screen that provides an output interface between the electronic device 400 and the 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 touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the demarcation of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 408 includes a front camera and / or a rear camera. When the electronic device 400 is in an operating mode, such as a shooting mode or a multimedia mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0149] The audio component 410 is used to output and / or input audio signals. For example, the audio component 410 includes a microphone (MIC), and when the electronic device 400 is in an operation mode, such as a call mode, a recording mode, and a voice acquisition mode, the microphone is used to receive an external audio signal. The received audio signal can be further stored in the memory 404 or sent via the communication component 416. In some embodiments, the audio component 410 also includes a speaker for outputting audio signals.
[0150] 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: a home button, a volume button, a start button, and a lock button.
[0151] The sensor assembly 414 includes one or more sensors for providing various aspects of status assessment for the electronic device 400. For example, the sensor assembly 414 can detect the open / closed state of the electronic device 400, the relative positioning of components, such as the display and keypad of the electronic device 400, and the sensor assembly 414 can also detect the position change of the electronic device 400 or a component of the electronic device 400, the presence or absence of user contact with the electronic device 400, the orientation or acceleration / deceleration of the electronic device 400, and the temperature change of the electronic device 400. The sensor assembly 414 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 414 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 414 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0152] The communication component 416 is used to facilitate wired or wireless communication between the electronic device 400 and other devices. The electronic device 400 can access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 416 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 416 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency acquisition (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0153] 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 an embodiment of the present application.
[0154] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 404 including instructions, and the above instructions can be executed by a processor 420 of an electronic device 400 to perform the above method. For example, the non-transitory storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0155] Figure 7 is a block diagram of an electronic device 500 according to an exemplary embodiment. For example, the electronic device 500 may be provided as a server. Figure 7 The electronic device 500 includes a processing component 522, which further includes one or more processors, and a memory resource represented by a memory 532 for storing instructions that can be executed by the processing component 522, such as an application. The application stored in the memory 532 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 522 is configured to execute instructions to perform a code processing method provided in an embodiment of the present application.
[0156] The electronic device 500 may also include a power supply component 526 configured to perform power management of the electronic device 500, a wired or wireless network interface 550 configured to connect the electronic device 500 to a network, and an input / output (I / O) interface 558. The electronic device 500 may operate based on an operating system stored in the memory 532, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™ or the like.
[0157] An embodiment of the present 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.
[0158] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the application disclosed herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0159] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
[0160] The above are only preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
[0161] The above is a detailed introduction to a code processing method, device, electronic device and computer-readable storage medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for a person skilled in the art, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A code processing method, characterized in that: Applied to the compiler, the methods include: Obtain a file to be processed and a first language type of a code in the file to be processed; 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 a code of a preset language type; Based on the first code conversion rule, converting the code of the first language type in the to-be-processed file into a code of a preset language type; The code converted into the preset language type is subjected to grammatical analysis to obtain a grammatical tree of the file to be processed, and a target code is obtained according to the grammatical tree.
2. The method according to claim 1, characterized in that: The acquiring a first code conversion rule corresponding to the first language type includes: Acquire a correspondence between a preset language type and a code conversion rule; the code conversion rule is used to convert a code of a language type corresponding to the code conversion rule into a code of the preset language type; According to the preset correspondence between the language type and the code conversion rule, a first code conversion rule corresponding to the first language type is acquired.
3. The method according to claim 1, characterized in that The target code is a code of a hardware description language; the file to be processed includes at least one main function; and obtaining the target code according to the syntax tree includes: According to the syntax tree, obtain the code segments corresponding to the to-be-processed file and each of the main functions respectively; Each of the code segments is converted into a program block that meets the grammatical requirements of the hardware description language to obtain a target code; during the subsequent execution of the target code, each of the program blocks is executed in parallel.
4. The method according to claim 1, characterized in that: There are multiple first language types of the code in the to-be-processed file, and obtaining a first code conversion rule corresponding to the first language type includes: Acquire a first code conversion rule corresponding to each of the first language types; The converting the code of the first language type in the to-be-processed file into a code of a preset language type based on the first code conversion rule includes: Based on the first code conversion rule corresponding to each first language type, the code corresponding to each first language type in the to-be-processed file is converted into the code of the preset language type.
5. The method according to claim 1, characterized in that The target code is a code of a hardware description language, or a code of a language type other than the hardware description language; after obtaining the target code according to the syntax tree, the method further includes: If the second language type of the target code is a hardware description language, executing the target code 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 using preset simulation software.
6. The method according to claim 1, characterized in that The obtaining of the to-be-processed file comprises: Based on a parameter setting format adapted to the compiler, generating a parameter setting statement for performing parameter setting; Inserting a parameter setting statement into the file to be processed to obtain the file to be processed including the parameter setting statement.
7. The method according to claim 1, characterized in that The target code has a corresponding second language type; and obtaining the target code according to the syntax tree comprises: Setting a state counter value of a state machine for a statement in the syntax tree; According to the state counter value, a state machine corresponding to the statement is generated 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 compatible with the second language type.
8. A code processing device, characterized in that: The device comprises: A first acquisition module, used to acquire a file to be processed and a first language type of a code in the file to be processed; A 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 a code of a preset language type; A conversion module, configured to convert the code of the first language type in the to-be-processed file into a code of a preset language type based on the first code conversion rule; The third acquisition module is used to perform syntax analysis on the code converted into the preset language type to obtain a syntax tree of the file to be processed, and obtain the target code according to the syntax tree.
9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the method as claimed in any one of claims 1 to 7.
Citation Information
Patent Citations
Programming language integration method, programming software system and electronic device
CN111651165A
Multi-language compiling method, system and device and computer storage medium
CN116737161A
Program language conversion method and device, equipment and storage medium
CN117093228A
Code compiling method and device and compiler
CN117519715A
System and Method for translating high programming level languages code into Hardware Description Language code
US20100131933A1