Code generation method for hardware code expansion

文档序号:1391804 发布日期:2020-02-28 浏览:21次 中文

阅读说明:本技术 一种可用于硬件代码扩展的代码生成方法 (Code generation method for hardware code expansion ) 是由 郑重 隋兵才 倪晓强 雷国庆 王俊辉 郭维 郭辉 孙彩霞 王永文 黄立波 于 2019-11-14 设计创作,主要内容包括:本发明公开了一种可用于硬件代码扩展的代码生成方法,实施步骤包括针对待处理的硬件代码,抽取硬件代码中需要扩展的代码;针对需要扩展的代码提取其中的元操作,所述元操作是指硬件代码扩展时具有规律的代码修改的操作,且预先配置有对应的使用其他软件编程语言实现的软件代码;将需要扩展的硬件代码使用元操作和硬件语言进行混合表示;判断需要扩展的硬件代码使用元操作时是否存在需要配置的参数,如果存在需要配置的参数则配置对应的参数;将元操作表示的软件代码进行扩展,生成目标硬件语言的新的硬件代码。本发明具有效率高、代码清晰、维护性强、便于移植的优点。(The invention discloses a code generation method for hardware code expansion, which comprises the following implementation steps of extracting codes needing to be expanded in hardware codes aiming at the hardware codes to be processed; extracting meta-operation in the code to be expanded, wherein the meta-operation refers to operation of regular code modification when the hardware code is expanded, and is pre-configured with corresponding software code realized by using other software programming languages; performing mixed representation on hardware codes needing to be expanded by using meta-operation and hardware languages; judging whether parameters needing to be configured exist in the hardware code using element operation needing to be expanded, and configuring corresponding parameters if the parameters needing to be configured exist; and expanding the software code represented by the meta-operation to generate a new hardware code of the target hardware language. The invention has the advantages of high efficiency, clear codes, strong maintainability and convenient transplantation.)

1. A code generation method usable for hardware code expansion, characterized by the implementation steps comprising:

1) extracting codes needing to be expanded in the hardware codes aiming at the hardware codes to be processed;

2) extracting meta-operation in the code to be expanded, wherein the meta-operation refers to operation of regular code modification when the hardware code is expanded, and is pre-configured with corresponding software code realized by using other software programming languages;

3) performing mixed representation on hardware codes needing to be expanded by using meta-operation and hardware languages;

4) judging whether parameters needing to be configured exist in the hardware code using element operation needing to be expanded, and configuring corresponding parameters if the parameters needing to be configured exist;

5) and expanding the software code represented by the meta-operation to generate a new hardware code of the target hardware language.

2. The code generation method applicable to hardware code expansion according to claim 1, wherein the step 5) is followed by adding hardware code, which is expressed by mixing meta-operation and hardware language, as an annotation to the hardware code to facilitate maintenance of the hardware code.

3. The code generation method applicable to hardware code extension according to claim 1, wherein step 5) specifically refers to generating new hardware code of the target hardware language in an editor of an integrated development environment of hardware code.

4. A code generation system operable for hardware code expansion, comprising:

the code extraction program unit is used for extracting codes needing to be expanded in the hardware codes aiming at the hardware codes to be processed;

the meta-operation extraction program unit is used for extracting meta-operations in the code to be expanded, wherein the meta-operations refer to operations with regular code modification when the hardware code is expanded, and are pre-configured with corresponding software codes realized by using other software programming languages;

a code representation program unit for performing mixed representation on the hardware code needing to be expanded by using meta-operation and hardware language;

the parameter configuration program unit is used for judging whether parameters needing to be configured exist in the hardware code using element operation needing to be expanded, and if the parameters needing to be configured exist, configuring corresponding parameters;

and a code generation program unit for expanding the software code expressed by the meta-operation to generate a new hardware code of the target hardware language.

5. A code generation system usable for hardware code expansion, comprising a computer device, characterized in that the computer device is programmed or configured to perform the steps of the code generation method usable for hardware code expansion as claimed in any one of claims 1 to 3.

