Skip to content
Closed
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
13 changes: 13 additions & 0 deletions conformance/sv-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ The full pinned run reviewed all 2,054 rows, with 496 passing cases in 2state
and 498 in 4state; no passing case regresses. The existing scanf probes retain
their verdicts because their other unsupported constructs remain unchanged.

Classes update fourteen reviewed expectation rows: both state modes for
`8.4--instantiation`, `8.5--properties`, `8.6--methods`, `8.12--assignment`,
`8.24--out_of_block_methods`, `8.26.5--implemented_class_handle` and
`6.20.6--const` change from fail to pass. The simulated cases were run and their
values checked, including the shared object behind two handles in
`8.12--assignment`. Full official runs at the pinned revision report 524 passing
cases in 2state and 526 in 4state. No passing case regresses: classes that are
declared but never constructed, interface classes and pure virtual methods are
not lowered. `8.7--constructor` keeps failing because it initializes an
implicitly static procedural variable without the `static` keyword, which IEEE
1800-2023 6.21 requires. Inheritance with constructors, `super`, static members,
virtual dispatch and parameterized classes stay unsupported.

The report contains each case’s state mode, verdict, selected execution mode,
tags, tool return code and path to the official log. The output directory retains
both the official log and runner diagnostics for each case and state mode.
Expand Down
28 changes: 14 additions & 14 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,8 @@ chapter-6/6.20.5--specparam.sv 2state pass
chapter-6/6.20.5--specparam.sv 4state pass
chapter-6/6.20.5--specparam_inv.sv 2state pass
chapter-6/6.20.5--specparam_inv.sv 4state pass
chapter-6/6.20.6--const.sv 2state fail
chapter-6/6.20.6--const.sv 4state fail
chapter-6/6.20.6--const.sv 2state pass
chapter-6/6.20.6--const.sv 4state pass
chapter-6/6.23--localparam_type_decl.sv 2state pass
chapter-6/6.23--localparam_type_decl.sv 4state pass
chapter-6/6.23--type_op.sv 2state fail
Expand Down Expand Up @@ -1465,8 +1465,8 @@ chapter-8/8.10--static_methods.sv 2state fail
chapter-8/8.10--static_methods.sv 4state fail
chapter-8/8.11--this.sv 2state pass
chapter-8/8.11--this.sv 4state pass
chapter-8/8.12--assignment.sv 2state fail
chapter-8/8.12--assignment.sv 4state fail
chapter-8/8.12--assignment.sv 2state pass
chapter-8/8.12--assignment.sv 4state pass
chapter-8/8.12--shallow_copy.sv 2state fail
chapter-8/8.12--shallow_copy.sv 4state fail
chapter-8/8.13--inheritance.sv 2state fail
Expand Down Expand Up @@ -1499,8 +1499,8 @@ chapter-8/8.22--dynamic_method_lookup.sv 2state fail
chapter-8/8.22--dynamic_method_lookup.sv 4state fail
chapter-8/8.23--scope_resolution.sv 2state fail
chapter-8/8.23--scope_resolution.sv 4state fail
chapter-8/8.24--out_of_block_methods.sv 2state fail
chapter-8/8.24--out_of_block_methods.sv 4state fail
chapter-8/8.24--out_of_block_methods.sv 2state pass
chapter-8/8.24--out_of_block_methods.sv 4state pass
chapter-8/8.25--parametrized_class_extend.sv 2state fail
chapter-8/8.25--parametrized_class_extend.sv 4state fail
chapter-8/8.25.1--parametrized_class_invalid_scope_resolution.sv 2state pass
Expand All @@ -1525,8 +1525,8 @@ chapter-8/8.26.4--illegal_implements_parameter.sv 2state pass
chapter-8/8.26.4--illegal_implements_parameter.sv 4state pass
chapter-8/8.26.5--cast_between_interface_classes.sv 2state fail
chapter-8/8.26.5--cast_between_interface_classes.sv 4state fail
chapter-8/8.26.5--implemented_class_handle.sv 2state fail
chapter-8/8.26.5--implemented_class_handle.sv 4state fail
chapter-8/8.26.5--implemented_class_handle.sv 2state pass
chapter-8/8.26.5--implemented_class_handle.sv 4state pass
chapter-8/8.26.5--invalid_interface_instantiation.sv 2state pass
chapter-8/8.26.5--invalid_interface_instantiation.sv 4state pass
chapter-8/8.26.6.1--name_conflict_resolved.sv 2state fail
Expand All @@ -1545,16 +1545,16 @@ chapter-8/8.26.7--partial_implementation.sv 2state fail
chapter-8/8.26.7--partial_implementation.sv 4state fail
chapter-8/8.27--forward_declaration.sv 2state pass
chapter-8/8.27--forward_declaration.sv 4state pass
chapter-8/8.4--instantiation.sv 2state fail
chapter-8/8.4--instantiation.sv 4state fail
chapter-8/8.4--instantiation.sv 2state pass
chapter-8/8.4--instantiation.sv 4state pass
chapter-8/8.5--parameters.sv 2state fail
chapter-8/8.5--parameters.sv 4state fail
chapter-8/8.5--properties.sv 2state fail
chapter-8/8.5--properties.sv 4state fail
chapter-8/8.5--properties.sv 2state pass
chapter-8/8.5--properties.sv 4state pass
chapter-8/8.5--properties_enum.sv 2state fail
chapter-8/8.5--properties_enum.sv 4state fail
chapter-8/8.6--methods.sv 2state fail
chapter-8/8.6--methods.sv 4state fail
chapter-8/8.6--methods.sv 2state pass
chapter-8/8.6--methods.sv 4state pass
chapter-8/8.7--constructor.sv 2state fail
chapter-8/8.7--constructor.sv 4state fail
chapter-8/8.7--constructor_param.sv 2state fail
Expand Down
2 changes: 2 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ pub enum ValueKind {
Bits,
/// A handle of a string in the simulator's heap.
StrRef,
/// A handle of a class object in the simulator's heap, `0` for `null`.
ObjRef,
}

