2323#include " expr2verilog.h"
2424#include " sva_expr.h"
2525#include " verilog_expr.h"
26+ #include " verilog_initializer.h"
2627#include " verilog_lowering.h"
2728#include " verilog_typecheck_expr.h"
2829
@@ -1463,6 +1464,7 @@ void verilog_synthesist::synth_module_instance(
14631464 module_identifier,
14641465 standard,
14651466 ignore_initial,
1467+ initial_zero,
14661468 get_message_handler ());
14671469
14681470 for (auto &instance : statement.instances ())
@@ -1933,6 +1935,8 @@ void verilog_synthesist::synth_decl(const verilog_declt &statement) {
19331935 {
19341936 DATA_INVARIANT (declarator.id () == ID_declarator, " must have declarator" );
19351937
1938+ auto lhs = declarator.symbol_expr ();
1939+
19361940 // This is reg x = ... or wire x = ...
19371941 if (declarator.has_value ())
19381942 {
@@ -1941,9 +1945,7 @@ void verilog_synthesist::synth_decl(const verilog_declt &statement) {
19411945 construct=constructt::INITIAL;
19421946 event_guard=event_guardt::NONE;
19431947
1944- auto lhs = declarator.symbol_expr ();
19451948 auto rhs = declarator.value ();
1946-
19471949 const symbolt &symbol = ns.lookup (lhs);
19481950
19491951 if (symbol.is_state_var )
@@ -1964,6 +1966,26 @@ void verilog_synthesist::synth_decl(const verilog_declt &statement) {
19641966 synth_continuous_assign (assign);
19651967 }
19661968 }
1969+ else if (initial_zero)
1970+ {
1971+ const symbolt &symbol = ns.lookup (lhs);
1972+
1973+ if (symbol.is_state_var )
1974+ {
1975+ // much like: initial LHS=0;
1976+ auto rhs_opt = verilog_zero_initializer (lhs.type ());
1977+ if (!rhs_opt.has_value ())
1978+ {
1979+ throw errort ().with_location (declarator.source_location ())
1980+ << " cannot zero-initialize `" << to_string (lhs) << " '" ;
1981+ }
1982+ verilog_initialt initial{verilog_blocking_assignt{lhs, *rhs_opt}};
1983+ initial.statement ().add_source_location () =
1984+ declarator.source_location ();
1985+ initial.add_source_location () = declarator.source_location ();
1986+ synth_initial (initial);
1987+ }
1988+ }
19671989 }
19681990}
19691991
@@ -3724,11 +3746,18 @@ bool verilog_synthesis(
37243746 const irep_idt &module ,
37253747 verilog_standardt standard,
37263748 bool ignore_initial,
3749+ bool initial_zero,
37273750 message_handlert &message_handler)
37283751{
37293752 const namespacet ns (symbol_table);
37303753 verilog_synthesist verilog_synthesis (
3731- standard, ignore_initial, ns, symbol_table, module , message_handler);
3754+ standard,
3755+ ignore_initial,
3756+ initial_zero,
3757+ ns,
3758+ symbol_table,
3759+ module ,
3760+ message_handler);
37323761 return verilog_synthesis.typecheck_main ();
37333762}
37343763
@@ -3757,7 +3786,13 @@ bool verilog_synthesis(
37573786 message_handler.get_message_count (messaget::M_ERROR);
37583787
37593788 verilog_synthesist verilog_synthesis (
3760- standard, false , ns, symbol_table, module_identifier, message_handler);
3789+ standard,
3790+ false ,
3791+ false ,
3792+ ns,
3793+ symbol_table,
3794+ module_identifier,
3795+ message_handler);
37613796
37623797 try
37633798 {
0 commit comments