A C++-based FPGA hardware construction language implementation system

Through the C++-based FPGA hardware construction language implementation system, the problem of insufficient abstraction and expression capabilities of the hardware description language is solved, the hardware design efficiency and controllability are improved, and multi-clock domain design support and efficient hardware development are achieved.

CN114756219BActive Publication Date: 2024-08-23ZHEJIANG UNIV
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210376210.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-11
Publication Date
2024-08-23
Estimated Expiration
2042-04-11

AI Technical Summary

Technical Problem

Existing hardware description languages ​​lack abstraction and expression capabilities, resulting in low hardware design efficiency and repetitive work. Existing hardware design tools have poor cross-platform support for software systems, making it difficult to achieve high customization and rapid debugging.

Method used

The FPGA hardware construction language based on C++ is used to implement the system. Through the code design unit, code compilation unit, intermediate language parsing unit and conversion unit, the C++ syntax design module is compiled into an intermediate language, and the hardware description language Verilog HDL is generated to support multi-clock domain design. and flexible register definition.

Benefits of technology

It improves hardware development efficiency and expression capabilities, achieves lower system resource consumption and faster conversion process, supports multi-clock domain design, and provides higher hardware controllability and customization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114756219B
    Figure CN114756219B
Patent Text Reader

Abstract

The present invention discloses a C++-based FPGA hardware construction language implementation system, comprising a code design unit, a code compilation unit, an intermediate language parsing unit and a conversion unit; the code design unit is used to provide a syntax design module implemented based on C++, and transmit a constructor designed based on the syntax design module to the code compilation unit, wherein the constructor records circuit design information; the code compilation unit is used to compile the design constructor using a C++ compiler to form an intermediate language; the intermediate language parsing unit is used to parse the intermediate language to obtain an intermediate language syntax tree; the conversion unit is used to generate a hardware description language Verilog HDL by analyzing the intermediate language syntax tree. The system integrates high-level programming language features into hardware design, improving hardware development efficiency and expression capabilities.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of hardware design, and in particular relates to a C++-based FPGA hardware construction language implementation system. Background Art

[0002] There are several problems in the current hardware design field:

[0003] First, the existing hardware description language lacks abstract ability and has weak expression ability, which results in problems such as difficult hardware design, much repetitive work, and low design efficiency, bringing a high threshold to hardware development.

[0004] Second, the community ecology in the hardware field is not as perfect as that in the software community. It lacks library support that allows for easy reuse, scalability, and rapid design construction, which makes the hardware design cycle relatively long and inefficient.

[0005] Third, hardware design is largely restricted by development tools, and existing hardware design tools have poor cross-platform support for software systems. In addition, the version compatibility of the tools themselves cannot meet the needs of designers and cannot provide designers with a good development experience.

[0006] The existence of the above three problems, on the one hand, hinders the development of the hardware design field itself, and on the other hand, increases the learning cost of hardware design, which in turn brings great difficulties to the progress of work in related fields of software and hardware collaboration.

[0007] In order to solve the above problems, there is a design method HLS (such as Vivado HLS) that quickly maps hardware design through high-level programming languages, which can automatically generate hardware design with corresponding functions for existing algorithms in software design. However, this design method is usually suitable for scenarios where certain algorithms need to be quickly implemented on hardware, but the controllability of the hardware finally mapped is low, and it is difficult to control it in a fine-grained manner. In addition, it is difficult to find and debug problems after design errors, so it cannot provide high customization.

[0008] Different from high-level synthesis languages, some foreign hardware construction languages ​​have also tried to solve the problems in hardware design. Hardware construction languages ​​are generally implemented by embedding a certain software programming language and finally converted into corresponding hardware designs. Existing research on hardware construction languages ​​is mainly based on Python and Scala implementations. For example, Pyverilog is based on Python, Chisel and SpinalHDL are based on Scala, and their target languages ​​are Verilog HDL. The implementation ideas of these technologies are to use software programming classes or functions to implement and convert hardware structures. There is no similar technology in China. Summary of the invention