impl ValueKind {
Expand Down
48 changes: 26 additions & 22 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ const EVENT_PREFIX: &str = "$event[";
#[derive(Clone)]
struct SvVariable {
float: Option<celox_sir::FloatPrecision>,
/// A `string`: each element is a heap handle.
string: bool,
/// What each element holds: packed bits, or a heap handle of a string
/// or a class object.
value_kind: celox_design::ValueKind,
path: Vec<String>,
width: usize,
signed: bool,
Expand All @@ -95,7 +96,7 @@ fn reads_string_variable(
names: &HashMap<String, SourceVarId>,
) -> bool {
matches!(expr, sv::ir::Expr::Ident(name)
if names.get(name).and_then(|id| variables.get(id)).is_some_and(|v| v.string))
if names.get(name).and_then(|id| variables.get(id)).is_some_and(|v| v.value_kind == celox_design::ValueKind::StrRef))
}

impl SvVariable {
Expand All @@ -110,11 +111,7 @@ impl SvVariable {
kind: self.domain_kind,
type_kind: self.type_kind,
array_dims: self.array_dims.clone(),
value_kind: if self.string {
celox_design::ValueKind::StrRef
} else {
celox_design::ValueKind::Bits
},
value_kind: self.value_kind,
},
unpacked_ranges: self.unpacked_ranges.clone(),
packed_dims: self
Expand Down Expand Up @@ -1165,7 +1162,7 @@ impl DriverScan<'_> {
}
continue;
}
sv::ir::Callee::String(_) => continue,
sv::ir::Callee::String(_) | sv::ir::Callee::Object(_) => continue,
sv::ir::Callee::Subroutine(name) => name,
};
let Some(subroutine) = self
Expand Down Expand Up @@ -1549,7 +1546,7 @@ fn prepare_external_hierarchy_collecting(
SvVariable {
float: None,

string: false,
value_kind: celox_design::ValueKind::Bits,
path: vec![variable.path.join("$")],
width: variable.metadata.width,
signed: variable.signed,
Expand Down Expand Up @@ -2773,7 +2770,7 @@ fn lower_module_with_overrides(
let variable = SvVariable {
float: type_info.float,

string: type_info.string,
value_kind: type_info.value_kind,
path,
width: type_info.width,
signed: type_info.signed,
Expand Down Expand Up @@ -2857,7 +2854,7 @@ fn lower_module_with_overrides(
let variable = SvVariable {
float: type_info.float,

string: type_info.string,
value_kind: type_info.value_kind,
path,
width: type_info.width,
signed: type_info.signed,
Expand Down Expand Up @@ -2933,7 +2930,7 @@ fn lower_module_with_overrides(
SvVariable {
float: None,

string: false,
value_kind: celox_design::ValueKind::Bits,
path: vec![parameter.name().to_string()],
width,
signed,
Expand Down Expand Up @@ -4061,7 +4058,7 @@ fn lower_initial_processes(
SvVariable {
float: None,

string: false,
value_kind: celox_design::ValueKind::Bits,
path: vec![format!("$initial[{index}]"), slot.to_string()],
width,
signed: false,
Expand Down Expand Up @@ -4463,7 +4460,7 @@ fn ensure_parent_output_signals(
let variable = SvVariable {
float: None,

string: false,
value_kind: celox_design::ValueKind::Bits,
path: vec![actual.to_string()],
width: 1,
signed: false,
Expand Down Expand Up @@ -5771,7 +5768,7 @@ fn signal_kind_from_port_direction(

struct SvSignalType {
float: Option<celox_sir::FloatPrecision>,
string: bool,
value_kind: celox_design::ValueKind,
width: usize,
signed: bool,
is_4state: bool,
Expand Down Expand Up @@ -5860,8 +5857,11 @@ fn signal_type_from_sv(
sv::ir::TypeKind::Shortreal => Some(celox_sir::FloatPrecision::F32),
_ => None,
};
let is_4state =
float.is_none() && !matches!(typ.kind(), sv::ir::TypeKind::Bit | sv::ir::TypeKind::String);
let is_4state = float.is_none()
&& !matches!(
typ.kind(),
sv::ir::TypeKind::Bit | sv::ir::TypeKind::String | sv::ir::TypeKind::Object
);
let packed_ranges = typ
.packed_ranges()
.iter()
Expand All @@ -5886,10 +5886,14 @@ fn signal_type_from_sv(
sv::ir::TypeKind::Logic | sv::ir::TypeKind::Reg | sv::ir::TypeKind::Implicit => {
PortTypeKind::Logic
}
sv::ir::TypeKind::String => PortTypeKind::Other,
sv::ir::TypeKind::String | sv::ir::TypeKind::Object => PortTypeKind::Other,
};
let value_kind = match typ.kind() {
sv::ir::TypeKind::String => celox_design::ValueKind::StrRef,
sv::ir::TypeKind::Object => celox_design::ValueKind::ObjRef,
_ => celox_design::ValueKind::Bits,
};
let string = typ.kind() == sv::ir::TypeKind::String;
if string && !array_dims.is_empty() {
if value_kind == celox_design::ValueKind::StrRef && !array_dims.is_empty() {
// Selects of such an array would need to tell element selects from
// character selects.
return Err(sv::AnalyzerError::Unsupported(
Expand All @@ -5898,7 +5902,7 @@ fn signal_type_from_sv(
}
Ok(SvSignalType {
float,
string,
value_kind,
width,
signed,
is_4state,
Expand Down
19 changes: 15 additions & 4 deletions crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

mod file_io;
mod fread;
mod objects;
mod scan;
mod strings;

Expand Down Expand Up @@ -267,7 +268,7 @@ impl<'p, 'a> Ff<'p, 'a> {
}
continue;
}
sv::ir::Callee::String(_) => continue,
sv::ir::Callee::String(_) | sv::ir::Callee::Object(_) => continue,
sv::ir::Callee::Subroutine(name) => name,
};
let Some(subroutine) = self.m.subroutine(&name).cloned() else {
Expand Down Expand Up @@ -874,6 +875,11 @@ impl<'p, 'a> Ff<'p, 'a> {
args,
..
} => self.string_call(*op, args)?,
Expr::Call {
callee: sv::ir::Callee::Object(op),
args,
..
} => self.object_call(op, args)?,
Expr::Call {
callee: sv::ir::Callee::System(sv::ir::SystemFunction::Fopen),
args,
Expand Down Expand Up @@ -1009,8 +1015,11 @@ impl<'p, 'a> Ff<'p, 'a> {
sv::ir::TypeKind::Shortreal => Some(celox_sir::FloatPrecision::F32),
_ => None,
};
self.m.variables.get_mut(&temp).unwrap().string =
r#type.kind() == sv::ir::TypeKind::String;
self.m.variables.get_mut(&temp).unwrap().value_kind = match r#type.kind() {
sv::ir::TypeKind::String => celox_design::ValueKind::StrRef,
sv::ir::TypeKind::Object => celox_design::ValueKind::ObjRef,
_ => celox_design::ValueKind::Bits,
};
let Some(result) = result else {
return Err(unsupported(format!(
"void function `{name}` used as a value"
Expand Down Expand Up @@ -4687,7 +4696,7 @@ impl Ff<'_, '_> {
source: None,
hidden: true,
force_control: None,
string: false,
value_kind: Default::default(),
},
);
let mut renames = HashMap::default();
Expand Down Expand Up @@ -4916,6 +4925,8 @@ fn impure_call(pm: &ProcModule<'_>, expr: &sv::ir::Expr) -> Option<String> {
}
// A string operation is a value of its operands.
sv::ir::Callee::String(_) => continue,
// A property can change without the handle changing.
sv::ir::Callee::Object(op) => return Some(op.to_string()),
sv::ir::Callee::Subroutine(name) => name,
};
if !visited.insert(name.clone()) {
Expand Down
81 changes: 81 additions & 0 deletions crates/celox-frontend-sv/src/lowering/ff/objects.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//! Class object operations (IEEE 1800-2023 clause 8), lowered to calls of
//! the heap helper.
//!
//! An object handle is 32 bits like a string handle. The analyzer has laid
//! out each class, so an operation carries the byte offset and width of the
//! property it reads or writes.

use super::*;
use celox_heap::ops;
use sv::ir::{HandleProperty, ObjectOp};

impl Ff<'_, '_> {
/// The value of object operation `op`, as a temporary.
pub(super) fn object_call(
&mut self,
op: &ObjectOp,
args: &[Option<sv::ir::Expr>],
) -> Result<sv::ir::Expr, sv::AnalyzerError> {
let args = args
.iter()
.map(|arg| {
arg.clone()
.ok_or_else(|| unsupported(format!("omitted argument of {op}")))
})
.collect::<Result<Vec<_>, _>>()?;
let result = match op {
ObjectOp::New {
class,
size,
handles,
} => {
let size = self.constant64(u64::from(*size));
let object =
self.heap_call(ops::encode(ops::OBJECT_NEW, u64::from(*class)), &[size]);
for &(offset, kind) in handles {
let offset = self.constant64(u64::from(offset));
let kind = self.constant64(match kind {
HandleProperty::String => 0,
HandleProperty::Object => 1,
});
self.heap_call(ops::OBJECT_HANDLE, &[object, offset, kind]);
}
object
}
ObjectOp::Load(field) => {
let object = self.handle(&args[0])?;
let offset = self.constant64(u64::from(field.offset));
let count = self.constant64(u64::from(field.bytes()));
self.heap_call(ops::OBJECT_LOAD, &[object, offset, count])
}
ObjectOp::Store(field) => {
let object = self.handle(&args[0])?;
let place =
self.constant64(u64::from(field.offset) | u64::from(field.bytes()) << 32);
let value = self.integer_of_width(&args[1], field.width as usize, field.signed)?;
self.heap_call(ops::OBJECT_STORE, &[object, place, value])
}
ObjectOp::ClassOf => {
let object = self.handle(&args[0])?;
self.heap_call(ops::OBJECT_CLASS, &[object])
}
};
let (width, signed) = op.result_type();
let value = self.b.alloc_bit(width, signed);
self.b.emit(SIRInstruction::Slice(value, result, 0, width));
let (temp, name) = self.m.temp("object", width, signed, false);
let kind = match op {
ObjectOp::New { .. } => Some(celox_design::ValueKind::ObjRef),
ObjectOp::Load(field) => field.handle.map(|handle| match handle {
HandleProperty::String => celox_design::ValueKind::StrRef,
HandleProperty::Object => celox_design::ValueKind::ObjRef,
}),
ObjectOp::Store(_) | ObjectOp::ClassOf => None,
};
if let Some(kind) = kind {
self.m.variables.get_mut(&temp).unwrap().value_kind = kind;
}
self.store(temp, SIROffset::Static(0), width, value);
Ok(sv::ir::Expr::Ident(name))
}
}
Loading
Loading