6. A code generating system for hardware code expansion, comprising a computer device, characterized in that the computer device at least comprises a microprocessor and a memory, and the memory stores a computer program programmed or configured to execute the code generating method for hardware code expansion according to any one of claims 1 to 3.

7. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a computer program programmed or configured to execute the code generation method for hardware code expansion of any one of claims 1 to 3.

Technical Field

The invention relates to the field of hardware code programming, in particular to a code generation method for hardware code expansion.

Background

In the engineering of a processor or other hardware design, different hardware design codes may be obtained by modifying the resource size on the same design for different requirements, such as different performances, power consumption, and the like. Or when the performance evaluation is carried out, a plurality of versions of codes are configured to evaluate the optimal design. For example, in a design, to evaluate the impact of different queue depths on overall performance and power consumption, code implementing queues of different numbers of entries is required.

Current hardware design languages, such as Verilog, may support some of the different configurations through macro definition methods. However, macro definitions are generally used to define data of different widths, and complex designs are difficult to implement by simple macro definitions. Different code versions can also be modified manually by hardware designers, the modification is time-consuming and labor-consuming, only a few limited configuration codes can be realized, and the method needs to maintain a plurality of sets of codes, thereby increasing the complexity of engineering. Another method is to print all the code to be modified in a scripting language and then generate new code according to the required configuration. Therefore, repeated manual labor can be avoided, but the script language has the problems of difficulty in reading and maintenance. Meanwhile, a script language written for a specific hardware code is difficult to be easily transplanted to other projects.

Disclosure of Invention

The technical problems to be solved by the invention are as follows: aiming at the problems in the prior art, the code generation method which is high in efficiency, clear in code, strong in maintainability and convenient to transplant and can be used for hardware code expansion is provided.

In order to solve the technical problems, the invention adopts the technical scheme that:

a code generation method for hardware code extension includes the following implementation steps:

1) extracting codes needing to be expanded in the hardware codes aiming at the hardware codes to be processed;

2) extracting meta-operation in the code to be expanded, wherein the meta-operation refers to operation of regular code modification when the hardware code is expanded, and is pre-configured with corresponding software code realized by using other software programming languages;

3) performing mixed representation on hardware codes needing to be expanded by using meta-operation and hardware languages;

4) judging whether parameters needing to be configured exist in the hardware code using element operation needing to be expanded, and configuring corresponding parameters if the parameters needing to be configured exist;

5) and expanding the software code represented by the meta-operation to generate a new hardware code of the target hardware language.

Optionally, in order to facilitate the maintenance of the hardware code, step 5) is followed by adding the hardware code, which is expressed by mixing the meta-operation and the hardware language, as an annotation to the hardware code to facilitate the maintenance of the hardware code.

Optionally, in order to implement the unification of the hardware programming environment, the step 5) specifically refers to generating new hardware code of the target hardware language in an editor of the integrated development environment of the hardware code.

In addition, the present invention also provides a code generation system for hardware code extension, comprising:

the code extraction program unit is used for extracting codes needing to be expanded in the hardware codes aiming at the hardware codes to be processed;

the meta-operation extraction program unit is used for extracting meta-operations in the code to be expanded, wherein the meta-operations refer to operations with regular code modification when the hardware code is expanded, and are pre-configured with corresponding software codes realized by using other software programming languages;

a code representation program unit for performing mixed representation on the hardware code needing to be expanded by using meta-operation and hardware language;

the parameter configuration program unit is used for judging whether parameters needing to be configured exist in the hardware code using element operation needing to be expanded, and if the parameters needing to be configured exist, configuring corresponding parameters;

and a code generation program unit for expanding the software code expressed by the meta-operation to generate a new hardware code of the target hardware language.

Furthermore, the present invention also provides a code generation system usable for hardware code expansion, comprising a computer device programmed or configured to execute the steps of the code generation method usable for hardware code expansion.

Furthermore, the present invention also provides a code generation system usable for hardware code expansion, comprising a computer device including at least a microprocessor and a memory, and the memory having stored thereon a computer program programmed or configured to execute the code generation method usable for hardware code expansion.

Furthermore, the present invention also provides a computer-readable storage medium having stored thereon a computer program programmed or configured to execute the code generation method usable for hardware code expansion.