[0009] In view of the above, the purpose of the present invention is to provide a C++-based FPGA hardware construction language implementation system, which integrates high-level programming language features into hardware design and improves hardware development efficiency and expression capabilities.

[0010] To achieve the above-mentioned invention object, the embodiment provides a C++-based FPGA hardware construction language implementation system, including a code design unit, a code compilation unit, an intermediate language parsing unit, and a conversion unit;

[0011] The code design unit is used to provide a syntax design module based on C++ implementation, and transmit a constructor of a class designed based on the syntax design module to the code compilation unit, wherein the constructor records circuit design information;

[0012] The code compiling unit is used to compile the design constructor using a C++ compiler to form an intermediate language;

[0013] The intermediate language parsing unit is used to parse the intermediate language to obtain an intermediate language syntax tree;

[0014] The conversion unit is used to generate a hardware description language Verilog HDL by analyzing an intermediate language syntax tree.

[0015] In one embodiment, the syntax design module includes a port set and a module design part, the module design part is implemented by a C++ constructor, and the module design part includes a wire net, a register, a hardware primitive module, a control flow, and a submodule;

[0016] The port set includes an input port and an output port, which are used to connect the designed circuit nodes, and the input port and the output port are implemented by a struct class in C++;

[0017] The wire net is used to record the connection relationship between the nodes of the design circuit, which is implemented by a class in C++, and the wire net name and the module to which the wire net belongs are recorded by defining the corresponding class of the wire net;

[0018] The register is used to record the intermediate value of the circuit element and hardware design, and is implemented by a class in C++, and the register name and the module to which the register belongs are recorded by defining the corresponding class of the wire net;

[0019] The hardware primitive module is implemented as a built-in function through a C++ function, and the port list corresponding to the function parameters is provided to the designer for design and use;

[0020] The control flow is implemented by classes in C++, avoiding built-in control flow keywords in C++, and supporting the if-else control flow mode and the switch-case control flow mode for design;

[0021] The submodule refers to a submodule of the grammar design module and has the same function as the grammar design module.

[0022] In one embodiment, the register supports multi-clock domain triggering, that is, the data contained in the register is changed by specifying a trigger signal of the register.

[0023] In one embodiment, the constructor parameter corresponding to the register maintains a sensitivity list, which includes multiple clock trigger signals, and the clock trigger signals are represented by different level signals or clock edges.

[0024] In one embodiment, the syntax design module supports overloading of related operators of hardware types such as wire nets, registers, input ports, and output ports, records the operator type and the names of the elements involved in the operation, and generates a hardware type of an intermediate node as the operation result to be returned, so as to enable continuous operation processes of multiple hardware types.

[0025] In one embodiment, the intermediate language parsing unit uses a grammar and lexical analysis tool to perform lexical analysis and generate a syntax tree for the intermediate language, thereby obtaining an intermediate language syntax tree in the memory that fully describes the hardware design, and each node of the intermediate language syntax tree is a component in the circuit design.

[0026] In one embodiment, in the conversion unit, the process of analyzing the intermediate language syntax tree to generate the hardware description language Verilog HDL includes:

[0027] (1) Construct an element reference mapping graph, that is, a mapping from an element reference name to an element reference type Ref class, where the Ref class records the element's hardware name, hardware type, and data type Type node. The hardware type includes a wire net, register, port, intermediate node, and port of an instantiated module.

[0028] (2) Construct a sensitivity list mapping diagram, that is, construct a mapping from the complete sensitivity list string in the Verilog HDL to the corresponding triggered register name list;

[0029] (3) Processing module names and port definitions, that is, outputting module names according to the syntax of Verilog HDL, and then processing module ports, where processing refers to outputting corresponding information based on the module's direction, bit width, whether it has a symbol, and name;

