3 KiB
Circuit2Verilog Module
Primary Contributors:
- James H - J Yeh, Ph.D.
- Satvik Ramaprasad
Introduction
This is an experimental module which generates verilog netlist (structural verilog) given the circuit. Currently, the module generates fully functional verilog code for basic circuits. For complex circuit, additional (manual) work may need to be done in order to make it work. We are continuously improving this module to work with more and more complex circuits.
Algorithm
The basic algorithm is fairly straight forward. We have the circuit graph in memory. We just need to convert this graph into verilog netlist. It is done by performing a DFS on the circuit graph. The DFS involves the following steps
- Creating verilog wires as and when required
- Connecting verilog wires in element instantiations
Some background information
The different sub circuits form a DAG (Directed Acyclic Graph) or dependency graph. Each sub circuit itself (called scope internally) is actually a (cyclic) graph on its own. Therefore the verilog generation is done in a 2 step DFS approach. The first DFS is performed on the dependency graph. The second DFS is done on individual sub circuit (scope).
Code/Algorithm workflow
exportVerilog()
- entry pointexportVerilogScope()
- DFS(1) on Sub Circuits Dependency Graph- Set Verilog Labels for all elements
generateHeader()
- Generates Module HeadergenerateOutputList()
- Output Output ListgenerateInputList()
- Generates Input ListprocessGraph()
- DFS(2) on individual subcircuit/scope- DFS starts from inputs
- Calls
processVerilog()
on all circuit elements (graph nodes) - resolves label names and adds neighbors to DFS stack. - Calls
generateVerilog()
on all circuit elements to get final verilog.
- Generate Wire initializations
Functions
Verilog Module Functions:
verilog.exportVerilog()
- Entry pointverilog.exportVerilogScope()
- Recursive DFS function on subcircuit graphverilog.processGraph()
- Iterative DFS function on subcircuit scopeverilog.resetLabels()
- Resets labels in scopeverilog.setLabels()
- Sets labels in scopeverilog.generateHeader()
- Generates Verilog Module Headerverilog.generateInputList()
- Generates Verilog Module Input Listverilog.generateOutputList()
- Generates Verilog Module Output Listverilog.sanitizeLabel()
- Sanitizes label for node/wireverilog.generateNodeName()
- Helper function to resolve node/wire name
CircuitElement Functions:
These functions can be overriden by derived classes.
CircuitElement.prototype.processVerilog()
- Graph algorithm to resolve verilog wire labelsCircuitElement.prototype.verilogName()
- Generate verilog nameCircuitElement.prototype.generateVerilog()
- Generate final verilog codeCircuitElement.prototype.verilogType
- Verilog type nameCircuitElement.moduleVerilog
- Custom module verilog for elements