-
Notifications
You must be signed in to change notification settings - Fork 22
/
test_ff.py
43 lines (35 loc) · 1.34 KB
/
test_ff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import magma as m
import magma.testing
import os
import pytest
@pytest.mark.parametrize("target", ["verilog", "coreir", "coreir-verilog"])
@pytest.mark.parametrize("circuit_type", ["declare", "define"])
def test_ff_param(target, circuit_type):
suffix = {
"verilog": "v",
"coreir": "json",
"coreir-verilog": "v"
}[target]
constructor = {
"declare": m.DeclareFromVerilogFile,
"define": m.DefineFromVerilogFile
}[circuit_type]
ff_file = os.path.join(os.path.dirname(__file__), "ff.v")
FF = constructor(
ff_file,
type_map={"clk": m.In(m.Clock), "rst": m.In(m.AsyncReset)}
)[0]
class Top(m.Circuit):
IO = ["I", m.In(m.Bits[2]), "O", m.Out(m.Bits[2])] + \
m.ClockInterface(has_async_reset=True)
@classmethod
def definition(io):
# keyword arguments to instancing call are passed as verilog
# parameters
ff0 = FF(init=0)
ff1 = FF(init=1)
io.O <= m.join([ff0, ff1])(d=io.I, rst=io.ASYNCRESET)
m.compile(f"build/top-{circuit_type}-{target}", Top, output=target)
assert m.testing.check_files_equal(__file__,
f"build/top-{circuit_type}-{target}.{suffix}",
f"gold/top-{circuit_type}-{target}.{suffix}")