diff --git a/crates/celox-design/src/lib.rs b/crates/celox-design/src/lib.rs
index 7cb1572d8e2..088c230da03 100644
--- a/crates/celox-design/src/lib.rs
+++ b/crates/celox-design/src/lib.rs
@@ -1054,6 +1054,12 @@ pub struct EventTopology {
/// a signal needs a settle before its domains evaluate.
#[serde(default)]
pub combinationally_read: BTreeSet,
+ /// Canonical events whose own domain reads no level of their signal: its
+ /// flip-flops do not sample the signal as data. With
+ /// [`Self::combinationally_read`] it says whether a run of the domain
+ /// observes the signal's level. Absent means it may.
+ #[serde(default)]
+ pub level_unread_by_domain: BTreeSet,
}
/// A clock computed combinationally from an event's signal.
@@ -1149,6 +1155,7 @@ impl Default for EventTopology {
combinational_derived: BTreeMap::new(),
independent_derived: BTreeSet::new(),
combinationally_read: BTreeSet::new(),
+ level_unread_by_domain: BTreeSet::new(),
}
}
}
diff --git a/crates/celox-frontend-core/src/symbolic/assembly.rs b/crates/celox-frontend-core/src/symbolic/assembly.rs
index 6a8f45347bb..3597877c643 100644
--- a/crates/celox-frontend-core/src/symbolic/assembly.rs
+++ b/crates/celox-frontend-core/src/symbolic/assembly.rs
@@ -956,6 +956,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
combinational_derived,
independent_derived,
combinationally_read,
+ level_unread_by_domain,
} = timed_sub!(
"analyze_clock_dependencies",
analyze_clock_dependencies(
@@ -1802,6 +1803,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
.collect(),
independent_derived: independent_derived.into_iter().map(project).collect(),
combinationally_read: combinationally_read.into_iter().map(project).collect(),
+ level_unread_by_domain: level_unread_by_domain.into_iter().map(project).collect(),
combinational_derived: combinational_derived
.into_iter()
.map(|(event, clocks)| {
@@ -4629,6 +4631,8 @@ struct ClockAnalysis {
independent_derived: BTreeSet,
/// Events whose signal combinational logic reads.
combinationally_read: BTreeSet,
+ /// Events whose own domain does not read their signal.
+ level_unread_by_domain: BTreeSet,
}
fn analyze_clock_dependencies(
@@ -5023,6 +5027,27 @@ fn analyze_clock_dependencies(
}
Some((reads, writes))
};
+ // A domain reads its own clock's level when a flip-flop samples it as
+ // data. An external call may read anything.
+ let canonical = |address: AbsoluteAddr| clock_domains.get(&address).copied().unwrap_or(address);
+ let level_unread_by_domain: BTreeSet = eval_apply_ffs
+ .iter()
+ .filter(|(domain, units)| {
+ let domain = canonical(**domain);
+ !units
+ .iter()
+ .flat_map(|unit| unit.blocks.values())
+ .flat_map(|block| &block.instructions)
+ .any(|instruction| match instruction {
+ SIRInstruction::Load(_, address, ..) | SIRInstruction::Commit(address, ..) => {
+ canonical(address.absolute_addr()) == domain
+ }
+ SIRInstruction::ExternCall { .. } => true,
+ _ => false,
+ })
+ })
+ .map(|(domain, _)| canonical(*domain))
+ .collect();
let mut independent_derived = BTreeSet::new();
let combinationally_read: BTreeSet = comb_deps
.values()
@@ -5070,6 +5095,7 @@ fn analyze_clock_dependencies(
combinational_derived,
independent_derived,
combinationally_read,
+ level_unread_by_domain,
}
}
diff --git a/crates/celox-runtime/src/edge.rs b/crates/celox-runtime/src/edge.rs
index 1b971593394..1348822b39f 100644
--- a/crates/celox-runtime/src/edge.rs
+++ b/crates/celox-runtime/src/edge.rs
@@ -13,7 +13,7 @@
//! so the inactive edge of a clock that only clocks flip-flops costs no
//! settle on the next active edge.
-use celox_design::{DomainKind, EventTopology, edges::LEVEL_UNKNOWN};
+use celox_design::{DomainKind, EventTopology, GateOp, edges::LEVEL_UNKNOWN};
use crate::{
AbsoluteAddr, SignalRef,
@@ -60,6 +60,15 @@ pub struct EventEdge {
pub kind: Option,
/// Combinational logic reads the signal.
pub comb_read: bool,
+ /// A run of the event's own domain can observe the signal's level:
+ /// combinational logic or one of the domain's flip-flops reads it.
+ pub level_read: bool,
+ /// The edge opposite to [`Self::active_edge`] can run a domain: the
+ /// event's own, or that of a clock computed combinationally from the
+ /// signal that this edge can move to its active edge. When it cannot,
+ /// nothing commits on that edge, so no domain clocked from state runs
+ /// either, and a host only needs to store the level.
+ pub inactive_runs: bool,
}
impl EventEdge {
@@ -108,15 +117,130 @@ pub fn build_event_edges(
.iter()
.map(|address| {
let canonical = events.canonical(*address);
- EventEdge {
+ let kind = kinds.get(&canonical).copied();
+ let comb_read = events.combinationally_read.contains(&canonical);
+ let mut info = EventEdge {
signal: backend.resolve_signal(&canonical),
- kind: kinds.get(&canonical).copied(),
- comb_read: events.combinationally_read.contains(&canonical),
- }
+ kind,
+ comb_read,
+ level_read: comb_read || !events.level_unread_by_domain.contains(&canonical),
+ inactive_runs: false,
+ };
+ let inactive = info.active_edge().opposite();
+ info.inactive_runs = info.can_fire(inactive)
+ || events
+ .combinational_derived
+ .get(&canonical)
+ .into_iter()
+ .flatten()
+ // A clock without a domain of its own runs nothing.
+ .filter(|clock| backend.resolve_event_opt(&clock.clock).is_some())
+ .any(|clock| {
+ let moves = clock
+ .gate
+ .as_deref()
+ .and_then(dependence)
+ .unwrap_or(Dependence::Mixed);
+ moves.can_reach(inactive, kinds.get(&clock.clock).copied())
+ });
+ info
})
.collect()
}
+/// How a gate program's value depends on its source's level, bitwise:
+/// whether raising the source can only raise each bit, only lower it, or
+/// either. The operations it treats as monotone also are over the order
+/// 0 < x < 1 of four-state values, so it holds for four-state designs.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+enum Dependence {
+ Independent,
+ Positive,
+ Negative,
+ Mixed,
+}
+
+impl Dependence {
+ fn invert(self) -> Self {
+ match self {
+ Dependence::Positive => Dependence::Negative,
+ Dependence::Negative => Dependence::Positive,
+ other => other,
+ }
+ }
+
+ /// A monotone function of both operands, such as `&` or `|`.
+ fn join(self, other: Self) -> Self {
+ match (self, other) {
+ (Dependence::Independent, other) | (other, Dependence::Independent) => other,
+ (lhs, rhs) if lhs == rhs => lhs,
+ _ => Dependence::Mixed,
+ }
+ }
+
+ /// A function of the operands that is not monotone, such as `^`.
+ fn scramble(self, other: Self) -> Self {
+ if self == Dependence::Independent && other == Dependence::Independent {
+ Dependence::Independent
+ } else {
+ Dependence::Mixed
+ }
+ }
+
+ /// Whether `edge` of the source can be an edge of a clock of `kind`
+ /// computed with this dependence.
+ fn can_reach(self, edge: Edge, kind: Option) -> bool {
+ let moves = match self {
+ Dependence::Independent => return false,
+ Dependence::Mixed => return true,
+ Dependence::Positive => edge,
+ Dependence::Negative => edge.opposite(),
+ };
+ match kind {
+ Some(DomainKind::ClockPosedge | DomainKind::ResetAsyncHigh) => moves == Edge::Rising,
+ Some(DomainKind::ClockNegedge | DomainKind::ResetAsyncLow) => moves == Edge::Falling,
+ _ => true,
+ }
+ }
+}
+
+/// The [`Dependence`] of a gate program's value on its source, or `None`
+/// for a malformed program.
+fn dependence(ops: &[GateOp]) -> Option {
+ let mut stack: Vec = Vec::new();
+ for op in ops {
+ let value = match op {
+ GateOp::Source => Dependence::Positive,
+ GateOp::Load { .. } | GateOp::Const(_) => Dependence::Independent,
+ GateOp::Not { .. } | GateOp::LogicNot => stack.pop()?.invert(),
+ GateOp::ReduceAnd { .. } | GateOp::ReduceOr | GateOp::Slice { .. } => stack.pop()?,
+ GateOp::ReduceXor => stack.pop()?.scramble(Dependence::Independent),
+ GateOp::And | GateOp::Or | GateOp::LogicAnd | GateOp::LogicOr => {
+ let rhs = stack.pop()?;
+ stack.pop()?.join(rhs)
+ }
+ GateOp::Xor | GateOp::Eq | GateOp::Ne => {
+ let rhs = stack.pop()?;
+ stack.pop()?.scramble(rhs)
+ }
+ GateOp::Mux => {
+ let otherwise = stack.pop()?;
+ let then = stack.pop()?;
+ match stack.pop()? {
+ // A fixed condition selects one of two monotone values.
+ Dependence::Independent => then.join(otherwise),
+ _ => Dependence::Mixed,
+ }
+ }
+ };
+ stack.push(value);
+ }
+ match stack.as_slice() {
+ [value] => Some(*value),
+ _ => None,
+ }
+}
+
/// What an edge did.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum EdgeOutcome {
@@ -174,6 +298,12 @@ pub fn set_level(backend: &mut B, signal: SignalRef, level: u8) {
backend.set(signal, level);
}
+/// Whether `info`'s signal is at the known level `edge` leaves it at.
+#[inline]
+pub fn at_level(backend: &B, info: &EventEdge, edge: Edge) -> bool {
+ level(backend, info.signal) == edge.level()
+}
+
/// Move `info`'s signal to the level of `edge` through `write`. Returns the
/// level it had (`None` while unknown), or `None` when it already was at
/// that level.
@@ -398,3 +528,69 @@ where
}
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ type Op = GateOp<()>;
+
+ const LOAD: Op = GateOp::Load {
+ address: (),
+ lsb: 0,
+ width: 1,
+ };
+
+ #[test]
+ fn gates_follow_their_source_through_monotone_operations() {
+ use Dependence::*;
+ let cases: [(&[Op], Dependence); 8] = [
+ (&[GateOp::Source, LOAD, GateOp::And], Positive),
+ (&[GateOp::Source, GateOp::Not { width: 1 }], Negative),
+ (
+ &[GateOp::Source, GateOp::LogicNot, LOAD, GateOp::LogicOr],
+ Negative,
+ ),
+ (&[LOAD, GateOp::Const(1), GateOp::Or], Independent),
+ (&[GateOp::Source, LOAD, GateOp::Xor], Mixed),
+ (
+ &[
+ GateOp::Source,
+ GateOp::Source,
+ GateOp::Not { width: 1 },
+ GateOp::Or,
+ ],
+ Mixed,
+ ),
+ (
+ &[LOAD, GateOp::Source, GateOp::Const(0), GateOp::Mux],
+ Positive,
+ ),
+ (
+ &[GateOp::Source, LOAD, GateOp::Const(0), GateOp::Mux],
+ Mixed,
+ ),
+ ];
+ for (ops, expected) in cases {
+ assert_eq!(dependence(ops), Some(expected), "{ops:?}");
+ }
+ assert_eq!(dependence::<()>(&[GateOp::And]), None);
+ assert_eq!(dependence::<()>(&[GateOp::Source, GateOp::Source]), None);
+ }
+
+ #[test]
+ fn a_clock_is_reached_by_the_edges_its_dependence_allows() {
+ use DomainKind::*;
+ let posedge = Some(ClockPosedge);
+ let negedge = Some(ClockNegedge);
+ // The falling edge of a positive-edge clock's source.
+ let edge = Edge::Falling;
+ assert!(!Dependence::Positive.can_reach(edge, posedge));
+ assert!(Dependence::Positive.can_reach(edge, negedge));
+ assert!(Dependence::Negative.can_reach(edge, posedge));
+ assert!(!Dependence::Negative.can_reach(edge, Some(ResetAsyncLow)));
+ assert!(Dependence::Positive.can_reach(edge, None));
+ assert!(!Dependence::Independent.can_reach(edge, None));
+ assert!(Dependence::Mixed.can_reach(edge, posedge));
+ }
+}
diff --git a/crates/celox-runtime/src/lib.rs b/crates/celox-runtime/src/lib.rs
index 6dd1b5f2158..2a32ee2d4d0 100644
--- a/crates/celox-runtime/src/lib.rs
+++ b/crates/celox-runtime/src/lib.rs
@@ -24,8 +24,8 @@ pub use derived_tick::{
EventDomain, Gate, GatedDomain, TickExecutor, build_derived_tick_plans,
};
pub use edge::{
- Edge, EdgeOutcome, EventEdge, EventEdges, SignalWrite, build_event_edges, move_signal,
- run_edge, run_edges, run_tick, set_level,
+ Edge, EdgeOutcome, EventEdge, EventEdges, SignalWrite, at_level, build_event_edges,
+ move_signal, run_edge, run_edges, run_tick, set_level,
};
pub use error::{SimulatorErrorCode, comb_fatal_code, comb_fatal_site};
pub use event_buffer::RuntimeEventBuffer;
diff --git a/crates/celox-runtime/src/simulation/wait.rs b/crates/celox-runtime/src/simulation/wait.rs
index f8497a81a6d..1bb95a744e9 100644
--- a/crates/celox-runtime/src/simulation/wait.rs
+++ b/crates/celox-runtime/src/simulation/wait.rs
@@ -48,9 +48,24 @@ impl SimulationState {
for (term, baseline) in terms.iter().zip(&mut waiter.baselines) {
match term.counter {
Some(counter) => {
- *baseline = Baseline::Counter {
- seen: backend.get_as(counter),
- value: read(backend, term.signal),
+ let seen = backend.get_as(counter);
+ match planes(backend, term.signal) {
+ Some(image) => {
+ if let Baseline::RawCounter { seen: last, raw } = baseline {
+ *last = seen;
+ copy_planes(raw, image, term.signal.width);
+ } else {
+ let mut raw = Vec::with_capacity(image.len());
+ copy_planes(&mut raw, image, term.signal.width);
+ *baseline = Baseline::RawCounter { seen, raw };
+ }
+ }
+ None => {
+ *baseline = Baseline::Counter {
+ seen,
+ value: read(backend, term.signal),
+ }
+ }
}
}
None => match planes(backend, term.signal) {
@@ -128,20 +143,40 @@ impl SimulationState {
continue;
}
let baseline = &mut waiter.baselines[index];
+ // The common term: a plain signal no counter counts.
+ if let Baseline::Raw(last) = baseline {
+ let now = state.planes(term.signal).expect("a plain signal");
+ wake |= Self::advance(term.kind, last, now, term.signal.width);
+ continue;
+ }
+ let counted = |seen: u32| {
+ term.counter
+ .is_some_and(|counter| backend.get_as::(counter) != seen)
+ };
wake |= match baseline {
- Baseline::Counter { seen, value } => {
- let counted = term
- .counter
- .is_some_and(|counter| backend.get_as::(counter) != *seen);
- let now = read(backend, term.signal);
- let changed = occurs(term.kind, value, &now);
- *value = now;
- counted || changed
- }
- Baseline::Raw(last) => {
+ Baseline::RawCounter { seen, raw } => {
let now = state.planes(term.signal).expect("a plain signal");
- Self::advance(term.kind, last, now, term.signal.width)
+ let changed = Self::advance(term.kind, raw, now, term.signal.width);
+ counted(*seen) || changed
}
+ Baseline::Counter { seen, value } => match state.planes(term.signal) {
+ // A baseline loaded from a state file.
+ Some(now) => {
+ let seen = *seen;
+ let mut raw = encode_planes(value, term.signal.width, now.len());
+ let changed =
+ Self::advance(term.kind, &mut raw, now, term.signal.width);
+ *baseline = Baseline::RawCounter { seen, raw };
+ counted(seen) || changed
+ }
+ None => {
+ let now = read(backend, term.signal);
+ let changed = occurs(term.kind, value, &now);
+ *value = now;
+ counted(*seen) || changed
+ }
+ },
+ Baseline::Raw(_) => unreachable!("tested above"),
Baseline::Value(last) => match state.planes(term.signal) {
// A baseline loaded from a state file.
Some(now) => {
@@ -191,7 +226,7 @@ impl SimulationState {
}
match baseline {
// Counters are bumped by the write itself.
- Baseline::Counter { .. } => {}
+ Baseline::Counter { .. } | Baseline::RawCounter { .. } => {}
Baseline::Raw(last) => {
let now = encode_planes(value, signal.width, last.len());
wake |= Self::advance(term.kind, last, &now, signal.width);
@@ -224,6 +259,9 @@ pub enum Baseline {
/// (see [`planes`]) with the bits above its width cleared. Checks
/// compare it with the state in place.
Raw(Vec),
+ /// Like `Counter`, with the signal's state at the last check kept as
+ /// in [`Baseline::Raw`].
+ RawCounter { seen: u32, raw: Vec },
}
/// A process suspended at a wait.
diff --git a/crates/celox-sv-analyzer/src/ast/interface_binding.rs b/crates/celox-sv-analyzer/src/ast/interface_binding.rs
index c768f78170a..0c42bc267c0 100644
--- a/crates/celox-sv-analyzer/src/ast/interface_binding.rs
+++ b/crates/celox-sv-analyzer/src/ast/interface_binding.rs
@@ -29,6 +29,8 @@ pub(super) struct ScopeBinding {
pub(super) struct ArrayBinding {
pub elements: Vec,
pub shape: Vec,
+ /// Authored bounds, retained for selecting actual interface array elements.
+ pub ranges: Vec<(i128, i128)>,
}
pub(super) fn analyze_module(
@@ -419,6 +421,7 @@ pub(super) fn analyze_module(
})
.collect(),
shape: elements.shape.clone(),
+ ranges: elements.ranges.clone(),
};
imported.interface_arrays.insert(qualified, absolute);
if let Some(item) = &generated_item {
@@ -636,26 +639,7 @@ pub(super) fn analyze_module(
let actual =
connection_expression(authored, &port.name, interfaces.get(&original))?;
let env = &item.env;
- let handle = match actual {
- Some(actual) => {
- actual_handle_key(actual, tree, env, &active_scope.type_aliases)?
- }
- None => port.name.clone(),
- };
- let actuals = if port.array_rank == 0 {
- ArrayBinding {
- elements: vec![handle.clone()],
- shape: Vec::new(),
- }
- } else {
- active_scope
- .interface_arrays
- .get(&handle)
- .cloned()
- .ok_or_else(|| {
- unsupported(format!("interface array actual `{handle}`"))
- })?
- };
+ let actuals = connection_array(actual, &port.name, tree, env, &active_scope)?;
if actuals.shape.len() != port.array_rank {
return Err(unsupported(format!(
"interface array rank mismatch at `{original}.{}`",
@@ -1239,6 +1223,7 @@ fn instance_elements(
let ranges = constant_binding::bind_unpacked_ranges(dimensions, tree, &context)?;
validate_unpacked_dimension_sizes(&tree.state, &ranges, env)?;
let mut shape = Vec::new();
+ let mut bounds = Vec::new();
let mut elements = vec![handle.to_string()];
for range in ranges {
let left = eval_ast_const_expr(&tree.state, &range.left, env)
@@ -1256,6 +1241,7 @@ fn instance_elements(
})
.ok_or_else(|| unsupported("interface array elaboration limit exceeded"))?;
shape.push(count);
+ bounds.push((left, right));
elements = elements
.into_iter()
.flat_map(|prefix| {
@@ -1270,7 +1256,165 @@ fn instance_elements(
})
.collect();
}
- Ok(ArrayBinding { elements, shape })
+ Ok(ArrayBinding {
+ elements,
+ shape,
+ ranges: bounds,
+ })
+}
+
+/// Bind an interface actual as a selection of elaborated instances. Selections
+/// consume authored dimensions; a slice retains its dimension while an index
+/// removes it. Elements stay in declaration order for left-to-left port mapping.
+fn connection_array(
+ actual: Option,
+ implicit: &str,
+ tree: &AnalysisContext<'_>,
+ env: &HashMap,
+ scope: &scope::ScopeSymbols,
+) -> Converted {
+ use celox_sv_syntax::ExprKind;
+ let native = tree.declarations();
+ let mut selections = Vec::new();
+ let mut root = actual;
+ while let Some(id) = root {
+ let id = expression_binding::ungroup(id, native);
+ if let ExprKind::Select {
+ expression,
+ dimension,
+ } = &native.expression(id).kind
+ {
+ selections.push(&dimension.kind);
+ root = Some(*expression);
+ } else {
+ root = Some(id);
+ break;
+ }
+ }
+ let handle = match root {
+ Some(root) => actual_handle_key(root, tree, env, &scope.type_aliases)?,
+ None => implicit.to_string(),
+ };
+ let Some(array) = scope.interface_arrays.get(&handle) else {
+ // A selection in a hierarchical prefix may name a generated scope;
+ // retain the existing scalar-handle resolution for that case.
+ return Ok(ArrayBinding {
+ elements: vec![match actual {
+ Some(actual) => actual_handle_key(actual, tree, env, &scope.type_aliases)?,
+ None => handle,
+ }],
+ shape: Vec::new(),
+ ranges: Vec::new(),
+ });
+ };
+ if selections.is_empty() {
+ return Ok(array.clone());
+ }
+ if selections.len() > array.shape.len() {
+ return Err(unsupported("too many interface array selections"));
+ }
+ if selections
+ .iter()
+ .filter(|selection| {
+ matches!(
+ selection,
+ celox_sv_syntax::DimensionKind::Range { .. }
+ | celox_sv_syntax::DimensionKind::Indexed { .. }
+ )
+ })
+ .count()
+ > 1
+ {
+ return Err(unsupported("interface array slices in multiple dimensions"));
+ }
+ let context = PackedDimensions::new(HashMap::default(), env, &scope.type_aliases);
+ let evaluate = |root| -> Converted {
+ constant_binding::bind(root, tree, &context)?
+ .and_then(|value| eval_ast_const_expr(&tree.state, &value, env))
+ .ok_or_else(|| unsupported("nonconstant interface array selection"))
+ };
+ let selections = selections.into_iter().rev().collect::>();
+ let mut offsets = vec![0];
+ let mut shape = Vec::new();
+ let mut ranges = Vec::new();
+ for (dimension, (&size, &(left, right))) in array.shape.iter().zip(&array.ranges).enumerate() {
+ let (selected_left, selected_right, retain) = match selections.get(dimension) {
+ None => (left, right, true),
+ Some(celox_sv_syntax::DimensionKind::Index(index)) => {
+ let index = evaluate(*index)?;
+ (index, index, false)
+ }
+ Some(selection) => {
+ let (start, end) = selection_range(selection, left <= right, &evaluate)?;
+ (start, end, true)
+ }
+ };
+ if selected_left < left.min(right)
+ || selected_left > left.max(right)
+ || selected_right < left.min(right)
+ || selected_right > left.max(right)
+ {
+ return Err(unsupported(
+ "interface array selection outside its declared range",
+ ));
+ }
+ if selected_left != selected_right && (selected_left < selected_right) != (left < right) {
+ return Err(unsupported("reversed interface array selection"));
+ }
+ // Bounds were checked against an elaborated dimension (at most 4096
+ // elements), so these differences and products fit in usize.
+ let start = left.abs_diff(selected_left) as usize;
+ let end = left.abs_diff(selected_right) as usize;
+ offsets = offsets
+ .into_iter()
+ .flat_map(|prefix| (start..=end).map(move |index| prefix * size + index))
+ .collect();
+ if retain {
+ shape.push(end - start + 1);
+ ranges.push((selected_left, selected_right));
+ }
+ }
+ Ok(ArrayBinding {
+ elements: offsets
+ .into_iter()
+ .map(|offset| array.elements[offset].clone())
+ .collect(),
+ shape,
+ ranges,
+ })
+}
+
+fn selection_range(
+ selection: &celox_sv_syntax::DimensionKind,
+ ascending: bool,
+ evaluate: &impl Fn(celox_sv_syntax::ExprId) -> Converted,
+) -> Converted<(i128, i128)> {
+ use celox_sv_syntax::DimensionKind;
+ match selection {
+ DimensionKind::Range { left, right } => Ok((evaluate(*left)?, evaluate(*right)?)),
+ DimensionKind::Indexed {
+ base,
+ operator,
+ width,
+ } => {
+ let base = evaluate(*base)?;
+ let width = evaluate(*width)?;
+ let extent = width
+ .checked_sub(1)
+ .filter(|_| width > 0)
+ .ok_or_else(|| unsupported("nonpositive interface array selection width"))?;
+ let (low, high) = if operator == "+:" {
+ (Some(base), base.checked_add(extent))
+ } else {
+ (base.checked_sub(extent), Some(base))
+ };
+ let (low, high) = low
+ .zip(high)
+ .ok_or_else(|| unsupported("interface array selection bound overflow"))?;
+ Ok(if ascending { (low, high) } else { (high, low) })
+ }
+ _ => Err(unsupported("interface array selection")),
+ }
}
pub(super) fn actual_handle_key(
@@ -1288,6 +1432,7 @@ pub(super) fn actual_handle_key(
let mut root = root;
let mut suffixes = Vec::new();
let mut handle = loop {
+ root = expression_binding::ungroup(root, native);
match &native.expression(root).kind {
ExprKind::Name(name) => break instances::normalize_identifier(&name.spelling),
ExprKind::Member {
diff --git a/crates/celox-sv-analyzer/src/ast/interfaces.rs b/crates/celox-sv-analyzer/src/ast/interfaces.rs
index c7a6e0db247..dfe0c33870b 100644
--- a/crates/celox-sv-analyzer/src/ast/interfaces.rs
+++ b/crates/celox-sv-analyzer/src/ast/interfaces.rs
@@ -2205,7 +2205,7 @@ struct TokenReference {
/// The interface handle an actual names, optionally selected and qualified by a modport.
fn actual_handle(expression: ExprId, file: &File<'_>) -> Converted