-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconditioned_input.py
More file actions
40 lines (31 loc) · 934 Bytes
/
Copy pathconditioned_input.py
File metadata and controls
40 lines (31 loc) · 934 Bytes
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
import pyrtl
from fsm import FSM
input_1 = pyrtl.Input(bitwidth=1, name='1')
input_2 = pyrtl.Input(bitwidth=1, name='2')
input_3 = pyrtl.Input(bitwidth=1, name='3')
output = pyrtl.Output(bitwidth=1, name='o')
ex_states = ["A", "B", "C"]
ex_rules = [
"A + 0 -> A, 0",
"A + 1 -> C, 1",
"B + 0 -> B, 0",
"B + 1 -> B, 1",
"C + 0 -> A, 0",
"C + 1 -> C, 1"
]
ex_machine = FSM(input_bitwidth=1, output_bitwidth=1, states=ex_states, rulesList=ex_rules)
with pyrtl.conditional_assignment:
with input_1:
ex_machine |= input_2
with pyrtl.otherwise:
ex_machine |= input_3
output <<= ex_machine()[0]
sim_trace = pyrtl.SimulationTrace()
sim = pyrtl.Simulation(tracer=sim_trace)
sim_inputs = {
'1' : '11111111111000000110000',
'2' : '01010101011111111111111',
'3' : '00000000000000000000000'
}
sim.step_multiple(sim_inputs)
sim_trace.render_trace(trace_list=['1', '2', '3', 'o'])