diff --git a/conformance/sv-tests/expected.tsv b/conformance/sv-tests/expected.tsv index dd7fd87a78c..b4e64f909ce 100644 --- a/conformance/sv-tests/expected.tsv +++ b/conformance/sv-tests/expected.tsv @@ -1833,22 +1833,22 @@ generated/binary_op/11.4.8--binary_op_bit_xor.sv 2state pass generated/binary_op/11.4.8--binary_op_bit_xor.sv 4state pass generated/easyUVM/top.sv 2state fail generated/easyUVM/top.sv 4state fail -generated/encapsulation/8.18--inherited_local_from_inside.sv 2state fail -generated/encapsulation/8.18--inherited_local_from_inside.sv 4state fail -generated/encapsulation/8.18--inherited_local_from_outside.sv 2state fail -generated/encapsulation/8.18--inherited_local_from_outside.sv 4state fail +generated/encapsulation/8.18--inherited_local_from_inside.sv 2state pass +generated/encapsulation/8.18--inherited_local_from_inside.sv 4state pass +generated/encapsulation/8.18--inherited_local_from_outside.sv 2state pass +generated/encapsulation/8.18--inherited_local_from_outside.sv 4state pass generated/encapsulation/8.18--inherited_prot_from_inside.sv 2state pass generated/encapsulation/8.18--inherited_prot_from_inside.sv 4state pass -generated/encapsulation/8.18--inherited_prot_from_outside.sv 2state fail -generated/encapsulation/8.18--inherited_prot_from_outside.sv 4state fail +generated/encapsulation/8.18--inherited_prot_from_outside.sv 2state pass +generated/encapsulation/8.18--inherited_prot_from_outside.sv 4state pass generated/encapsulation/8.18--local_from_inside.sv 2state pass generated/encapsulation/8.18--local_from_inside.sv 4state pass -generated/encapsulation/8.18--local_from_outside.sv 2state fail -generated/encapsulation/8.18--local_from_outside.sv 4state fail +generated/encapsulation/8.18--local_from_outside.sv 2state pass +generated/encapsulation/8.18--local_from_outside.sv 4state pass generated/encapsulation/8.18--prot_from_inside.sv 2state pass generated/encapsulation/8.18--prot_from_inside.sv 4state pass -generated/encapsulation/8.18--prot_from_outside.sv 2state fail -generated/encapsulation/8.18--prot_from_outside.sv 4state fail +generated/encapsulation/8.18--prot_from_outside.sv 2state pass +generated/encapsulation/8.18--prot_from_outside.sv 4state pass generated/equality_operators_sim/11.4.5--equality_operator_0.sv 2state fail generated/equality_operators_sim/11.4.5--equality_operator_0.sv 4state fail generated/equality_operators_sim/11.4.5--equality_operator_1.sv 2state fail diff --git a/crates/celox-sv-analyzer/src/ast/classes.rs b/crates/celox-sv-analyzer/src/ast/classes.rs index 467292a8c8e..4d60ddf1d3c 100644 --- a/crates/celox-sv-analyzer/src/ast/classes.rs +++ b/crates/celox-sv-analyzer/src/ast/classes.rs @@ -58,6 +58,8 @@ impl Property { #[derive(Debug, Clone, PartialEq, Eq)] pub(super) struct StaticProperty { pub name: String, + pub local: bool, + pub protected: bool, /// The class that declares the property. pub owner: String, pub r#type: Type, @@ -460,6 +462,8 @@ pub(super) fn class( if property.qualifiers.is_static { statics.retain(|known| known.name != property_name); statics.push(StaticProperty { + local: property.qualifiers.local, + protected: property.qualifiers.protected, variable: Class::subroutine_name(name, &property_name), name: property_name, owner: name.to_owned(), diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding.rs b/crates/celox-sv-analyzer/src/ast/expression_binding.rs index aa217e1c1b2..dc6bc26f503 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding.rs @@ -16,9 +16,9 @@ pub(super) use direct::{ pub(super) use lvalues::{net_lvalue, variable_lvalue}; pub(super) use objects::{ Cast as ObjectCast, Receiver as ObjectReceiver, cast as object_cast, - check_assignment as check_handle_assignment, constructor as object_constructor, - method as object_method, property as object_property, rand_mode_call as object_rand_mode_call, - receiver as object_receiver, this as object_this, + check_access as check_member_access, check_assignment as check_handle_assignment, + constructor as object_constructor, method as object_method, property as object_property, + rand_mode_call as object_rand_mode_call, receiver as object_receiver, this as object_this, }; pub(super) use strings::{ call as string_call, method as string_method, native_string, to_string as string_operand, 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 1c91118b142..c5417adf83e 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs @@ -53,6 +53,38 @@ pub(in crate::ast) fn native_class( property.r#type.class().map(str::to_owned) } +/// Access depends on the lexical class, not the class of the receiver (8.18). +pub(in crate::ast) fn check_access( + tree: &AnalysisContext<'_>, + dimensions: &PackedDimensions, + owner: &str, + name: &str, + local: bool, + protected: bool, +) -> Converted<()> { + if !local && !protected { + return Ok(()); + } + if let Some(scope) = dimensions.class_scope.as_deref() { + if scope == owner + || (!local + && class(tree, dimensions, scope)?.derives_from( + tree, + owner, + &dimensions.const_env, + &dimensions.type_aliases, + )) + { + return Ok(()); + } + } + Err(AnalyzerError::InaccessibleClassMember { + owner: owner.to_owned(), + name: name.to_owned(), + visibility: if local { "local" } else { "protected" }, + }) +} + /// The class whose method is being bound, whose properties and methods /// unqualified names may refer to. pub(in crate::ast) fn scope_class(dimensions: &PackedDimensions) -> Option { @@ -115,9 +147,20 @@ pub(in crate::ast) fn static_property( let Some(class_name) = class_name else { return Ok(None); }; - Ok(class(tree, dimensions, &class_name)? - .static_property(&instances::normalize_identifier(&name.spelling)) - .map(|property| property.variable.clone())) + let class = class(tree, dimensions, &class_name)?; + let Some(property) = class.static_property(&instances::normalize_identifier(&name.spelling)) + else { + return Ok(None); + }; + check_access( + tree, + dimensions, + &property.owner, + &property.name, + property.local, + property.protected, + )?; + Ok(Some(property.variable.clone())) } /// The property that native expression `id` names, `h.p` or an unqualified @@ -157,9 +200,28 @@ pub(in crate::ast) fn property( _ => return Ok(None), }; let class = class(tree, dimensions, &class_name)?; - let Some(property) = class.property(&instances::normalize_identifier(&name.spelling)) else { + let name = instances::normalize_identifier(&name.spelling); + let Some(property) = class.property(&name) else { + if let Some(property) = class.static_property(&name) { + check_access( + tree, + dimensions, + &property.owner, + &property.name, + property.local, + property.protected, + )?; + } return Ok(None); }; + check_access( + tree, + dimensions, + &property.owner, + &property.name, + property.local, + property.protected, + )?; if receiver.is_none() && dimensions.get(THIS).is_none() { return Err(unsupported(format!( "non-static property `{}` in a static method", @@ -202,8 +264,26 @@ pub(in crate::ast) fn unqualified_property( }; let class = class(tree, dimensions, &class_name)?; let Some(property) = class.property(name) else { + if let Some(property) = class.static_property(name) { + check_access( + tree, + dimensions, + &property.owner, + &property.name, + property.local, + property.protected, + )?; + } return Ok(None); }; + check_access( + tree, + dimensions, + &property.owner, + &property.name, + property.local, + property.protected, + )?; if dimensions.get(THIS).is_none() { return Err(unsupported(format!( "non-static property `{name}` in a static method" @@ -300,6 +380,14 @@ pub(in crate::ast) fn method( let Some(method) = class.method(&method_name) else { return Ok(None); }; + check_access( + tree, + dimensions, + &method.owner, + &method.name, + method.qualifiers.local, + method.qualifiers.protected, + )?; if through_super && method.is_pure() { return Err(unsupported(format!( "pure virtual method `{}` called through `super`", @@ -485,6 +573,16 @@ pub(in crate::ast) fn constructor( _ => return Ok(None), }; let class = class(tree, dimensions, &class_name)?; + if let Some(method) = class.method("new") { + check_access( + tree, + dimensions, + &method.owner, + &method.name, + method.qualifiers.local, + method.qualifiers.protected, + )?; + } if class.is_abstract { return Err(unsupported(format!( "object of abstract class `{class_name}`" @@ -674,28 +772,12 @@ fn check_random_access( dimensions: &PackedDimensions, property: &classes::Property, ) -> Converted<()> { - let scope = scope_class(dimensions); - let accessible = if property.local { - scope.as_deref() == Some(&property.owner) - } else if property.protected { - scope - .and_then(|name| class(tree, dimensions, &name).ok()) - .is_some_and(|class| { - class.derives_from( - tree, - &property.owner, - &dimensions.const_env, - &dimensions.type_aliases, - ) - }) - } else { - true - }; - if !accessible { - return Err(unsupported(format!( - "randomization access to non-public property `{}`", - property.name - ))); - } - Ok(()) + check_access( + tree, + dimensions, + &property.owner, + &property.name, + property.local, + property.protected, + ) } diff --git a/crates/celox-sv-analyzer/src/ast/procedural.rs b/crates/celox-sv-analyzer/src/ast/procedural.rs index 17604d9017c..ec9374ac1a0 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural.rs @@ -283,6 +283,11 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { .push(entry); } for property in &class.statics { + // A base's local static is not visible in the derived class (8.18). + // Keep it out of the alias table so binding can diagnose its use. + if property.local && property.owner != class.name { + continue; + } let entry = self.take_binding( &property.name, Some(property.variable.clone()), @@ -2468,6 +2473,16 @@ impl BodyBuilder<'_, '_, '_> { &self.dims.const_env, &self.dims.type_aliases, )?; + if let Some(method) = base.method("new") { + expression_binding::check_member_access( + self.tree, + &self.dims, + &method.owner, + &method.name, + method.qualifiers.local, + method.qualifiers.protected, + )?; + } let formals = base.constructor_formals(native); if arguments.len() > formals { return Err(unsupported(format!( diff --git a/crates/celox-sv-analyzer/src/lib.rs b/crates/celox-sv-analyzer/src/lib.rs index 35997a2c289..09e54787e5b 100644 --- a/crates/celox-sv-analyzer/src/lib.rs +++ b/crates/celox-sv-analyzer/src/lib.rs @@ -66,6 +66,13 @@ pub enum AnalyzerError { Parse(String), #[error("Unsupported SystemVerilog construct: {0}")] Unsupported(String), + /// A class member is inaccessible from the lexical scope (IEEE 1800-2023 8.18). + #[error("{visibility} class member `{owner}::{name}` is not accessible from this scope")] + InaccessibleClassMember { + owner: String, + name: String, + visibility: &'static str, + }, /// A dotted name whose first component names no variable or interface /// of the scope: a hierarchical name (IEEE 1800-2023 23.6) that the /// caller did not resolve to a signal of another instance. diff --git a/crates/celox-sv-analyzer/src/tests.rs b/crates/celox-sv-analyzer/src/tests.rs index c3c271322e4..5c6a2c29d8c 100644 --- a/crates/celox-sv-analyzer/src/tests.rs +++ b/crates/celox-sv-analyzer/src/tests.rs @@ -6628,8 +6628,8 @@ fn class_randomize_rejects_unsupported_semantics() { "not an instance property", ), ("const int x = 1;", "c.randomize(x)", "const"), - ("local int x;", "c.randomize(x)", "non-public"), - ("protected int x;", "c.randomize(x)", "non-public"), + ("local int x;", "c.randomize(x)", "not accessible"), + ("protected int x;", "c.randomize(x)", "not accessible"), ("rand int x;", "c.rand_mode()", "getter requires"), ("int x;", "c.x.rand_mode()", "rand or randc"), ( @@ -6822,3 +6822,140 @@ fn class_randc_checks_domain_limits() { } } } + +#[test] +fn class_visibility_rejects_inaccessible_members() { + for visibility in ["local", "protected"] { + for member in [ + "int x;", + "static int x;", + "function int x(); return 1; endfunction", + "static function int x(); return 1; endfunction", + ] { + let access = if member.contains("function") { + "c.x()" + } else { + "c.x" + }; + for derived in [false, true] { + let declaration = if derived { + "class D extends C; endclass D c;" + } else { + "C c;" + }; + let source = format!( + "module Top; class C; {visibility} {member} endclass {declaration} int result; initial begin c=new; result={access}; end endmodule" + ); + let error = analyze_source(&source, Path::new("visibility.sv")).unwrap_err(); + assert!( + matches!(&error, AnalyzerError::InaccessibleClassMember { owner, .. } if owner == "C"), + "{source}: {error}" + ); + } + } + } + for member in [ + "int x;", + "static int x;", + "function int x(); return 1; endfunction", + "static function int x(); return 1; endfunction", + ] { + let access = if member.contains("function") { + "x()" + } else { + "x" + }; + for prefix in ["", "this.", "super."] { + let source = format!( + "module Top; class C; local {member} endclass class D extends C; function int read(); return {prefix}{access}; endfunction endclass D c; int result; initial begin c=new; result=c.read(); end endmodule" + ); + let error = analyze_source(&source, Path::new("visibility.sv")).unwrap_err(); + assert!( + matches!(&error, AnalyzerError::InaccessibleClassMember { owner, .. } if owner == "C"), + "{source}: {error}" + ); + } + } + for access in ["x=2", "x++"] { + let source = format!( + "module Top; class C; local static int x; endclass class D extends C; function void write(); {access}; endfunction endclass D c; initial begin c=new; c.write(); end endmodule" + ); + let error = analyze_source(&source, Path::new("visibility.sv")).unwrap_err(); + assert!( + matches!(&error, AnalyzerError::InaccessibleClassMember { owner, .. } if owner == "C"), + "{source}: {error}" + ); + } + for access in ["c.x=2", "c.x++", "C::x=2"] { + let source = format!( + "module Top; class C; local static int x; endclass C c; initial begin c=new; {access}; end endmodule" + ); + let error = analyze_source(&source, Path::new("visibility.sv")).unwrap_err(); + assert!( + matches!(&error, AnalyzerError::InaccessibleClassMember { owner, .. } if owner == "C"), + "{source}: {error}" + ); + } +} + +#[test] +fn class_visibility_accepts_lexical_access_and_shadowing() { + for member in [ + "int x;", + "static int x;", + "function int x(); return 1; endfunction", + "static function int x(); return 1; endfunction", + ] { + let access = if member.contains("function") { + "x()" + } else { + "x" + }; + for visibility in ["local", "protected"] { + let source = format!( + "module Top; class C; {visibility} {member} function int read(C other); return other.{access}; endfunction endclass class D extends C; endclass D c; int result; initial begin c=new; result=c.read(c); end endmodule" + ); + analyze_source(&source, Path::new("visibility.sv")) + .unwrap_or_else(|e| panic!("{source}: {e}")); + } + for prefix in ["", "this.", "super."] { + let source = format!( + "module Top; class C; protected {member} endclass class D extends C; function int read(); return {prefix}{access}; endfunction endclass D c; int result; initial begin c=new; result=c.read(); end endmodule" + ); + analyze_source(&source, Path::new("visibility.sv")) + .unwrap_or_else(|e| panic!("{source}: {e}")); + } + } + for storage in ["", "static"] { + let source = format!( + "module Top; class C; local {storage} int x; endclass class D extends C; int x; function int read(int x); return x; endfunction function int own(); return x; endfunction endclass D c; int result; initial begin c=new; c.x=2; result=c.own(); end endmodule" + ); + analyze_source(&source, Path::new("visibility.sv")).unwrap(); + } +} + +#[test] +fn class_visibility_checks_constructors() { + for visibility in ["local", "protected"] { + let source = format!( + "module Top; class C; {visibility} function new(); endfunction endclass C c; initial c=new; endmodule" + ); + let error = analyze_source(&source, Path::new("visibility.sv")).unwrap_err(); + assert!( + matches!(&error, AnalyzerError::InaccessibleClassMember { owner, .. } if owner == "C"), + "{source}: {error}" + ); + let source = format!( + "module Top; class C; {visibility} function new(); endfunction endclass class D extends C; endclass D c; initial c=new; endmodule" + ); + let result = analyze_source(&source, Path::new("visibility.sv")); + if visibility == "local" { + assert!(matches!( + result.unwrap_err(), + AnalyzerError::InaccessibleClassMember { .. } + )); + } else { + result.unwrap(); + } + } +} diff --git a/crates/celox-vpi/src/bin/celox.rs b/crates/celox-vpi/src/bin/celox.rs index 0f04453b598..a996e6eb580 100644 --- a/crates/celox-vpi/src/bin/celox.rs +++ b/crates/celox-vpi/src/bin/celox.rs @@ -58,6 +58,15 @@ struct RunArgs { #[command(flatten)] save_state: SaveStateArgs, + + /// Pass a plusarg such as `+iterations=9` to a SystemVerilog testbench + /// (repeatable); a positional argument starting with `+` does the same. + /// They reach `$test$plusargs` and `$value$plusargs` in command-line + /// order. + #[arg(long = "plusarg", value_name = "+ARG", allow_hyphen_values = true)] + plusarg: Vec, + #[arg(skip)] + plusargs: Vec, } /// When `celox run` saves state files for `celox state dump/diff`. @@ -98,6 +107,7 @@ struct RunConfig { opt_level: celox::OptLevel, max_steps: u64, save_state: SaveStateArgs, + plusargs: Vec, } fn resolve_design(arguments: DesignArgs) -> Design { @@ -111,11 +121,22 @@ fn resolve_design(arguments: DesignArgs) -> Design { fn cli_from_matches(matches: &clap::ArgMatches) -> Result { let mut cli = Cli::from_arg_matches(matches)?; match &mut cli.command { - CliCommand::Run(arguments) => arguments.design.capture_input_order( - matches + CliCommand::Run(arguments) => { + let matches = matches .subcommand_matches("run") - .expect("parsed run command"), - ), + .expect("parsed run command"); + let mut plusargs = arguments.design.take_plusargs(matches); + plusargs.extend( + matches + .indices_of("plusarg") + .into_iter() + .flatten() + .zip(std::mem::take(&mut arguments.plusarg)), + ); + plusargs.sort_by_key(|&(position, _)| position); + arguments.plusargs = plusargs.into_iter().map(|(_, plusarg)| plusarg).collect(); + arguments.design.capture_input_order(matches); + } CliCommand::Vpi(VpiArgs { command: VpiCommand::Build(arguments), }) => { @@ -153,6 +174,7 @@ fn resolve_run_config(arguments: RunArgs) -> RunConfig { .unwrap_or(1_000_000), design, save_state: arguments.save_state, + plusargs: arguments.plusargs, } } @@ -176,6 +198,9 @@ fn run_testbench(arguments: RunArgs) -> Result<(), String> { { return Err("pass .sv/.v sources, or Veryl project sources".into()); } + if !arguments.plusargs.is_empty() { + return Err("plusargs currently require a SystemVerilog testbench".into()); + } if !arguments.save_state.is_empty() { return Err( "--save-state-on and --save-state-at-time currently require a SystemVerilog testbench" @@ -206,7 +231,8 @@ fn run_sv(arguments: RunConfig) -> Result<(), String> { .opt_level(arguments.opt_level) .diagnostic_policy(arguments.design.diagnostics.clone()) .sv_timescale(arguments.design.timescale) - .signal_access(arguments.design.signal_access.clone()); + .signal_access(arguments.design.signal_access.clone()) + .plusargs(arguments.plusargs.iter().cloned()); let builder = arguments.design.apply_parameters(builder); let max_steps = if arguments.execution.unlimited { u64::MAX diff --git a/crates/celox-vpi/src/bin/celox/project.rs b/crates/celox-vpi/src/bin/celox/project.rs index 99fa3b8341b..6ef505b7af2 100644 --- a/crates/celox-vpi/src/bin/celox/project.rs +++ b/crates/celox-vpi/src/bin/celox/project.rs @@ -10,7 +10,8 @@ use serde::Deserialize; #[derive(Args, Default)] pub(super) struct DesignArgs { - /// Ordered SV sources, or one Veryl project entry file. + /// Ordered SV sources, or one Veryl project entry file. For `run`, an + /// argument starting with `+` is a plusarg instead. pub sources: Vec, /// Select a Veryl source relative to --project (repeatable). #[arg(long = "source-file")] @@ -78,6 +79,10 @@ pub(super) struct DesignArgs { top: Option, #[arg(skip)] input_order: Vec, + /// The command-line positions of `sources`, once plusargs are taken out + /// of them. + #[arg(skip)] + source_positions: Option>, } enum Input { @@ -163,21 +168,52 @@ pub(super) struct Design { } impl DesignArgs { + /// Take the positional arguments starting with `+` out of the sources, + /// with their command-line positions. + pub fn take_plusargs(&mut self, matches: &clap::ArgMatches) -> Vec<(usize, String)> { + let positions = matches + .indices_of("sources") + .map(Iterator::collect::>) + .unwrap_or_default(); + let mut plusargs = Vec::new(); + let mut sources = Vec::new(); + let mut source_positions = Vec::new(); + for (source, position) in std::mem::take(&mut self.sources).into_iter().zip(positions) { + match source.to_str() { + Some(argument) if argument.starts_with('+') => { + plusargs.push((position, argument.to_string())) + } + _ => { + sources.push(source); + source_positions.push(position); + } + } + } + self.sources = sources; + self.source_positions = Some(source_positions); + plusargs + } + pub fn capture_input_order(&mut self, matches: &clap::ArgMatches) { let mut inputs = Vec::new(); for (id, is_list) in [("sources", false), ("filelists", true)] { - if let Some(indices) = matches.indices_of(id) { - inputs.extend(indices.enumerate().map(|(offset, position)| { - ( - position, - if is_list { - Input::Filelist(offset) - } else { - Input::Source(offset) - }, - ) - })); - } + let indices: Vec = match (id, &self.source_positions) { + ("sources", Some(positions)) => positions.clone(), + _ => matches + .indices_of(id) + .map(Iterator::collect) + .unwrap_or_default(), + }; + inputs.extend(indices.into_iter().enumerate().map(|(offset, position)| { + ( + position, + if is_list { + Input::Filelist(offset) + } else { + Input::Source(offset) + }, + ) + })); } inputs.sort_by_key(|(position, _)| *position); self.input_order = inputs.into_iter().map(|(_, input)| input).collect(); diff --git a/crates/celox-vpi/tests/run_cli.rs b/crates/celox-vpi/tests/run_cli.rs index 1c7365115b8..41b68e1aa44 100644 --- a/crates/celox-vpi/tests/run_cli.rs +++ b/crates/celox-vpi/tests/run_cli.rs @@ -710,3 +710,50 @@ endmodule "{output:?}" ); } + +#[cfg(feature = "systemverilog")] +#[test] +fn sv_plusargs_reach_the_testbench_in_order() { + let source = r#"module Top; + int iterations; + logic [8*8-1:0] mode; + int verbose; + initial begin + if (!$value$plusargs("iterations=%d", iterations)) $fatal(1, "no iterations"); + if (!$value$plusargs("mode=%s", mode)) $fatal(1, "no mode"); + verbose = $test$plusargs("verbose"); + $display("iterations=%0d mode=%0s verbose=%0d", iterations, mode, verbose); + end +endmodule +"#; + for backend in ["tiered", "interpreter", "native"] { + // The first match wins, so the order of the two kinds matters. + let output = run( + &[("top.sv", source)], + &[ + "+iterations=9", + "--plusarg", + "+mode=fast", + "+iterations=7000", + "--plusarg=+verbose", + "--backend", + backend, + ], + ); + assert!(output.status.success(), "{backend}: {output:?}"); + assert_eq!( + String::from_utf8_lossy(&output.stdout), + "iterations=9 mode=fast verbose=1\n", + "{backend}" + ); + } + let output = run( + &[("top.sv", source)], + &["--plusarg", "+mode=slow", "+iterations=7000"], + ); + assert!(output.status.success(), "{output:?}"); + assert_eq!( + String::from_utf8_lossy(&output.stdout), + "iterations=7000 mode=slow verbose=0\n" + ); +} diff --git a/docs/guide/cocotb.md b/docs/guide/cocotb.md index 713f6c42825..808ca646789 100644 --- a/docs/guide/cocotb.md +++ b/docs/guide/cocotb.md @@ -60,6 +60,14 @@ limit before completion fails the command. This limit does not bound compilation or work within a single step/tick; use an external process timeout when a wall clock limit is needed. `--unlimited` removes the step/tick limit. Source languages cannot be mixed in one invocation. +For a SystemVerilog testbench, a positional argument starting with `+` (or +`--plusarg +ARG`, repeatable) is a plusarg, not a source: `$test$plusargs` and +`$value$plusargs` see them in command-line order, on every backend. + +```sh +celox run tb.v --top tb +iterations=9 --plusarg +trace +``` + ## Select execution and collect measurements `celox run` accepts `--threads N` (1–64, default 1) and `--four-state` for both diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index b3059ada2d8..e76ef25edc3 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -741,7 +741,8 @@ edge-triggered `always` / `always_ff` processes, including their subroutines. These calls are unsupported in combinational procedures. A bare `Simulator` rejects edge procedures that need this timed execution. -Supply ordered command-line arguments with `.plusargs(["+COUNT=12", "+TRACE"])`. +Supply ordered command-line arguments with `.plusargs(["+COUNT=12", "+TRACE"])`, +or as `+` arguments of [`celox run`](./cocotb.md). `$test$plusargs` matches a prefix; `$value$plusargs` supports integer conversions and `%s` into packed integral variables. The first matching argument wins, and an unmatched value query preserves its destination. Real conversions and dynamic diff --git a/docs/ja/guide/cocotb.md b/docs/ja/guide/cocotb.md index b2318bdef50..c0fb56ef5d9 100644 --- a/docs/ja/guide/cocotb.md +++ b/docs/ja/guide/cocotb.md @@ -54,6 +54,13 @@ Verylでは完了前にtick上限に達すると失敗します。 コンパイルや1ステップ・tick内の処理時間は制限しないため、実時間の制限が必要な場合は 外部のタイムアウト機能を使ってください。1回の実行で言語を混在させることはできません。 +SVのtestbenchでは、`+`で始まる位置引数(または繰り返し指定できる`--plusarg +ARG`)はソースではなくplusargです。 +`$test$plusargs`と`$value$plusargs`はコマンドラインの順に参照します(全バックエンド対応)。 + +```sh +celox run tb.v --top tb +iterations=9 --plusarg +trace +``` + 両言語とも`--backend native|tiered|interpreter|cranelift|wasm`で実行方式を選べます(既定native)。 tieredはインタープリターで開始し、待機中のイベントを保ちながら生成コードへ移行します。 両言語とも`--threads N`(1〜64、既定1)で並列度を指定できます。 diff --git a/docs/ja/guide/systemverilog-reference.md b/docs/ja/guide/systemverilog-reference.md index 3396d7837ff..aa70dec1646 100644 --- a/docs/ja/guide/systemverilog-reference.md +++ b/docs/ja/guide/systemverilog-reference.md @@ -536,7 +536,7 @@ program の書き込みが駆動する設計の連続代入と組み合わせ論 ホスト I/O には `Simulation::from_sv_sources` を使います。組合せプロセスからは 未対応です。時間付き実行が必要なエッジプロセスを `Simulator` で構築するとエラーになります。 -引数は `.plusargs(["+COUNT=12", "+TRACE"])` で順序を保って渡します。 +引数は `.plusargs(["+COUNT=12", "+TRACE"])`、または [`celox run`](./cocotb.md) の `+` 引数で順序を保って渡します。 `$test$plusargs` は前方一致で検索し、`$value$plusargs` は整数変換と packed 整数変数への `%s` を扱います。最初に一致した引数を使い、未一致の場合は書き込み先の値を保持します。 real 変換と動的 string は未対応です。