[0030] (4) Processing the statement blocks of the grammar design module sentence by sentence according to the element reference mapping map and the sensitivity list mapping map, including expanding the control flow processing and merging the same sensitivity list processing;

[0031] (5) Integrate the output streams of step (3) and step (4) to generate Verilog HDL code.

[0032] In step (1) of one embodiment, constructing an element reference map includes:

[0033] For ports, insert all port names and corresponding data types of the syntax design module into the element reference map;

[0034] For nets and registers, if they are net and register definitions, just insert the corresponding information into the element reference map;

[0035] For intermediate nodes, you need to first get the data type of the node based on the operator type of the intermediate node and the data type involved in the operation, and then record the reference information;

[0036] For module instantiation statements, you need to record the instantiated module ports one by one;

[0037] For the control flow, it is necessary to recursively call the element reference mapping function for each of the two branches of the control flow, that is, repeat the entire process of building the element reference mapping.

[0038] In step (2) of one embodiment, constructing a sensitivity list mapping diagram includes:

[0039] First, all statements of register definition types in the syntax design module are processed to obtain the sensitivity list corresponding to the register definition; then the sensitivity list is converted into the trigger string corresponding to the final Verilog HDL, and finally the trigger string corresponding to the sensitivity list is used as the key of the mapping diagram, and the register name defined by the statement is inserted into the register name list corresponding to the key, thereby completing the construction of the sensitivity list mapping diagram.

[0040] In step (4) of one embodiment, the control flow expansion process includes: flattening two branches of the control flow statement using a Mux selection expression, and if there is a nested control flow, nesting the corresponding Mux expression;

[0041] The merging of the same sensitive list processing includes: for register assignment statements, register assignment statements with the same sensitive list are merged, that is, only a mapping table from string to string stream is needed, that is, for different sensitive list strings, corresponding to different assignment statement streams, in the final conversion, only this mapping table needs to be traversed to obtain the merged sensitive list assignment block.

[0042] Compared with the prior art, the present invention has the following beneficial effects:

[0043] The C++-based hardware construction language integrates high-level programming language features into hardware design to improve hardware development efficiency and expression capabilities; the implemented hardware construction language is based on C++, and the conversion process consumes less system resources and time; the implemented hardware construction language better supports multi-clock domain design, and different clock signals can be flexibly and conveniently selected as sensitive variables as needed when defining registers. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art 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.

[0045] Figure 1 It is a schematic diagram of the structure of the FPGA hardware construction language implementation system based on C++ provided in the embodiment;

[0046] Figure 2 It is a flow chart of a method for implementing a system based on a C++ FPGA hardware construction language provided in an embodiment;

[0047] Figure 3 is a schematic diagram of the structure of a grammar design module provided in an embodiment;

[0048] Figure 4 is an example diagram of a syntax tree provided by an embodiment;

[0049] Figure 5 It is a flow chart of analyzing an intermediate language syntax tree to generate hardware description language Verilog HDL provided by an embodiment. DETAILED DESCRIPTION

[0050] To make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific implementation methods described herein are only used to explain the present invention and do not limit the scope of protection of the present invention.

[0051] The traditional hardware description language lacks abstraction ability and weak expression ability, resulting in low hardware design efficiency; the hardware controllability of the final mapping of the hardware high-level synthesis HLS is low, and it is difficult to control it in a fine-grained manner; the existing hardware construction language is mainly based on software programming languages ​​such as Scala or Python, and the conversion process consumes a lot of memory and other resources, and is time-consuming and has poor performance; the existing hardware construction language lacks sufficient support for multi-clock domain design and is more complicated to use. The embodiment provides a C++-based FPGA hardware construction language implementation system and method.

