diff --git a/conformance/sv-tests/expected.tsv b/conformance/sv-tests/expected.tsv
index a6186810a34..404b148ae0e 100644
--- a/conformance/sv-tests/expected.tsv
+++ b/conformance/sv-tests/expected.tsv
@@ -777,18 +777,18 @@ chapter-21/21.2--write-boh.sv 2state pass
chapter-21/21.2--write-boh.sv 4state pass
chapter-21/21.2--write.sv 2state pass
chapter-21/21.2--write.sv 4state pass
-chapter-21/21.3--fdisplay-boh.sv 2state fail
-chapter-21/21.3--fdisplay-boh.sv 4state fail
-chapter-21/21.3--fdisplay.sv 2state fail
-chapter-21/21.3--fdisplay.sv 4state fail
+chapter-21/21.3--fdisplay-boh.sv 2state pass
+chapter-21/21.3--fdisplay-boh.sv 4state pass
+chapter-21/21.3--fdisplay.sv 2state pass
+chapter-21/21.3--fdisplay.sv 4state pass
chapter-21/21.3--feof.sv 2state pass
chapter-21/21.3--feof.sv 4state pass
chapter-21/21.3--ferror.sv 2state fail
chapter-21/21.3--ferror.sv 4state fail
chapter-21/21.3--fflush.sv 2state pass
chapter-21/21.3--fflush.sv 4state pass
-chapter-21/21.3--fgetc.sv 2state fail
-chapter-21/21.3--fgetc.sv 4state fail
+chapter-21/21.3--fgetc.sv 2state pass
+chapter-21/21.3--fgetc.sv 4state pass
chapter-21/21.3--fgets.sv 2state fail
chapter-21/21.3--fgets.sv 4state fail
chapter-21/21.3--file.sv 2state pass
@@ -797,16 +797,16 @@ chapter-21/21.3--fmonitor.sv 2state fail
chapter-21/21.3--fmonitor.sv 4state fail
chapter-21/21.3--fpos.sv 2state pass
chapter-21/21.3--fpos.sv 4state pass
-chapter-21/21.3--fread.sv 2state fail
-chapter-21/21.3--fread.sv 4state fail
-chapter-21/21.3--fscanf.sv 2state fail
-chapter-21/21.3--fscanf.sv 4state fail
+chapter-21/21.3--fread.sv 2state pass
+chapter-21/21.3--fread.sv 4state pass
+chapter-21/21.3--fscanf.sv 2state pass
+chapter-21/21.3--fscanf.sv 4state pass
chapter-21/21.3--fstrobe.sv 2state fail
chapter-21/21.3--fstrobe.sv 4state fail
-chapter-21/21.3--fwrite-boh.sv 2state fail
-chapter-21/21.3--fwrite-boh.sv 4state fail
-chapter-21/21.3--fwrite.sv 2state fail
-chapter-21/21.3--fwrite.sv 4state fail
+chapter-21/21.3--fwrite-boh.sv 2state pass
+chapter-21/21.3--fwrite-boh.sv 4state pass
+chapter-21/21.3--fwrite.sv 2state pass
+chapter-21/21.3--fwrite.sv 4state pass
chapter-21/21.3--sscanf.sv 2state pass
chapter-21/21.3--sscanf.sv 4state pass
chapter-21/21.3--ungetc.sv 2state fail
@@ -1579,8 +1579,8 @@ chapter-9/9.2.2.3--always_latch.sv 2state fail
chapter-9/9.2.2.3--always_latch.sv 4state fail
chapter-9/9.2.2.4--always_ff.sv 2state pass
chapter-9/9.2.2.4--always_ff.sv 4state pass
-chapter-9/9.2.3--final.sv 2state fail
-chapter-9/9.2.3--final.sv 4state fail
+chapter-9/9.2.3--final.sv 2state pass
+chapter-9/9.2.3--final.sv 4state pass
chapter-9/9.3.1--sequential_block.sv 2state pass
chapter-9/9.3.1--sequential_block.sv 4state pass
chapter-9/9.3.2--parallel_block_join.sv 2state fail
@@ -1735,46 +1735,46 @@ generated/assignment_op/11.4.1--plus_assignment.sv 2state pass
generated/assignment_op/11.4.1--plus_assignment.sv 4state pass
generated/assignment_op/11.4.1--xor_assignment.sv 2state pass
generated/assignment_op/11.4.1--xor_assignment.sv 4state pass
-generated/assignment_sim/11.4.1--and_assignment-sim-0.sv 2state fail
-generated/assignment_sim/11.4.1--and_assignment-sim-0.sv 4state fail
-generated/assignment_sim/11.4.1--and_assignment-sim-1.sv 2state fail
-generated/assignment_sim/11.4.1--and_assignment-sim-1.sv 4state fail
-generated/assignment_sim/11.4.1--div_assignment-sim-0.sv 2state fail
-generated/assignment_sim/11.4.1--div_assignment-sim-0.sv 4state fail
-generated/assignment_sim/11.4.1--div_assignment-sim-1.sv 2state fail
-generated/assignment_sim/11.4.1--div_assignment-sim-1.sv 4state fail
-generated/assignment_sim/11.4.1--log_shl_assignment-sim-0.sv 2state fail
-generated/assignment_sim/11.4.1--log_shl_assignment-sim-0.sv 4state fail
-generated/assignment_sim/11.4.1--log_shl_assignment-sim-1.sv 2state fail
-generated/assignment_sim/11.4.1--log_shl_assignment-sim-1.sv 4state fail
-generated/assignment_sim/11.4.1--log_shr_assignment-sim-0.sv 2state fail
-generated/assignment_sim/11.4.1--log_shr_assignment-sim-0.sv 4state fail
-generated/assignment_sim/11.4.1--log_shr_assignment-sim-1.sv 2state fail
-generated/assignment_sim/11.4.1--log_shr_assignment-sim-1.sv 4state fail
-generated/assignment_sim/11.4.1--minus_assignment-sim-0.sv 2state fail
-generated/assignment_sim/11.4.1--minus_assignment-sim-0.sv 4state fail
-generated/assignment_sim/11.4.1--minus_assignment-sim-1.sv 2state fail
-generated/assignment_sim/11.4.1--minus_assignment-sim-1.sv 4state fail
-generated/assignment_sim/11.4.1--mod_assignment-sim-0.sv 2state fail
-generated/assignment_sim/11.4.1--mod_assignment-sim-0.sv 4state fail
-generated/assignment_sim/11.4.1--mod_assignment-sim-1.sv 2state fail
-generated/assignment_sim/11.4.1--mod_assignment-sim-1.sv 4state fail
-generated/assignment_sim/11.4.1--mul_assignment-sim-0.sv 2state fail
-generated/assignment_sim/11.4.1--mul_assignment-sim-0.sv 4state fail
-generated/assignment_sim/11.4.1--mul_assignment-sim-1.sv 2state fail
-generated/assignment_sim/11.4.1--mul_assignment-sim-1.sv 4state fail
-generated/assignment_sim/11.4.1--or_assignment-sim-0.sv 2state fail
-generated/assignment_sim/11.4.1--or_assignment-sim-0.sv 4state fail
-generated/assignment_sim/11.4.1--or_assignment-sim-1.sv 2state fail
-generated/assignment_sim/11.4.1--or_assignment-sim-1.sv 4state fail
-generated/assignment_sim/11.4.1--plus_assignment-sim-0.sv 2state fail
-generated/assignment_sim/11.4.1--plus_assignment-sim-0.sv 4state fail
-generated/assignment_sim/11.4.1--plus_assignment-sim-1.sv 2state fail
-generated/assignment_sim/11.4.1--plus_assignment-sim-1.sv 4state fail
-generated/assignment_sim/11.4.1--xor_assignment-sim-0.sv 2state fail
-generated/assignment_sim/11.4.1--xor_assignment-sim-0.sv 4state fail
-generated/assignment_sim/11.4.1--xor_assignment-sim-1.sv 2state fail
-generated/assignment_sim/11.4.1--xor_assignment-sim-1.sv 4state fail
+generated/assignment_sim/11.4.1--and_assignment-sim-0.sv 2state pass
+generated/assignment_sim/11.4.1--and_assignment-sim-0.sv 4state pass
+generated/assignment_sim/11.4.1--and_assignment-sim-1.sv 2state pass
+generated/assignment_sim/11.4.1--and_assignment-sim-1.sv 4state pass
+generated/assignment_sim/11.4.1--div_assignment-sim-0.sv 2state pass
+generated/assignment_sim/11.4.1--div_assignment-sim-0.sv 4state pass
+generated/assignment_sim/11.4.1--div_assignment-sim-1.sv 2state pass
+generated/assignment_sim/11.4.1--div_assignment-sim-1.sv 4state pass
+generated/assignment_sim/11.4.1--log_shl_assignment-sim-0.sv 2state pass
+generated/assignment_sim/11.4.1--log_shl_assignment-sim-0.sv 4state pass
+generated/assignment_sim/11.4.1--log_shl_assignment-sim-1.sv 2state pass
+generated/assignment_sim/11.4.1--log_shl_assignment-sim-1.sv 4state pass
+generated/assignment_sim/11.4.1--log_shr_assignment-sim-0.sv 2state pass
+generated/assignment_sim/11.4.1--log_shr_assignment-sim-0.sv 4state pass
+generated/assignment_sim/11.4.1--log_shr_assignment-sim-1.sv 2state pass
+generated/assignment_sim/11.4.1--log_shr_assignment-sim-1.sv 4state pass
+generated/assignment_sim/11.4.1--minus_assignment-sim-0.sv 2state pass
+generated/assignment_sim/11.4.1--minus_assignment-sim-0.sv 4state pass
+generated/assignment_sim/11.4.1--minus_assignment-sim-1.sv 2state pass
+generated/assignment_sim/11.4.1--minus_assignment-sim-1.sv 4state pass
+generated/assignment_sim/11.4.1--mod_assignment-sim-0.sv 2state pass
+generated/assignment_sim/11.4.1--mod_assignment-sim-0.sv 4state pass
+generated/assignment_sim/11.4.1--mod_assignment-sim-1.sv 2state pass
+generated/assignment_sim/11.4.1--mod_assignment-sim-1.sv 4state pass
+generated/assignment_sim/11.4.1--mul_assignment-sim-0.sv 2state pass
+generated/assignment_sim/11.4.1--mul_assignment-sim-0.sv 4state pass
+generated/assignment_sim/11.4.1--mul_assignment-sim-1.sv 2state pass
+generated/assignment_sim/11.4.1--mul_assignment-sim-1.sv 4state pass
+generated/assignment_sim/11.4.1--or_assignment-sim-0.sv 2state pass
+generated/assignment_sim/11.4.1--or_assignment-sim-0.sv 4state pass
+generated/assignment_sim/11.4.1--or_assignment-sim-1.sv 2state pass
+generated/assignment_sim/11.4.1--or_assignment-sim-1.sv 4state pass
+generated/assignment_sim/11.4.1--plus_assignment-sim-0.sv 2state pass
+generated/assignment_sim/11.4.1--plus_assignment-sim-0.sv 4state pass
+generated/assignment_sim/11.4.1--plus_assignment-sim-1.sv 2state pass
+generated/assignment_sim/11.4.1--plus_assignment-sim-1.sv 4state pass
+generated/assignment_sim/11.4.1--xor_assignment-sim-0.sv 2state pass
+generated/assignment_sim/11.4.1--xor_assignment-sim-0.sv 4state pass
+generated/assignment_sim/11.4.1--xor_assignment-sim-1.sv 2state pass
+generated/assignment_sim/11.4.1--xor_assignment-sim-1.sv 4state pass
generated/binary_op/11.4.10--binary_op_arith_shl.sv 2state pass
generated/binary_op/11.4.10--binary_op_arith_shl.sv 4state pass
generated/binary_op/11.4.10--binary_op_arith_shr.sv 2state pass
@@ -2467,22 +2467,22 @@ generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_2.sv 2s
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_2.sv 4state fail
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_3.sv 2state fail
generated/logical_implication_operator_sim/11.4.7--logical_impl_operator_3.sv 4state fail
-generated/logical_operators_sim/11.4.7--logical_operator_0.sv 2state fail
-generated/logical_operators_sim/11.4.7--logical_operator_0.sv 4state fail
-generated/logical_operators_sim/11.4.7--logical_operator_1.sv 2state fail
-generated/logical_operators_sim/11.4.7--logical_operator_1.sv 4state fail
-generated/logical_operators_sim/11.4.7--logical_operator_2.sv 2state fail
-generated/logical_operators_sim/11.4.7--logical_operator_2.sv 4state fail
-generated/logical_operators_sim/11.4.7--logical_operator_3.sv 2state fail
-generated/logical_operators_sim/11.4.7--logical_operator_3.sv 4state fail
-generated/logical_operators_sim/11.4.7--logical_operator_4.sv 2state fail
-generated/logical_operators_sim/11.4.7--logical_operator_4.sv 4state fail
-generated/logical_operators_sim/11.4.7--logical_operator_5.sv 2state fail
-generated/logical_operators_sim/11.4.7--logical_operator_5.sv 4state fail
-generated/logical_operators_sim/11.4.7--logical_operator_6.sv 2state fail
-generated/logical_operators_sim/11.4.7--logical_operator_6.sv 4state fail
-generated/logical_operators_sim/11.4.7--logical_operator_7.sv 2state fail
-generated/logical_operators_sim/11.4.7--logical_operator_7.sv 4state fail
+generated/logical_operators_sim/11.4.7--logical_operator_0.sv 2state pass
+generated/logical_operators_sim/11.4.7--logical_operator_0.sv 4state pass
+generated/logical_operators_sim/11.4.7--logical_operator_1.sv 2state pass
+generated/logical_operators_sim/11.4.7--logical_operator_1.sv 4state pass
+generated/logical_operators_sim/11.4.7--logical_operator_2.sv 2state pass
+generated/logical_operators_sim/11.4.7--logical_operator_2.sv 4state pass
+generated/logical_operators_sim/11.4.7--logical_operator_3.sv 2state pass
+generated/logical_operators_sim/11.4.7--logical_operator_3.sv 4state pass
+generated/logical_operators_sim/11.4.7--logical_operator_4.sv 2state pass
+generated/logical_operators_sim/11.4.7--logical_operator_4.sv 4state pass
+generated/logical_operators_sim/11.4.7--logical_operator_5.sv 2state pass
+generated/logical_operators_sim/11.4.7--logical_operator_5.sv 4state pass
+generated/logical_operators_sim/11.4.7--logical_operator_6.sv 2state pass
+generated/logical_operators_sim/11.4.7--logical_operator_6.sv 4state pass
+generated/logical_operators_sim/11.4.7--logical_operator_7.sv 2state pass
+generated/logical_operators_sim/11.4.7--logical_operator_7.sv 4state pass
generated/nets/6.6.1--net_tri.sv 2state pass
generated/nets/6.6.1--net_tri.sv 4state pass
generated/nets/6.6.1--net_wire.sv 2state pass
@@ -2507,42 +2507,42 @@ generated/nets/6.6.6--net_supply0.sv 2state fail
generated/nets/6.6.6--net_supply0.sv 4state fail
generated/nets/6.6.6--net_supply1.sv 2state fail
generated/nets/6.6.6--net_supply1.sv 4state fail
-generated/operators_sim/11.4.10--log_shl_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.10--log_shl_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.10--log_shl_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.10--log_shl_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.10--log_shr_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.10--log_shr_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.10--log_shr_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.10--log_shr_operator_sim_1.sv 4state fail
+generated/operators_sim/11.4.10--log_shl_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.10--log_shl_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.10--log_shl_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.10--log_shl_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.10--log_shr_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.10--log_shr_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.10--log_shr_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.10--log_shr_operator_sim_1.sv 4state pass
generated/operators_sim/11.4.10--simple_log_shl_operator_sim.sv 2state pass
generated/operators_sim/11.4.10--simple_log_shl_operator_sim.sv 4state pass
generated/operators_sim/11.4.10--simple_log_shr_operator_sim.sv 2state pass
generated/operators_sim/11.4.10--simple_log_shr_operator_sim.sv 4state pass
-generated/operators_sim/11.4.3--div_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.3--div_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.3--div_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.3--div_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.3--exp_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.3--exp_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.3--exp_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.3--exp_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.3--minus_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.3--minus_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.3--minus_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.3--minus_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.3--mod_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.3--mod_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.3--mod_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.3--mod_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.3--mul_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.3--mul_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.3--mul_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.3--mul_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.3--plus_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.3--plus_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.3--plus_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.3--plus_operator_sim_1.sv 4state fail
+generated/operators_sim/11.4.3--div_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.3--div_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.3--div_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.3--div_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.3--exp_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.3--exp_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.3--exp_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.3--exp_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.3--minus_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.3--minus_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.3--minus_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.3--minus_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.3--mod_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.3--mod_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.3--mod_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.3--mod_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.3--mul_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.3--mul_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.3--mul_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.3--mul_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.3--plus_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.3--plus_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.3--plus_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.3--plus_operator_sim_1.sv 4state pass
generated/operators_sim/11.4.3--simple_div_operator_sim.sv 2state pass
generated/operators_sim/11.4.3--simple_div_operator_sim.sv 4state pass
generated/operators_sim/11.4.3--simple_exp_operator_sim.sv 2state pass
@@ -2555,22 +2555,22 @@ generated/operators_sim/11.4.3--simple_mul_operator_sim.sv 2state pass
generated/operators_sim/11.4.3--simple_mul_operator_sim.sv 4state pass
generated/operators_sim/11.4.3--simple_plus_operator_sim.sv 2state pass
generated/operators_sim/11.4.3--simple_plus_operator_sim.sv 4state pass
-generated/operators_sim/11.4.4--ge_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.4--ge_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.4--ge_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.4--ge_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.4--gt_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.4--gt_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.4--gt_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.4--gt_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.4--le_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.4--le_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.4--le_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.4--le_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.4--lt_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.4--lt_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.4--lt_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.4--lt_operator_sim_1.sv 4state fail
+generated/operators_sim/11.4.4--ge_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.4--ge_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.4--ge_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.4--ge_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.4--gt_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.4--gt_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.4--gt_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.4--gt_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.4--le_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.4--le_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.4--le_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.4--le_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.4--lt_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.4--lt_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.4--lt_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.4--lt_operator_sim_1.sv 4state pass
generated/operators_sim/11.4.4--simple_ge_operator_sim.sv 2state pass
generated/operators_sim/11.4.4--simple_ge_operator_sim.sv 4state pass
generated/operators_sim/11.4.4--simple_gt_operator_sim.sv 2state pass
@@ -2579,14 +2579,14 @@ generated/operators_sim/11.4.4--simple_le_operator_sim.sv 2state pass
generated/operators_sim/11.4.4--simple_le_operator_sim.sv 4state pass
generated/operators_sim/11.4.4--simple_lt_operator_sim.sv 2state pass
generated/operators_sim/11.4.4--simple_lt_operator_sim.sv 4state pass
-generated/operators_sim/11.4.5--log_eq_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.5--log_eq_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.5--log_eq_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.5--log_eq_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.5--log_neq_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.5--log_neq_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.5--log_neq_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.5--log_neq_operator_sim_1.sv 4state fail
+generated/operators_sim/11.4.5--log_eq_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.5--log_eq_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.5--log_eq_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.5--log_eq_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.5--log_neq_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.5--log_neq_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.5--log_neq_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.5--log_neq_operator_sim_1.sv 4state pass
generated/operators_sim/11.4.5--simple_eq_operator_sim.sv 2state pass
generated/operators_sim/11.4.5--simple_eq_operator_sim.sv 4state pass
generated/operators_sim/11.4.5--simple_eq_xz_operator_sim.sv 2state pass
@@ -2595,18 +2595,18 @@ generated/operators_sim/11.4.5--simple_neq_operator_sim.sv 2state pass
generated/operators_sim/11.4.5--simple_neq_operator_sim.sv 4state pass
generated/operators_sim/11.4.5--simple_neq_xz_operator_sim.sv 2state pass
generated/operators_sim/11.4.5--simple_neq_xz_operator_sim.sv 4state pass
-generated/operators_sim/11.4.8--bit_and_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.8--bit_and_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.8--bit_and_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.8--bit_and_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.8--bit_or_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.8--bit_or_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.8--bit_or_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.8--bit_or_operator_sim_1.sv 4state fail
-generated/operators_sim/11.4.8--bit_xor_operator_sim_0.sv 2state fail
-generated/operators_sim/11.4.8--bit_xor_operator_sim_0.sv 4state fail
-generated/operators_sim/11.4.8--bit_xor_operator_sim_1.sv 2state fail
-generated/operators_sim/11.4.8--bit_xor_operator_sim_1.sv 4state fail
+generated/operators_sim/11.4.8--bit_and_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.8--bit_and_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.8--bit_and_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.8--bit_and_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.8--bit_or_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.8--bit_or_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.8--bit_or_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.8--bit_or_operator_sim_1.sv 4state pass
+generated/operators_sim/11.4.8--bit_xor_operator_sim_0.sv 2state pass
+generated/operators_sim/11.4.8--bit_xor_operator_sim_0.sv 4state pass
+generated/operators_sim/11.4.8--bit_xor_operator_sim_1.sv 2state pass
+generated/operators_sim/11.4.8--bit_xor_operator_sim_1.sv 4state pass
generated/operators_sim/11.4.8--simple_bit_and_operator_sim.sv 2state pass
generated/operators_sim/11.4.8--simple_bit_and_operator_sim.sv 4state pass
generated/operators_sim/11.4.8--simple_bit_or_operator_sim.sv 2state pass
diff --git a/crates/celox-design/src/lib.rs b/crates/celox-design/src/lib.rs
index 7294c286a4e..42bf3b118f7 100644
--- a/crates/celox-design/src/lib.rs
+++ b/crates/celox-design/src/lib.rs
@@ -616,6 +616,17 @@ impl std::fmt::Display for ProcessOrigin {
}
}
+/// When a procedural kernel is invoked by the runtime.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
+pub enum ProcessKind {
+ /// Static declarations run before ordinary HDL procedures.
+ Initializer,
+ #[default]
+ Regular,
+ /// A final procedure runs only when simulation ends (IEEE 1800-2023 9.2.3).
+ Final,
+}
+
/// State through which one process kernel exchanges control with the runtime.
///
/// A process kernel is a resumable function. On entry it reads `resume` to
@@ -625,9 +636,9 @@ impl std::fmt::Display for ProcessOrigin {
/// checkpoints capture a suspended process.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ProcessSlots {
- /// A static declaration initializer, executed before all HDL procedures.
- pub is_initializer: bool,
- /// This kernel originated from an edge procedure and must execute in Simulation.
+ /// The phase in which the runtime invokes this kernel.
+ pub kind: ProcessKind,
+ /// This kernel requires Simulation's process scheduler rather than Simulator.
pub requires_timed_simulation: bool,
/// Every delay the kernel suspends for is a constant of at least one
/// time unit.
@@ -646,7 +657,7 @@ pub struct ProcessSlots {
impl ProcessSlots {
pub fn map(self, mut map: impl FnMut(A) -> B) -> ProcessSlots {
ProcessSlots {
- is_initializer: self.is_initializer,
+ kind: self.kind,
requires_timed_simulation: self.requires_timed_simulation,
const_delays: self.const_delays,
program: self.program.map(&mut map),
diff --git a/crates/celox-frontend-core/src/sdk.rs b/crates/celox-frontend-core/src/sdk.rs
index f955fda9e87..c5c89c1135f 100644
--- a/crates/celox-frontend-core/src/sdk.rs
+++ b/crates/celox-frontend-core/src/sdk.rs
@@ -1729,7 +1729,7 @@ fn lower_processes(
for (index, process) in artifact.processes().iter().enumerate() {
let name = |slot: &str| vec![format!("$process[{index}]"), slot.to_string()];
let slots = ProcessSlots {
- is_initializer: false,
+ kind: celox_design::ProcessKind::Regular,
requires_timed_simulation: false,
const_delays: false,
program: None,
diff --git a/crates/celox-frontend-core/src/symbolic/assembly.rs b/crates/celox-frontend-core/src/symbolic/assembly.rs
index 1b720f15176..e01059c7e68 100644
--- a/crates/celox-frontend-core/src/symbolic/assembly.rs
+++ b/crates/celox-frontend-core/src/symbolic/assembly.rs
@@ -1940,7 +1940,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
.collect();
let declaration_startup = processes
.iter()
- .any(|process| process.slots.is_initializer)
+ .any(|process| process.slots.kind == celox_design::ProcessKind::Initializer)
.then(|| {
let targets: BTreeSet<_> = folded_initials.iter().map(|init| init.address).collect();
let mut reset = targets
diff --git a/crates/celox-frontend-sv/src/lowering.rs b/crates/celox-frontend-sv/src/lowering.rs
index b5b0d177f4c..11a49c86e24 100644
--- a/crates/celox-frontend-sv/src/lowering.rs
+++ b/crates/celox-frontend-sv/src/lowering.rs
@@ -1348,7 +1348,7 @@ fn kernel_window_writes(
for process in module
.initial_processes()
.iter()
- .filter(|process| !process.is_initializer())
+ .filter(|process| !process.is_initializer() && !process.is_final())
{
let body = process.body();
let first = if process.repeats() {
@@ -4978,6 +4978,7 @@ fn process_origin(process: &sv::ir::InitialProcess) -> celox_design::ProcessOrig
let construct = match process.site() {
Some(site) => site.construct,
None if process.is_initializer() => "declaration initializer",
+ None if process.is_final() => "final",
None if process.repeats() => "always",
None => "initial",
};
@@ -4988,9 +4989,9 @@ fn process_origin(process: &sv::ir::InitialProcess) -> celox_design::ProcessOrig
}
}
-/// The `initial` blocks and declaration initializers (IEEE 1800-2023 9.2.1,
-/// 10.5): the initial state they define, and the processes that run the
-/// others from time zero.
+/// Lower declaration initializers and procedural kernels. Final procedures
+/// retain kernels but execute only at simulation termination (9.2.3); they
+/// must never contribute folded initial state.
///
/// A block whose writes have constant values defines initial state, with
/// the hidden variables used while executing it discarded. Declaration
@@ -5062,7 +5063,10 @@ fn lower_initial_processes(
// initial state. A program's `initial` procedure runs in the reactive
// region set (IEEE 1800-2023 24.3.1), after the design's processes of
// time zero, so it is not folded either.
- if process.repeats() || (module.is_program() && !process.is_initializer()) {
+ if process.is_final()
+ || process.repeats()
+ || (module.is_program() && !process.is_initializer())
+ {
runtime.push((process, random_seed));
continue;
}
@@ -5138,8 +5142,8 @@ fn lower_initial_processes(
id
};
ProcessSlots {
- is_initializer: process.is_initializer(),
- requires_timed_simulation: process.is_scheduled_edge(),
+ kind: process.kind(),
+ requires_timed_simulation: process.is_scheduled_edge() || process.is_final(),
const_delays: false,
program: None,
resume: declare("resume", PROCESS_RESUME_WIDTH),
@@ -5155,10 +5159,10 @@ fn lower_initial_processes(
let program = slots
.iter()
.zip(&runtime)
- .find(|(_, (process, _))| !process.is_initializer())
+ .find(|(_, (process, _))| !process.is_initializer() && !process.is_final())
.map(|(slots, _)| slots.status);
for (slots, (process, _)) in slots.iter_mut().zip(&runtime) {
- if !process.is_initializer() {
+ if !process.is_initializer() && !process.is_final() {
slots.program = program;
}
}
@@ -10725,7 +10729,7 @@ endmodule
.runtime_schema
.processes
.iter()
- .filter(|process| !process.is_initializer)
+ .filter(|process| process.kind != celox_design::ProcessKind::Initializer)
.count()
}
diff --git a/crates/celox-runtime/src/error.rs b/crates/celox-runtime/src/error.rs
index 33603a87ee6..5cb9f3f2f03 100644
--- a/crates/celox-runtime/src/error.rs
+++ b/crates/celox-runtime/src/error.rs
@@ -5,6 +5,11 @@ pub enum SimulatorErrorCode {
DetectedTrueLoopAt {
signals: Vec,
},
+ /// `$fatal` also implicitly requests simulation termination.
+ Fatal {
+ message: String,
+ signals: Vec,
+ },
Runtime {
message: String,
signals: Vec,
@@ -36,6 +41,16 @@ impl PartialEq for SimulatorErrorCode {
signals: sb,
},
) => a == b && sa == sb,
+ (
+ Self::Fatal {
+ message: a,
+ signals: sa,
+ },
+ Self::Fatal {
+ message: b,
+ signals: sb,
+ },
+ ) => a == b && sa == sb,
(Self::NotAnEvent(a), Self::NotAnEvent(b)) => a == b,
_ => false,
}
@@ -54,8 +69,12 @@ impl std::fmt::Display for SimulatorErrorCode {
Self::DetectedTrueLoopAt { signals } => {
write!(f, "Detected True Loop: {}", signals.join(", "))
}
- Self::Runtime { message, signals } if signals.is_empty() => write!(f, "{message}"),
- Self::Runtime { message, signals } => {
+ Self::Fatal { message, signals } | Self::Runtime { message, signals }
+ if signals.is_empty() =>
+ {
+ write!(f, "{message}")
+ }
+ Self::Fatal { message, signals } | Self::Runtime { message, signals } => {
write!(f, "{}: {}", message, signals.join(", "))
}
Self::InternalError => write!(f, "Internal Error"),
diff --git a/crates/celox-runtime/src/schedule.rs b/crates/celox-runtime/src/schedule.rs
index 064c9049bad..99e07af4d2a 100644
--- a/crates/celox-runtime/src/schedule.rs
+++ b/crates/celox-runtime/src/schedule.rs
@@ -198,7 +198,7 @@ impl ResolvedSchedule {
.processes
.iter()
.map(|process| ProcessRefs {
- is_initializer: process.slots.is_initializer,
+ kind: process.slots.kind,
program: process.slots.program.as_ref().map(resolve),
resume: resolve(&process.slots.resume),
starts_with_event_wait: process.slots.requires_timed_simulation,
@@ -312,7 +312,9 @@ impl ResolvedSchedule {
program_processes: processes
.iter()
.enumerate()
- .filter(|(_, process)| process.program.is_some())
+ .filter(|(_, process)| {
+ process.kind == celox_design::ProcessKind::Regular && process.program.is_some()
+ })
.map(|(index, _)| index)
.collect(),
processes,
diff --git a/crates/celox-runtime/src/simulation/compiled.rs b/crates/celox-runtime/src/simulation/compiled.rs
index 7173050bca6..852dd20dd2e 100644
--- a/crates/celox-runtime/src/simulation/compiled.rs
+++ b/crates/celox-runtime/src/simulation/compiled.rs
@@ -161,6 +161,10 @@ impl SimulationState {
}
Err(Halt::Stop) => Ok(Some(self.scheduler.time)),
Err(Halt::Error(error)) => {
+ if matches!(&error, SimulatorErrorCode::Fatal { .. }) {
+ let _ = self.finalize_terminal(executor);
+ return Err(error);
+ }
let _ = self.finish_timed_boundary(executor, self.scheduler.time);
let _ = executor.flush_output();
Err(error)
diff --git a/crates/celox-runtime/src/simulation/mod.rs b/crates/celox-runtime/src/simulation/mod.rs
index dded48af181..a0e68d89208 100644
--- a/crates/celox-runtime/src/simulation/mod.rs
+++ b/crates/celox-runtime/src/simulation/mod.rs
@@ -10,6 +10,7 @@ mod persist;
mod process;
mod round;
mod stats;
+mod terminal;
mod time;
mod wait;
@@ -146,6 +147,8 @@ pub struct SimulationState {
host_pending: bool,
/// A process requested the end of the simulation.
finished: bool,
+ /// Next final procedure while terminal execution is suspended by `$stop`.
+ finalizing: Option,
/// A process suspended the simulation (`$stop`) in the last step.
stopped: bool,
/// The round a `$stop` suspended, which the next step continues.
@@ -193,7 +196,9 @@ impl SimulationState {
.processes
.iter()
.enumerate()
- .filter_map(|(index, process)| process.is_initializer.then_some(index))
+ .filter_map(|(index, process)| {
+ (process.kind == celox_design::ProcessKind::Initializer).then_some(index)
+ })
.collect();
let declarations_pending = !declaration_processes.is_empty();
let mut state = Self {
@@ -202,6 +207,7 @@ impl SimulationState {
last_clock_unknown: BitSet::new(),
four_state: backend.layout().four_state,
process_wakeups: (0..model.processes.len())
+ .filter(|&index| model.processes[index].kind != celox_design::ProcessKind::Final)
.map(|process| Reverse((0, process)))
.collect(),
model,
@@ -210,6 +216,7 @@ impl SimulationState {
declarations_pending,
host_pending: false,
finished: false,
+ finalizing: None,
stopped: false,
suspended: None,
scratch: None,
@@ -253,6 +260,13 @@ impl SimulationState {
E: SimulationExecutor,
{
self.stopped = false;
+ if self.finalizing.is_some() {
+ if self.scheduler.time > limit {
+ return Ok(None);
+ }
+ self.finalize_terminal(executor)?;
+ return Ok(Some(self.scheduler.time));
+ }
match self.step_time(executor, limit) {
Ok(time) => Ok(time),
Err(Halt::Finish) => {
@@ -262,6 +276,10 @@ impl SimulationState {
// The time slot goes on when the simulation continues.
Err(Halt::Stop) => Ok(Some(self.scheduler.time)),
Err(Halt::Error(error)) => {
+ if matches!(&error, SimulatorErrorCode::Fatal { .. }) {
+ let _ = self.finalize_terminal(executor);
+ return Err(error);
+ }
// Preserve the primary runtime failure even if diagnostic
// waveform output also fails. This does not resume processes.
let _ = self.finish_timed_boundary(executor, self.scheduler.time);
@@ -312,7 +330,10 @@ impl SimulationState {
// A process the scheduler does not run waits: the slot stays in
// the reference loop. Test that first, as designs with such
// processes fail it at every step.
- let compiled = if compiles && self.process_state.waiters.len() <= waiting_kernels {
+ let compiled = if self.finalizing.is_none()
+ && compiles
+ && self.process_state.waiters.len() <= waiting_kernels
+ {
self.compiled_limit(executor, end, observer.one_slot())
} else {
None
@@ -405,9 +426,14 @@ impl SimulationState {
{
match executor.try_finish_timed_step(time) {
Ok(()) => Ok(()),
- Err(Halt::Error(error)) => Err(error),
+ Err(Halt::Error(error)) => {
+ if matches!(&error, SimulatorErrorCode::Fatal { .. }) {
+ let _ = self.finalize_terminal(executor);
+ }
+ Err(error)
+ }
Err(Halt::Finish) => {
- self.finish_checked(executor)?;
+ self.finalize_terminal(executor)?;
Ok(())
}
Err(Halt::Stop) => {
@@ -417,34 +443,6 @@ impl SimulationState {
}
}
- fn finish_checked(&mut self, executor: &mut E) -> Result<(), SimulatorErrorCode>
- where
- E: SimulationExecutor,
- {
- self.finished = true;
- executor.try_freeze()
- }
-
- /// Once $finish is consumed, output errors must not make execution resumable.
- pub fn finalize_terminal(&mut self, executor: &mut E) -> Result<(), SimulatorErrorCode>
- where
- E: SimulationExecutor,
- {
- self.finished = true;
- let output = self.finish_timed_boundary(executor, self.scheduler.time);
- let frozen = executor.try_freeze();
- output.and(frozen)
- }
-
- /// End the simulation where it is.
- pub fn finish(&mut self, executor: &mut E)
- where
- E: SimulationExecutor,
- {
- self.finished = true;
- executor.freeze();
- }
-
/// Whether a process requested the end of the simulation.
pub fn is_finished(&self) -> bool {
self.finished
@@ -461,7 +459,8 @@ impl SimulationState {
/// Whether the simulation is suspended in the middle of a time slot, so
/// that its scheduling state cannot be captured.
pub fn is_suspended(&self) -> bool {
- self.suspended.is_some() || (self.stopped && self.declarations_pending)
+ self.suspended.is_some()
+ || (self.stopped && (self.declarations_pending || self.finalizing.is_some()))
}
/// Settle externally driven state against the previous edge baseline even
@@ -486,6 +485,10 @@ impl SimulationState {
}
Err(Halt::Stop) => Ok(Some(self.scheduler.time)),
Err(Halt::Error(error)) => {
+ if matches!(&error, SimulatorErrorCode::Fatal { .. }) {
+ let _ = self.finalize_terminal(executor);
+ return Err(error);
+ }
// Preserve the primary runtime failure even if diagnostic
// waveform output also fails. This does not resume processes.
let _ = self.finish_timed_boundary(executor, self.scheduler.time);
@@ -556,7 +559,7 @@ impl SimulationState {
return None;
}
// Host writes are work of the current time.
- if self.host_pending {
+ if self.host_pending || self.finalizing.is_some() {
return Some(self.scheduler.time);
}
self.next_work_time()
diff --git a/crates/celox-runtime/src/simulation/persist.rs b/crates/celox-runtime/src/simulation/persist.rs
index aa0a94ff8e9..d652d9f9e82 100644
--- a/crates/celox-runtime/src/simulation/persist.rs
+++ b/crates/celox-runtime/src/simulation/persist.rs
@@ -26,6 +26,7 @@ impl SimulationState {
declarations_pending: self.declarations_pending,
host_pending: self.host_pending,
finished: self.finished,
+ finalizing: self.finalizing,
}
}
@@ -63,6 +64,7 @@ impl SimulationState {
self.declarations_pending = snapshot.declarations_pending;
self.host_pending = snapshot.host_pending;
self.finished = snapshot.finished;
+ self.finalizing = snapshot.finalizing;
self.stopped = false;
self.suspended = None;
Ok(())
@@ -190,17 +192,14 @@ impl SimulationState {
.map(|(process, time)| Reverse((time, process)))
.collect();
self.process_state = parts.process_state;
- self.declarations_pending = self
- .process_wakeups
- .iter()
- .any(|Reverse((_, index))| self.model.processes[*index].is_initializer)
- || self
- .process_state
- .ready
- .iter()
- .any(|&index| self.model.processes[index].is_initializer);
+ self.declarations_pending = self.process_wakeups.iter().any(|Reverse((_, index))| {
+ self.model.processes[*index].kind == celox_design::ProcessKind::Initializer
+ }) || self.process_state.ready.iter().any(|&index| {
+ self.model.processes[index].kind == celox_design::ProcessKind::Initializer
+ });
self.host_pending = parts.host_pending;
self.finished = parts.finished;
+ self.finalizing = None;
self.stopped = false;
self.suspended = None;
}
@@ -218,6 +217,7 @@ pub struct SimulationSnapshot {
declarations_pending: bool,
host_pending: bool,
finished: bool,
+ finalizing: Option,
}
impl Clone for SimulationSnapshot {
@@ -233,6 +233,7 @@ impl Clone for SimulationSnapshot {
declarations_pending: self.declarations_pending,
host_pending: self.host_pending,
finished: self.finished,
+ finalizing: self.finalizing,
}
}
}
@@ -300,6 +301,7 @@ impl SimulationState {
declarations_pending: self.declarations_pending,
host_pending: self.host_pending,
finished: self.finished,
+ finalizing: self.finalizing,
stopped: self.stopped,
suspended: self.suspended.is_some(),
}
@@ -329,6 +331,7 @@ pub struct ScheduleKey {
pub declarations_pending: bool,
pub host_pending: bool,
pub finished: bool,
+ pub finalizing: Option,
pub stopped: bool,
pub suspended: bool,
}
diff --git a/crates/celox-runtime/src/simulation/process.rs b/crates/celox-runtime/src/simulation/process.rs
index bc74b2729d8..e8a7324dabd 100644
--- a/crates/celox-runtime/src/simulation/process.rs
+++ b/crates/celox-runtime/src/simulation/process.rs
@@ -29,7 +29,12 @@ impl SimulationState {
self.stopped = true;
Ok(())
}
- Err(Halt::Error(error)) => Err(error),
+ Err(Halt::Error(error)) => {
+ if matches!(&error, SimulatorErrorCode::Fatal { .. }) {
+ let _ = self.finalize_terminal(executor);
+ }
+ Err(error)
+ }
}
}
diff --git a/crates/celox-runtime/src/simulation/terminal.rs b/crates/celox-runtime/src/simulation/terminal.rs
new file mode 100644
index 00000000000..8d2553e935d
--- /dev/null
+++ b/crates/celox-runtime/src/simulation/terminal.rs
@@ -0,0 +1,99 @@
+//! Terminal procedures run sequentially, without scheduling another HDL event.
+
+use celox_design::{HostRequestKind, ProcessKind, ProcessStatus};
+
+use super::{SimulationExecutor, SimulationState};
+use crate::{SimulatorErrorCode, backend::SimBackend, timing::Halt};
+
+impl SimulationState {
+ /// Finish once, running final procedures before flushing output and freezing.
+ /// A `$stop` in a final procedure suspends this phase; the next step resumes it.
+ pub fn finalize_terminal(&mut self, executor: &mut E) -> Result<(), SimulatorErrorCode>
+ where
+ E: SimulationExecutor,
+ {
+ if self.finished {
+ return Ok(());
+ }
+ self.stopped = false;
+ if self.finalizing.is_none() {
+ // An explicit host finish may replace a stopped ordinary round.
+ self.suspended = None;
+ self.host_pending = false;
+ self.finalizing = Some(0);
+ }
+ let result = self.run_final_procedures(executor);
+ if matches!(result, Err(Halt::Stop)) {
+ self.stopped = true;
+ return Ok(());
+ }
+ // A failed final procedure or output flush cannot make termination resumable.
+ self.finished = true;
+ self.finalizing = None;
+ let output = self.finish_timed_boundary(executor, self.scheduler.time);
+ let frozen = executor.try_freeze();
+ match result {
+ Ok(()) | Err(Halt::Finish) => output.and(frozen),
+ Err(Halt::Error(error)) => Err(error),
+ Err(Halt::Stop) => unreachable!(),
+ }
+ }
+
+ /// Explicitly end simulation at its current time. Merely exhausting currently
+ /// scheduled work does not end an externally driven simulation.
+ pub fn finish(&mut self, executor: &mut E) -> Result<(), SimulatorErrorCode>
+ where
+ E: SimulationExecutor,
+ {
+ self.finalize_terminal(executor)
+ }
+
+ fn run_final_procedures(&mut self, executor: &mut E) -> Result<(), Halt>
+ where
+ E: SimulationExecutor,
+ {
+ let mut returns = 0;
+ while let Some(index) = self
+ .finalizing
+ .filter(|&index| index < self.model.processes.len())
+ {
+ let process = &self.model.processes[index];
+ if process.kind != ProcessKind::Final {
+ self.finalizing = Some(index + 1);
+ continue;
+ }
+ executor.run_process(index)?;
+ returns += 1;
+ self.charge(returns, Some(index))?;
+ let status: u8 = executor.backend().get_as(process.status);
+ match ProcessStatus::from_code(status) {
+ Some(ProcessStatus::Done) => self.finalizing = Some(index + 1),
+ Some(ProcessStatus::Finish) => return Err(Halt::Finish),
+ Some(ProcessStatus::Stop) => return Err(Halt::Stop),
+ Some(ProcessStatus::HostRequest) => {
+ let encoded: u64 = executor.backend().get_as(process.delay);
+ let (kind, site) = HostRequestKind::decode(encoded)
+ .ok_or(SimulatorErrorCode::InternalError)?;
+ let request = process
+ .host_requests
+ .iter()
+ .filter(|request| request.kind == kind)
+ .nth(site as usize)
+ .ok_or(SimulatorErrorCode::InternalError)?;
+ executor.host_request(request, self.scheduler.time)?;
+ }
+ // Yield is an implementation boundary, not an HDL timing control.
+ // NBA events created by a final never run after termination (9.2.3).
+ Some(ProcessStatus::Yield | ProcessStatus::Nba) => {}
+ _ => {
+ return Err(SimulatorErrorCode::Runtime {
+ message: "final procedure cannot suspend for HDL timing".into(),
+ signals: Vec::new(),
+ }
+ .into());
+ }
+ }
+ }
+ Ok(())
+ }
+}
diff --git a/crates/celox-runtime/src/simulation/time.rs b/crates/celox-runtime/src/simulation/time.rs
index e25822ae243..89f621c1e8d 100644
--- a/crates/celox-runtime/src/simulation/time.rs
+++ b/crates/celox-runtime/src/simulation/time.rs
@@ -299,7 +299,10 @@ impl SimulationState {
if self.finished {
return None;
}
- if !self.process_state.ready.is_empty() || !self.process_state.reactive.is_empty() {
+ if self.finalizing.is_some()
+ || !self.process_state.ready.is_empty()
+ || !self.process_state.reactive.is_empty()
+ {
return Some(self.scheduler.time);
}
let process = self.process_wakeups.peek().map(|&Reverse((time, _))| time);
diff --git a/crates/celox-runtime/src/timing.rs b/crates/celox-runtime/src/timing.rs
index 9edb4ed0927..20cdc112493 100644
--- a/crates/celox-runtime/src/timing.rs
+++ b/crates/celox-runtime/src/timing.rs
@@ -153,7 +153,7 @@ pub struct NbaSiteRefs {
/// Control slots and sites of one process kernel.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ProcessRefs {
- pub is_initializer: bool,
+ pub kind: celox_design::ProcessKind,
/// The status slot naming the program instance of a program kernel
/// ([`celox_design::ProcessSlots::program`]), which runs in the reactive
/// region set.
@@ -175,7 +175,7 @@ impl ProcessRefs {
/// A process without wait or nonblocking sites.
pub fn new(status: SignalRef, delay: SignalRef) -> Self {
Self {
- is_initializer: false,
+ kind: celox_design::ProcessKind::Regular,
program: None,
resume: status,
starts_with_event_wait: false,
diff --git a/crates/celox-sv-analyzer/src/ast.rs b/crates/celox-sv-analyzer/src/ast.rs
index cb6cbe72434..9472313a755 100644
--- a/crates/celox-sv-analyzer/src/ast.rs
+++ b/crates/celox-sv-analyzer/src/ast.rs
@@ -1331,7 +1331,7 @@ impl Module {
// Declaration initializers run before the other initial blocks.
let first_block = initial_processes
.iter()
- .position(|process| !process.initializer)
+ .position(|process| !process.is_initializer())
.unwrap_or(initial_processes.len());
initial_processes.insert(
first_block,
@@ -1340,7 +1340,8 @@ impl Module {
site: None,
condition: None,
body: static_initializers,
- initializer: true,
+ kind: celox_design::ProcessKind::Initializer,
+ validation_body: Vec::new(),
synthetic: false,
repeats: false,
},
@@ -1379,6 +1380,7 @@ impl Module {
}
for process in &mut initial_processes {
process.body = body(std::mem::take(&mut process.body));
+ process.validation_body = body(std::mem::take(&mut process.validation_body));
}
for subroutine in &mut subroutines {
*subroutine = rename.subroutine(subroutine.clone());
@@ -2535,14 +2537,16 @@ impl FfProcess {
}
}
-/// An `initial` process.
+/// A scheduled procedure, including initial/always processes and final procedures.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InitialProcess {
creation_order: usize,
site: Option,
condition: Option,
body: Vec,
- initializer: bool,
+ kind: celox_design::ProcessKind,
+ /// Folded-away statements retained only for final-procedure legality checks.
+ validation_body: Vec,
synthetic: bool,
/// An `always` process: its body runs forever.
repeats: bool,
@@ -2562,6 +2566,16 @@ impl InitialProcess {
self.condition.as_ref()
}
+ /// The procedure's simulation phase.
+ pub fn kind(&self) -> celox_design::ProcessKind {
+ self.kind
+ }
+
+ /// A final procedure runs once when the simulation finishes (9.2.3).
+ pub fn is_final(&self) -> bool {
+ self.kind == celox_design::ProcessKind::Final
+ }
+
/// Compiler-generated storage initialization, without a user static process.
pub fn is_synthetic(&self) -> bool {
self.synthetic
@@ -2569,7 +2583,7 @@ impl InitialProcess {
/// Whether this process holds variable declaration initializers.
pub fn is_initializer(&self) -> bool {
- self.initializer
+ self.kind == celox_design::ProcessKind::Initializer
}
/// Whether this is an `always` process, which runs its body forever and
diff --git a/crates/celox-sv-analyzer/src/ast/array_parameters.rs b/crates/celox-sv-analyzer/src/ast/array_parameters.rs
index 6dfd67cbc94..8429bf932e9 100644
--- a/crates/celox-sv-analyzer/src/ast/array_parameters.rs
+++ b/crates/celox-sv-analyzer/src/ast/array_parameters.rs
@@ -220,7 +220,8 @@ impl ArrayParameter {
rhs: value,
nonblocking: false,
}],
- initializer: false,
+ kind: celox_design::ProcessKind::Regular,
+ validation_body: Vec::new(),
synthetic: true,
repeats: false,
})
diff --git a/crates/celox-sv-analyzer/src/ast/comb_process.rs b/crates/celox-sv-analyzer/src/ast/comb_process.rs
index d958288a35a..4bc6aaf825e 100644
--- a/crates/celox-sv-analyzer/src/ast/comb_process.rs
+++ b/crates/celox-sv-analyzer/src/ast/comb_process.rs
@@ -295,7 +295,10 @@ fn comb_process_from_procedure(
parameter_literals: &HashMap,
state: &mut procedural::BodyState<'_>,
) -> Result