8 from ..dialects._ods_common
import _cext
as _ods_cext
9 from ..ir
import IntegerType, OpView, StringAttr, InsertionPoint
10 from ..support
import BackedgeBuilder, NamedValueOpView
11 from ._seq_ops_gen
import *
12 from ._seq_ops_gen
import _Dialect
13 from .seq
import CompRegOp, InitialOp
21 def reg(value, clock, reset=None, reset_value=None, name=None, sym_name=None):
23 from ..ir
import IntegerAttr
24 value_type = value.type
27 zero = IntegerAttr.get(value_type, 0)
29 return CompRegOp.create(value_type,
33 reset_value=reset_value,
35 sym_name=sym_name).data.value
37 return CompRegOp.create(value_type,
41 sym_name=sym_name).data.value
50 if arg_name ==
"input":
51 operand_type = data_type
53 operand_type = IntegerType.get_signless(1)
54 return BackedgeBuilder.create(operand_type, arg_name, self)
72 operands = [input, clk]
75 results.append(data_type)
76 operand_segment_sizes = [1, 1]
77 if isinstance(self, CompRegOp):
78 if clockEnable
is not None:
79 raise Exception(
"Clock enable not supported on compreg")
80 elif isinstance(self, CompRegClockEnabledOp):
81 if clockEnable
is None:
82 raise Exception(
"Clock enable required on compreg.ce")
83 operands.append(clockEnable)
84 operand_segment_sizes.append(1)
86 assert False,
"Class not recognized"
87 if reset
is not None and reset_value
is not None:
88 operands.append(reset)
89 operands.append(reset_value)
90 operand_segment_sizes += [1, 1]
92 operand_segment_sizes += [0, 0]
93 operands += [
None,
None]
95 if power_on_value
is not None:
96 if isinstance(power_on_value.type, seq.ImmutableType):
99 if power_on_value.owner
is None:
100 assert False,
"Initial value must not be port"
102 init = InitialOp([seq.ImmutableType.get(power_on_value.type)], [])
103 init.body.blocks.append()
104 with InsertionPoint(init.body.blocks[0]):
105 cloned_constant = power_on_value.owner.clone()
106 seq.YieldOp(cloned_constant)
108 power_on_value = init.results[0]
110 assert False,
"Non-constant initial value not supported"
111 operands.append(power_on_value)
112 operand_segment_sizes.append(1)
114 operands.append(
None)
115 operand_segment_sizes.append(0)
117 attributes[
"name"] = StringAttr.get(
"")
119 attributes[
"name"] = StringAttr.get(name)
120 if sym_name
is not None:
121 attributes[
"inner_sym"] = hw.InnerSymAttr.get(StringAttr.get(sym_name))
128 attributes=attributes,
140 return [
"input",
"clk"]
143 @_ods_cext.register_operation(_Dialect, replace=True)
158 reset_value=reset_value,
161 needs_result_type=
True)
167 return [
"input",
"clk",
"clockEnable"]
170 @_ods_cext.register_operation(_Dialect, replace=True)
185 reset_value=reset_value,
188 needs_result_type=
True)
def create(cls, result_type, reset=None, reset_value=None, name=None, sym_name=None, **kwargs)
def create_initial_value(self, index, data_type, arg_name)
def __init__(self, data_type, input, clk, clockEnable=None, *reset=None, reset_value=None, power_on_value=None, name=None, sym_name=None, loc=None, ip=None)
def create(cls, result_type, reset=None, reset_value=None, name=None, sym_name=None, **kwargs)
def reg(value, clock, reset=None, reset_value=None, name=None, sym_name=None)