[0052] Figure 1 It is a structural diagram of a C++-based FPGA hardware construction language implementation system provided in an embodiment. Figure 2 1 is a flow chart of a method for implementing a system based on a C++ FPGA hardware construction language provided in an embodiment. Figure 1 and Figure 2 As shown, the C++-based FPGA hardware construction language implementation system provided in the embodiment includes a code design unit, a code compilation unit, an intermediate language parsing unit and a conversion unit. Among them, the code design unit is used to provide a syntax design module based on C++ implementation, and transmit the code designed based on the syntax design module to the code compilation unit; the code compilation unit is used to compile the design code using a C++ compiler to form an intermediate language; the intermediate language parsing unit is used to parse the intermediate language to obtain an intermediate language syntax tree; the conversion unit is used to generate a hardware description language Verilog HDL by analyzing the intermediate language syntax tree. The following is a detailed description of each unit.

[0053] Grammar Design Unit

[0054] In the embodiment, the syntax design unit mainly provides the syntax design function, and the user performs syntax design through the provided syntax design module. The syntax design module is implemented based on the Module class in C++, and contains a member variable of a special composite structure (struct class) to represent the port set of the model, and records the hardware design related information in the C++ constructor, that is, the design of the hardware circuit is connected with other modules, and then the constructor is exported in the form of a command as a design code input into the code compilation unit.

[0055] C++ is a type-safe programming language, and all variables need to be specified before use. Based on this, in this embodiment, when implementing the syntax design module based on the C++ class, type definition is also required. Specifically, all the contents contained in the syntax design module are divided into two categories, one is the hardware type, and the other is the data type. Among them, the hardware type corresponds to all possible elements in the hardware design, such as modules, ports, registers, and wire nets, etc., and the data type corresponds to the data contained in each wire net or register in the hardware design, including its bit width, literal value, whether it is signed, and other attributes.

[0056] like Figure 3 As shown, the syntax design module provided in the embodiment includes a port list and a module design part. Among them, the port set Port refers to the set of module input ports and output ports, which is similar to the C++ struct class in use and can only contain port objects of the Input, Output and InOutput types. However, since C++ itself has no reflection mechanism, in the implementation process, the port set Port is a macro-defined syntax, which will be converted into a custom class during the final compilation, inherited from the PortVec class, containing the current module name and its instantiated name for subsequent use.

[0057] The connect() function is used to connect the port sets of two different modules as a whole. The connect() function connects all ports with the same name in the two port sets. The ports between the same level models must be connected from input to output and from output to input. The port connection direction of the parent module and the child module is from input to input and from output to output. For ports with mismatched names, the connect() function does not automatically connect at the port set level, but can be connected using the connect() assignment operator.

[0058] In the embodiment, in order to ensure that the generated HDL code has good code specifications, the input port and the output port are fixed to the wire net type, that is, their class inherits from the wire net class, and the port direction, the module name and the name of the corresponding instantiation of the module need to be additionally recorded during construction.

[0059] like Figure 3 As shown in FIG. 1 , the module design part includes multiple wire nets, multiple registers, hardware primitive modules, control flows, and submodules. The wire nets and registers are also implemented by classes in C++, and information including the name and the module to which they belong is recorded during their construction.

[0060] The wire type corresponds to the wrie in Verilog and is a circuit node. When defining a wire instance, you need to pass in the data type it contains. If you need a custom name for the wire, you need to pass the custom wire name into the constructor; if not, the name will be randomly generated. The assignment of the wire is achieved by overloading the "=" assignment operator, that is, during use, you only need to use the assignment operator to assign a value to the wire, and you can also use the assignment operator to connect a wire to other circuit nodes.

[0061] The register Reg type corresponds to reg in Verilog, and the value only jumps at a given trigger time. The usage and constructor of the register are similar to those of the wire net, except that the trigger signal of the register can be specified. The default trigger signal is *, which means that when any dependent signal changes, the value of the register may change. If the register trigger signal needs to be changed, a sensitive list is given from the third parameter of the constructor, and the sensitive list contains the trigger signal. In the embodiment, different level signals or clock edges (indicating trigger signals) in the sensitive list are used as types in the variable parameter list and passed in as parameters when defining the register, so as to record the complete sensitive list.

