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 (in release mode) and then copy everything to $HOME/.local/virdant.

Warning

You will need to add $HOME/.local/virdant/bin to your $PATH! If you forget, you’ll see vir: command not found.

Running Hello World

Create a new Virdant project by running:

console
$ vir new hello
$ cd hello

Next, we can run our project in the Virdant simulator.

console
$ vir run
Hello, Virdant!

Hello to you too, Virdant!

What Virdant Looks Like

Next, let’s just glance at the source code. Open the file src/top.vir in the hello project you just created. You will see our hello world design.

Note

In software, you may be used to talking about your “program”. But in hardware, we call them “designs”.

And rather than a function called main, as you might be used to in programming, the entry point to a hardware design is traditionally a module called Top

We won’t worry about how any of this works for now. The guide will teach you from scratch. Just get a feel for what Virdant looks like:

src/top.vir
import virt

pub mod Top for virt::Virt {
    incoming clock : Clock

    outgoing exit : Valid[Word[8]] {
        it := if {
            when mem[dyn index] == 0 => @Valid(0)
            else => @Invalid()
        }
    }

    @image_inline("Hello, Virdant!\n\r\0")
    memory mem[64] : Word[8]

    reg index : Word[6] {
        initial it <= 0
        it <= it + 1
    }

    outgoing debug : Valid[Word[8]] {
        it := @Valid(mem[dyn index])
    }
}

Compiling to Verilog

You can compile Virdant to Verilog with the following:

console
$ vir build

We won’t be using this feature for now. But I’ll mention it for those who are experienced with hardware design.