Skip to main content

A library for constructing a Verilog HDL source code in Python

Project description

Veriloggen

A library for constructing a Verilog HDL source code in Python

Copyright (C) 2015, Shinya Takamaeda-Yamazaki

E-mail: shinya_at_is.naist.jp

License

Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)

What’s Veriloggen?

Veriloggen is an open-sourced library for constructing a Verilog HDL source code in Python.

Veriloggen is not a behavior synthesis (or high level synthesis). Veriloggen provides a lightweight abstraction of Verilog HDL AST. You can build up a hardware design written in Verilog HDL very easily by using the AST abstraction and the entire functionality of Python.

Veriloggen is not designed for designing a hardware by programmer directly, but is for providing an efficient abstraction to develop a more efficient domain specific language and tools.

Installation

Requirements

  • Python: 2.7, 3.4 or later

Python3 is recommended.

  • Icarus Verilog: 0.9.7 or later

Install on your platform. For exmple, on Ubuntu:

sudo apt-get install iverilog
  • Jinja2: 2.8 or later

Install on your python environment by using pip.

pip install jinja2
  • Pyverilog: 1.0.1 or later

Install from pip:

pip install pyverilog

Options

  • pytest: 2.8.2 or later

  • pytest-pythonpath: 0.7 or later

These softwares are required for running the tests in tests and examples.

pip install pytest pytest-pythonpath
  • Graphviz: 2.38.0 or later

  • Pygraphviz: 1.3.1 or later

These softwares are required for graph visualization by lib.dataflow.

sudo apt-get install graphviz
pip install pygraphviz

Install

Install Veriloggen.

python setup.py install

On Docker

Dockerfile is available, so that you can try Veriloggen on Docker without any installation on your host platform.

cd docker
sudo docker build -t user/veriloggen .
sudo docker run --name veriloggen -i -t user/veriloggen /bin/bash
cd veriloggen/examples/led/
make

Getting Started

You can find some examples in ‘veriloggen/examples/’ and ‘veriloggen/tests’.

Let’s begin veriloggen by an example. Create a example Python script in Python as below. A blinking LED hardware is modeled in Python. Open ‘hello_led.py’ in the root directory.

import sys
import os
from veriloggen import *

def mkLed():
    m = Module('blinkled')
    width = m.Parameter('WIDTH', 8)
    clk = m.Input('CLK')
    rst = m.Input('RST')
    led = m.OutputReg('LED', width)
    count = m.Reg('count', 32)

    m.Always(Posedge(clk))(
        If(rst)(
            count(0)
        ).Else(
            If(count == 1023)(
                count(0)
            ).Else(
                count(count + 1)
            )
        ))

    m.Always(Posedge(clk))(
        If(rst)(
            led(0)
        ).Else(
            If(count == 1024 - 1)(
                led(led + 1)
            )
        ))

    return m

if __name__ == '__main__':
    led = mkLed()
    # led.to_verilog(filename='tmp.v')
    verilog = led.to_verilog()
    print(verilog)

Run the script.

python led.py

You will have a complete Verilog HDL source code that is generated by the source code generator.

module blinkled #
(
  parameter WIDTH = 8
)
(
  input CLK,
  input RST,
  output reg [(WIDTH - 1):0] LED
);

  reg [(32 - 1):0] count;

  always @(posedge CLK) begin
    if(RST) begin
      count <= 0;
    end else begin
      if((count == 1023)) begin
        count <= 0;
      end else begin
        count <= (count + 1);
      end
    end
  end


  always @(posedge CLK) begin
    if(RST) begin
      LED <= 0;
    end else begin
      if((count == 1023)) begin
        LED <= (LED + 1);
      end
    end
  end


endmodule

Publication

Not yet.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

veriloggen-0.5.0.tar.gz (82.7 kB view details)

Uploaded Source

File details

Details for the file veriloggen-0.5.0.tar.gz.

File metadata

  • Download URL: veriloggen-0.5.0.tar.gz
  • Upload date:
  • Size: 82.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for veriloggen-0.5.0.tar.gz
Algorithm Hash digest
SHA256 db8031ac31a7b490bcf34015f6f9b4db8f99215bbb0d06a2e236e849cb970439
MD5 a2396f47a2ec8fb10c760082c5104825
BLAKE2b-256 2cc007597396ff9d2c52db06cfec94bb802205b40b066bacde52611ac96a417f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page