[0062] In order to ensure that the generated hardware description code has a good and unified code style, the embodiment does not support blocking assignments for registers, but interprets all assignment operations related to registers as non-blocking assignments. This limitation means that if designers need to implement combinational circuits, they can only design them through wire net variables, and the circuits involving registers will eventually be synthesized into sequential circuits.

[0063] In the embodiment, the operators related to the hardware types of the wire net, register, input port, and output port can be overloaded, the operator type and the element name involved in the operation are recorded, and the hardware type of an intermediate node is generated as the operation result to be returned, so that a continuous operation process of multiple hardware types can be performed. In the implementation, the wire net and the register can accommodate some data, indicating the data bit width, literal value, overloaded operator, and whether there is a sign and other attributes that can be carried.

[0064] The hardware primitive module is implemented as a built-in function through a C++ function, and the port list corresponding to the function parameter is provided to the designer for design and use. In the embodiment, it is supported to call the Verilog HDL primitive module in the form of a C++ function, such as and, nand, or, xor, etc. Similarly, the hardware primitive module name needs to be defined and needs to be given in the first parameter of the constructor.

[0065] Control flow refers to the branch design pattern caused by conditional judgment in hardware design. It supports the if-else control flow pattern and the switch-case control flow pattern for design. However, the control flow conflicts with the keywords in the C++ syntax, so the control flow is treated as a different class, and its constructor is the judgment node of the control flow. The judgment node records the information of the control flow branch. Then a syntax block is followed as the design of the branch in the control flow.

[0066] Specifically, since C++ itself has four types of keywords, if, else, switch, and case, the control flow provided in the embodiment needs to be distinguished from C++, so if-Elif-Else and Switch-Case are used to achieve the purpose of control flow trial implementation. In addition, due to its own implementation mechanism, macro syntax expressing the end needs to be added after all control flow statement blocks, such as ENDIF must be declared after if-Elif-Else, and ENDSWITCH must be declared after Switch-Case.

[0067] The submodule refers to a submodule of the syntax design module, and has the same function as the syntax design module. In the embodiment, when using the syntax design module for circuit design, the following four conditions need to be met: (1) the template class Module class under the Fracpp namespace is inherited, and it is itself a template parameter of the template class and must be a public inheritance; (2) the module needs to define a public member variable of the Port type; (3) the internal circuit connection is performed in the class construction method, which may include multiple construction methods, and the modules generated after the final conversion to Verilog are different; (4) the this->endModule() function needs to be called at the end of the constructor to indicate the completion of the design.

[0068] Code compilation unit

[0069] In the embodiment, the input of the code compilation unit is the code designed by the code design unit. Different hardware elements are represented by different C++ classes, and their constructors are responsible for recording the specific information of the circuit design, namely, the name of each module, input and output signals, the internal composition of the module, the interconnection between the wire network and the register, the operation and other information. A global object is used to store the composition information of different modules and the names of all modules of the current design. Then, through the compilation of a general C++ compiler, the circuit design information of each module stored is exported to a file in the form of a string to obtain the corresponding intermediate language.

[0070] The intermediate language is actually an imperative custom language that describes the implementation logic of a large hardware design from the top module to all submodules in the form of commands. These commands include the port composition within the module, the definition of hardware elements, the connection between signals, the assignment of registers, the intermediate nodes involved in all calculation processes, the calling of modules, and the control flow, etc. These elements together constitute a complete hardware design.

[0071] Intermediate Language Parsing Unit

[0072] Based on the code design unit, the hardware design is based on modules, which contain ports and are implemented in the constructor. The designed code can be run through the code compilation unit to obtain an imperative intermediate language. The intermediate language command queue corresponding to the module will be retained in the memory or dumped to the file system according to the user's practical method, and then read in to parse the intermediate language and form an intermediate expression language tree.