Compared with the prior art, the invention has the following advantages:

1) the efficiency is high. After the codes are realized through the meta-operation once, the generation of different codes only needs to configure different parameters, the codes with different configurations can be generated quickly, and the time-consuming operation of manual modification is avoided.

2) The code is clear and convenient to manage. Compared with the hardware code generated by completely using the script language, the implementation mode of the meta-operation mixed hardware language has the advantages of clear and readable code and convenience in management and modification.

3) The portability is strong. Because the meta-operation is self-defined, the meta-operation with the same function can be repeatedly used in different designs without repeated definition, thereby avoiding the problem that codes are difficult to reuse when a script language is completely used.

Drawings

FIG. 1 is a schematic diagram of a basic flow of a method according to an embodiment of the present invention.

FIG. 2 is a diagram of codes requiring expansion with a queue depth of 4 according to an embodiment of the present invention.

FIG. 3 is a diagram of code with a queue depth of 8 according to an embodiment of the present invention.

FIG. 4 is a diagram of extensible code written in a hardware language and meta-operations according to an embodiment of the present invention.

FIG. 5 is a diagram illustrating integration of extensible code into a hardware code source file according to an embodiment of the present invention.

Detailed Description

As shown in fig. 1, the implementation steps of the code generation method for hardware code extension of this embodiment include:

1) extracting codes needing to be expanded in the hardware codes aiming at the hardware codes to be processed;

according to the requirements of design and code extension, only part of the code in the hardware code generally relates to part of the code, and the part of the code needs to be extracted to determine the code needing to be modified. And meanwhile, determining a code modification mode according to the requirements of extension, namely what the code should be modified when the code is extended to different requirements. This part of the work is necessary regardless of the method of using any code extension. For example, in a certain part of code, the hardware code that needs to be extended is shown in fig. 2.

2) Extracting meta-operation in the code to be expanded, wherein the meta-operation refers to operation of regular code modification when the hardware code is expanded, and is pre-configured with corresponding software code realized by using other software programming languages;

meta-operation refers to the form of code modification with certain rules when hardware code is extended. For example, when the queue depth is 4, the code for data selection is as shown in fig. 2, and when the queue depth is 8, the code for data selection is as shown in fig. 3. With reference to fig. 2 and 3, the meta-operations of the code extension that need to be summarized can be two of: first, the assignment of the number of queue depths, that is, dst [4:0] = qx _ data [4:0], that is, here, it is necessary to be able to automatically generate assignment statements of the number of configurations according to the configurations. When the queue depth is 4, 4 assignment statements are needed, when the queue depth is 8, 8 assignment statements are needed, and qx of each assignment statement is different: from q0 to q 7. This requires a meta-operation that automatically generates such hardware code. At this time, an element operation may be defined as loop (N), and the relevant code may be printed by performing N cycles. And secondly, generating a condition value of the Case statement, namely, a constant before the assignment statement, such as 3' b 010. Here, it is required that the constants of the assignment statements generated in 2.1 are configured, here we can see that regular binary representations of 0-7, and one meta-operation is required to generate some number of binary representations. Here, the number of bin operations may be defined as n _ bin (n), which means that a certain number n is represented in binary form.

It should be noted that the implementation of meta-operations using other programming languages as described in fig. 1 only indicates the time-series relationship of meta-operations implemented using other programming languages, and the meta-operations can be pre-configured by recording the meta-operations in advance as needed during actual application. Generally, a hardware language does not have such characteristics, and cannot be realized in the hardware language, and needs to be realized by other software programming languages. For example, the LOOP and n _ bank meta operations defined above in this embodiment may be implemented by a scripting language, such as Python.

3) Performing mixed representation on hardware codes needing to be expanded by using meta-operation and hardware languages;

and expressing the functions to be realized by mixing the codes to be expanded by using a meta-operation and hardware language. The code at this time is not a legitimate hardware code and cannot be used directly. For example, in fig. 2, after the meta-operation and hardware language in 2) are rewritten into the extensible code, as shown in fig. 4, wherein Q _ NUM is a configuration parameter indicating the depth of Queue of the current configuration, and Q _ LOG parameter indicates the bit width of Q _ NUM. The @ symbol indicates the number of current cycles in the LOOP cycle. Endlog indicates the end of the loop body.

