1 from nmigen
import Module
, Elaboratable
, Signal
2 from nmigen
.back
.pysim
import Simulator
, Delay
, Settle
3 from nmigen
.test
.utils
import FHDLTestCase
4 from nmigen
.cli
import rtlil
8 from power_major_decoder
import (PowerMajorDecoder
, Function
,
9 InternalOp
, major_opcodes
)
11 class DecoderTestCase(FHDLTestCase
):
12 def test_function_unit(self
):
16 function_unit
= Signal(Function
)
17 internal_op
= Signal(InternalOp
)
19 m
.submodules
.dut
= dut
= PowerMajorDecoder()
20 comb
+= [dut
.opcode_in
.eq(opcode
),
21 function_unit
.eq(dut
.function_unit
),
22 internal_op
.eq(dut
.internal_op
)]
26 for row
in major_opcodes
:
27 yield opcode
.eq(int(row
['opcode']))
29 result
= yield function_unit
30 expected
= Function
[row
['unit']].value
31 self
.assertEqual(expected
, result
)
33 result
= yield internal_op
34 expected
= InternalOp
[row
['internal op']].value
35 self
.assertEqual(expected
, result
)
36 sim
.add_process(process
)
37 with sim
.write_vcd("test.vcd", "test.gtkw", traces
=[opcode
, function_unit
, internal_op
]):
41 dut
= PowerMajorDecoder()
42 vl
= rtlil
.convert(dut
, ports
=[dut
.opcode_in
, dut
.function_unit
])
43 with
open("power_major_decoder.il", "w") as f
:
46 if __name__
== "__main__":