加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

PyVerilator

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 .
Copyright (c) 2018-2019 Massachusetts Institute of Technology Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化