Skip to main content

Python interface to Verilator models

Project description

This package provides a wrapper to generate and use verilator hardware models in python.

Installing Non-Development Version

If you want to just install the pyverilator package, you should be able to using the following command:

$ pip3 install pyverilator

Usage

Assume you have the following verilog module stored in counter.v.

module counter (
        input        clk,
        input        rst,
        input        en,
        output [7:0] out
    );
    reg [7:0] count_reg;
    wire [7:0] next_count_reg;
    assign next_count_reg = (en == 1) ? count_reg + 1 : count_reg;
    assign out = next_count_reg;
    always @(posedge clk) begin
        if (rst == 1) count_reg <= 0;
        else          count_reg <= next_count_reg;
    end
endmodule'''

Then you can use pyverilator to simulate this module using verilator in python.

sim = pyverilator.PyVerilator.build('counter.v')

# start gtkwave to view the waveforms as they are made
sim.start_gtkwave()

# add all the io and internal signals to gtkwave
sim.send_signals_to_gtkwave(sim.io)
sim.send_signals_to_gtkwave(sim.internals)

# add all the io and internal signals to gtkwave
sim.send_to_gtkwave(sim.io)
sim.send_to_gtkwave(sim.internals)

# tick the automatically detected clock
sim.clock.tick()

# set rst back to 0
sim.io.rst = 0

# check out when en = 0
sim.io.en = 0
curr_out = sim.io.out
# sim.io is a pyverilator.Collection, accessing signals by attribute or
# dictionary syntax returns a SignalValue object which inherits from int.
# sim.io.out can be used just like an int in most cases, and it has extra
# features like being able to add it to gtkwave with
# sim.io.out.send_to_gtkwave(). To just get the int value, you can call
# sim.io.out.value
print('sim.io.out = ' + str(curr_out))

# check out when en = 1
sim.io.en = 1
curr_out = sim.io.out
print('sim.io.out = ' + str(curr_out))

sim.clock.tick()

# check out after ticking clock
curr_out = sim.io.out
print('sim.io.out = ' + str(curr_out))

The full code for this and other examples can be found in the examples folder of the git repository.

Installing for Development

To install this package for development, you should use a virtual environment, and install the package in editable mode using pip.

To create a virtual environment for this project, run the command below.

$ python3 -m venv path/to/new-venv-folder

To start using your new virtual environment, run the command below. This needs to be run each time you open a new terminal.

$ source path/to/new-venv-folder/bin/activate

At this point you are now using your new virtual environment. Python packages you install in this environment will not be available outside your virtual environment. If you want to stop using the virtual environment, just run deactivate.

To install the pyverilator package in editable mode, inside the pyverilator top git repository folder, run the command below.

$ pip3 install -e .

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

PyVerilator-0.7.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

PyVerilator-0.7.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file PyVerilator-0.7.0.tar.gz.

File metadata

  • Download URL: PyVerilator-0.7.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for PyVerilator-0.7.0.tar.gz
Algorithm Hash digest
SHA256 66168ba0151e1a31825a237ed296d2457e9e38e313a23f51c0d4f19b1fefe59c
MD5 6cfa258f4f8a1ce933dc56fd9b98a2f4
BLAKE2b-256 9b0268f33790a73a3a16beb329f916a4e5f62a7379e2542fc1b2cd8c67e910e8

See more details on using hashes here.

File details

Details for the file PyVerilator-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: PyVerilator-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for PyVerilator-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc150aa9e31fa4a1534dbc58fd37718c5e7eedb11d81742a6eea99a2c3beea01
MD5 dd1cbdfd0bdf0d0630d5bc1d00f770fd
BLAKE2b-256 c0e3bb797b52e233f2ea1c56fbef9119dad56dd857ca6d5f6a331b83e88513e1

See more details on using hashes here.

Supported by

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