Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/celox-frontend-core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ impl HiddenObjects<'_> {
},
array_dims: Vec::new(),
},
unpacked_ranges: Vec::new(),
packed_dims: vec![width],
source: None,
module_affiliated: false,
Expand Down Expand Up @@ -1817,6 +1818,7 @@ pub fn lower_frontend_artifact(
type_kind,
array_dims: Vec::new(),
},
unpacked_ranges: Vec::new(),
packed_dims: vec![signal.value_type().width()],
source: None,
module_affiliated: true,
Expand Down
2 changes: 2 additions & 0 deletions crates/celox-frontend-core/src/shared/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub struct VariableInfo {
/// arrays because that is the source-independent storage shape. The
/// testbench adapter also needs packed shape for chained selects.
pub packed_dims: Vec<usize>,
/// Declared unpacked bounds, in storage order; empty uses zero-based dimensions.
pub unpacked_ranges: Vec<(i128, i128)>,
}

impl std::ops::Deref for VariableInfo {
Expand Down
2 changes: 2 additions & 0 deletions crates/celox-frontend-core/src/symbolic/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub struct SymbolicVariable {
pub signed: bool,
pub metadata: VariableMetadata,
pub packed_dims: Vec<usize>,
/// Declared unpacked bounds, in storage order; empty uses zero-based dimensions.
pub unpacked_ranges: Vec<(i128, i128)>,
pub source: Option<SourceLocation>,
pub module_affiliated: bool,
}
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,7 @@ fn module_variables(
var_kind: variable.kind,
signed: variable.signed,
packed_dims: variable.packed_dims.clone(),
unpacked_ranges: variable.unpacked_ranges.clone(),
metadata: variable.metadata.clone(),
},
);
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-core/src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ pub fn declare_counter_slots(
type_kind: PortTypeKind::Bit,
array_dims: Vec::new(),
},
unpacked_ranges: Vec::new(),
packed_dims: vec![EVENT_COUNTER_WIDTH],
source: None,
module_affiliated: false,
Expand Down
15 changes: 15 additions & 0 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct SvVariable {
is_4state: bool,
packed_ranges: Vec<(i128, i128)>,
array_dims: Vec<usize>,
unpacked_ranges: Vec<(i128, i128)>,
domain_kind: DomainKind,
kind: VariableKind,
type_kind: PortTypeKind,
Expand All @@ -91,6 +92,7 @@ impl SvVariable {
type_kind: self.type_kind,
array_dims: self.array_dims.clone(),
},
unpacked_ranges: self.unpacked_ranges.clone(),
packed_dims: self
.packed_ranges
.iter()
Expand Down Expand Up @@ -1443,6 +1445,7 @@ fn prepare_external_hierarchy_collecting(
.map(|&width| ((width - 1) as i128, 0))
.collect(),
array_dims: variable.metadata.array_dims.clone(),
unpacked_ranges: variable.unpacked_ranges.clone(),
domain_kind: variable.metadata.kind,
kind: variable.kind,
type_kind: variable.metadata.type_kind,
Expand Down Expand Up @@ -2420,6 +2423,7 @@ fn lower_module_with_overrides(
is_4state: type_info.is_4state,
packed_ranges: type_info.packed_ranges,
array_dims: type_info.array_dims,
unpacked_ranges: type_info.unpacked_ranges,
domain_kind: DomainKind::Other,
kind,
type_kind: type_info.type_kind,
Expand Down Expand Up @@ -2500,6 +2504,7 @@ fn lower_module_with_overrides(
is_4state: type_info.is_4state,
packed_ranges: type_info.packed_ranges,
array_dims: type_info.array_dims,
unpacked_ranges: type_info.unpacked_ranges,
domain_kind: DomainKind::Other,
kind: VariableKind::Variable,
type_kind: type_info.type_kind,
Expand Down Expand Up @@ -2572,6 +2577,7 @@ fn lower_module_with_overrides(
is_4state: true,
packed_ranges: vec![(width as i128 - 1, 0)],
array_dims: Vec::new(),
unpacked_ranges: Vec::new(),
domain_kind: DomainKind::Other,
kind: VariableKind::Parameter,
type_kind: PortTypeKind::Logic,
Expand Down Expand Up @@ -3607,6 +3613,7 @@ fn lower_initial_processes(
is_4state: false,
packed_ranges: vec![(width as i128 - 1, 0)],
array_dims: Vec::new(),
unpacked_ranges: Vec::new(),
domain_kind: DomainKind::Other,
kind: VariableKind::Variable,
type_kind: PortTypeKind::Bit,
Expand Down Expand Up @@ -3956,6 +3963,7 @@ fn ensure_parent_output_signals(
is_4state: true,
packed_ranges: Vec::new(),
array_dims: Vec::new(),
unpacked_ranges: Vec::new(),
domain_kind: DomainKind::Other,
kind: VariableKind::Variable,
type_kind: PortTypeKind::Logic,
Expand Down Expand Up @@ -5151,6 +5159,7 @@ struct SvSignalType {
is_4state: bool,
packed_ranges: Vec<(i128, i128)>,
array_dims: Vec<usize>,
unpacked_ranges: Vec<(i128, i128)>,
type_kind: PortTypeKind,
}

Expand Down Expand Up @@ -5214,6 +5223,11 @@ fn signal_type_from_sv(
.ok_or_else(|| {
sv::AnalyzerError::Unsupported("unresolved unpacked array dimension".to_string())
})?;
let unpacked_ranges = typ
.unpacked_ranges()
.iter()
.filter_map(|range| unpacked_range_bounds(range, constants, parameter_types))
.collect();
let element_count = array_dims
.iter()
.copied()
Expand Down Expand Up @@ -5253,6 +5267,7 @@ fn signal_type_from_sv(
is_4state,
packed_ranges,
array_dims,
unpacked_ranges,
type_kind,
})
}
Expand Down
3 changes: 3 additions & 0 deletions crates/celox-frontend-sv/src/lowering/procedural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ impl<'a> ProcModule<'a> {
is_4state,
packed_ranges: vec![(i128::try_from(width.max(1)).unwrap_or(1) - 1, 0)],
array_dims: Vec::new(),
unpacked_ranges: Vec::new(),
domain_kind: DomainKind::Other,
kind: VariableKind::Variable,
type_kind: if is_4state {
Expand Down Expand Up @@ -631,6 +632,7 @@ impl<'a> ProcModule<'a> {
is_4state: source.is_4state,
packed_ranges: vec![(0, 0)],
array_dims: Vec::new(),
unpacked_ranges: Vec::new(),
domain_kind: kind,
kind: VariableKind::Variable,
type_kind: source.type_kind,
Expand Down Expand Up @@ -1033,6 +1035,7 @@ pub(super) fn register_locals(
is_4state: type_info.is_4state,
packed_ranges: type_info.packed_ranges,
array_dims: type_info.array_dims,
unpacked_ranges: type_info.unpacked_ranges,
domain_kind: DomainKind::Other,
kind: VariableKind::Variable,
type_kind: type_info.type_kind,
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-veryl/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ pub(crate) fn project_module_with_ids(
.collect(),
},
packed_dims,
unpacked_ranges: Vec::new(),
source: Some(celox_frontend_core::SourceLocation {
path: variable.token.beg.source.to_string(),
text: source_texts
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-veryl/src/testbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3821,6 +3821,7 @@ mod tests {
path: path.clone(),
var_kind: VariableKind::Variable,
signed: false,
unpacked_ranges: Vec::new(),
packed_dims: vec![8],
metadata: VariableMetadata {
width: 8,
Expand Down
2 changes: 1 addition & 1 deletion crates/celox-runtime/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub trait SimBackend {
if let Some(trace) = self.layout().trace.as_ref() {
let len = signal.array_layout.map_or_else(
|| celox_state_layout::get_byte_size(signal.width),
|array| array.plane_size,
|array| array.element_count * array.element_stride,
);
let (ptr, _) = self.memory_as_ptr();
// SAFETY: layout homes and metadata fit in the writable state image.
Expand Down
15 changes: 15 additions & 0 deletions crates/celox-runtime/src/reflection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct ReflectionSignal {
pub signed: bool,
pub packed_dims: Vec<usize>,
pub unpacked_dims: Vec<usize>,
pub unpacked_ranges: Vec<(i128, i128)>,
pub type_kind: PortTypeKind,
}

Expand Down Expand Up @@ -127,6 +128,20 @@ impl DesignReflection {
signal.full_name
));
}
if signal.unpacked_dims.len() != signal.unpacked_ranges.len()
|| signal
.unpacked_dims
.iter()
.zip(&signal.unpacked_ranges)
.any(|(&size, &(left, right))| {
size == 0 || left.abs_diff(right).checked_add(1) != Some(size as u128)
})
{
return Err(format!(
"signal `{}` has invalid unpacked bounds",
signal.full_name
));
}
if index > 0 && self.signals[index - 1].full_name >= signal.full_name {
return Err("reflection signals are not uniquely name-sorted".into());
}
Expand Down
14 changes: 11 additions & 3 deletions crates/celox-vpi/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub(super) struct VlogStorage {
arg_ptrs: Vec<*mut c_char>,
}

fn callback_signal(data: &VpiCbData) -> Option<celox::ReflectionSignalId> {
fn callback_signal(data: &VpiCbData) -> Option<super::SignalSelection> {
if data.reason != CB_VALUE_CHANGE {
return None;
}
Expand Down Expand Up @@ -626,8 +626,16 @@ pub unsafe extern "C" fn vpi_chk_error(_info: *mut VpiErrorInfo) -> i32 {
/// # Safety
///
/// A non-null `reference` must be a live handle returned by this library.
pub unsafe extern "C" fn vpi_handle_by_index(_reference: VpiHandle, _index: i32) -> VpiHandle {
ptr::null_mut()
pub unsafe extern "C" fn vpi_handle_by_index(reference: VpiHandle, index: i32) -> VpiHandle {
// Safety: forwarded from the caller under the VPI handle contract.
let Some(ObjectRef::Signal(selection)) = (unsafe { object_ref(reference) }) else {
return ptr::null_mut();
};
super::with_runtime(|runtime| selection.select(runtime, index))
.flatten()
.map_or(ptr::null_mut(), |selection| {
super::new_object_handle(ObjectRef::Signal(selection))
})
}

#[unsafe(no_mangle)]
Expand Down
Loading
Loading