[0073] In the embodiment, a lexical analysis tool (such as Antlr4) is used to parse the intermediate language and generate a syntax tree, so as to obtain an intermediate language syntax tree that fully describes the hardware design in the memory, and each node of the intermediate language syntax tree is a component of the circuit design. Figure 4 As shown in the figure, the syntax tree structure generated by the embodiment, the solid line box in the figure represents the syntax tree node, and the dotted line box represents the enumeration type. The root node of the tree is a file, that is, the overall hardware design file. A file contains multiple syntax design modules, and each module contains two parts, one part is multiple module ports, and the other is the module design part.

[0074] Conversion Unit

[0075] The conversion unit mainly traverses the intermediate language syntax tree from the root node downward, performs different processing on different nodes to generate corresponding Verilog HDL statements, and finally outputs them in the form of files or strings. These tasks are specifically completed by the CodeGenerator class and the ModuleEmitter class.

[0076] Figure 5 This is a flow chart of analyzing the intermediate language syntax tree to generate the hardware description language Verilog HDL provided by the embodiment. Figure 5 As shown, the conversion process from the intermediate language syntax tree to Verilog HDL includes:

[0077] Step 1: Build the Reference Map

[0078] That is, the mapping from the element reference name to the element reference type Ref class, where the Ref class records the element reference name, reference type (including wire nets, registers, ports, intermediate nodes, ports of instantiated modules), data type Type node and other key information. To build an element reference map, you need to first record all the input and output ports of the module, and insert their names and corresponding data types into the element reference map. Then analyze and judge each statement in the module design part sentence by sentence: if it is a wire net and register definition, just insert it into the element reference map according to the corresponding information; if it is an intermediate node, you need to first get the node data type according to the operator type of the intermediate node and the data type involved in the operation, and then record the reference information; if it is a module instantiation statement, you need to record the instantiated module ports one by one; if it is a control flow, you need to recursively call the element reference map function for the two branches of the control flow, that is, repeat the entire reference map construction process.

[0079] Step 2: Build a Trigger Map for the Sensitive List

[0080] Trigger Map is a mapping of the complete sensitive list string in the final HDL to the corresponding triggered register name list. In order to complete the construction of this map, it is necessary to process all register definition statements in the module to obtain the corresponding sensitive list when defining the register, and then convert the sensitive list to the trigger string corresponding to the final HDL. Finally, the sensitive list string is used as the key of the map, and the register name defined by this statement is inserted into the register name list corresponding to the key, thereby completing the construction of the sensitive list map.

[0081] Step 3: Process module name and port definition

[0082] This step is relatively simple. You only need to output the module name according to the syntax of Verilog HDL, and then process the module ports one by one. The processing of the module port needs to output the corresponding information according to the direction, bit width, whether it has a symbol, and name of the module. It should be noted that the "output" mentioned in this step is not directly output to the command line or string, but to a private member variable of the string stream type of ModuleEmitter.

[0083] Step 4: Process the module statement block sentence by sentence

[0084] Each statement in the module is processed one by one. Different types of statements are processed differently according to the syntax of Verilog HDL. Different string streams are input according to their types, including hardware element definition string stream, module instantiation string stream, native Verilog HDL embedded string stream, wire net connection string stream, hardware primitive module string stream, and register assignment string stream. In this process, it is worth mentioning the control flow statement. For the control flow statement, it cannot be directly converted into the corresponding HDL code. Instead, the two branches of the control flow statement need to be flattened with a Mux selection expression. If there is a nested control flow, the corresponding Mux expression can be nested. In this way, the right value expression corresponding to each assigned element in the control flow block can be obtained and recorded in the assignment table. Each item in the assignment table is a pair of a string and an expression, that is, for each hardware element assigned in the control flow, what kind of expression node is its assignment source. After processing the module, each item in the assignment table is processed one by one.

[0085] In addition, for register assignment statements, register assignment statements with the same sensitivity list also need to be merged. However, this process is relatively simple, and only requires a mapping table from string to string stream, that is, for different sensitive list strings, corresponding to different assignment statement streams, in the final conversion, only this mapping table needs to be traversed to obtain the merged sensitive list assignment block.

