ruverta
Rust to Verilog: Very Simple Verilog Builder
English | 日本語
Supports only a simple subset of SystemVerilog.
- Variables: Only
logicis available. Noregorwire. - Combinational circuits: Only
always_combis available. Noassign. - Sequential circuits: Only
always_ffis available. Noalways.
Table of Contents
Installation
$ cargo add ruverta
Basic API
use ;
module test_module #(
parameter BIT = 8
) (
input logic clk,
input logic rstn,
input logic [ 7:0] in0,
input logic [ 7:0] in1,
output logic [ 7:0] out
);
always_comb
out = in0 + in1;
always_ff @(posedge clk)
begin
a <= b;
end
endmodule;
Input/Output Ports
.input(name, width).output(name, width).inout(name, width)
Parameters
.param(name, default_value).lparam(name, value)
Wires
.logic(name, bit, len)
Instances
.instant(inst: Instant)
Combinational Circuits
.always_comb(stmt: Stmt)
Stmt is a class representing a statement.
Sequential Circuits
.always_ff(Sens, Stmt)
Sens is a class representing a sensitivity list.
.posedge(wire_name).negedge(wire_name).bothedge(wire_name)
Verilog Generation
Generate Verilog with .verilog(). Since it returns Vec<String>, use .join("\n") to concatenate.
The API design is quite rough, so feel free to request anything~
Extended API
Extend the builder methods of Module to easily construct various circuits.
DFF
When implementing sequential circuits, it is recommended to use sync_ff / async_ff api instead of always_ff.
DFF has several usage patterns depending on the clock and reset settings.
- clock edge: posedge / negedge / bothedge
- reset edge: positive / negative
- reset timing: sync / async
Currently, only the following patterns are supported.
| clock edge | reset logic | reset timing | |
|---|---|---|---|
sync_ff |
posedge | negative | sync |
async_ff |
posedge | negative | async |
new
.input
.input
.input
.input
.output
.sync_ff;
Comb
When implementing combinational circuits, it is recommended to use comb instead of always_comb.
Since it always requires a default, there are no omissions in case distinctions.
new
.input
.input
.input
.comb;
FSM
Construct a state machine with a single state variable.
new
.input
.input
.input
.sync_fsm;
Stream
FIFO
Bus API
| Rust | Verilog | Test | |
|---|---|---|---|
| AXILiteSlave | axi_lite_slave.rs | axi_lite_slave.sv | axi_lite_slave_tb.sv |
| PicoSlave |
new
.input
.input
.axi_lite_slave;
- AXI Lite Slave
- Pico Slave
Test
Tests are located under tests.
will output sv files under tests/verilog/.
Running make will launch gtkwave.
??? is the name of the test case.