5 from .
import fsm
as fsm
7 from ..dialects._ods_common
import _cext
as _ods_cext
9 from ._fsm_ops_gen
import *
10 from ._fsm_ops_gen
import _Dialect
14 if len(region.blocks) == 0:
15 region.blocks.append(*args)
16 return region.blocks[0]
19 @_ods_cext.register_operation(_Dialect, replace=True)
31 attributes[
"sym_name"] = StringAttr.get(name)
32 attributes[
"initialState"] = StringAttr.get(initial_state)
36 for (i, (_, port_type))
in enumerate(input_ports):
37 input_types.append(port_type)
39 for (i, (_, port_type))
in enumerate(output_ports):
40 output_types.append(port_type)
42 attributes[
"function_type"] = TypeAttr.get(
43 FunctionType.get(inputs=input_types, results=output_types))
47 self.build_generic(attributes=attributes,
59 return FunctionType(TypeAttr(self.attributes[
"function_type"]).value)
61 def instantiate(self, name: str, loc=
None, ip=
None, **kwargs):
62 """ FSM Instantiation function"""
63 in_names = support.attribute_to_var(self.attributes[
'in_names'])
64 inputs = [kwargs[port].value
for port
in in_names]
71 clock = support.BackedgeBuilder().create(
72 IntegerType.get_signed(1),
73 StringAttr(self.attributes[
'clock_name']).value, self)
74 reset = support.BackedgeBuilder().create(
75 IntegerType.get_signed(1),
76 StringAttr(self.attributes[
'reset_name']).value, self)
78 op = fsm.HWInstanceOp(outputs=self.
typetype.results,
80 sym_name=StringAttr.get(name),
81 machine=FlatSymbolRefAttr.get(self.sym_name.value),
83 reset=reset.result
if reset
else None,
88 def set_OpOperand(name, backedge):
90 for i, operand
in enumerate(op.operands):
91 if operand == backedge.result:
94 assert index
is not None
95 op_operand = support.OpOperand(op, index, op.operands[index], op)
96 setattr(op, f
'_{name}_backedge', op_operand)
97 op.backedges[i] = backedge
99 set_OpOperand(
'clock', clock)
101 set_OpOperand(
'reset', reset)
106 @_ods_cext.register_operation(_Dialect, replace=True)
115 """Executes a function to generate a guard for the transition.
116 The function is executed within the guard region of this operation."""
118 with InsertionPoint(guard_block):
120 guard_type = support.type_to_pytype(guard.type)
121 if guard_type.width != 1:
122 raise ValueError(
'The guard must be a single bit')
123 fsm.ReturnOp(operand=guard)
126 @_ods_cext.register_operation(_Dialect, replace=True)
131 attributes[
"sym_name"] = StringAttr.get(name)
135 self.build_generic(attributes=attributes,
156 @_ods_cext.register_operation(_Dialect, replace=True)
def instantiate(self, str name, loc=None, ip=None, **kwargs)
def __init__(self, name, initial_state, input_ports, output_ports, *attributes={}, loc=None, ip=None)
def __init__(self, name, *loc=None, ip=None)
def set_guard(self, guard_fn)
def _get_or_add_single_block(region, args=[])