11/*
2- * Copyright (c) 2001-2021 Stephen Williams ([email protected] ) 2+ * Copyright (c) 2001-2024 Stephen Williams ([email protected] ) 33 *
44 * This source code is free software; you can redistribute it
55 * and/or modify it in source code form under the terms of the GNU
@@ -891,9 +891,20 @@ void compile_vpi_time_precision(long pre)
891891 *
892892 * The real value is sign * (mant ** exp).
893893 */
894+ static bool crstring_header_test (const char *str)
895+ {
896+ if ((str[0 ] != ' C' ) && (str[0 ] != ' c' ))
897+ return false ;
898+ if ((str[1 ] != ' r' ) || (str[2 ] != ' <' ))
899+ return false ;
900+
901+ return true ;
902+ }
903+
894904bool crstring_test (const char *str)
895905{
896- if (strncmp (str, " Cr<" , 3 ) != 0 ) return false ;
906+ if (!crstring_header_test (str))
907+ return false ;
897908 const char *tp = strchr (str, ' >' );
898909 if (tp == 0 ) return false ;
899910 if (tp[1 ] != 0 ) return false ;
@@ -906,6 +917,8 @@ bool crstring_test(const char*str)
906917
907918double crstring_to_double (const char *label)
908919{
920+ assert (crstring_header_test (label));
921+
909922 const char *cp = label+3 ;
910923 assert (*cp == ' m' );
911924 cp += 1 ;
@@ -956,14 +969,21 @@ void input_connect(vvp_net_t*fdx, unsigned port, char*label)
956969
957970 vvp_vector4_t tmp = c4string_to_vector4 (label);
958971
959- // Inputs that are constants are schedule to execute as
972+ // Inputs that are constants are scheduled to execute as
960973 // soon at the simulation starts. In Verilog, constants
961974 // start propagating when the simulation starts, just
962975 // like any other signal value. But letting the
963976 // scheduler distribute the constant value has the
964977 // additional advantage that the constant is not
965978 // propagated until the network is fully linked.
966- schedule_set_vector (ifdx, tmp);
979+ // For constants that initialise an undriven net, we
980+ // schedule execution before time 0, to make sure it
981+ // occurs before any sensitive processes are started
982+ // or VPI callbacks are executed.
983+ if (label[0 ] == ' c' )
984+ schedule_init_vector (ifdx, tmp);
985+ else
986+ schedule_set_vector (ifdx, tmp);
967987
968988 free (label);
969989 return ;
@@ -973,7 +993,10 @@ void input_connect(vvp_net_t*fdx, unsigned port, char*label)
973993 if (c8string_test (label)) {
974994
975995 vvp_vector8_t tmp = c8string_to_vector8 (label);
976- schedule_set_vector (ifdx, tmp);
996+ if (label[0 ] == ' c' )
997+ schedule_init_vector (ifdx, tmp);
998+ else
999+ schedule_set_vector (ifdx, tmp);
9771000
9781001 free (label);
9791002 return ;
@@ -985,7 +1008,10 @@ void input_connect(vvp_net_t*fdx, unsigned port, char*label)
9851008
9861009 double tmp = crstring_to_double (label);
9871010
988- schedule_set_vector (ifdx, tmp);
1011+ if (label[0 ] == ' c' )
1012+ schedule_init_vector (ifdx, tmp);
1013+ else
1014+ schedule_set_vector (ifdx, tmp);
9891015 free (label);
9901016 return ;
9911017 }
0 commit comments