SumInterface constructor
Creates a new SumInterface with a fixed or variable amount, optionally
with an enable, in either positive or negative direction based on
increments.
If width is null, it can be inferred from fixedAmount if provided
with a type that contains width information (e.g. a LogicValue). There
must be enough information provided to determine the width.
If a fixedAmount is provided, then amount will be tied to a Const. A
provided fixedAmount must be parseable by LogicValue.of. Note that the
fixedAmount will always be interpreted as a positive value truncated to
width. If no fixedAmount is provided, then amount will be a normal
port with width bits.
If hasEnable is true, then an enable port will be added to the
interface.
Implementation
SumInterface(
{this.fixedAmount,
this.increments = true,
int? width,
this.hasEnable = false})
: width = (width == null && fixedAmount == null)
? throw RohdHclException(
'Must provide either a fixedAmount or width.')
: width ?? max(LogicValue.ofInferWidth(fixedAmount).width, 1) {
if (this.width <= 0) {
throw RohdHclException('Width must be positive.');
}
setPorts([
if (fixedAmount == null) Logic.port('amount', this.width),
if (hasEnable) Logic.port('enable'),
], [
PairDirection.fromProvider
]);
}