[0086] Step 5: Integrate all string flows and output Verilog HDL code

[0087] The codes obtained in all the above processes are stored in different string streams according to the statement type. In this step, you only need to merge and output the strings in the stream in a reasonable order to obtain the final HDL code. The order of output string streams is: port definition stream, hardware element definition stream, module instantiation stream, native Verilog HDL stream, wire network connection stream, hardware primitive module stream, and optimized register assignment stream. After all string streams are output, endmodule is output according to the Verilog HDL syntax to indicate the end of the module design, and the HDL generation process of a module can be completed.

[0088] It should be noted that there are solutions that directly translate circuit design information into Verilog design code without going through the intermediate language analysis process. However, such solutions have poor scalability and cannot achieve specific implementation goals, such as integrating register assignment statements corresponding to the same trigger list, so the Verilog code generated by such solutions cannot achieve higher readability.

[0089] Experimental example

[0090] Taking the clock divider ClockDiv as an experiment, the specific design process of the code design unit is as follows:

[0091]

[0092] Among them, the custom ClockDiv class is a clock divider module, which inherits from the Module class. It contains a member variable of the Port structure to represent the input and output port set of the module. Among them, clk and rst are input signals with a bit width of 1, representing the clock signal and reset signal respectively; clkdiv is an output signal with a bit width of 32, representing the clock distribution output signal.

[0093] Connect the circuit in the constructor of ClockDiv. First, define clkdiv_reg as a register type with a bit width of 32, which represents the frequency division signal. When defining it, specify the sensitive variables as the positive edge of the clk signal and the negative edge of the rst signal. When the rst signal is high, reset clkdiv_reg to 0, otherwise it increments by 1. Finally, connect clkdiv_reg to the output signal clkdiv to complete the module design.

[0094]

[0095] As shown in the above code, the defined ClockDiv class is instantiated in the main function, and the conversion function is called for conversion, and the following Verilog code is finally obtained:

[0096]

[0097] The specific implementation methods described above provide a detailed description of the technical solutions and beneficial effects of the present invention. It should be understood that the above is only the most preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, supplements and equivalent substitutions made within the scope of the principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A C++ based FPGA hardware construction language implementation system, characterized in that: It includes a code design unit, a code compilation unit, an intermediate language parsing unit and a conversion unit; The code design unit is used to provide a syntax design module implemented based on C++, and transmit a constructor of a class designed based on the syntax design module to the code compilation unit, wherein the constructor records circuit design information, wherein the syntax design module includes a port set and a module design part, the module design part is implemented by a C++ constructor, and the module design part includes a wire net, a register, a hardware primitive module, a control flow, and a submodule; The port set includes an input port and an output port, which are used to connect the designed circuit nodes, and the input port and the output port are implemented by a struct class in C++; The wire net is used to record the connection relationship between the nodes of the design circuit, which is implemented by a class in C++, and the wire net name and the module to which the wire net belongs are recorded by defining the corresponding class of the wire net; The register is used to record the intermediate value of the circuit element and hardware design, and is implemented by a class in C++, and the register name and the module to which the register belongs are recorded by defining the corresponding class of the wire net; The hardware primitive module is implemented as a built-in function through a C++ function, and the port list corresponding to the function parameters is provided to the designer for design and use; The control flow adopts a class different from C++, and supports the if-else control flow mode and the switch-case control flow mode for design; The submodule refers to a submodule of the grammar design module and has the same function as the grammar design module; The code compiling unit is used to compile the design constructor using a C++ compiler to form an intermediate language; The intermediate language parsing unit is used to parse the intermediate language to obtain an intermediate language syntax tree; The conversion unit is used to generate a hardware description language Verilog HDL by analyzing the intermediate language syntax tree, and the specific process includes: (1) Construct an element reference mapping diagram, that is, a mapping from an element reference name to an element reference type Ref class. The Ref class records the element's hardware name, hardware type, and data type Type node. The hardware type includes a wire net, register, port, intermediate node, and port of an instantiated module. (2) Construct a sensitivity list mapping diagram, that is, construct a mapping from the complete sensitivity list string in Verilog HDL to the corresponding triggered register name list; (3) Processing module names and port definitions, that is, outputting module names according to the syntax of Verilog HDL, and then processing module ports. Processing refers to outputting corresponding information based on the module's direction, bit width, whether it has a symbol, and name. (4) Process the statement blocks of the grammar design module sentence by sentence based on the element reference mapping map and the sensitivity list mapping map, including expanding the control flow processing and merging the same sensitivity list processing; (5) Integrate the output streams of steps (3) and (4) to generate Verilog HDL code.