4) Judging whether parameters needing to be configured exist in the hardware code using element operation needing to be expanded, and configuring corresponding parameters if the parameters needing to be configured exist;

the related parameters that need to be configured in the meta-operation are, for example, the queue depth mentioned earlier, where the parameters that need to be configured are Q _ NUM and Q _ LOG. When the queue depth is 8, Q _ NUM is 8 and Q _ LOG is 3.

5) And expanding the software code represented by the meta-operation to generate a new hardware code of the target hardware language.

And taking the software code expressed by the meta-operation as an implemented meta-operation interpreter, and expanding the code expressed by the meta-operation to generate a code of a target hardware language. At this time, the new hardware code is a legal hardware code and can be directly used for the subsequent flow of hardware design. When the queue depth is 8, the hardware code of fig. 3 will be generated directly after the code in fig. 4 is expanded.

As an alternative embodiment, step 5) is followed by adding hardware code, which is expressed by mixing the meta-operation and the hardware language, as an annotation to the hardware code to facilitate maintenance of the hardware code. Therefore, in the whole project, only one source code file needs to be maintained, and project management is facilitated. The code expressed by the meta-operation does not influence the hardware code, and when the expanded code has design problems, the expression of the meta-operation can be modified in the current code, and new code can be regenerated. For example, in FIG. 5, the extension code portion is put in the annotation of the code, and all of the extension code and object code can be managed using one file. And simultaneously, the CODE generated by automatic expansion is marked by the// AUTO CODE Begin and the// AUTO CODE End, so that when the CODE is regenerated, the original CODE can be deleted firstly, and the corresponding CODE can be regenerated.

As an alternative implementation, step 5) specifically refers to generating new hardware code of the target hardware language in an editor of the integrated development environment of the hardware code. The unification of the programming environment can be formed by integrating the hardware code extension function of the method of the embodiment into an editor, such as Vim or emails. After the codes needing to be expanded are expressed by using the meta-operation and the hardware language, the expansion effect can be immediately seen in the editing process, and the working efficiency is improved. For example, the extension function is put into a plug-in of a Vim editor, and shortcut keys for extending and deleting the extension are defined, so that the generation and browsing of the extensible code are realized.

In addition, the present embodiment also provides a code generation system for hardware code extension, including:

the code extraction program unit is used for extracting codes needing to be expanded in the hardware codes aiming at the hardware codes to be processed;

the meta-operation extraction program unit is used for extracting meta-operations in the code to be expanded, wherein the meta-operations refer to operations with regular code modification when the hardware code is expanded, and are pre-configured with corresponding software codes realized by using other software programming languages;

a code representation program unit for performing mixed representation on the hardware code needing to be expanded by using meta-operation and hardware language;

the parameter configuration program unit is used for judging whether parameters needing to be configured exist in the hardware code using element operation needing to be expanded, and if the parameters needing to be configured exist, configuring corresponding parameters;

and a code generation program unit for expanding the software code expressed by the meta-operation to generate a new hardware code of the target hardware language.

In addition, the present embodiment also provides a code generating system for hardware code expansion, which includes a computer device programmed or configured to execute the steps of the aforementioned code generating method for hardware code expansion of the present embodiment.

In addition, the present embodiment also provides a code generating system for hardware code expansion, which includes a computer device, where the computer device includes at least a microprocessor and a memory, and the memory stores thereon a computer program programmed or configured to execute the foregoing code generating method for hardware code expansion according to the present embodiment.

Furthermore, the present embodiment also provides a computer-readable storage medium, on which a computer program is stored, which is programmed or configured to execute the code generation method for hardware code expansion of the present embodiment.

The above description is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments, and all technical solutions belonging to the idea of the present invention belong to the protection scope of the present invention. It should be noted that modifications and embellishments within the scope of the invention may occur to those skilled in the art without departing from the principle of the invention, and are considered to be within the scope of the invention.

9页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种基于超收敛插值逼近的三维电磁慢扩散数值模拟方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类