From a37c612c38eb05957294eea77c92a411ea2e8d9c Mon Sep 17 00:00:00 2001 From: tignear Date: Wed, 28 Oct 2026 19:01:53 +0900 Subject: [PATCH] feat(sv): support unpacked structures as dynamic container elements Queues, dynamic arrays and associative arrays of an unpacked structure type were rejected. A structure of at most 64 bits whose members are all 2-state or all 4-state and hold no handle is kept as its flat value, so the container's default element is the structure's default. Any other structure is held as an immutable heap record: `ObjectOp::Box` builds a record from the flat value on `push`, `insert` or an assignment, and `ObjectOp::Unbox` reads it back. Each leaf is a record field, so the collector traces string and handle members through the record's handle list, and 4-state members keep their X/Z bits. Record fields are `nullable`: the new `OBJECT_LOAD_NULLABLE` heap operation reads a null record as zeros without a fault, which is the default structure for a missing associative entry or a new dynamic array element. Records are not seeded, so they do not draw from the process RNG. `e.m` reads a member of an element `q[i]`, `aa[k]` or a popped element directly from the record or the flat value, including a handle member's properties (`q[0].orig.m_type.n`). Patterns, typed patterns and values of the structure type initialize elements. Comparing containers of records and sorting structures without `with` are rejected, as is writing a member of an element. Assignment patterns passed to a method argument now receive the formal's shape, which method calls taking a structure need. Change-Id: Iac820f46cbee8d792f4b0fbde28baccdd54ecf31 --- crates/celox-frontend-sv/src/lowering/ff.rs | 11 +- .../src/lowering/ff/objects.rs | 148 +++++++-- crates/celox-heap/src/lib.rs | 6 + crates/celox-heap/src/objects.rs | 51 ++++ crates/celox-heap/src/ops.rs | 9 + crates/celox-sv-analyzer/src/ast.rs | 3 + crates/celox-sv-analyzer/src/ast/case.rs | 20 +- crates/celox-sv-analyzer/src/ast/classes.rs | 3 +- .../celox-sv-analyzer/src/ast/containers.rs | 287 ++++++++++++++++-- .../src/ast/expression_binding/direct.rs | 53 +++- .../src/ast/expression_binding/enums.rs | 11 + .../src/ast/expression_binding/objects.rs | 4 + .../src/ast/expression_binding/strings.rs | 12 + crates/celox-sv-analyzer/src/ast/inlining.rs | 1 + .../celox-sv-analyzer/src/ast/procedural.rs | 13 + .../src/ast/unpacked_structs.rs | 67 ++++ crates/celox-sv-analyzer/src/ir.rs | 2 +- .../celox-sv-analyzer/src/system_functions.rs | 33 +- crates/celox-test-suite/LIMITATIONS.md | 2 +- .../src/sv/cases/unpacked_structs.vtest | 129 ++++++++ .../sv/icarus/unpacked_structs.json | 92 ++++++ .../verification/sv/limitations.json | 4 + .../sv/verilator/unpacked_structs.json | 44 +++ .../sv/xezim/unpacked_structs.json | 44 +++ .../systemverilog/unpacked_structs.rs | 158 +++++++++- docs/guide/systemverilog-reference.md | 14 +- docs/guide/systemverilog.md | 2 +- docs/ja/guide/systemverilog-reference.md | 3 +- docs/ja/guide/systemverilog.md | 2 +- 29 files changed, 1163 insertions(+), 65 deletions(-) diff --git a/crates/celox-frontend-sv/src/lowering/ff.rs b/crates/celox-frontend-sv/src/lowering/ff.rs index fb0cf6b38c3..1616a675ef9 100644 --- a/crates/celox-frontend-sv/src/lowering/ff.rs +++ b/crates/celox-frontend-sv/src/lowering/ff.rs @@ -3622,9 +3622,11 @@ impl<'p, 'a> Ff<'p, 'a> { let mut arena = SLTNodeArena::new(); let node = self.expr_slt(rhs, Some((total, signed)), &mut arena)?; let node = coerce_node_width(&mut arena, node, Some(total), signed).map_err(slt_error)?; - // Capture the value before any part is written. - let (temp, temp_name) = self.m.temp("concat", total, false, true); + // Capture the value before any part is written, in a temporary of + // the value's state kind. let value = self.lower_slt(&arena, node)?; + let four_state = matches!(self.b.register(&value), RegisterType::Logic { .. }); + let (temp, temp_name) = self.m.temp("concat", total, false, four_state); self.store(temp, SIROffset::Static(0), total, value); let mut lsb = total; for (part, width) in parts.iter().zip(widths) { @@ -7838,14 +7840,15 @@ fn impure_call(pm: &ProcModule<'_>, expr: &sv::ir::Expr) -> Option { // Container contents are immutable: reading an element is a // value of the container handle and index, unlike a class // property that can change without its handle changing. + // A record of a structure element is immutable as well. sv::ir::Callee::Object(op) if matches!( *op, sv::ir::ObjectOp::Container { op: sv::ir::ContainerOp::Get, .. - } - ) => + } | sv::ir::ObjectOp::Unbox(_) + ) || matches!(*op, sv::ir::ObjectOp::Load(field) if field.nullable) => { continue; } diff --git a/crates/celox-frontend-sv/src/lowering/ff/objects.rs b/crates/celox-frontend-sv/src/lowering/ff/objects.rs index 8f4a36cc2d4..46908086f68 100644 --- a/crates/celox-frontend-sv/src/lowering/ff/objects.rs +++ b/crates/celox-frontend-sv/src/lowering/ff/objects.rs @@ -25,6 +25,11 @@ impl Ff<'_, '_> { .collect::, _>>()?; if args.iter().any(|arg| self.m.calls(arg)) { for (index, arg) in args.iter_mut().enumerate() { + // A record is built from a flat structure value, not a handle. + if let ObjectOp::Box(record) = op { + *arg = self.heap_operand(arg, Some((record.width(), false)), None)?; + continue; + } let (width, signed) = if index == 0 { (32, false) } else { @@ -118,36 +123,87 @@ impl Ff<'_, '_> { } ObjectOp::Load(field) if field.four_state && self.m.four_state => { let object = self.handle(&args[0])?; - let [value, mask] = [0, field.bytes()].map(|plane| { - let offset = self.constant64(u64::from(field.offset + plane)); - let count = self.constant64(u64::from(field.bytes())); - let stored = self.heap_call(ops::OBJECT_LOAD, &[object, offset, count]); - self.complement(stored) - }); + let result = self.load_field(object, *field); let width = field.width as usize; - let result = self.container_join(value, mask, width, true); let (temp, name) = self.m.temp("object", width, field.signed, true); self.store(temp, SIROffset::Static(0), width, result); return Ok(sv::ir::Expr::Ident(name)); } 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]) + self.load_field(object, *field) + } + ObjectOp::Unbox(record) => { + let object = self.handle(&args[0])?; + let parts = record + .fields + .iter() + .map(|field| self.load_field(object, *field)) + .collect::>(); + let width = record.width(); + let four_state = self.m.four_state && record.fields.iter().any(|f| f.four_state); + let value = if four_state { + self.b.alloc_logic(width) + } else { + self.b.alloc_bit(width, false) + }; + self.b.emit(SIRInstruction::Concat(value, parts)); + let (temp, name) = self.m.temp("record", width, false, four_state); + self.store(temp, SIROffset::Static(0), width, value); + return Ok(sv::ir::Expr::Ident(name)); + } + ObjectOp::Box(record) => { + // Evaluate the value first: its calls may end the block, so + // the record's handle is only used after them. + let expr = self.hoist(&args[0])?; + let width = record.width(); + let mut arena = SLTNodeArena::new(); + let node = self.expr_slt(&expr, Some((width, false)), &mut arena)?; + let node = + coerce_node_width(&mut arena, node, Some(width), false).map_err(slt_error)?; + let value = self.lower_slt(&arena, node)?; + // A record is not seeded: it has no random state, and seeding + // would draw from the creating process's RNG. + let size = self.constant64(u64::from(record.size)); + let object = self.heap_call( + ops::encode(ops::OBJECT_NEW, u64::from(sv::ir::Record::CLASS)), + &[size], + ); + for field in &record.fields { + if let Some(kind) = field.handle { + let offset = self.constant64(u64::from(field.offset)); + let kind = self.constant64(match kind { + HandleProperty::String => 0, + HandleProperty::Object => 1, + }); + self.heap_call(ops::OBJECT_HANDLE, &[object, offset, kind]); + } + } + let mut lsb = width; + for field in &record.fields { + lsb -= field.width as usize; + let part = if matches!(self.b.register(&value), RegisterType::Logic { .. }) { + self.b.alloc_logic(field.width as usize) + } else { + self.b.alloc_bit(field.width as usize, false) + }; + self.b.emit(SIRInstruction::Slice( + part, + value, + lsb, + field.width as usize, + )); + self.store_field(object, *field, part); + } + // An equal value keeps the handle it already has, so that + // storing it again leaves a container unchanged. + self.heap_call(ops::OBJECT_FINISH_RECORD, &[object]) } ObjectOp::Store(field) if field.four_state && self.m.four_state => { let object = self.handle(&args[0])?; let expr = self.hoist(&args[1])?; let value = self.eval(&expr, Some((field.width as usize, field.signed)))?; - let (value, mask) = self.container_split(value); - for (plane, bits) in [(0, value), (field.bytes(), mask)] { - let place = self.constant64( - u64::from(field.offset + plane) | u64::from(field.bytes()) << 32, - ); - let stored = self.complement(bits); - self.heap_call(ops::OBJECT_STORE, &[object, place, stored]); - } + self.store_field(object, *field, value); self.constant64(0) } ObjectOp::Store(field) => { @@ -223,7 +279,10 @@ impl Ff<'_, '_> { let (temp, name) = self.m.temp("object", width, signed, false); let kind = match op { ObjectOp::Container { .. } => unreachable!("handled by container_call"), - ObjectOp::New { .. } | ObjectOp::Copy => Some(celox_design::ValueKind::ObjRef), + ObjectOp::New { .. } | ObjectOp::Copy | ObjectOp::Box(_) => { + Some(celox_design::ValueKind::ObjRef) + } + ObjectOp::Unbox(_) => unreachable!("lowered to its own temporary"), ObjectOp::Load(field) => field.handle.map(|handle| match handle { HandleProperty::String => celox_design::ValueKind::StrRef, HandleProperty::Object => celox_design::ValueKind::ObjRef, @@ -251,6 +310,57 @@ impl Ff<'_, '_> { Ok(sv::ir::Expr::Ident(name)) } + /// The value of `field` of the object in 64-bit `object`: a register of + /// the field's width, 4-state for a 4-state field in 4-state simulation. + fn load_field(&mut self, object: RegisterId, field: sv::ir::ObjectField) -> RegisterId { + let opcode = if field.nullable { + ops::OBJECT_LOAD_NULLABLE + } else { + ops::OBJECT_LOAD + }; + let width = field.width as usize; + if field.four_state && self.m.four_state { + let [value, mask] = [0, field.bytes()].map(|plane| { + let offset = self.constant64(u64::from(field.offset + plane)); + let count = self.constant64(u64::from(field.bytes())); + let stored = self.heap_call(opcode, &[object, offset, count]); + self.complement(stored) + }); + return self.container_join(value, mask, width, true); + } + let offset = self.constant64(u64::from(field.offset)); + let count = self.constant64(u64::from(field.bytes())); + let loaded = self.heap_call(opcode, &[object, offset, count]); + let value = self.b.alloc_bit(width, field.signed); + self.b.emit(SIRInstruction::Slice(value, loaded, 0, width)); + value + } + + /// Store register `value` of `field`'s width into `field` of the object in + /// 64-bit `object`. + fn store_field(&mut self, object: RegisterId, field: sv::ir::ObjectField, value: RegisterId) { + let planes = if field.four_state && self.m.four_state { + let (value, mask) = self.container_split(value); + vec![ + (0, self.complement(value)), + (field.bytes(), self.complement(mask)), + ] + } else { + let known = self.b.alloc_bit(field.width as usize, false); + self.b + .emit(SIRInstruction::Unary(known, UnaryOp::ToTwoState, value)); + let wide = self.b.alloc_bit(64, false); + self.b + .emit(SIRInstruction::Unary(wide, UnaryOp::Ident, known)); + vec![(0, wide)] + }; + for (plane, bits) in planes { + let place = + self.constant64(u64::from(field.offset + plane) | u64::from(field.bytes()) << 32); + self.heap_call(ops::OBJECT_STORE, &[object, place, bits]); + } + } + /// A 4-state property holds the complement of its value and mask planes, /// so the zeroed bytes of a new object read as X (IEEE 1800-2023 6.8). fn complement(&mut self, plane: RegisterId) -> RegisterId { diff --git a/crates/celox-heap/src/lib.rs b/crates/celox-heap/src/lib.rs index 0e0c65aa918..93d8e9cb3a5 100644 --- a/crates/celox-heap/src/lib.rs +++ b/crates/celox-heap/src/lib.rs @@ -81,6 +81,9 @@ pub struct Heap { next_object: Handle, containers: HashMap>, container_lookup: HashMap, Handle>, + /// Structure records by their contents, see [`ops::OBJECT_FINISH_RECORD`]. + #[serde(default)] + record_lookup: HashMap, /// The first heap operation error since the runtime last checked. fault: Option, /// Entries below this handle are never collected. @@ -112,6 +115,7 @@ impl Heap { next_object: NULL + 1, containers: HashMap::default(), container_lookup: HashMap::default(), + record_lookup: HashMap::default(), fault: None, pinned: 1, created: 0, @@ -241,6 +245,8 @@ impl Heap { self.containers.retain(|handle, _| objects.contains(handle)); self.container_lookup .retain(|_, handle| objects.contains(handle)); + self.record_lookup + .retain(|_, handle| objects.contains(handle)); // No buffer outlives the kernel that built it. self.buffers.clear(); self.free_buffers.clear(); diff --git a/crates/celox-heap/src/objects.rs b/crates/celox-heap/src/objects.rs index f42213cff1e..f094190c86a 100644 --- a/crates/celox-heap/src/objects.rs +++ b/crates/celox-heap/src/objects.rs @@ -79,7 +79,36 @@ impl std::fmt::Display for Fault { } } +/// The contents of a structure record: its bytes and handle fields. +pub(crate) type RecordContents = (Box<[u8]>, Vec<(u32, HandleKind)>); + impl Heap { + /// The handle of the record with the contents of the finished `record`, + /// so that equal values of an unpacked structure have one handle, as + /// equal strings and containers do: `null` for the default value, whose + /// bytes are all zero (a `null` record reads as its members' defaults). + /// A record is never written after it is finished. + pub fn finish_record(&mut self, record: Handle) -> Handle { + let Some(object) = self.objects.get(&record) else { + return record; + }; + if object.bytes.iter().all(|&byte| byte == 0) { + self.objects.remove(&record); + return NULL; + } + let contents = (object.bytes.clone(), object.handles.clone()); + match self.record_lookup.get(&contents) { + Some(&canonical) if canonical != record && self.objects.contains_key(&canonical) => { + self.objects.remove(&record); + canonical + } + _ => { + self.record_lookup.insert(contents, record); + record + } + } + } + /// A new object of `class` with `size` zeroed bytes. pub fn new_object(&mut self, class: u32, size: usize) -> Handle { let handle = self.next_object; @@ -335,6 +364,28 @@ mod tests { assert_eq!(heap.take_fault(), None); } + #[test] + fn equal_records_share_one_handle_until_collected() { + let mut heap = Heap::new(); + let record = |heap: &mut Heap, value: u64| { + let record = heap.new_object(u32::MAX, 8); + heap.declare_handle(record, 0, HandleKind::String); + heap.store(record, 4, 4, value); + heap.finish_record(record) + }; + let first = record(&mut heap, 1); + let second = record(&mut heap, 1); + let other = record(&mut heap, 2); + assert_eq!(first, second); + assert_ne!(first, other); + assert_eq!(heap.objects.len(), 2); + assert_eq!(record(&mut heap, 0), NULL); + assert_eq!(heap.objects.len(), 2); + heap.collect([Root::object(other)]); + assert_eq!(heap.record_lookup.len(), 1); + assert_ne!(record(&mut heap, 1), first); + } + #[test] fn null_dereferences_are_faults_that_read_zero() { let mut heap = Heap::new(); diff --git a/crates/celox-heap/src/ops.rs b/crates/celox-heap/src/ops.rs index 333b3cc25cb..f1bc8b4cbe4 100644 --- a/crates/celox-heap/src/ops.rs +++ b/crates/celox-heap/src/ops.rs @@ -91,6 +91,12 @@ pub const OBJECT_RANDOMIZE_INPUTS: u64 = 65; /// Constraint index is encoded in the parameter; set-all uses u32::MAX. pub const OBJECT_CONSTRAINT_MODE_GET: u64 = 66; pub const OBJECT_CONSTRAINT_MODE_SET: u64 = 67; +/// `load(record, offset, count)` of a structure record: `null` reads as +/// zero bytes without a fault. +pub const OBJECT_LOAD_NULLABLE: u64 = 68; +/// `finish(record)` of a structure record whose fields are all stored: the +/// handle of the one record with its contents, which may replace `record`. +pub const OBJECT_FINISH_RECORD: u64 = 69; /// The opcode word of `op` with parameter `parameter`. pub const fn encode(op: u64, parameter: u64) -> u64 { @@ -196,6 +202,9 @@ impl Heap { 0 } OBJECT_LOAD => self.load(a as Handle, b as usize, c as usize), + OBJECT_LOAD_NULLABLE if a as Handle == crate::objects::NULL => 0, + OBJECT_LOAD_NULLABLE => self.load(a as Handle, b as usize, c as usize), + OBJECT_FINISH_RECORD => self.finish_record(a as Handle).into(), OBJECT_STORE => { self.store(a as Handle, b as u32 as usize, (b >> 32) as usize, c); 0 diff --git a/crates/celox-sv-analyzer/src/ast.rs b/crates/celox-sv-analyzer/src/ast.rs index 8ea57e2326b..654368947f6 100644 --- a/crates/celox-sv-analyzer/src/ast.rs +++ b/crates/celox-sv-analyzer/src/ast.rs @@ -2291,6 +2291,9 @@ struct ContainerType { key: Option, layout: system_functions::ContainerLayout, element: Type, + /// The record that holds an element of unpacked structure type which is + /// not kept as a flat value. + record: Option, } impl Type { diff --git a/crates/celox-sv-analyzer/src/ast/case.rs b/crates/celox-sv-analyzer/src/ast/case.rs index 2fbcb574320..e5db4c9ded0 100644 --- a/crates/celox-sv-analyzer/src/ast/case.rs +++ b/crates/celox-sv-analyzer/src/ast/case.rs @@ -87,9 +87,23 @@ pub(super) fn expr_is_two_state( Expr::Call { callee: Callee::Object(op), .. - } => { - !matches!(**op, ObjectOp::Container { op, layout } if !layout.two_state && (op.reduction().is_some() || matches!(op, ContainerOp::Get | ContainerOp::PopFront | ContainerOp::PopBack | ContainerOp::Equal))) - } + } => match **op { + // A 4-state property or member of a record may hold X or Z. + ObjectOp::Load(field) => !field.four_state, + ObjectOp::Unbox(ref record) => !record.fields.iter().any(|field| field.four_state), + ObjectOp::Container { op, layout } => { + layout.two_state + || !(op.reduction().is_some() + || matches!( + op, + ContainerOp::Get + | ContainerOp::PopFront + | ContainerOp::PopBack + | ContainerOp::Equal + )) + } + _ => true, + }, Expr::Call { callee: Callee::Subroutine(name), .. diff --git a/crates/celox-sv-analyzer/src/ast/classes.rs b/crates/celox-sv-analyzer/src/ast/classes.rs index a7bdf10cb3c..72e88c35b85 100644 --- a/crates/celox-sv-analyzer/src/ast/classes.rs +++ b/crates/celox-sv-analyzer/src/ast/classes.rs @@ -1266,7 +1266,7 @@ fn out_of_block_definition( /// The layout of a property of type `ty` at the first aligned offset at or /// after `offset`. -fn field( +pub(super) fn field( state: &AnalysisState, ty: &Type, env: &HashMap, @@ -1303,6 +1303,7 @@ fn field( ty.kind(), TypeKind::Logic | TypeKind::Reg | TypeKind::Implicit ), + nullable: false, }) } diff --git a/crates/celox-sv-analyzer/src/ast/containers.rs b/crates/celox-sv-analyzer/src/ast/containers.rs index 5c7aadc5856..8bea51bc93f 100644 --- a/crates/celox-sv-analyzer/src/ast/containers.rs +++ b/crates/celox-sv-analyzer/src/ast/containers.rs @@ -79,23 +79,30 @@ pub(super) fn with_dimensions( if matches!(base.kind(), TypeKind::Real | TypeKind::Shortreal) { return Err(unsupported("real dynamic container elements")); } - if base.unpacked_struct().is_some() { - return Err(unsupported("dynamic container of unpacked structures")); - } + let record = match base.unpacked_struct() { + Some(aggregate) => unpacked_structs::record(&tree.state, aggregate, &context.const_env)?, + None => None, + }; let shape = casts::expr_type_from_type(&tree.state, &base, &context.const_env) .ok_or_else(|| unsupported("dynamic container element type"))?; - if shape.width == 0 || shape.width > 64 { + if record.is_none() && (shape.width == 0 || shape.width > 64) { return Err(unsupported("dynamic container elements wider than 64 bits")); } let handle = match base.kind() { + // An element in a record is the record's handle. + _ if record.is_some() => Some(HandleProperty::Object), TypeKind::String => Some(HandleProperty::String), TypeKind::Object => Some(HandleProperty::Object), _ => None, }; let layout = ContainerLayout { kind, - width: shape.width as u32, - signed: shape.signed, + width: if record.is_some() { + classes::HANDLE_WIDTH as u32 + } else { + shape.width as u32 + }, + signed: shape.signed && record.is_none(), two_state: matches!(base.kind(), TypeKind::Bit | TypeKind::Process) || handle.is_some(), handle, }; @@ -108,6 +115,7 @@ pub(super) fn with_dimensions( key: index_type, layout, element: base, + record, })); Ok(ty) } @@ -251,8 +259,17 @@ fn element_value( "container element assignment".into() })?; } + if let Some(aggregate) = target.element.unpacked_struct() { + unpacked_structs::check_value(aggregate, id, native, tree, dims)?; + } let shape = procedural::dimensions_from_type(&target.element); let value = expression_binding::bind_value(id, native, tree, dims, Some(&shape))?; + if let Some(record) = &target.record { + return Ok(classes::object_call( + ObjectOp::Box(record.clone()), + vec![value], + )); + } Ok(if target.layout.handle == Some(HandleProperty::String) { expression_binding::string_operand(value, dims) } else { @@ -353,6 +370,11 @@ pub(super) fn value( )); } + if target.record.is_some() { + return Err(unsupported( + "comparison of dynamic containers of unpacked structures", + )); + } let op = match operator.as_str() { "==" | "!=" => ContainerOp::Equal, "===" | "!==" => ContainerOp::CaseEqual, @@ -391,24 +413,32 @@ pub(super) fn value( } _ => return Err(unsupported("dynamic container slice")), }; - Ok(Some(call( - ContainerOp::Get, - target.layout, - vec![ - expression_binding::value(*expression, native, tree, dims)?, - match index { - Some(index) => index_value(index, *expression, tree, dims, &target)?, - None => Expr::Binary { - left: Box::new(call( - ContainerOp::Size, - target.layout, - vec![expression_binding::value(*expression, native, tree, dims)?], - )), - op: BinaryOp::Sub, - right: Box::new(Expr::Literal("1".into())), + Ok(Some(element_read( + &target, + call( + ContainerOp::Get, + target.layout, + vec![ + expression_binding::value(*expression, native, tree, dims)?, + match index { + Some(index) => index_value(index, *expression, tree, dims, &target)?, + None => Expr::Binary { + left: Box::new(call( + ContainerOp::Size, + target.layout, + vec![expression_binding::value( + *expression, + native, + tree, + dims, + )?], + )), + op: BinaryOp::Sub, + right: Box::new(Expr::Literal("1".into())), + }, }, - }, - ], + ], + ), ))) } ExprKind::Call { .. } | ExprKind::Member { .. } => { @@ -444,6 +474,11 @@ pub(super) fn value( "sort" => ContainerOp::Sort, _ => ContainerOp::Rsort, }; + if op != ContainerOp::Reverse && target.element.unpacked_struct().is_some() { + return Err(unsupported( + "sorting unpacked structures requires a with expression", + )); + } if op != ContainerOp::Reverse && target.layout.handle == Some(HandleProperty::Object) { @@ -550,7 +585,14 @@ pub(super) fn value( args.push(index_value(id, *base, tree, dims, &target)?); } } - Ok(Some(call(op, target.layout, args))) + let value = call(op, target.layout, args); + Ok(Some( + if matches!(op, ContainerOp::PopFront | ContainerOp::PopBack) { + element_read(&target, value) + } else { + value + }, + )) } _ => Ok(None), } @@ -885,3 +927,200 @@ mod method_call_tests { } } } + +/// An element that `get` reads, as a whole value: the flat structure value +/// of a record element. +fn element_read(target: &ContainerType, get: Expr) -> Expr { + match &target.record { + Some(record) => classes::object_call(ObjectOp::Unbox(record.clone()), vec![get]), + None => get, + } +} + +/// The container and the element read of native expression `id` when it +/// reads an element of unpacked structure type (`q[i]`, `q.pop_front()`), +/// before a record element is unboxed. +fn struct_element( + id: ExprId, + native: &celox_sv_syntax::Declarations, + tree: &AnalysisContext<'_>, + dims: &PackedDimensions, +) -> Converted, Expr)>> { + let id = expression_binding::ungroup(id, native); + let base = match &native.expression(id).kind { + ExprKind::Select { expression, .. } => *expression, + ExprKind::Call { .. } | ExprKind::Member { .. } => { + let callee = match &native.expression(id).kind { + ExprKind::Call { expression, .. } => *expression, + _ => id, + }; + match &native.expression(callee).kind { + ExprKind::Member { + expression, name, .. + } if matches!(name.spelling.as_str(), "pop_front" | "pop_back") => *expression, + _ => return Ok(None), + } + } + _ => return Ok(None), + }; + let Some(target) = native_type(base, native, tree, dims)? else { + return Ok(None); + }; + if target.element.unpacked_struct().is_none() { + return Ok(None); + } + let Some(value) = value(id, native, tree, dims, false)? else { + return Ok(None); + }; + let raw = match value { + Expr::Call { + callee: Callee::Object(op), + mut args, + .. + } if matches!(*op, ObjectOp::Unbox(_)) => args + .pop() + .flatten() + .ok_or_else(|| unsupported("structure record read"))?, + value => value, + }; + Ok(Some((target, raw))) +} + +/// The unpacked structure type of native expression `id` when it reads a +/// container element of such a type. +pub(super) fn native_struct_element( + id: ExprId, + native: &celox_sv_syntax::Declarations, + tree: &AnalysisContext<'_>, + dims: &PackedDimensions, +) -> Converted>> { + let id = expression_binding::ungroup(id, native); + let base = match &native.expression(id).kind { + ExprKind::Select { expression, .. } => *expression, + ExprKind::Call { expression, .. } => match &native.expression(*expression).kind { + ExprKind::Member { + expression, name, .. + } if matches!(name.spelling.as_str(), "pop_front" | "pop_back") => *expression, + _ => return Ok(None), + }, + ExprKind::Member { + expression, name, .. + } if matches!(name.spelling.as_str(), "pop_front" | "pop_back") => *expression, + _ => return Ok(None), + }; + Ok(native_type(base, native, tree, dims)? + .and_then(|target| target.element.unpacked_struct().cloned())) +} + +/// A member `e.m` (or `e.m.n`) of a container element `e` of unpacked +/// structure type: its type and its value. +pub(super) fn element_member( + id: ExprId, + native: &celox_sv_syntax::Declarations, + tree: &AnalysisContext<'_>, + dims: &PackedDimensions, +) -> Converted> { + let mut names = Vec::new(); + let mut current = expression_binding::ungroup(id, native); + let element = loop { + let ExprKind::Member { + expression, + separator, + name, + } = &native.expression(current).kind + else { + return Ok(None); + }; + if separator != "." { + return Ok(None); + } + names.push(instances::normalize_identifier(&name.spelling)); + current = expression_binding::ungroup(*expression, native); + if native_struct_element(current, native, tree, dims)?.is_some() { + break current; + } + }; + names.reverse(); + let Some((target, raw)) = struct_element(element, native, tree, dims)? else { + return Ok(None); + }; + let aggregate = target + .element + .unpacked_struct() + .expect("a structure element") + .clone(); + // A path into a packed structure member selects its bits; a path + // through a class handle member continues as a property access. + let mut packed = Vec::new(); + let (member_type, leaves) = loop { + if let Some(found) = unpacked_structs::member_leaves(&aggregate, &names) { + break found; + } + let Some(name) = names.pop() else { + return Ok(None); + }; + packed.insert(0, name); + }; + if !packed.is_empty() && member_type.members.is_empty() { + return Ok(None); + } + let leaves_in_order = aggregate.leaves(); + let parts = leaves + .iter() + .map(|leaf| { + let index = leaves_in_order + .iter() + .position(|candidate| candidate.path == leaf.path) + .expect("a leaf of the structure"); + match &target.record { + Some(record) => { + classes::object_call(ObjectOp::Load(record.fields[index]), vec![raw.clone()]) + } + None => Expr::Select { + expr: Box::new(raw.clone()), + msb: ConstExpr::Literal((leaf.offset + leaf.width - 1).to_string()), + lsb: ConstExpr::Literal(leaf.offset.to_string()), + signed: leaf.r#type.is_signed, + }, + } + }) + .collect::>(); + // Each leaf is read from the element, which a pop or any other call + // with an effect (a subroutine, `$urandom`) would change. + if parts.len() > 1 && inlining::effectful(&raw) { + return Err(unsupported( + "structure member with several members of an element read with a side effect", + )); + } + let value = if member_type.unpacked_struct().is_some() { + Expr::Concat(parts) + } else { + parts.into_iter().next().expect("one leaf") + }; + let mut member_type = member_type; + let mut value = value; + for name in packed { + let Some(member) = member_type + .members + .iter() + .find(|member| member.name() == name) + .cloned() + else { + return Err(unsupported(format!("structure member `{name}`"))); + }; + if member.is_tagged() { + return Err(unsupported("tagged union member of a container element")); + } + let width = casts::expr_type_from_type(&tree.state, member.r#type(), &dims.const_env) + .ok_or_else(|| unsupported("structure member width"))? + .width; + value = Expr::Select { + expr: Box::new(value), + msb: ConstExpr::Literal((member.offset() + width - 1).to_string()), + lsb: ConstExpr::Literal(member.offset().to_string()), + signed: member.r#type().is_signed(), + }; + member_type = member.r#type().clone(); + } + Ok(Some((member_type, value))) +} diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs b/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs index 530288d7e7c..5829c89dd6d 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs @@ -579,7 +579,10 @@ pub(in crate::ast) fn bind_value( if let objects::Receiver::Handle(handle) = receiver { children.push((handle, None)); } + // The shapes of the formals, after `this` of a method + // that is not static, receive assignment patterns. let first = usize::from(receiver != objects::Receiver::Static); + let shapes = dimensions.subroutine_param_shapes.get(&name); for (position, arg) in args.iter().filter(|_| selection.is_none()).enumerate() { @@ -596,7 +599,12 @@ pub(in crate::ast) fn bind_value( tree, dimensions, )?; - children.push((value, None)); + let shape = shapes + .and_then(|shapes| shapes.get(first + position)) + .filter(|shape| shape.unpacked_struct.is_some()) + .cloned() + .map(Rc::new); + children.push((value, shape)); } ( Finish::MethodCall { @@ -945,6 +953,14 @@ pub(in crate::ast) fn bind_value( ); continue; } + ExprKind::Member { .. } + if containers::element_member(id, native, tree, dimensions)?.is_some() => + { + let (_, value) = containers::element_member(id, native, tree, dimensions)? + .expect("checked by the guard"); + values.push(value); + continue; + } ExprKind::Member { .. } if objects::aggregate_property(tree, id, native, dimensions)?.is_some() => { @@ -1680,9 +1696,40 @@ fn selected_value( { return Err(unsupported("bit-select or part-select of a real variable")); } - if let ExprKind::Concatenation(_) | ExprKind::Replication { .. } = native.expression(base).kind + // A select of a member of a container element reads the member first. + let element_member = if suffix.is_empty() { + None + } else { + containers::element_member(base, native, tree, dimensions)? + }; + if element_member.is_some() + || matches!( + native.expression(base).kind, + ExprKind::Concatenation(_) | ExprKind::Replication { .. } + ) { - let expr = bind_value(base, native, tree, dimensions, None)?; + let expr = match element_member { + Some((ty, value)) => { + // The select indices are offsets from bit 0, which only a + // `[N-1:0]` range declares. + let zero_based = match ty.packed_ranges() { + [range] => { + eval_ast_const_expr(&tree.state, range.right(), &dimensions.const_env) + == Some(0) + && eval_ast_const_expr(&tree.state, range.left(), &dimensions.const_env) + .is_some_and(|left| left >= 0) + } + _ => false, + }; + if !zero_based || ty.unpacked_struct().is_some() || !ty.members.is_empty() { + return Err(unsupported( + "select of a container element member that is not declared [N-1:0]", + )); + } + value + } + None => bind_value(base, native, tree, dimensions, None)?, + }; if suffix.len() != 1 { return Err(unsupported("concatenation select")); } diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding/enums.rs b/crates/celox-sv-analyzer/src/ast/expression_binding/enums.rs index 0771dd19d61..ebe79bea067 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/enums.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/enums.rs @@ -119,6 +119,17 @@ pub(super) fn domain( } None => match objects::property(tree, id, native, dimensions)? { Some((property, _)) => scalar(&property.r#type), + // A member of a container element of unpacked structure + // type. + None if let Some((ty, _)) = containers::element_member( + ungroup(id, native), + native, + tree, + dimensions, + )? => + { + scalar(&ty) + } // A member of a packed struct. None => dimensions::operand_shape(id, tree, dimensions) .ok() diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs b/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs index dc66344bd04..cbde300a9a2 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs @@ -46,6 +46,10 @@ pub(in crate::ast) fn native_class( if let Some(name) = unpacked_structs::native_member(ungroup(id, native), native, dimensions) { return dimensions.get(&name)?.class.clone(); } + // A class handle member of a container element of unpacked structure type. + if let Ok(Some((ty, _))) = containers::element_member(id, native, tree, dimensions) { + return ty.class().map(str::to_owned); + } let expression = native.expression(ungroup(id, native)); if let ExprKind::Select { expression, diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding/strings.rs b/crates/celox-sv-analyzer/src/ast/expression_binding/strings.rs index 0fadf8370fa..f740f2c6adc 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/strings.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/strings.rs @@ -179,6 +179,18 @@ pub(in crate::ast) fn native_string( } // `e.name` without parentheses (6.19.5.6, 6.19.5.7). ExprKind::Member { .. } if enum_name(tree, id, native, dimensions) => true, + // A string member of a container element of unpacked structure type. + ExprKind::Member { .. } + if containers::element_member(ungroup(id, native), native, tree, dimensions) + .ok() + .flatten() + .is_some() => + { + containers::element_member(ungroup(id, native), native, tree, dimensions) + .ok() + .flatten() + .is_some_and(|(ty, _)| ty.kind() == TypeKind::String) + } // A string member of an unpacked structure variable. ExprKind::Member { .. } if unpacked_structs::native_member(ungroup(id, native), native, dimensions) diff --git a/crates/celox-sv-analyzer/src/ast/inlining.rs b/crates/celox-sv-analyzer/src/ast/inlining.rs index 83296533343..c02141d6831 100644 --- a/crates/celox-sv-analyzer/src/ast/inlining.rs +++ b/crates/celox-sv-analyzer/src/ast/inlining.rs @@ -154,6 +154,7 @@ fn reads_only(callee: &Callee) -> bool { Callee::Object(op) => matches!( **op, ObjectOp::Load(_) + | ObjectOp::Unbox(_) | ObjectOp::Container { op: ContainerOp::Get | ContainerOp::Size | ContainerOp::Exists, .. diff --git a/crates/celox-sv-analyzer/src/ast/procedural.rs b/crates/celox-sv-analyzer/src/ast/procedural.rs index e194c29f6d3..b03fb5067f0 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural.rs @@ -582,6 +582,13 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { native: (celox_sv_syntax::ExprId, celox_sv_syntax::ExprId), ) -> Result { let (left, right) = native; + if containers::element_member(left, self.tree.declarations(), self.tree, &self.dims)? + .is_some() + { + return Err(unsupported( + "assignment to a member of a dynamic container element", + )); + } if let Some(mut stmt) = containers::set(left, right, op, nonblocking, self.tree, &self.dims)? { @@ -1151,6 +1158,11 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { _ => return Err(unsupported("increment or decrement operator")), }; let native = self.tree.declarations(); + if containers::element_member(*expression, native, self.tree, &self.dims)?.is_some() { + return Err(unsupported( + "assignment to a member of a dynamic container element", + )); + } if let Some((property, receiver)) = expression_binding::object_property(self.tree, *expression, native, &self.dims)? { @@ -3214,6 +3226,7 @@ fn dispatch_body( signed: false, handle: None, four_state: false, + nullable: false, }), vec![this.clone()], ); diff --git a/crates/celox-sv-analyzer/src/ast/unpacked_structs.rs b/crates/celox-sv-analyzer/src/ast/unpacked_structs.rs index 1262333ff4b..19536904eae 100644 --- a/crates/celox-sv-analyzer/src/ast/unpacked_structs.rs +++ b/crates/celox-sv-analyzer/src/ast/unpacked_structs.rs @@ -248,6 +248,9 @@ pub(in crate::ast) fn native_struct( .and_then(|parts| dims.get(&parts[0])?.unpacked_struct.clone()) { Some(aggregate) => Some(aggregate), + None if let Some((ty, _)) = containers::element_member(id, native, tree, dims)? => { + ty.unpacked_struct().cloned() + } // A class property of unpacked structure type. None => expression_binding::object_aggregate_property(tree, id, native, dims)? .and_then(|(aggregate, _, _)| aggregate.r#type.unpacked_struct().cloned()), @@ -271,6 +274,9 @@ pub(in crate::ast) fn native_struct( } if std::ptr::eq(native, tree.declarations()) => { patterns::typed_shape(id, tree, dims)?.and_then(|shape| shape.unpacked_struct) } + _ if containers::native_struct_element(id, native, tree, dims)?.is_some() => { + containers::native_struct_element(id, native, tree, dims)? + } // A method of the scope class hides a module function of its name, // as call binding resolves it. ExprKind::Call { expression, .. } => { @@ -448,3 +454,64 @@ pub(in crate::ast) fn leaf_parts(aggregate: &UnpackedStruct, value: &Expr) -> Op // A whole variable is one part per leaf. (parts.len() == aggregate.leaves().len()).then(|| parts.clone()) } + +/// The record that holds a container element of type `aggregate`, or `None` +/// when the element is kept as its flat value: at most 64 bits, with no +/// handle member and members that are all 2-state or all 4-state, so the +/// container's default element is the structure's default. +pub(in crate::ast) fn record( + state: &AnalysisState, + aggregate: &UnpackedStruct, + env: &HashMap, +) -> Converted> { + let leaves = aggregate.leaves(); + let two_state = |leaf: &Leaf| { + matches!( + leaf.r#type.kind, + TypeKind::Bit | TypeKind::String | TypeKind::Object | TypeKind::Process + ) + }; + let handles = leaves + .iter() + .any(|leaf| matches!(leaf.r#type.kind, TypeKind::String | TypeKind::Object)); + let uniform = leaves.iter().all(two_state) || !leaves.iter().any(two_state); + if aggregate.width() <= 64 && !handles && uniform { + return Ok(None); + } + let mut size = 0; + let mut fields = Vec::new(); + for leaf in &leaves { + let mut field = classes::field(state, &leaf.r#type, env, size)?; + field.nullable = true; + size = field.offset + field.storage(); + fields.push(field); + } + Ok(Some(crate::system_functions::Record { + size: size.max(1), + fields, + })) +} + +/// The member at `path` of `aggregate`, with its type and the leaves it +/// covers. +pub(in crate::ast) fn member_leaves( + aggregate: &UnpackedStruct, + path: &[String], +) -> Option<(Type, Vec)> { + let mut ty = None::<&Type>; + let mut current = aggregate; + for (index, name) in path.iter().enumerate() { + let member = current.member(name)?; + ty = Some(&member.r#type); + if index + 1 < path.len() { + current = member.r#type.unpacked_struct()?; + } + } + let ty = ty?.clone(); + let leaves = aggregate + .leaves() + .into_iter() + .filter(|leaf| leaf.path.starts_with(path)) + .collect(); + Some((ty, leaves)) +} diff --git a/crates/celox-sv-analyzer/src/ir.rs b/crates/celox-sv-analyzer/src/ir.rs index a0638827e7b..981586eb202 100644 --- a/crates/celox-sv-analyzer/src/ir.rs +++ b/crates/celox-sv-analyzer/src/ir.rs @@ -9,7 +9,7 @@ pub use crate::procedural::{ }; pub use crate::system_functions::{ ArrayQuery, Callee, ContainerKind, ContainerLayout, ContainerOp, HandleProperty, MemoryFormat, - ObjectField, ObjectOp, Radix, Severity, StringOp, SystemFunction, SystemTask, VcdTask, + ObjectField, ObjectOp, Radix, Record, Severity, StringOp, SystemFunction, SystemTask, VcdTask, }; /// A procedural statement of the analyzed IR. diff --git a/crates/celox-sv-analyzer/src/system_functions.rs b/crates/celox-sv-analyzer/src/system_functions.rs index d1c53dc514d..2502e6b3ad3 100644 --- a/crates/celox-sv-analyzer/src/system_functions.rs +++ b/crates/celox-sv-analyzer/src/system_functions.rs @@ -839,6 +839,27 @@ pub struct ObjectField { pub handle: Option, /// A 4-state value: its unknown-bit mask follows the value bytes. pub four_state: bool, + /// A member of a [`Record`]: `null` reads as the member's default. + pub nullable: bool, +} + +/// The layout of an immutable heap record that holds the value of an +/// unpacked structure (IEEE 1800-2023 7.2) as a container element: one +/// field per leaf member, first declared first. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Record { + pub size: u32, + pub fields: Vec, +} + +impl Record { + /// The run-time class of a record, which no class shares. + pub const CLASS: u32 = u32::MAX; + + /// Bits of the flat structure value. + pub fn width(&self) -> usize { + self.fields.iter().map(|field| field.width as usize).sum() + } } /// What a handle property refers to. @@ -1011,6 +1032,11 @@ pub enum ObjectOp { /// A new object of the class of the object in the argument, with a copy /// of its properties (IEEE 1800-2023 8.12). Copy, + /// A new record holding the flat structure value in the argument. + Box(Record), + /// The flat structure value of the record in the argument; `null` is + /// the default value. + Unbox(Record), } impl ObjectOp { @@ -1042,7 +1068,10 @@ impl ObjectOp { | Self::ModeSelected(_) => (32, false), Self::ModeGet(..) | Self::ConstraintModeGet(_) => (32, true), Self::Load(field) => (field.width as usize, field.signed), - Self::New { .. } | Self::ClassOf | Self::Store(_) | Self::Copy => (32, false), + Self::Unbox(record) => (record.width(), false), + Self::New { .. } | Self::ClassOf | Self::Store(_) | Self::Copy | Self::Box(_) => { + (32, false) + } } } } @@ -1069,6 +1098,8 @@ impl fmt::Display for ObjectOp { Self::ModeSelect(..) => "select random property", Self::ModeSelected(_) => "selected random property query", Self::Copy => "shallow copy", + Self::Box(_) => "structure record", + Self::Unbox(_) => "structure record read", }) } } diff --git a/crates/celox-test-suite/LIMITATIONS.md b/crates/celox-test-suite/LIMITATIONS.md index 70155d7e067..5ea627f90fd 100644 --- a/crates/celox-test-suite/LIMITATIONS.md +++ b/crates/celox-test-suite/LIMITATIONS.md @@ -627,7 +627,7 @@ four-state expectations; the assertions remain enabled on all Celox variants. | `sv_icarus_integral_format_string` | execute | icarus | 1 | Icarus 13.0 compiles `$sformatf` with a `bit` vector variable as the format, then `vvp` stops: "$sformatf's first argument must be a string or a register." IEEE 1800-2023 21.3.3 reads the content of an integral format expression as the format; Verilator 5.052 gives the expected output, xezim 0.11.3 prints the format as a value (`sv_integral_format_string` in the xezim review). | | `sv_icarus_string_associative_arrays_and_property_queue_methods` | compile | icarus | 2 | Icarus 13.0 rejects associative arrays with `string` and `bit [63:0]` indices and queue methods called on a class property ("Can't find task push_back in class Log"), which IEEE 1800-2023 7.8 and 7.10 define; Verilator 5.052 and xezim 0.11.3 compile the cases. | | `sv_verilator_associative_index_cast` | execute | verilator | 1 | Verilator 5.052 evaluates an associative index `x + 32'd1` at 32 bits and stores key 0; IEEE 1800-2023 7.8.4 evaluates it as a cast to the `bit [63:0]` index type (6.24.1), giving `64'h100000000`. xezim 0.11.3 also stores key 0 (`sv_associative_index_cast` in its review). [Evidence](verification/repros/sv_associative_index_cast.json). | -| `sv_icarus_unpacked_structs` | compile | icarus | 12 | Icarus 13.0 does not support unpacked structures ("sorry: Unpacked structs not supported."), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default. | +| `sv_icarus_unpacked_structs` | compile | icarus | 16 | Icarus 13.0 does not support unpacked structures ("sorry: Unpacked structs not supported."), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default. | | `sv_verilator_nested_struct_default` | execute | verilator | 1 | Verilator 5.052 applies '{default: 5, ...} to the int member of a nested unpacked structure but leaves its bit [3:0] member 0 ("5 0000 1" in the standalone source; a top-level '{default: 5} sets both). IEEE 1800-2023 10.9.2 applies the default recursively to each member of an unmatched substructure and evaluates it in the context of an assignment to a simple bit vector member, giving 4'b0101. | The `string_format` cases compare `$sformatf`, `$sformat` and `$swrite` with diff --git a/crates/celox-test-suite/src/sv/cases/unpacked_structs.vtest b/crates/celox-test-suite/src/sv/cases/unpacked_structs.vtest index ebf1175badc..096581f0eaa 100644 --- a/crates/celox-test-suite/src/sv/cases/unpacked_structs.vtest +++ b/crates/celox-test-suite/src/sv/cases/unpacked_structs.vtest @@ -449,3 +449,132 @@ endmodule (top Top) (run_until 6000) (expect_output "x 1\no x\n[2999!] [2999] 3000\n")) + +(case container_elements + (source "unpacked_struct_containers.sv" #" +module Top(output bit done); + class Node; + string n; + function new(string n); + this.n = n; + endfunction + endclass + typedef struct { string name; string regex; } acs_t; + typedef struct { Node m_type; string m_type_name; } pair_t; + typedef struct { pair_t orig; string alias_name; } alias_t; + typedef struct { int read_time; int write_time; int unsigned read_count; } access_t; + typedef enum { NEVER, STARTED, FINISHED } state_e; + typedef struct { state_e state; bit ret_val; } info_t; + initial begin + acs_t q[$]; + acs_t s, t; + alias_t aliases[$]; + access_t access[string]; + access_t ar; + info_t states[int]; + info_t da[]; + Node a; + s.name = "foo"; + s.regex = ""; + q.push_back(s); + q.push_back('{name: "", regex: "b.*"}); + s.name = "changed"; + $display("size %0d %s|%s %s", q.size(), q[0].name, q[1].regex, q[$].regex); + while (q.size()) begin + t = q.pop_front(); + $display("acs %s|%s", t.name, t.regex); + end + a = new("A"); + aliases.push_back('{orig: '{a, "A"}, alias_name: "al"}); + $display("alias %s %s %s", aliases[0].orig.m_type.n, aliases[0].orig.m_type_name, + aliases[0].alias_name); + ar = access["x"]; + $display("miss %0d %0d %0d", ar.read_time, ar.read_count, access.exists("x")); + ar.read_count++; + ar.read_time = 5; + access["x"] = ar; + ar.read_count = 99; + $display("hit %0d %0d %0d", access["x"].read_count, access["x"].read_time, access.num()); + states[3] = '{STARTED, 1}; + $display("info %0d %0d %0d", states[3].state, states[3].ret_val, states[4].state); + da = new[2]; + da[1] = '{FINISHED, 1}; + $display("da %0d %0d %0d", da[0].state, da[1].state, da[1] == info_t'{FINISHED, 1}); + foreach (access[k]) $display("key %s %0d", k, access[k].read_count); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "size 2 foo|b.* b.*\nacs foo|\nacs |b.*\nalias A A al\nmiss 0 0 0\nhit 1 5 1\ninfo 1 1 0\nda 0 2 1\nkey x 1\n")) + +(case container_element_member_selects + (source "unpacked_struct_element_selects.sv" #" +module Top(output bit done); + typedef struct { int x, y; } inner_t; + typedef struct { inner_t inner; bit [7:0] data; string s; } element_t; + initial begin + element_t q[$]; + inner_t i; + int k; + q.push_back('{'{1, 2}, 8'hA5, "a"}); + q.push_back('{'{3, 4}, 8'h3C, "b"}); + k = 1; + $display("%h %h %b %0d", q[0].data[3:0], q[k].data[7:4], q[1].data[0], q[0].inner.y); + i = q[1].inner; + $display("%0d %0d %0d", i.x, i.y, q.size()); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "5 3 0 2\n3 4 2\n")) + +(case container_element_four_state_defaults + (four_state) + (source "unpacked_struct_container_states.sv" #" +module Top(output bit done); + typedef struct { time t; int unsigned n; logic [3:0] l; } access_t; + typedef struct { logic [3:0] a; logic [3:0] b; } nibbles_t; + initial begin + access_t access[string]; + nibbles_t q[]; + access_t x; + x = access["missing"]; + $display("%0d %0d %b", x.t, x.n, x.l); + x.l = 4'b1z0x; + access["k"] = x; + $display("%0d %b", access["k"].t, access["k"].l); + q = new[2]; + q[0] = '{4'bx01z, 4'b0011}; + $display("%b %b %b", q[0].a, q[0].b, q[1].a); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "x 0 xxxx\nx 1z0x\nx01z 0011 xxxx\n")) + +(case container_records_survive_heap_collections + (source "unpacked_struct_container_heap.sv" #" +module Top(output int n); + typedef struct { string name; string regex; } acs_t; + logic clk = 0; + always #1 clk = ~clk; + acs_t names[$]; + acs_t byname[string]; + string number; + always @(posedge clk) begin + number.itoa(n); + names.push_back('{name: number, regex: {number, "*"}}); + if (names.size() > 3) void'(names.pop_front()); + byname[number] = '{name: {"n", number}, regex: ""}; + n = n + 1; + end + initial #6000 $display("%0d [%s] [%s] [%s] %0d", names.size(), names[0].name, names[$].regex, + byname["2999"].name, byname.num()); +endmodule +"#) + (top Top) + (run_until 6000) + (expect_output "3 [2997] [2999*] [n2999] 3000\n")) diff --git a/crates/celox-test-suite/verification/sv/icarus/unpacked_structs.json b/crates/celox-test-suite/verification/sv/icarus/unpacked_structs.json index 49cfe0947a9..f0921a6595b 100644 --- a/crates/celox-test-suite/verification/sv/icarus/unpacked_structs.json +++ b/crates/celox-test-suite/verification/sv/icarus/unpacked_structs.json @@ -115,6 +115,98 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_unpacked_structs.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_unpacked_structs", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "upstream": [] + }, + "name": "unpacked_structs::container_element_four_state_defaults", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_unpacked_structs.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_unpacked_structs", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "upstream": [] + }, + "name": "unpacked_structs::container_element_member_selects", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_unpacked_structs.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_unpacked_structs", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "upstream": [] + }, + "name": "unpacked_structs::container_elements", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_unpacked_structs.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_unpacked_structs", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "upstream": [] + }, + "name": "unpacked_structs::container_records_survive_heap_collections", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", diff --git a/crates/celox-test-suite/verification/sv/limitations.json b/crates/celox-test-suite/verification/sv/limitations.json index cf96d93d2dd..b4e804a0208 100644 --- a/crates/celox-test-suite/verification/sv/limitations.json +++ b/crates/celox-test-suite/verification/sv/limitations.json @@ -2988,6 +2988,10 @@ "unpacked_structs::class_properties_inheritance_and_collections", "unpacked_structs::class_property_assignment_order", "unpacked_structs::class_property_four_state_members", + "unpacked_structs::container_element_four_state_defaults", + "unpacked_structs::container_element_member_selects", + "unpacked_structs::container_elements", + "unpacked_structs::container_records_survive_heap_collections", "unpacked_structs::four_state_members", "unpacked_structs::handle_members_survive_heap_collections", "unpacked_structs::initializers_results_and_defaults", diff --git a/crates/celox-test-suite/verification/sv/verilator/unpacked_structs.json b/crates/celox-test-suite/verification/sv/verilator/unpacked_structs.json index e2b3c126390..037e6d81c89 100644 --- a/crates/celox-test-suite/verification/sv/verilator/unpacked_structs.json +++ b/crates/celox-test-suite/verification/sv/verilator/unpacked_structs.json @@ -67,6 +67,50 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "four-state expectations", + "expectation": "Simulation", + "name": "unpacked_structs::container_element_four_state_defaults", + "phase": "compile", + "status": "unsupported", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::container_element_member_selects", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::container_elements", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::container_records_survive_heap_collections", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "four-state expectations", diff --git a/crates/celox-test-suite/verification/sv/xezim/unpacked_structs.json b/crates/celox-test-suite/verification/sv/xezim/unpacked_structs.json index 9da00089498..e368bcbaa51 100644 --- a/crates/celox-test-suite/verification/sv/xezim/unpacked_structs.json +++ b/crates/celox-test-suite/verification/sv/xezim/unpacked_structs.json @@ -55,6 +55,50 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::container_element_four_state_defaults", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::container_element_member_selects", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::container_elements", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::container_records_survive_heap_collections", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", diff --git a/crates/celox/tests/frontends/systemverilog/unpacked_structs.rs b/crates/celox/tests/frontends/systemverilog/unpacked_structs.rs index 99cf93ba158..00b23d1619c 100644 --- a/crates/celox/tests/frontends/systemverilog/unpacked_structs.rs +++ b/crates/celox/tests/frontends/systemverilog/unpacked_structs.rs @@ -77,6 +77,42 @@ sv_backends! { assert_eq!(sim.get(value), BigUint::from(342u16)); } + fn container_elements_with_packed_and_process_members(sim) { + @setup { + let source = r#"module Top(output bit [3:0] code, output bit [7:0] header, + output bit null_process, output int changes); + timeunit 1ps / 1ps; + typedef struct packed { bit [3:0] code; bit [3:0] kind; } header_t; + typedef struct { header_t header; string s; } element_t; + typedef struct { process p; logic flag; } waiter_t; + typedef struct { string name; bit flag; } entry_t; + entry_t q[$]; + initial begin + element_t r[$]; + waiter_t w[]; + r.push_back('{8'hA5, "a"}); + code = r[0].header.code; + header = r[0].header; + w = new[1]; + null_process = w[0].p == null; + q.push_back('{"x", 0}); + #1 q[0] = '{"x", 1}; + end + initial begin + @(q[0].flag); + changes = 1; + end + endmodule"#; + } + @build celox::Simulation::from_sv_sources(vec![(source, Path::new("struct.sv"))], "Top") + .four_state(true); + sim.run_until(5).unwrap(); + for (name, value) in [("code", 0xau8), ("header", 0xa5), ("null_process", 1), ("changes", 1)] { + let signal = sim.signal(name); + assert_eq!(sim.get(signal), BigUint::from(value), "{name}"); + } + } + fn constructors_in_structure_patterns(sim) { @setup { let source = r#"module Top(output bit ok); @@ -117,6 +153,65 @@ sv_backends! { assert_eq!(sim.get(first), BigUint::from(22u8)); assert_eq!(sim.get(second), BigUint::from(22u8)); } + fn unknown_record_members_and_properties_are_not_folded(sim) { + @setup { + let source = r#"module Top(output int value); + typedef struct { string name; logic flag; } row_t; + class H; + logic f; + endclass + initial begin + row_t q[$]; + row_t d[]; + H h; + h = new; + q.push_back('{name: "a", flag: 'x}); + value = 0; + if (q[0].flag || !q[0].flag) value += 1; + else value += 10; + if (h.f || !h.f) value += 100; + else value += 1000; + d = new[2]; + if ((d[0] == d[1]) || (d[0] != d[1])) value += 10000; + else value += 100000; + end + endmodule"#; + } + @build celox::Simulation::from_sv_sources(vec![(source, Path::new("struct.sv"))], "Top") + .four_state(true); + sim.run_until(0).unwrap(); + let value = sim.signal("value"); + assert_eq!(sim.get(value), BigUint::from(101010u32)); + } + fn equal_record_updates_preserve_event_waits(sim) { + @setup { + let source = r#"`timescale 1ns/1ns + module Top(output bit done, output int changes); + typedef struct { string name; int value; } row_t; + row_t q[$], d[]; + int count, before_count; + initial begin + q.push_back('{"a", 1}); + d = new[1]; + #1 before_count = count; + d[0] = d[0]; + d[0] = '{default: 0, name: ""}; + q[0] = q[0]; + q[0] = '{{"a"}, 1}; + #1 q = '{'{"a", 1}}; + #1 done = count == before_count; + q[0] = '{"b", 1}; + #1 changes = count - before_count; + end + always @(q or d) count = count + 1; + endmodule"#; + } + @build celox::Simulation::from_sv_sources(vec![(source, Path::new("struct.sv"))], "Top"); + sim.run_until(4).unwrap(); + let (done, changes) = (sim.signal("done"), sim.signal("changes")); + assert_eq!(sim.get(done), BigUint::from(1u8)); + assert_eq!(sim.get(changes), BigUint::from(1u8)); + } fn static_nested_string_initializers(sim) { @setup { let source = r#"module Top(output int n); @@ -154,6 +249,28 @@ sv_backends! { let out = sim.signal("out"); assert_eq!(sim.get(out), BigUint::from(71u8)); } + fn enumeration_methods_of_container_element_members(sim) { + @setup { + let source = r#"module Top(output bit done); + typedef enum { STARTED, FINISHED } state_e; + typedef struct { state_e state; string tag; } rec_t; + typedef struct { state_e state; int n; } flat_t; + initial begin + rec_t m[int]; + flat_t q[$]; + string s; + m[2] = '{STARTED, "x"}; + q.push_back('{FINISHED, 3}); + s = {m[2].state.name(), " ", q[0].state.name, " ", m[2].state.next().name()}; + done = s == "STARTED FINISHED FINISHED" && q[0].state.prev() == STARTED; + end + endmodule"#; + } + @build celox::Simulation::from_sv_sources(vec![(source, Path::new("struct.sv"))], "Top"); + sim.run_until(0).unwrap(); + let done = sim.signal("done"); + assert_eq!(sim.get(done), BigUint::from(1u8)); + } fn redeclared_structure_properties_hide_their_members(sim) { @setup { let source = r#"module Top(output int value); @@ -205,6 +322,18 @@ sv_backends! { fn unpacked_struct_class_properties_inheritance_and_collections(sim) { @case "unpacked_structs::class_properties_inheritance_and_collections"; } + fn unpacked_struct_container_elements(sim) { + @case "unpacked_structs::container_elements"; + } + fn unpacked_struct_container_element_member_selects(sim) { + @case "unpacked_structs::container_element_member_selects"; + } + fn unpacked_struct_container_element_four_state_defaults(sim) { + @case "unpacked_structs::container_element_four_state_defaults"; + } + fn unpacked_struct_container_records_survive_heap_collections(sim) { + @case "unpacked_structs::container_records_survive_heap_collections"; + } } #[test] @@ -264,7 +393,34 @@ fn unsupported_and_illegal_uses_are_rejected() { "parameter i_t P = '{1, 0};", "parameter of unpacked structure type", ), - ("i_t q[$];", "dynamic container of unpacked structures"), + ( + "s_t q[$], r[$]; bit x; initial x = q == r;", + "comparison of dynamic containers of unpacked structures", + ), + ( + "i_t q[$]; initial q.sort();", + "sorting unpacked structures requires a with expression", + ), + ( + "s_t q[$]; initial begin q.push_back('{1, \"x\"}); q[0].a = 5; end", + "assignment to a member of a dynamic container element", + ), + ( + "s_t q[$]; initial begin q.push_back('{1, \"x\"}); q[0].a++; end", + "assignment to a member of a dynamic container element", + ), + ( + "typedef struct { bit [15:8] hi; string s; } h_t; h_t q[$]; bit x; initial x = q[0].hi[8];", + "select of a container element member that is not declared [N-1:0]", + ), + ( + "typedef struct { s_t inner; } n_t; n_t q[$]; s_t i; initial i = q.pop_front().inner;", + "structure member with several members of an element read with a side effect", + ), + ( + "typedef struct { s_t inner; } n_t; n_t q[$]; s_t i; initial i = q[$urandom_range(0, 1)].inner;", + "structure member with several members of an element read with a side effect", + ), ( "class C; static i_t v; endclass", "static class property of unpacked structure type", diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index 96887cf304a..5c603abfd30 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -330,7 +330,8 @@ SystemVerilog emitted by Veryl. Unpacked structures (IEEE 1800-2023 7.2) may have integral, enumeration, `string`, class handle, packed structure and nested unpacked structure members, each keeping its own 2-state or 4-state type. Variables of such a -type may be module variables, procedural locals, class properties, and +type may be module variables, procedural locals, class properties, queue, +dynamic and associative array elements (`q[i].m` reads a member), and subroutine arguments of any direction and results. Members are read and written like variables of their type; a whole structure is assigned and compared with `==`, `!=`, `===` and `!==` against a value of the same type, chosen with `?:`, or built @@ -362,7 +363,7 @@ constructs without a dedicated issue point to the frontend roadmap, [#88](https: - Declarations: variable declaration initializers of members of an interface array, ANSI port default values, tagged unions, unpacked unions, packed union assignment patterns, internal nets without a driver ([#460](https://github.com/celox-sim/celox/issues/460)), `real`, and unpacked structs as ports, nets, parameters, static, `rand` or - `const` class properties, array or container elements, or with members that + `const` class properties, fixed-size array elements, or with members that are arrays, `real`, or have default values. - Sequential processes: `iff` qualifiers in `always_ff` event lists ([#452](https://github.com/celox-sim/celox/issues/452)), and in `always_ff` edge operands other than a plain signal ([#464](https://github.com/celox-sim/celox/issues/464)), multi-bit @@ -484,8 +485,13 @@ including changes caused by ordering methods (9.4.2). Associative arrays cannot use ordering methods. Fixed-array ordering, `shuffle`, `with` expressions and iterator arguments remain unsupported. -Elements may be packed integral values up to 64 bits, strings or class -handles. Positional assignment patterns and element concatenations construct +Elements may be packed integral values up to 64 bits, strings, class +handles or [unpacked structures](#unpacked-structures); a missing +associative entry or a new dynamic array element of structure type has the +structure's default members. Containers of unpacked structures with a string +or handle member, or wider than 64 bits, are not compared with `==` or sorted +without `with`; a member of such an element is read, not written (assign +the whole element). Positional assignment patterns and element concatenations construct sequences; assignments between dynamic arrays and queues copy values and respect the destination queue's bound. Associative assignment requires the same key type. Equality (`==`, `!=`, `===`, `!==`) between equivalent container types compares contents, diff --git a/docs/guide/systemverilog.md b/docs/guide/systemverilog.md index 06cf2f87910..a3c7d54a783 100644 --- a/docs/guide/systemverilog.md +++ b/docs/guide/systemverilog.md @@ -100,7 +100,7 @@ Common reasons a design needs changes are: and `iff` in `always_ff` event controls ([#452](https://github.com/celox-sim/celox/issues/452)). - Nonblocking latch assignments, multiple drivers and tri-state buses. Inferred latches in `always_comb` require `inferred_latch = "warn"` or `"allow"` in the common `[diagnostics]` configuration. - Non-ANSI module ports, wildcard `.*` connections, gate primitives and `bind`. -- `real`, unpacked structs in ports and containers, and several interface features. +- `real`, unpacked structs in ports and fixed-size arrays, and several interface features. The [complete limitations list](./systemverilog-reference#what-is-not-supported) includes narrower restrictions and tracking issues. Unsupported constructs diff --git a/docs/ja/guide/systemverilog-reference.md b/docs/ja/guide/systemverilog-reference.md index a7db5796460..6ae5d465d85 100644 --- a/docs/ja/guide/systemverilog-reference.md +++ b/docs/ja/guide/systemverilog-reference.md @@ -209,6 +209,7 @@ SystemVerilog に対しても、共有の Veryl 適合性スイートを実行 unpacked 構造体(IEEE 1800-2023 7.2)のメンバには、整数型、列挙型、`string`、 クラスハンドル、packed 構造体、入れ子の unpacked 構造体を使え、各メンバは自身の 2 値・4 値の型を保ちます。この型の変数は、モジュール変数、手続き内のローカル変数、クラスプロパティ、 +キュー・動的配列・連想配列の要素(`q[i].m` でメンバを読めます)、 任意の方向のサブルーチン引数と戻り値にできます。メンバはその型の変数と同じように 読み書きできます。構造体全体は、同じ型の値との代入と `==`・`!=`・`===`・`!==` による 比較、`?:` による選択、assignment pattern(`'{a, b}`、`'{m: v, default: d}`、 @@ -236,7 +237,7 @@ unpacked 構造体(IEEE 1800-2023 7.2)のメンバには、整数型、列 - `always_comb` の暗黙のラッチ推論はデフォルトで拒否します。`celox.toml` の `[diagnostics]` で `inferred_latch = "warn"` または `"allow"` を指定すると許可できます。通常の `always @*` と明示的な `always_latch` にはこの設定は不要です。 - ポートとインスタンス:non-ANSI 形式のポート式(`module m({a, b}, c[3:0], .p(d))` など、[#1953](https://github.com/celox-sim/celox/issues/1953))、`ref` ポート([#427](https://github.com/celox-sim/celox/issues/427))、 ワイルドカード接続 `.*`([#442](https://github.com/celox-sim/celox/issues/442))、ゲートプリミティブ([#457](https://github.com/celox-sim/celox/issues/457))、`bind`。 -- 宣言:interface 配列のメンバーの変数宣言の初期化子、ANSI ポートの既定値、tagged union、unpacked union、packed union の assignment pattern、ドライバを持たない内部ネット([#460](https://github.com/celox-sim/celox/issues/460))、`real`、ポート・ネット・パラメータ・static / `rand` / `const` のクラスプロパティ・配列やコンテナの要素としての unpacked 構造体、配列・`real`・既定値を持つメンバ。 +- 宣言:interface 配列のメンバーの変数宣言の初期化子、ANSI ポートの既定値、tagged union、unpacked union、packed union の assignment pattern、ドライバを持たない内部ネット([#460](https://github.com/celox-sim/celox/issues/460))、`real`、ポート・ネット・パラメータ・static / `rand` / `const` のクラスプロパティ・固定長配列の要素としての unpacked 構造体、配列・`real`・既定値を持つメンバ。 - 順序回路のプロセス:`always_ff` のイベントリストの `iff` 修飾([#452](https://github.com/celox-sim/celox/issues/452))、および `always_ff` での 単純な信号以外のエッジオペランド([#464](https://github.com/celox-sim/celox/issues/464))、複数ビットのエッジ信号、 非同期リセットを持たない複数のエッジ。 diff --git a/docs/ja/guide/systemverilog.md b/docs/ja/guide/systemverilog.md index 62648c54789..b8bd36cd88b 100644 --- a/docs/ja/guide/systemverilog.md +++ b/docs/ja/guide/systemverilog.md @@ -94,7 +94,7 @@ X/Z を扱う場合は builder に `.four_state(true)` を指定します。 `always_ff` のイベント制御の `iff`([#452](https://github.com/celox-sim/celox/issues/452))。 - ラッチ内のノンブロッキング代入、複数ドライバ、トライステートバス。`always_comb` の暗黙のラッチ推論は 共通の `[diagnostics]` 設定で `inferred_latch = "warn"` または `"allow"` を指定して許可します。 - 非 ANSI モジュールポート、ワイルドカード `.*` 接続、ゲートプリミティブ、`bind`。 -- `real`、ポート・コンテナの unpacked 構造体、interface の一部の機能。 +- `real`、ポート・固定長配列の unpacked 構造体、interface の一部の機能。 [制約の一覧](./systemverilog-reference#what-is-not-supported)に、より細かな条件と追跡 issue をまとめています。 未対応の構文は、構文名と追跡 issue を含む診断を返します。