Skip to content

Commit 3f4b517

Browse files
committed
first commit of veriloggen for GitHub
0 parents  commit 3f4b517

25 files changed

+1550
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pyc
2+
*.out
3+
parsetab.py

LICENSE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Apache License 2.0
2+
(http://www.apache.org/licenses/LICENSE-2.0)

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include README.md
2+
include README.rst

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.PHONY: all
2+
all: clean
3+
4+
.PHONY: clean
5+
clean:
6+
make clean -C ./veriloggen
7+
make clean -C ./sample
8+
rm -rf *.pyc __pycache__ pycoram.egg-info build dist
9+
10+
.PHONY: release
11+
release:
12+
pandoc README.md -t rst > README.rst

README.md

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
Veriloggen
2+
==============================
3+
4+
A library for constructing a Verilog HDL source code in Python
5+
6+
Copyright (C) 2015, Shinya Takamaeda-Yamazaki
7+
8+
E-mail: shinya\_at\_is.naist.jp
9+
10+
11+
License
12+
==============================
13+
14+
Apache License 2.0
15+
(http://www.apache.org/licenses/LICENSE-2.0)
16+
17+
18+
What's Veriloggen?
19+
==============================
20+
21+
Veriloggen is an open-sourced library for constructing a Verilog HDL source code in Python.
22+
23+
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.
24+
25+
26+
Requirements
27+
==============================
28+
29+
* Python (2.7 or later, 3.3 or later)
30+
31+
* Pyverilog (Python-based Verilog HDL Design Processing Toolkit)
32+
- Install from pip: 'pip install pyverilog' for Python2.7 or 'pip3 install pyverilog' for Python3
33+
- Install from github into this package: 'cd Pycoram; git clone https://github.com/shtaxxx/Pyverilog.git; cd pycoram; ln -s ../Pyverilog/pyverilog'
34+
* Jinja2 (2.7 or later)
35+
- The code generator uses Jinja2 template engine.
36+
- 'pip install jinja2' (for Python 2.x) or 'pip3 install jinja2' (for Python 3.x)
37+
38+
39+
Installation
40+
==============================
41+
42+
If you want to use Veriloggen as a general library, you can install on your environment by using setup.py.
43+
44+
If Python 2.7 is used,
45+
46+
python setup.py install
47+
48+
If Python 3.x is used,
49+
50+
python3 setup.py install
51+
52+
53+
Getting Started
54+
==============================
55+
56+
You can find some examples in 'veriloggen/sample/'.
57+
58+
Let's begin veriloggen by an example. Create a example Python script in Python as below. A blinking LED hardware is modeled in Python.
59+
60+
```python
61+
import sys
62+
import os
63+
64+
from veriloggen import *
65+
def mkLed():
66+
m = Module('blinkled')
67+
width = m.Parameter('WIDTH', 8)
68+
clk = m.Input('CLK')
69+
rst = m.Input('RST')
70+
led = m.OutputReg('LED', width)
71+
count = m.Reg('count', 32)
72+
73+
m.Always(Posedge(clk),
74+
[ If(rst,
75+
[ count.set(0) ],
76+
[ count.set(count + 1) ])])
77+
78+
m.Always(Posedge(clk),
79+
[ If(rst,
80+
[ led.set(0) ],
81+
[ If(count == 1024 - 1,
82+
[ led.set(led + 1) ])])])
83+
84+
return m
85+
86+
led = mkLed()
87+
verilog = led.toVerilog()
88+
print(verilog)
89+
```
90+
91+
Run the script.
92+
93+
```
94+
python led.py
95+
```
96+
97+
You will have a complete Verilog HDL source code that is generated by a source code generator of Pyverilog.
98+
Currently a source code generated by Pyverilog has no good indentation. Please prettify it by using a standard text editor.
99+
100+
```verilog
101+
module blinkled #
102+
(
103+
parameter WIDTH = 8
104+
105+
)
106+
(
107+
input [0:0] CLK,
108+
input [0:0] RST,
109+
output reg [(WIDTH - 1):0] LED
110+
111+
);
112+
reg [(32 - 1):0] count;
113+
always @(posedge CLK)
114+
begin
115+
if(RST) begin
116+
count <= 0;
117+
end
118+
else begin
119+
count <= (count + 1);
120+
end
121+
end
122+
always @(posedge CLK)
123+
begin
124+
if(RST) begin
125+
LED <= 0;
126+
end
127+
else begin
128+
if((count == 1023)) begin
129+
LED <= (LED + 1);
130+
end
131+
132+
end
133+
end
134+
endmodule
135+
```
136+
137+
138+
Class and method
139+
==============================
140+
141+
Module(name)
142+
--------------------
143+
144+
is corresponding to 'module' in Verilog HDL.
145+
The Module class has several class methods to describe signals and assignments.
146+
147+
Module.Input(name, width=None, length=None, signed=False, value=None)
148+
--------------------
149+
150+
is a class method to add a input port to the module.
151+
152+
Module.Output(name, width=None, length=None, signed=False, value=None)
153+
--------------------
154+
155+
is a class method to add a output port to the module.
156+
157+
Module.Inout(name, width=None, length=None, signed=False, value=None)
158+
--------------------
159+
160+
is a class method to add a inout port to the module.
161+
162+
Module.Reg(name, width=None, length=None, signed=False, value=None)
163+
--------------------
164+
165+
Module.Wire(name, width=None, length=None, signed=False, value=None)
166+
--------------------
167+
168+
Module.Parameter(name, value, width=None, length=None, signed=False)
169+
--------------------
170+
171+
Module.Localparam(name, value, width=None, length=None, signed=False)
172+
--------------------
173+
174+
Module.Always(sensitivity, statement)
175+
--------------------
176+
177+
Module.Assign(left, right)
178+
--------------------
179+
180+
Module.Instance(module, instname, params, ports)
181+
--------------------
182+
183+
184+
Publication
185+
==============================
186+
187+
Not yet.
188+
189+
190+
Related Project
191+
==============================
192+
193+
[Pyverilog](http://shtaxxx.github.io/Pyverilog/)
194+
- Python-based Hardware Design Processing Toolkit for Verilog HDL
195+
196+
[PyCoRAM](http://shtaxxx.github.io/PyCoRAM/)
197+
- Python-based Portable IP-core Synthesis Framework for FPGA-based Computing

0 commit comments

Comments
 (0)