Getting Started

Installation

For now, Virdant only works on Linux. You can install it by cloning the repository and running make install:

console
$ git clone https://github.com/virdant-lang/virdant
$ cd virdant
$ make install

This will build Virdant from source and then copy the binaries to $HOME/.local/virdant/bin. Make sure that this directory is on your $PATH.

Blinky

Tradition dictates that the first program that is written in any programming language should be Hello, World! In hardware projects, the equivalent of Hello, World! is to get an LED to blink on and off.

Create a new Virdant project by running:

console
$ vir new blink
$ cd blink

This will create a new project in a subdirectory named blink. If we look at the src/top.vir file, we will see our blinking LED design:

top.vir
 1mod Top {
 2    incoming clock : Clock
 3
 4    outgoing led : Bit
 5
 6    reg counter : Word[32] on clock
 7    counter <= counter + 1
 8
 9    led := counter[21]
10}

Compiling to Verilog

We can compile this design to Verilog with the following:

console
$ vir build

The result will be a new file called build/top.sv.

To simulate the design, you need a Verilog testbench. Here is one which will run the design for 100 cycles:

testbench.sv
 1module Testbench();
 2    \top::Top top(
 3        .clock(clock)
 4    );
 5
 6    reg clock = 1'b0;
 7    always #(5) clock = !clock;
 8
 9    initial begin
10        $dumpfile("build/out.vcd");
11        $dumpvars(0, top);
12
13        repeat(32) @(posedge clock);
14
15        $finish;
16    end
17endmodule

If you have Icarus Verilog installed, you can compile a simulator and run it with these commands:

console
$ iverilog testbench.sv build/top.sv -o build/blink
$ ./build/blink
VCD info: dumpfile build/out.vcd opened for output.

Finally, using a waveform viewer such as GTK Wave, you can view the waveform:

_images/waveform.png