2. The C++-based FPGA hardware construction language implementation system according to claim 1, characterized in that: The register supports multi-clock domain triggering, that is, the data contained in the register is changed by a trigger signal of a specified register.

3. The C++-based FPGA hardware construction language implementation system according to claim 2, characterized in that: The constructor parameter corresponding to the register maintains a sensitivity list, which contains multiple clock trigger signals. The clock trigger signals are represented by different level signals or clock edges.

4. The C++-based FPGA hardware construction language implementation system according to claim 1, characterized in that: The syntax design module supports overloading of related operators of hardware types of wire nets, registers, input ports, and output ports, records operator types and element names involved in the operation, and generates a hardware type of an intermediate node as a result of the operation to return, so as to enable continuous operation processes of multiple hardware types.

5. The C++-based FPGA hardware construction language implementation system according to claim 1, characterized in that: The intermediate language parsing unit uses a grammar and lexical analysis tool to perform lexical analysis and generate a syntax tree for the intermediate language, thereby obtaining an intermediate language syntax tree in the memory that fully describes the hardware design. Each node of the intermediate language syntax tree is a component of the circuit design.

6. The C++-based FPGA hardware construction language implementation system according to claim 1, characterized in that: In step (1), constructing the element reference map includes: For ports, insert all port names and corresponding data types of the syntax design module into the element reference map; For nets and registers, if they are net and register definitions, just insert the corresponding information into the element reference map; For intermediate nodes, you need to first get the data type of the node based on the operator type of the intermediate node and the data type involved in the operation, and then record the reference information; For module instantiation statements, you need to record the instantiated module ports one by one; For the control flow, it is necessary to recursively call the element reference mapping function for each of the two branches of the control flow, that is, repeat the entire process of building the element reference mapping.

7. The C++-based FPGA hardware construction language implementation system according to claim 1, characterized in that: In step (2), constructing the sensitive list mapping diagram includes: First, all statements of register definition types in the syntax design module are processed to obtain the sensitivity list corresponding to the register definition; then the sensitivity list is converted into the trigger string corresponding to the final Verilog HDL, and finally the trigger string corresponding to the sensitivity list is used as the key of the mapping diagram, and the register name defined by the statement is inserted into the register name list corresponding to the key, thereby completing the construction of the sensitivity list mapping diagram.

8. The C++-based FPGA hardware construction language implementation system according to claim 1, characterized in that: In step (4), the control flow expansion process includes: flattening the two branches of the control flow statement with a Mux selection expression, and if there is a nested control flow, nesting the corresponding Mux expression; The merging of the same sensitive list processing includes: for register assignment statements, register assignment statements with the same sensitive list are merged, that is, only a mapping table from string to string stream is needed, that is, for different sensitive list strings, corresponding to different assignment statement streams, in the final conversion, only this mapping table needs to be traversed to obtain the merged sensitive list assignment block.

Citation Information

Patent Citations

  • Compiling memory dereferencing instructions from software to hardware in an electronic design

    US20060031791A1

  • Method and system for translating software binaries and assembly code onto hardware

    US7565631B1

  • Code generation

    US8359586B1