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
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"crates/celox-frontend-sdk",
"crates/celox-frontend-sv",
"crates/celox-frontend-veryl",
"crates/celox-heap",
"crates/celox-sir",
"crates/celox-sir-opt",
"crates/celox-slt",
Expand Down Expand Up @@ -65,6 +66,7 @@ celox-frontend-core = { version = "=0.11.0", path = "crates/celox-frontend-c
celox-frontend-sdk = { version = "=0.11.0", path = "crates/celox-frontend-sdk" } # x-release-please-version
celox-frontend-sv = { version = "=0.11.0", path = "crates/celox-frontend-sv" } # x-release-please-version
celox-frontend-veryl = { version = "=0.11.0", path = "crates/celox-frontend-veryl" } # x-release-please-version
celox-heap = { version = "=0.11.0", path = "crates/celox-heap" } # x-release-please-version
celox-macros = { version = "=0.11.0", path = "crates/celox-macros" } # x-release-please-version
celox-napi = { version = "=0.11.0", path = "crates/celox-napi" } # x-release-please-version
celox-runtime = { version = "=0.11.0", path = "crates/celox-runtime" } # x-release-please-version
Expand Down
26 changes: 26 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ pub struct VariableMetadata {
/// Per-dimension sizes for array ports (for example, `[4]` for `logic<32>[4]`).
/// Empty means scalar.
pub array_dims: Vec<usize>,
/// What each element holds. Handle elements are 32-bit two-state slots.
#[serde(default)]
pub value_kind: ValueKind,
}

/// Bit width of a handle element in state memory.
pub const HANDLE_WIDTH: usize = 32;

/// What a state element holds.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ValueKind {
/// Packed bits.
#[default]
Bits,
/// A handle of a string in the simulator's heap.
StrRef,
}

impl ValueKind {
pub fn is_handle(self) -> bool {
self != Self::Bits
}
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -1604,6 +1626,7 @@ mod tests {
kind: DomainKind::Other,
type_kind: PortTypeKind::Logic,
array_dims: vec![4],
value_kind: Default::default(),
};

assert_eq!(metadata.width, 32);
Expand All @@ -1621,6 +1644,7 @@ mod tests {
kind: DomainKind::ClockPosedge,
type_kind: PortTypeKind::Clock,
array_dims: Vec::new(),
value_kind: Default::default(),
},
);
design.events.aliases.insert(11, 10);
Expand Down Expand Up @@ -1649,6 +1673,7 @@ mod tests {
kind,
type_kind: PortTypeKind::Logic,
array_dims: Vec::new(),
value_kind: Default::default(),
},
);
}
Expand Down Expand Up @@ -1681,6 +1706,7 @@ mod tests {
kind,
type_kind: PortTypeKind::Logic,
array_dims: Vec::new(),
value_kind: Default::default(),
},
);
}
Expand Down
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 @@ -1058,6 +1058,7 @@ impl HiddenObjects<'_> {
PortTypeKind::Bit
},
array_dims: Vec::new(),
value_kind: Default::default(),
},
unpacked_ranges: Vec::new(),
packed_dims: vec![width],
Expand Down Expand Up @@ -1821,6 +1822,7 @@ pub fn lower_frontend_artifact(
kind,
type_kind,
array_dims: Vec::new(),
value_kind: Default::default(),
},
unpacked_ranges: Vec::new(),
packed_dims: vec![signal.value_type().width()],
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-core/src/symbolic/comb_startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ mod tests {
kind: DomainKind::Other,
type_kind: PortTypeKind::Logic,
array_dims: vec![2],
value_kind: Default::default(),
},
)]
.into_iter()
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 @@ -501,6 +501,7 @@ pub fn declare_counter_slots(
kind: DomainKind::Other,
type_kind: PortTypeKind::Bit,
array_dims: Vec::new(),
value_kind: Default::default(),
},
unpacked_ranges: Vec::new(),
packed_dims: vec![EVENT_COUNTER_WIDTH],
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl SvVariable {
kind: self.domain_kind,
type_kind: self.type_kind,
array_dims: self.array_dims.clone(),
value_kind: Default::default(),
},
unpacked_ranges: self.unpacked_ranges.clone(),
packed_dims: self
Expand Down
5 changes: 5 additions & 0 deletions crates/celox-frontend-veryl/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ pub(crate) fn project_module_with_ids(
.iter()
.filter_map(|value| *value)
.collect(),
value_kind: if variable.r#type.is_string() {
celox_design::ValueKind::StrRef
} else {
celox_design::ValueKind::Bits
},
},
packed_dims,
unpacked_ranges: Vec::new(),
Expand Down
5 changes: 4 additions & 1 deletion crates/celox-frontend-veryl/src/lowering/bitaccess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ fn collect_dims(module: &Module, var_id: VarId) -> Result<Vec<usize>, ParserErro
// Enums and aggregates encode their packed width in TypeKind rather
// than the width Shape. Even a one-bit struct/union needs that dimension:
// Veryl represents member access as a select into the packed aggregate.
if width.is_empty() {
if var_type.is_string() {
// A string element is a handle into the simulator's heap.
dims.push(celox_design::HANDLE_WIDTH);
} else if width.is_empty() {
if let Some(kind_width) = var_type.kind.width()
&& (kind_width > 1 || (kind_width == 1 && var_type.is_struct_union()))
{
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-veryl/src/lowering/latch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub(crate) fn lower_retained_comb_process(
kind: DomainKind::Other,
type_kind: PortTypeKind::Logic,
array_dims: Vec::new(),
value_kind: Default::default(),
},
packed_dims: Vec::new(),
unpacked_ranges: Vec::new(),
Expand Down
11 changes: 8 additions & 3 deletions crates/celox-frontend-veryl/src/lowering/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ use crate::ParserError;

/// Resolve the total storage size of a variable.
pub fn resolve_total_width(module: &Module, variable: &Variable) -> Result<usize, ParserError> {
let width = variable.total_width().ok_or_else(|| {
ParserError::unresolved_width(module, variable, variable.r#type.to_string())
})?;
// A string element is a handle into the simulator's heap.
let width = if variable.r#type.is_string() {
celox_design::HANDLE_WIDTH
} else {
variable.total_width().ok_or_else(|| {
ParserError::unresolved_width(module, variable, variable.r#type.to_string())
})?
};
let array = variable.r#type.total_array().ok_or_else(|| {
ParserError::unresolved_width(module, variable, variable.r#type.to_string())
})?;
Expand Down
3 changes: 2 additions & 1 deletion crates/celox-frontend-veryl/src/testbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ impl ExprCompiler<'_> {
}
ops.push(TbOpcode::LoadString {
location: Self::state_location_at(address, 0),
elements: info.width,
elements: info.width / celox_design::HANDLE_WIDTH,
});
}

Expand Down Expand Up @@ -3922,6 +3922,7 @@ mod tests {
kind: DomainKind::Other,
type_kind: PortTypeKind::Logic,
array_dims: Vec::new(),
value_kind: Default::default(),
},
};

Expand Down
16 changes: 16 additions & 0 deletions crates/celox-heap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "celox-heap"
version.workspace = true
publish = ["crates-io"]
authors.workspace = true
repository.workspace = true
license.workspace = true
description = "Runtime heap of dynamic values referenced by handles in Celox state"
edition.workspace = true
rust-version.workspace = true

[dependencies]
fxhash = { workspace = true }

[lints]
workspace = true
Loading
Loading