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
4 changes: 4 additions & 0 deletions conformance/sv-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ modes of `13.3.1--task-static` now pass. Its `int a = 0;` in a static task is
initialized once and shared by the four calls, which print 1, 2, 3 and 4 in
the local simulation driver; the full run reports no other change.

The `chandle` type updates two expectations: both state modes of
`6.14--chandle`, which declares a chandle variable, now pass. It is the only
fail-to-pass transition in the full local run; no failure expectation is broadened.

The official runner’s process exit code is separate from the case verdict.
The wrapper reads its `PASS`/`FAIL` log messages; it does not reconstruct their
rules from tool exit codes or `should_fail` metadata. A negative test may pass
Expand Down
4 changes: 2 additions & 2 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,8 @@ chapter-6/6.12--shortreal.sv 2state pass
chapter-6/6.12--shortreal.sv 4state pass
chapter-6/6.13--void.sv 2state pass
chapter-6/6.13--void.sv 4state pass
chapter-6/6.14--chandle.sv 2state fail
chapter-6/6.14--chandle.sv 4state fail
chapter-6/6.14--chandle.sv 2state pass
chapter-6/6.14--chandle.sv 4state pass
chapter-6/6.16--string.sv 2state pass
chapter-6/6.16--string.sv 4state pass
chapter-6/6.16.1--string_len.sv 2state pass
Expand Down
17 changes: 10 additions & 7 deletions crates/celox-frontend-sv/src/lowering/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,14 @@ fn resolved_type(module: &ElaboratedModule, r#type: &sv::ir::Type) -> Option<sv:
.iter()
.map(|range| unpacked_range_bounds(range, &module.constants, &module.parameter_types))
.collect::<Option<Vec<_>>>()?;
Some(sv::ast::Type::resolved(
kind,
r#type.is_signed(),
r#type.signed_element_depth(),
&packed,
&unpacked,
))
Some(
sv::ast::Type::resolved(
kind,
r#type.is_signed(),
r#type.signed_element_depth(),
&packed,
&unpacked,
)
.with_chandle(r#type.is_chandle()),
)
}
5 changes: 5 additions & 0 deletions crates/celox-frontend-sv/src/lowering/procedural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,11 @@ impl<'a> ProcModule<'a> {
sv::ir::DpiType::Bit => ExternType::Bit,
sv::ir::DpiType::Logic => ExternType::Logic,
sv::ir::DpiType::Integer { width, signed } => ExternType::Integer { width, signed },
// A pointer, 64 bits on the supported hosts.
sv::ir::DpiType::Chandle => ExternType::Integer {
width: 64,
signed: false,
},
};
let function = ExternFunction {
name: import.c_name().to_string(),
Expand Down
74 changes: 73 additions & 1 deletion crates/celox-sv-analyzer/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,11 @@ impl Module {
&type_aliases,
header_ports,
)?;
if let Some(port) = ports.iter().find(|port| port.r#type.holds_chandle()) {
return Err(AnalyzerError::IllegalChandleUse {
detail: format!("port `{}` of chandle type", port.name),
});
}
ports.extend(imported.ports.iter().cloned());
let mut port_names = HashSet::default();
if let Some(port) = ports.iter().find(|port| !port_names.insert(port.name())) {
Expand Down Expand Up @@ -1242,6 +1247,37 @@ impl Module {
let dpi_items = generate::items(syntax_tree, session, &const_env, &type_aliases)?;
let mut dpi_imports = dpi::imports(&dpi_items, syntax_tree, session, &type_aliases)?;
for import in &dpi_imports {
// Shapes check the actuals as assignments to the formals.
subroutine_shapes.insert(
import.name().to_string(),
import
.arguments()
.iter()
.filter_map(|argument| {
let r#type = match argument.r#type() {
crate::ir::DpiType::Bit => type_binding::builtin_type("bit", None),
crate::ir::DpiType::Logic => {
type_binding::builtin_type("logic", None)
}
crate::ir::DpiType::Chandle => {
type_binding::builtin_type("chandle", None)
}
crate::ir::DpiType::Integer { width, signed } => {
type_binding::builtin_type(
match width {
8 => "byte",
16 => "shortint",
32 => "int",
_ => "longint",
},
Some(signed),
)
}
}?;
Some(procedural::dimensions_from_type(&r#type))
})
.collect(),
);
subroutine_params.insert(
import.name().to_string(),
import
Expand Down Expand Up @@ -1434,6 +1470,7 @@ impl Module {
signed: function.return_signed,
is_2state: function.return_is_2state,
string: function.return_string,
chandle: function.return_chandle,
pattern_type: function.return_type.clone(),
enum_domain: function.return_enum_domain.clone(),
class: function.return_class.clone(),
Expand All @@ -1452,10 +1489,13 @@ impl Module {
width: Some(r#type.width()),
first_packed_dimension_width: (r#type.width() > 1)
.then_some(r#type.width()),
dimensions: Some(usize::from(r#type.width() > 1)),
dimensions: Some(usize::from(
r#type.width() > 1 && r#type != crate::ir::DpiType::Chandle,
)),
signed: r#type.is_signed(),
is_2state: !r#type.is_4state(),
string: false,
chandle: r#type == crate::ir::DpiType::Chandle,
pattern_type: None,
enum_domain: None,
class: None,
Expand Down Expand Up @@ -2476,6 +2516,9 @@ pub struct Type {
/// The typedef that names an enumeration, struct or union type, and how
/// `$typename` spells the type where its structure does not tell.
spelling: type_names::Spelling,
/// A `chandle` (IEEE 1800-2023 6.14): an opaque 64-bit C pointer, held
/// as 2-state bits, whose uses the analyzer restricts.
chandle: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -2505,6 +2548,7 @@ impl Type {
container: None,
unpacked_struct: None,
spelling: type_names::Spelling::default(),
chandle: false,
}
}

Expand All @@ -2524,6 +2568,7 @@ impl Type {
container: None,
unpacked_struct: None,
spelling: type_names::Spelling::default(),
chandle: false,
}
}

Expand All @@ -2544,6 +2589,16 @@ impl Type {
self.spelling.declaration()
}

/// Whether the type is a chandle or an unpacked structure with a
/// chandle member, which no port may have and no randomization fill
/// (IEEE 1800-2023 6.14).
pub(in crate::ast) fn holds_chandle(&self) -> bool {
self.chandle
|| self
.unpacked_struct()
.is_some_and(|aggregate| aggregate.leaves().iter().any(|leaf| leaf.r#type.chandle))
}

/// The members of an unpacked structure type.
pub(in crate::ast) fn unpacked_struct(&self) -> Option<&Arc<unpacked_structs::UnpackedStruct>> {
self.unpacked_struct.as_ref()
Expand Down Expand Up @@ -2624,6 +2679,17 @@ impl Type {
..Self::new(kind)
}
}

/// Whether the type is a `chandle`.
pub(crate) fn is_chandle(&self) -> bool {
self.chandle
}

/// The type, a `chandle` if `chandle` (see [`crate::ir::Type::is_chandle`]).
pub fn with_chandle(mut self, chandle: bool) -> Self {
self.chandle = chandle;
self
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -3103,6 +3169,8 @@ struct Function {
return_string: bool,
/// Whether the function returns a class handle.
return_handle: bool,
/// The function returns a `chandle`.
return_chandle: bool,
name: String,
params: Vec<FunctionParam>,
/// The function's value as one expression of its arguments, or `None`
Expand Down Expand Up @@ -3357,6 +3425,8 @@ struct VariableDimensions {
unpacked_struct: Option<Arc<unpacked_structs::UnpackedStruct>>,
/// The declared type, for `$typename`.
declared: type_names::Declared,
/// A `chandle` variable (see [`Type::chandle`]).
chandle: bool,
}

type VariablePackedDimensions = HashMap<String, VariableDimensions>;
Expand All @@ -3379,6 +3449,8 @@ struct FunctionReturnMetadata {
is_2state: bool,
/// The function returns a `string`.
string: bool,
/// The function returns a `chandle` (IEEE 1800-2023 6.14).
chandle: bool,
/// Declared aggregate type, available before function bodies are inlined.
pattern_type: Option<Type>,
/// The members of an enumerated return type, for its methods.
Expand Down
2 changes: 1 addition & 1 deletion crates/celox-sv-analyzer/src/ast/array_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn array_parameters_from_declaration(
// default. Only defaults actually consumed here require their native ID.
let native_pattern = if bound.is_none() { pattern } else { None };
let parameter = ArrayParameter {
signal: Signal::new(name, type_with_unpacked_ranges(element, ranges)),
signal: Signal::new(name, type_with_unpacked_ranges(element, ranges)?),
native_pattern,
bound,
};
Expand Down
13 changes: 13 additions & 0 deletions crates/celox-sv-analyzer/src/ast/array_reductions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ use super::*;
use celox_sv_syntax::{Declarations, ExprId, ExprKind};
use system_functions::ContainerOp;

/// A chandle is no integral value to combine (IEEE 1800-2023 6.14).
fn chandle_elements() -> AnalyzerError {
AnalyzerError::IllegalChandleUse {
detail: "an array reduction of chandle elements".into(),
}
}

pub(super) fn bind(
id: ExprId,
native: &Declarations,
Expand Down Expand Up @@ -53,6 +60,9 @@ pub(super) fn bind(
"array reduction of elements wider than 64 bits",
));
}
if expression_binding::type_holds_chandle(&container.element) {
return Err(chandle_elements());
}
if container.layout.handle.is_some() {
return Err(unsupported("array reduction requires integral elements"));
}
Expand Down Expand Up @@ -87,6 +97,9 @@ pub(super) fn bind(
"array reduction arguments require a with expression",
));
}
if expression_binding::holds_chandle(shape) {
return Err(chandle_elements());
}
if shape.unpacked.len() != 1 || shape.real || shape.string || shape.class.is_some() {
return Err(unsupported(
"array reduction requires one-dimensional integral elements",
Expand Down
1 change: 1 addition & 0 deletions crates/celox-sv-analyzer/src/ast/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ impl Class {
}
if (property.rand || property.randc)
&& (property.field.handle.is_some()
|| property.r#type.holds_chandle()
Comment thread
tignear marked this conversation as resolved.
Resolved
Comment thread
tignear marked this conversation as resolved.
Resolved
|| (property.r#type.is_enum && property.r#type.enum_domain.is_none()))
{
return Err(unsupported(
Expand Down
4 changes: 4 additions & 0 deletions crates/celox-sv-analyzer/src/ast/classes/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ pub(in crate::ast) fn bind_inputs(
if property.field.four_state {
return Err("4-state class property in a constraint".into());
}
// A chandle has no integral value to constrain (6.14).
if property.r#type.holds_chandle() {
return Err("a chandle in a constraint".into());
}
Typed {
kind: Kind::Leaf(ConstraintExpr::Field(index)),
width: property.field.width,
Expand Down
44 changes: 40 additions & 4 deletions crates/celox-sv-analyzer/src/ast/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ pub(super) fn with_dimensions(
_ => None,
};
let Some(kind) = kind else {
return Ok(types::type_with_unpacked_ranges(
return types::type_with_unpacked_ranges(
base,
constant_binding::bind_unpacked_ranges(dims, tree, session, context)?,
));
);
};
// `T a[x][y]`: each element of `a` is a container `T [y]` (IEEE
// 1800-2023 7.4.5, 7.8), held by its handle like any container value.
Expand Down Expand Up @@ -464,6 +464,14 @@ fn element_value(
if let Some(aggregate) = target.element.unpacked_struct() {
unpacked_structs::check_value(aggregate, id, native, tree, session, dims)?;
}
expression_binding::check_chandle_assignment(
target.element.chandle && target.element.unpacked_ranges.is_empty(),
id,
tree,
native,
dims,
session,
)?;
let shape = procedural::dimensions_from_type(&target.element);
let value = expression_binding::bind_value(id, native, tree, session, dims, Some(&shape))?;
if let Some(record) = &target.record {
Expand Down Expand Up @@ -521,6 +529,9 @@ fn index_value(
|| "associative array index".into(),
)?;
}
// Only an associative array indexed by chandles takes a chandle index.
let chandle = target.key.as_ref().is_some_and(|key| key.chandle);
expression_binding::check_chandle_assignment(chandle, id, tree, native, dims, session)?;
if matches!(
target.layout.kind,
ContainerKind::Associative { string: true, .. }
Expand Down Expand Up @@ -548,7 +559,7 @@ fn index_value(
left,
operator,
right,
} if operator == "+" || operator == "-" => Expr::Binary {
} if !chandle && (operator == "+" || operator == "-") => Expr::Binary {
left: Box::new(index_value(*left, base, tree, session, dims, target)?),
op: if operator == "+" {
BinaryOp::Add
Expand All @@ -557,6 +568,9 @@ fn index_value(
},
right: Box::new(index_value(*right, base, tree, session, dims, target)?),
},
_ if chandle => {
expression_binding::bind_chandle_value(id, native, tree, session, dims, None)?
}
_ => expression_binding::value(id, native, tree, session, dims)?,
};
Ok(
Expand Down Expand Up @@ -718,6 +732,12 @@ pub(super) fn value(
if op != ContainerOp::Reverse && target.record.is_some() {
return Err(unsupported("sorting elements wider than 64 bits"));
}
// Chandles have no relational operators (6.14, 7.12.2).
if op != ContainerOp::Reverse && target.element.chandle {
return Err(AnalyzerError::IllegalChandleUse {
detail: "sorting chandles".into(),
});
}
if op != ContainerOp::Reverse
&& target.layout.handle == Some(HandleProperty::Object)
{
Expand Down Expand Up @@ -812,6 +832,14 @@ pub(super) fn value(
// reference, so it has the index's class (IEEE 1800-2023
// 7.9.4).
let key_class = target.key.as_ref().and_then(|key| key.class());
// So is the variable of a chandle index, which is no
// integral variable (6.14).
if shape.chandle != target.key.as_ref().is_some_and(|key| key.chandle) {
return Err(AnalyzerError::IllegalChandleUse {
detail: "an associative traversal index of another type than the index"
.into(),
});
}
if let ContainerKind::Associative { string, object, .. } = target.layout.kind
&& (shape.string != string
|| shape.container.is_some()
Expand All @@ -822,7 +850,13 @@ pub(super) fn value(
"incompatible associative traversal index variable",
));
}
args.push(expression_binding::value(id, native, tree, session, dims)?);
args.push(if shape.chandle {
expression_binding::bind_chandle_value(
id, native, tree, session, dims, None,
)?
} else {
expression_binding::value(id, native, tree, session, dims)?
});
} else if matches!(op, ContainerOp::PushFront | ContainerOp::PushBack)
|| op == ContainerOp::Insert && index == 1
{
Expand Down Expand Up @@ -905,12 +939,14 @@ fn query(
if name.spelling == "$unpacked_dimensions" {
unpacked
} else {
// A chandle has no packed dimensions (IEEE 1800-2023 6.14).
unpacked
// An integral element kept in a record keeps its
// packed dimensions; a structure has none.
+ if innermost.layout.handle.is_some()
&& (innermost.record.is_none()
|| innermost.element.unpacked_struct().is_some())
|| innermost.element.chandle
{
0
} else {
Expand Down
Loading
Loading