From 0e8194228aea23558908d3e45dcd72d9c9419cca Mon Sep 17 00:00:00 2001 From: tignear Date: Wed, 28 Oct 2026 19:03:54 +0900 Subject: [PATCH] feat(sv): support the $swrite family Implement `$swrite`, `$swriteb`, `$swriteo` and `$swriteh` (IEEE 1800-2023 21.3.3). Like `$write`, a string literal that no conversion consumes is a format, a later one included, and each value without a conversion of its own is written in the task's radix, a string as text and a real as `$write` writes it. `$display`, `$write`, `$fdisplay` and `$fwrite` now also treat a later unconsumed string literal as a further format, as Verilator, Icarus and xezim do (21.2.1.1), instead of printing its conversions literally. The analyzer builds that format and binds the call as the `$sformatf` string operation, then assigns the result to the output, a string variable, a function's return variable or a string class property. The shared swrite_matches_write case compares each form with `$write` of the same arguments; Verilator 5.052, Icarus 13.0 and xezim 0.11.3 pass it. Change-Id: Ie03af76400361cd0410abcac91959d1c272c56a1 --- .../src/ast/expression_binding.rs | 6 +- .../src/ast/expression_binding/direct.rs | 19 +- .../celox-sv-analyzer/src/ast/procedural.rs | 237 ++++++++++++++++-- .../celox-sv-analyzer/src/system_functions.rs | 6 +- crates/celox-test-suite/LIMITATIONS.md | 4 +- .../src/sv/cases/string_format.vtest | 60 +++++ .../frontends/systemverilog/string_format.rs | 40 +++ docs/guide/systemverilog-reference.md | 12 +- 8 files changed, 340 insertions(+), 44 deletions(-) diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding.rs b/crates/celox-sv-analyzer/src/ast/expression_binding.rs index a05aad62f55..730ee1d4d03 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding.rs @@ -13,7 +13,8 @@ mod strings; pub(super) use calls::{statement as call_statement, statement_root as call_statement_root}; pub(super) use direct::{ arguments, bind_value, call_name as native_name, callable_name, cast_target_native, - format_arguments, member_context, real_value, remove_real_division_guards, ungroup, + format_arguments, member_context, real_value, remove_real_division_guards, + string_literal_bytes, ungroup, }; pub(super) use lvalues::{net_lvalue, variable_lvalue}; pub(super) use objects::{ @@ -25,7 +26,8 @@ pub(super) use objects::{ receiver as object_receiver, static_property as object_static_property, this as object_this, }; pub(super) use strings::{ - call as string_call, method as string_method, native_string, to_string as string_operand, + call as string_call, method as string_method, native_string, string_value, + to_string as string_operand, }; fn disagreement() -> AnalyzerError { AnalyzerError::Parse("invalid native expression ownership".into()) 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 b44348c89ed..847b186a6fb 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs @@ -1879,6 +1879,18 @@ pub(in crate::ast) fn format_arguments( /// String literals in integral contexts are unsigned packed arrays of bytes /// (IEEE 1800-2023 5.9). Keep the semantic IR integral, including escapes. fn packed_string_literal(text: &str) -> Option { + let bytes = string_literal_bytes(text)?; + let width = (bytes.len() * 8).max(8); + Some(format!( + "{}'h{}", + width, + num_bigint::BigUint::from_bytes_be(&bytes).to_str_radix(16) + )) +} + +/// The bytes of string literal `text`, written with its quotes, after its +/// escapes (IEEE 1800-2023 5.9.1). +pub(in crate::ast) fn string_literal_bytes(text: &str) -> Option> { let text = if let Some(text) = text.strip_prefix("\"\"\"") { text.strip_suffix("\"\"\"")? } else { @@ -1939,12 +1951,7 @@ fn packed_string_literal(text: &str) -> Option { }; bytes.push(value); } - let width = (bytes.len() * 8).max(8); - Some(format!( - "{}'h{}", - width, - num_bigint::BigUint::from_bytes_be(&bytes).to_str_radix(16) - )) + Some(bytes) } pub(in crate::ast) fn real_value(expr: &Expr, dimensions: &PackedDimensions) -> bool { diff --git a/crates/celox-sv-analyzer/src/ast/procedural.rs b/crates/celox-sv-analyzer/src/ast/procedural.rs index d5ff37e914e..95062607189 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural.rs @@ -665,6 +665,76 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { .map(Some) } + /// Fold the arguments of a display or write task after its first format + /// into that format when a later string literal is a further format: a + /// string literal that no conversion consumes continues the format, and + /// a value without a conversion of its own is written in the radix of the + /// task (IEEE 1800-2023 21.2.1.1). + fn merge_display_formats( + &self, + task: SystemTask, + args: &mut Vec>, + ids: &mut Vec>, + ) { + let (SystemTask::Display(radix) + | SystemTask::Write(radix) + | SystemTask::Fdisplay(radix) + | SystemTask::Fwrite(radix)) = task + else { + return; + }; + let Some(start) = template_index(task, args) else { + return; + }; + let Some(SystemTaskArg::Str(first)) = args.get(start) else { + return; + }; + let mut text = first.clone(); + let mut pending = format_conversions(&text).len(); + let mut later_format = false; + for arg in &args[start + 1..] { + match arg { + SystemTaskArg::Str(literal) if pending == 0 => { + later_format = true; + pending = format_conversions(literal).len(); + text.push_str(literal); + } + _ if pending > 0 => pending -= 1, + SystemTaskArg::Expr(value) => text.push_str(&default_conversion( + expression_binding::string_value(value, &self.dims), + expression_binding::real_value(value, &self.dims), + radix, + )), + SystemTaskArg::Str(_) => unreachable!("an unconsumed literal is a format"), + SystemTaskArg::Empty => text.push_str(&default_conversion(false, false, radix)), + } + } + if !later_format { + return; + } + // The values keep their places; the further formats are folded into + // the first one. + let mut pending = format_conversions(first).len(); + let mut kept = vec![SystemTaskArg::Str(text)]; + let mut kept_ids = vec![ids.get(start).copied().flatten()]; + for (position, arg) in args.iter().enumerate().skip(start + 1) { + match arg { + SystemTaskArg::Str(literal) if pending == 0 => { + pending = format_conversions(literal).len(); + } + arg => { + pending = pending.saturating_sub(1); + kept.push(arg.clone()); + kept_ids.push(ids.get(position).copied().flatten()); + } + } + } + args.truncate(start); + args.extend(kept); + ids.truncate(start); + ids.extend(kept_ids); + } + /// `output = value` for the string `value` of `$sformat`, which assigns /// its output as a string literal is assigned (IEEE 1800-2023 21.3.3, /// 5.9). @@ -1453,6 +1523,74 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { ); return Ok(vec![self.format_assignment(output, value)?]); } + // `$swrite(output, args...)` assigns what `$write(args...)` would + // print, in the radix of its name (IEEE 1800-2023 21.3.3). + if let Some(radix) = swrite_radix(name) { + if arguments.iter().any(|arg| arg.name.is_some()) { + return Err(unsupported(format!("named arguments of `{name}`"))); + } + let output = arguments.first().and_then(|arg| arg.value).ok_or_else(|| { + AnalyzerError::InvalidSystemTfCall { + name: name.into(), + detail: "expected an output argument".into(), + } + })?; + // As for `$write`, a string literal that no conversion consumes + // continues the format, and a value without a conversion of its + // own is written in the radix of the task (21.2.1.1). + let mut text = Vec::new(); + let mut values = Vec::new(); + let mut pending = 0; + for (position, arg) in arguments.iter().enumerate().skip(1) { + let id = arg + .value + .ok_or_else(|| AnalyzerError::InvalidSystemTfCall { + name: name.into(), + detail: format!("argument {} is omitted", position + 1), + })?; + let literal = match &declarations.expression(id).kind { + celox_sv_syntax::ExprKind::Literal(text) => { + expression_binding::string_literal_bytes(text) + } + _ => None, + }; + if pending == 0 + && let Some(literal) = literal + { + pending = format_conversions(&String::from_utf8_lossy(&literal)).len(); + text.extend_from_slice(&literal); + continue; + } + let value = + expression_binding::bind_value(id, declarations, self.tree, &self.dims, None)?; + if pending > 0 { + pending -= 1; + } else { + text.extend_from_slice( + default_conversion( + literal.is_some() + || expression_binding::string_value(&value, &self.dims), + expression_binding::real_value(&value, &self.dims), + radix, + ) + .as_bytes(), + ); + } + values.push(value); + } + let format = Expr::Literal(format!( + "{}'h{}", + (text.len() * 8).max(8), + num_bigint::BigUint::from_bytes_be(&text).to_str_radix(16) + )); + let value = expression_binding::string_call( + StringOp::Format { + ticks_per_unit: timescales::time_divisor(root, self.tree)?, + }, + std::iter::once(format).chain(values).collect(), + ); + return Ok(vec![self.format_assignment(output, value)?]); + } if name == "$sformatf" { let mut value = expression_binding::bind_value(root, declarations, self.tree, &self.dims, None)?; @@ -1526,17 +1664,26 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { { return Ok(SystemTaskArg::Str(text.to_string())); } - let mut value = + // Renamed below, once the types of the source names have + // chosen the conversions of the format. + let value = expression_binding::bind_value(id, declarations, self.tree, &self.dims, None)?; - self.rename_expr(&mut value); Ok(SystemTaskArg::Expr(value)) }) .collect::, AnalyzerError>>()?; let mut args = args; + // The native expression of each argument, kept in step with `args`. + let mut ids = arguments.iter().map(|arg| arg.value).collect::>(); + self.merge_display_formats(task, &mut args, &mut ids); + for arg in &mut args { + if let SystemTaskArg::Expr(value) = arg { + self.rename_expr(value); + } + } // A string literal that %t converts is bound as a value: the binder // handles every literal form, triple quotes and escapes included. let mut bind = |index: usize| -> Result, AnalyzerError> { - let Some(id) = arguments.get(index).and_then(|arg| arg.value) else { + let Some(id) = ids.get(index).copied().flatten() else { return Ok(None); }; let mut value = @@ -3386,34 +3533,49 @@ pub(super) fn process_site( }) } -/// `%t` reports a time value in the units of `$timeformat`, by default the -/// smallest time precision of the design (IEEE 1800-2023 20.4.3, Table 20-3), -/// in which the simulation counts its time. The value is in the time unit of -/// the calling scope, of which `ticks_per_unit` simulation time units make -/// one, so each value a `%t` of the template converts is scaled by it. -fn scale_time_conversions( - task: SystemTask, - args: &mut [SystemTaskArg], - ticks_per_unit: u64, - bind: &mut impl FnMut(usize) -> Result, AnalyzerError>, -) -> Result<(), AnalyzerError> { - if ticks_per_unit == 1 { - return Ok(()); - } - let template = match task { +/// The position of the format among the arguments of a display, write or +/// severity task, which a leading string literal there is. +fn template_index(task: SystemTask, args: &[SystemTaskArg]) -> Option { + Some(match task { SystemTask::Display(_) | SystemTask::Write(_) | SystemTask::Severity(_) => 0, SystemTask::Fatal => usize::from(matches!(args.first(), Some(SystemTaskArg::Expr(_)))), SystemTask::Fdisplay(_) | SystemTask::Fwrite(_) | SystemTask::Assert | SystemTask::AssertContinue => 1, - _ => return Ok(()), - }; - let Some(SystemTaskArg::Str(text)) = args.get(template) else { - return Ok(()); - }; - // The conversions of the template, in the order they take arguments - // (21.2.1.2): flags, a width and a precision may precede each. + _ => return None, + }) +} + +/// The conversion that writes a value without one of its own in a task of +/// `radix` (IEEE 1800-2023 21.2.1.1): a string as text, a real as `$write` +/// writes reals. +fn default_conversion(string: bool, real: bool, radix: system_functions::Radix) -> String { + if real { + "%#g".into() + } else if string { + "%s".into() + } else { + format!("%{}", radix.letter()) + } +} + +/// The radix of a `$swrite` task named `name`. +fn swrite_radix(name: &str) -> Option { + use system_functions::Radix; + Some(match name { + "$swrite" => Radix::Decimal, + "$swriteb" => Radix::Binary, + "$swriteo" => Radix::Octal, + "$swriteh" => Radix::Hexadecimal, + _ => return None, + }) +} + +/// The conversions of a format, in the order they take arguments +/// (IEEE 1800-2023 21.2.1.2): flags, a width and a precision may precede +/// each. +fn format_conversions(text: &str) -> Vec { let mut conversions = Vec::new(); let mut chars = text.chars().peekable(); while let Some(ch) = chars.next() { @@ -3434,7 +3596,30 @@ fn scale_time_conversions( conversions.push(spec); } } - for (offset, spec) in conversions.into_iter().enumerate() { + conversions +} + +/// `%t` reports a time value in the units of `$timeformat`, by default the +/// smallest time precision of the design (IEEE 1800-2023 20.4.3, Table 20-3), +/// in which the simulation counts its time. The value is in the time unit of +/// the calling scope, of which `ticks_per_unit` simulation time units make +/// one, so each value a `%t` of the template converts is scaled by it. +fn scale_time_conversions( + task: SystemTask, + args: &mut [SystemTaskArg], + ticks_per_unit: u64, + bind: &mut impl FnMut(usize) -> Result, AnalyzerError>, +) -> Result<(), AnalyzerError> { + if ticks_per_unit == 1 { + return Ok(()); + } + let Some(template) = template_index(task, args) else { + return Ok(()); + }; + let Some(SystemTaskArg::Str(text)) = args.get(template) else { + return Ok(()); + }; + for (offset, spec) in format_conversions(text).into_iter().enumerate() { if !matches!(spec, 't' | 'T') { continue; } diff --git a/crates/celox-sv-analyzer/src/system_functions.rs b/crates/celox-sv-analyzer/src/system_functions.rs index d1b6cc97e63..d1c53dc514d 100644 --- a/crates/celox-sv-analyzer/src/system_functions.rs +++ b/crates/celox-sv-analyzer/src/system_functions.rs @@ -1557,13 +1557,13 @@ pub const SYSTEM_TFS: &[SystemTf] = &[ unsupported("$fmonitorb", Task), unsupported("$fmonitoro", Task), unsupported("$fmonitorh", Task), + // The binders convert `$swrite`, `$sformat` and `$sformatf` into string + // operations (`StringOp::Format`) before consulting the catalog, which + // rejects them anywhere else, such as in a constant expression. unsupported("$swrite", Task), unsupported("$swriteb", Task), unsupported("$swriteo", Task), unsupported("$swriteh", Task), - // The binders convert `$sformat` and `$sformatf` into string operations - // (`StringOp::Format`) before consulting the catalog, which rejects them - // anywhere else, such as in a constant expression. unsupported("$sformat", Task), unsupported("$sformatf", Function), function(SystemFunction::Fgetc, 1, Some(1)), diff --git a/crates/celox-test-suite/LIMITATIONS.md b/crates/celox-test-suite/LIMITATIONS.md index f08dae60b4a..cfce249e732 100644 --- a/crates/celox-test-suite/LIMITATIONS.md +++ b/crates/celox-test-suite/LIMITATIONS.md @@ -628,8 +628,8 @@ four-state expectations; the assertions remain enabled on all Celox variants. | `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). | -The `string_format` cases compare `$sformatf` and `$sformat` with `$display` -of the same format and arguments. The [Icarus observations](verification/sv/limitations/string-format-icarus.json) +The `string_format` cases compare `$sformatf`, `$sformat` and `$swrite` with +`$display` / `$write` of the same format and arguments. The [Icarus observations](verification/sv/limitations/string-format-icarus.json) retain the three failing runs with reduced adapter-free sources; the remaining cases pass in all three tools, except that Verilator 5.052 does not run the four-state case. `%m` is checked only in Celox, as each adapter wraps the diff --git a/crates/celox-test-suite/src/sv/cases/string_format.vtest b/crates/celox-test-suite/src/sv/cases/string_format.vtest index 1a28ab9d2a0..0d9ed8ee4f3 100644 --- a/crates/celox-test-suite/src/sv/cases/string_format.vtest +++ b/crates/celox-test-suite/src/sv/cases/string_format.vtest @@ -341,3 +341,63 @@ endmodule "#) (top Top) (run_until 0) (assert_eq done 1) (expect_output "a1<2>3-\n")) + +; 21.3.3: `$swrite` and its radix forms assign what `$write` and its radix +; forms print for the same arguments; a string literal that no conversion +; consumes is a further format (21.2.1.1). +(case swrite_matches_write + (source "swrite_write.sv" #" +module Top(output bit done); + string s, name; + int i; + bit [7:0] b; + initial begin + i = 12; + b = 8'h5a; + name = "n"; + $write("a=", i, " b=", b, " ", name, "\n"); + $swrite(s, "a=", i, " b=", b, " ", name, "\n"); + $write("%s", s); + $writeh(i, " ", b, "\n"); + $swriteh(s, i, " ", b, "\n"); + $write("%s", s); + $writeb(b, "\n"); + $swriteb(s, b, "\n"); + $write("%s", s); + $writeo(b, "\n"); + $swriteo(s, b, "\n"); + $write("%s", s); + $write("%0d-%s|", i, name, i, "\n"); + $swrite(s, "%0d-%s|", i, name, i, "\n"); + $write("%s", s); + $write(name, i, "\n"); + $swrite(s, name, i, "\n"); + $write("%s", s); + $write("a=%0d ", 1, "b=%0d", i, "|%s", "c", 2, "\n"); + $swrite(s, "a=%0d ", 1, "b=%0d", i, "|%s", "c", 2, "\n"); + $write("%s", s); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "a= 12 b= 90 n\na= 12 b= 90 n\n0000000c 5a\n0000000c 5a\n01011010\n01011010\n132\n132\n12-n| 12\n12-n| 12\nn 12\nn 12\na=1 b=12|c 2\na=1 b=12|c 2\n")) + +; 21.2.1.1: a later format literal of `$display` keeps the conversions of the +; values without one, here a block-local string, and a `%t` in it converts the +; value that follows it. Timed cases run at 1 ns / 1 ps. +(case display_later_formats + (source "display_later_formats.sv" #" +module Top(output bit done); + initial begin + string s; + s = "hello"; + $display("", s, "!"); + $display("[", "%t", "A", "]"); + $display("[%t]", "A"); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "hello!\n[ 65000]\n[ 65000]\n")) diff --git a/crates/celox/tests/frontends/systemverilog/string_format.rs b/crates/celox/tests/frontends/systemverilog/string_format.rs index 8647f7943c1..9f4d1b542a5 100644 --- a/crates/celox/tests/frontends/systemverilog/string_format.rs +++ b/crates/celox/tests/frontends/systemverilog/string_format.rs @@ -15,6 +15,8 @@ sv_backends! { fn sformatf_in_container_operands(sim) { @case "string_format::sformatf_in_container_operands"; } fn sformatf_with_associative_index(sim) { @case "string_format::sformatf_with_associative_index"; } fn sformatf_with_reference_argument(sim) { @case "string_format::sformatf_with_reference_argument"; } + fn swrite_matches_write(sim) { @case "string_format::swrite_matches_write"; } + fn display_later_formats(sim) { @case "string_format::display_later_formats"; } // External testbenches wrap the design, so the hierarchical name `%m` // prints differs between simulators; Celox prints the same for both. fn sformatf_scope_matches_display(sim) { @@ -83,3 +85,41 @@ fn container_owner_is_captured_before_formatting_operands() { assert_eq!(sim.get(first), BigUint::from(1u8)); assert_eq!(sim.get(other), BigUint::from(0u8)); } + +/// A value without a conversion of its own keeps its default conversion when a +/// later format literal is folded into the format: block-local strings and +/// reals print as they do without one (IEEE 1800-2023 21.2.1.1). +#[test] +fn later_formats_keep_default_conversions_of_locals() { + let source = r#" + module Top; + initial begin + string s; + real r; + s = "text"; + r = 1.5; + $write(s, r, "\n"); + $write("", s, r, "", "\n"); + end + endmodule + "#; + let mut sim = celox::Simulation::from_sv_sources(vec![(source, Path::new("locals.sv"))], "Top") + .build() + .unwrap(); + sim.run_until(0).unwrap(); + let messages: Vec<_> = sim + .drain_runtime_events() + .into_iter() + .map(|event| match event { + celox::RuntimeEvent::Write { message } => message, + other => panic!("{other:?}"), + }) + .collect(); + assert_eq!(messages.len(), 2); + assert_eq!(messages[0], messages[1]); + assert!( + messages[0].starts_with(b"text"), + "{:?}", + String::from_utf8_lossy(&messages[0]) + ); +} diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index a762a2f78b9..f0d706c6d46 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -32,7 +32,7 @@ synthesis and is tested at the design level. | Selects | constant and run-time bit selects and indexed part-selects (`[i]`, `[i +: W]`, `[i -: W]`), in reads and writes, in either declaration direction | | Patterns | assignment patterns for packed structs, packed arrays and unpacked arrays (`'{a, b}`, `'{x: a, default: 0}`, `'{n{a}}`, `T'{...}`) | | Dynamic containers | one-dimensional dynamic arrays, queues (including bounded queues), and associative arrays with integral or string keys; element access, value assignment, equality, `foreach` and built-in container methods. See [dynamic containers](#dynamic-containers) | -| Strings | `string` variables, function arguments and results: assignment of strings, string literals and casts (`string'(x)`), `==`, `!=` and ordering comparisons, concatenation and replication (with a run-time count), character reads and writes (`s[i]`), and the methods `len`, `getc`, `putc`, `toupper`, `tolower`, `compare`, `icompare`, `substr`, `atoi` / `atohex` / `atooct` / `atobin` and `itoa` / `hextoa` / `octtoa` / `bintoa`; `%s` and format-less display of string values; text formatted by `$sformatf` / `$sformat`. See [strings](#strings) | +| Strings | `string` variables, function arguments and results: assignment of strings, string literals and casts (`string'(x)`), `==`, `!=` and ordering comparisons, concatenation and replication (with a run-time count), character reads and writes (`s[i]`), and the methods `len`, `getc`, `putc`, `toupper`, `tolower`, `compare`, `icompare`, `substr`, `atoi` / `atohex` / `atooct` / `atobin` and `itoa` / `hextoa` / `octtoa` / `bintoa`; `%s` and format-less display of string values; text formatted by `$sformatf` / `$sformat` / `$swrite`. See [strings](#strings) | | Classes | classes declared in a module, a package or the compilation unit: properties of 2-state and 4-state integral types up to 64 bits (4-state properties start as X and keep X/Z bits), `string` and class handle types, plus dynamic arrays, queues and associative arrays, with initializers; `new` with and without arguments, implicit and explicit constructors; methods (`function` and `task`, also `extern` with an out-of-block body) called through a handle or unqualified inside the class; `this`, `null`, handle assignment and comparison; inheritance of properties and methods, with base constructors called by `super.new(...)` or `extends Base(...)`; `super.` members; virtual methods, abstract (`virtual`) classes and pure virtual methods; classes that implement interface classes and method calls through interface class handles; `$cast` of class handles, as a function and as a task; static properties and methods; `C::` scope resolution of static members and `C::new`; arrays of handles; parameterized classes with value and type parameters, parameters read through a handle or `C#(...)::`, typedefs of classes and interface classes and `C::T`; named constructor arguments; shallow copies (`new h`). See [classes](#classes) | | Parameters | integral parameters and overrides preserving widths beyond 128 bits and X/Z values, and parameters of unpacked array or packed struct type given by an assignment pattern (constant tables), including unpacked-array pattern overrides | @@ -318,7 +318,7 @@ waits zero. | Simulation time | `$time`, `$stime` and `$realtime` in clocked and combinational processes, continuous assignments, `initial` blocks and their subroutines | | Sampled values | `$sampled` in processes, combinational logic and the subroutines they call; `$past`, `$rose`, `$fell`, `$stable` and `$changed` in edge-triggered processes whose clock they infer and the subroutines those call; see [Sampled values](#sampled-values) | | System tasks | `$printtimescale`, `$display`, `$write` and their `b` / `o` / `h` forms, `$error`, `$warning`, `$info`, `$fatal`, `$finish`, `$stop`, `$exit` in `always` processes, subroutines and `initial` blocks; `$readmemh` / `$readmemb` there and in `initial` blocks; Veryl's `$assert` and `$assert_continue` | -| Runtime I/O | `$test$plusargs`, `$value$plusargs`, `$fopen`, `$fclose`, `$fdisplay` / `$fwrite` and radix variants, `$writememh` / `$writememb`, `$sformatf` / `$sformat` (see [Formatted output to strings](#formatted-output-to-strings)), and [VCD controls](./vcd#systemverilog-source-controls) in timed processes | +| Runtime I/O | `$test$plusargs`, `$value$plusargs`, `$fopen`, `$fclose`, `$fdisplay` / `$fwrite` and radix variants, `$writememh` / `$writememb`, `$sformatf` / `$sformat` / `$swrite` and its radix variants (see [Formatted output to strings](#formatted-output-to-strings)), and [VCD controls](./vcd#systemverilog-source-controls) in timed processes | | State | two-state and four-state simulation | Every construct above is covered by tests that compare the result with a @@ -1147,13 +1147,15 @@ be checkpointed; `$fscanf` uses external file state and prevents checkpoints. `$sformatf(format, args...)` returns, as a `string`, the text `$write` prints for the same format and arguments, and `$sformat(output, format, args...)` -assigns it to `output` (IEEE 1800-2023 21.3.3). Every conversion of `$display` +assigns it to `output` (IEEE 1800-2023 21.3.3). `$swrite(output, args...)` and +its `b` / `o` / `h` forms assign what `$write` and its radix forms print for +the same arguments. Every conversion of `$display` is available, with the same field widths, X/Z digits and `%t` scaling. `$sformatf` can appear in any expression of a procedural statement, including function results, arguments, concatenations and conditional operands. The format can be a string literal or, evaluated when the call runs, a `string` or integral -value. The output of `$sformat` must be a `string` variable or class property; -integral outputs, `%p` and the `$swrite` family are unsupported. +value. The output of `$sformat` and `$swrite` must be a `string` variable or +class property; integral outputs and `%p` are unsupported. Each call with conversions is a host request of a timed `Simulation`, like the file output tasks below; a format without conversions and arguments is a