Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions conformance/sv-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ the assertion. The [reviewed full CI run](https://github.com/celox-sim/celox/act
contains 2054 case/mode verdicts; these are the only two changed rows, and all
verdicts match the updated expectations.

Accepting undriven nets updates both rows for
`5.6.4--compiler-directives-pragma` from fail to pass. Its `protected_wire`
has no driver and now elaborates with the standard net default (IEEE 1800-2023
6.6 and 6.7.1). The official runner selects elaboration for this probe; runtime
high-impedance values are checked by the shared undriven-net simulation cases.
The [reviewed CI run](https://github.com/celox-sim/celox/actions/runs/40112270471)
changes only these two verdicts across 2,054 mode runs.

The report contains each case’s state mode, verdict, selected execution mode,
tags, tool return code and path to the official log. The output directory retains
both the official log and runner diagnostics for each case and state mode.
Expand Down
4 changes: 2 additions & 2 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,8 @@ chapter-5/5.6.4--compiler-directives-define.sv 2state pass
chapter-5/5.6.4--compiler-directives-define.sv 4state pass
chapter-5/5.6.4--compiler-directives-include.sv 2state pass
chapter-5/5.6.4--compiler-directives-include.sv 4state pass
chapter-5/5.6.4--compiler-directives-pragma.sv 2state fail
chapter-5/5.6.4--compiler-directives-pragma.sv 4state fail
chapter-5/5.6.4--compiler-directives-pragma.sv 2state pass
chapter-5/5.6.4--compiler-directives-pragma.sv 4state pass
chapter-5/5.6.4--compiler-directives-preprocessor-macro_0.sv 2state skip
chapter-5/5.6.4--compiler-directives-preprocessor-macro_0.sv 4state skip
chapter-5/5.6.4--compiler-directives-preprocessor-macro_1.sv 2state pass
Expand Down
14 changes: 4 additions & 10 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,19 +592,19 @@ fn validate_specialized_instance_net_drivers(
.signals()
.iter()
.filter(|signal| signal.is_net())
.map(|signal| (signal.name(), true))
.map(|signal| signal.name())
.chain(
module
.source
.ports()
.iter()
.filter(|port| port.is_net())
.map(|port| (port.name(), false)),
.map(|port| port.name()),
);
for (signal_name, require_driver) in net_names {
for signal_name in net_names {
let child_driver_ranges =
child_output_driver_ranges(module, signal_name, module_ids, modules);
validate_net_driver_ranges(module, signal_name, &child_driver_ranges, require_driver)?;
validate_net_driver_ranges(module, signal_name, &child_driver_ranges)?;
}

let variable_names = module
Expand Down Expand Up @@ -768,7 +768,6 @@ fn validate_net_driver_ranges(
module: &LoweredSvModule,
signal_name: &str,
child_driver_ranges: &[(usize, Option<(i128, i128)>)],
require_driver: bool,
) -> Result<(), sv::AnalyzerError> {
let local_drivers = local_driver_ranges(
&module.source,
Expand Down Expand Up @@ -803,11 +802,6 @@ fn validate_net_driver_ranges(
"multiple net drivers for `{signal_name}`"
)));
}
if require_driver && child_driver_ranges.is_empty() && local_drivers.is_empty() {
return Err(sv::AnalyzerError::Unsupported(format!(
"undriven net declaration `{signal_name}`"
)));
}
Ok(())
}

Expand Down
33 changes: 1 addition & 32 deletions crates/celox-sv-analyzer/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ use ff_process::ff_processes_from_scope;
use functions::{functions_from_scope, procedural_truth_condition};
use inlining::{expand_expr_calls, expr_signedness_with_return_types, substitute_expr_idents};
pub(crate) use instances::normalize_identifier;
use instances::{collect_connected_nets, expr_ident_name, instances_from_scope};
use instances::{expr_ident_name, instances_from_scope};
use parameters::{
apply_parameter_overrides, coerce_const_parameter_value, const_env_from_parameters,
const_expr_from_i128, const_expr_to_expr, enum_member_constants_from_scope,
Expand Down Expand Up @@ -1266,37 +1266,6 @@ impl Module {
},
);
}
let procedurally_written = procedural::written_names(
comb_processes
.iter()
.flat_map(|process| process.body.iter())
.chain(ff_processes.iter().flat_map(|process| process.body.iter())),
);
let mut connected_nets = HashSet::default();
for connection in instances
.iter()
.flat_map(|instance| instance.port_connections())
{
if let Some(expr) = connection.actual_expr() {
collect_connected_nets(expr, &mut connected_nets);
}
if let Some(pattern) = connection.bound_pattern() {
pattern.visit_expressions(&mut |expr| {
collect_connected_nets(expr, &mut connected_nets)
});
}
}
if let Some(signal) = signals.iter().find(|signal| {
!imported.declarations_only
&& signal.is_net()
&& !procedurally_written.contains(signal.name())
&& !connected_nets.contains(signal.name())
}) {
return Err(AnalyzerError::Unsupported(format!(
"undriven net declaration `{}`",
signal.name()
)));
}
// A call of a name an import binds calls the package subroutine or
// DPI import. Calls of subroutines declared in a generate block were
// already bound to those.
Expand Down
22 changes: 0 additions & 22 deletions crates/celox-sv-analyzer/src/ast/bound_patterns/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,6 @@ impl BoundPattern {
Ok(())
}

pub(in crate::ast) fn visit_expressions<'a>(&'a self, visit: &mut impl FnMut(&'a Expr)) {
fn value<'a>(value: &'a Value, visit: &mut impl FnMut(&'a Expr)) {
match value {
Value::Pattern(pattern) => pattern.visit_expressions(visit),
Value::Expression { expr, .. } => visit(expr),
}
}
match &self.items {
Items::Value(expr) | Items::ArrayValue { value: expr, .. } => visit(expr),
Items::List(items) | Items::Repeat(_, items) => {
for item in items {
value(item, visit);
}
}
Items::Keyed(items) => {
for (_, item) in items {
value(item, visit);
}
}
}
}

pub(in crate::ast) fn map_expressions(&mut self, map: &mut impl FnMut(Expr) -> Expr) {
fn value(value: &mut Value, map: &mut impl FnMut(Expr) -> Expr) {
match value {
Expand Down
22 changes: 0 additions & 22 deletions crates/celox-sv-analyzer/src/ast/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,28 +298,6 @@ pub(super) fn instance_ranges(
constant_binding::unpacked_ranges(&native.dimensions, tree, env, aliases)
}

// Child port directions are resolved by the frontend adapter. Defer its net
// driver check for selected/concatenated connections as well as whole nets.
pub(super) fn collect_connected_nets<'a>(expr: &'a Expr, names: &mut HashSet<&'a str>) {
match expr {
Expr::Ident(actual) => {
names.insert(actual);
}
Expr::Select { expr, .. }
| Expr::Resize { expr, .. }
| Expr::Unary {
op: UnaryOp::ToTwoState,
expr,
} => collect_connected_nets(expr, names),
Expr::Concat(parts) => {
for part in parts {
collect_connected_nets(part, names);
}
}
_ => {}
}
}

pub(super) fn expr_ident_name(expr: &Expr) -> Option<String> {
match expr {
Expr::Ident(name) => Some(name.clone()),
Expand Down
14 changes: 9 additions & 5 deletions crates/celox-sv-analyzer/src/source_tree/tests/net_ownership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,18 @@ fn native_net_declarators_and_initializers_are_authoritative() {
assert!(source.modules()[0].signals().is_empty());
assert_eq!(source.modules()[0].assignments().len(), 1);
} else if matches!(defect, "name" | "initializer") {
let error = Source::from_syntax(&tree).unwrap_err();
let source = Source::from_syntax(&tree).unwrap();
let module = &source.modules()[0];
let undriven = if defect == "name" { "other" } else { "b" };
assert!(
error
.to_string()
.contains(&format!("undriven net declaration `{undriven}`")),
"{error}"
module
.signals()
.iter()
.any(|signal| signal.name() == undriven)
);
assert!(!module.assignments().iter().any(|assignment| {
matches!(assignment.lhs_value(), LValue::Ident(name) if name == undriven)
}));
} else {
let source = Source::from_syntax(&tree).unwrap();
let module = &source.modules()[0];
Expand Down
52 changes: 52 additions & 0 deletions crates/celox-test-suite/src/sv/cases/types.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,55 @@
(top Top)
(eval)
(assert_eq matched 1))

(case undriven_internal_nets_are_high_impedance
(four_state)
(source "undriven_internal.sv" #"
module Driver(output wire y);
assign y=1'b1;
endmodule
module Sink(input wire a, output wire y);
assign y=a;
endmodule
module Parent #(parameter ENABLE=1)(output wire y);
wire w;
if (ENABLE) Driver driver(.y(w));
Sink sink(.a(w),.y(y));
endmodule
module Top(output wire [7:0] floating,
output wire [11:0] array_values,
output wire enabled,disabled,
output bit [3:0] two_state);
wire unused;
wire [7:0] w;
wire [3:0] words[3];
assign floating=w;
assign array_values={words[2],words[1],words[0]};
assign two_state=w[3:0];
Parent #(.ENABLE(1)) a(enabled);
Parent #(.ENABLE(0)) b(disabled);
endmodule
"#)
(top Top) (eval)
(assert_eq floating (fourstate 0 0xff))
(assert_eq array_values (fourstate 0 0xfff))
(assert_eq enabled 1)
(assert_eq disabled (fourstate 0 1))
(assert_eq two_state 0))

(case undriven_internal_nets_convert_to_two_state_zero
(source "undriven_two_state.sv" #"
module Sink(input bit [7:0] a, output wire [7:0] y);
assign y=a;
endmodule
module Top(output bit [7:0] y, output bit [11:0] array_values);
wire unused;
wire [7:0] w;
wire [3:0] words[3];
Sink sink(w,y);
assign array_values={words[2],words[1],words[0]};
endmodule
"#)
(top Top) (eval)
(assert_eq y 0)
(assert_eq array_values 0))
49 changes: 1 addition & 48 deletions crates/celox/tests/frontends/systemverilog/review_regressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,29 +946,6 @@ fn coerces_ir_parameter_constants_to_their_declared_widths() {
assert_eq!(sim.get(sim.signal("y")), 1u8.into());
}

#[test]
fn validates_net_drivers_after_parameter_specialization() {
let error = cranelift_build_error(
r#"
module Driver(output logic y); assign y = 1'b1; endmodule
module Sink(input logic a); endmodule
module Child #(parameter ENABLE = 1) (output logic y);
wire w;
if (ENABLE) Driver driver(.y(w));
Sink sink(.a(w));
assign y = 1'b0;
endmodule
module Top(output logic y);
Child #(.ENABLE(0)) child(.y(y));
endmodule
"#,
);
assert!(
error.contains("undriven net declaration `w`"),
"unexpected error: {error}"
);
}

#[test]
fn applies_unsigned_coercion_to_mixed_signed_constant_comparisons() {
let source = r#"
Expand All @@ -984,23 +961,6 @@ fn applies_unsigned_coercion_to_mixed_signed_constant_comparisons() {
assert_eq!(sim.get(sim.signal("y")), 0u8.into());
}

#[test]
fn does_not_count_child_inputs_as_net_drivers() {
let error = cranelift_build_error(
r#"
module Sink(input logic a, output logic y); assign y = a; endmodule
module Top(output logic y);
wire w;
Sink sink(.a(w), .y(y));
endmodule
"#,
);
assert!(
error.contains("undriven net declaration `w`"),
"unexpected error: {error}"
);
}

#[test]
fn rejects_top_level_localparam_overrides() {
let source = r#"
Expand Down Expand Up @@ -1412,8 +1372,7 @@ fn rejects_runtime_selected_child_outputs_to_nets() {
"#,
);
assert!(
error.contains("undriven net declaration `values`")
|| error.contains("systemverilog output port lvalue connection"),
error.contains("systemverilog output port lvalue connection"),
"unexpected error: {error}"
);
}
Expand Down Expand Up @@ -5630,12 +5589,6 @@ fn rejects_constructs_that_are_not_yet_lowered() {
module Top(input logic a, b, output logic y); and (y, a, b); endmodule
"#,
),
(
"undriven net declaration `w`",
r#"
module Top(output logic y); wire w; assign y = (w === 1'bz); endmodule
"#,
),
(
"unknown or duplicate systemverilog child port connection",
r#"
Expand Down
9 changes: 9 additions & 0 deletions crates/celox/tests/frontends/systemverilog/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,12 @@ sv_backends! {
@case "types::preserves_integer_atom_state_kinds";
}
}

sv_backends! {
fn undriven_internal_nets_are_high_impedance(sim) {
@case "types::undriven_internal_nets_are_high_impedance";
}
fn undriven_internal_nets_convert_to_two_state_zero(sim) {
@case "types::undriven_internal_nets_convert_to_two_state_zero";
}
}
Loading