-
Notifications
You must be signed in to change notification settings - Fork 18
SystemVerilog: --initial-zero
#1001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
0b9909e
to
86bf699
Compare
src/verilog/verilog_initializer.cpp
Outdated
std::optional<exprt> verilog_zero_initializer(const typet &type) | ||
{ | ||
if(type.id() == ID_signedbv || type.id() == ID_unsignedbv) | ||
return from_integer(0, type); | ||
else if(type.id() == ID_bool) | ||
return false_exprt{}; | ||
else if(type.id() == ID_array) | ||
{ | ||
auto &array_type = to_array_type(type); | ||
auto zero_element_opt = verilog_zero_initializer(array_type.element_type()); | ||
if(!zero_element_opt.has_value()) | ||
return {}; | ||
else | ||
return array_of_exprt{*zero_element_opt, array_type}; | ||
} | ||
else if(type.id() == ID_struct) | ||
{ | ||
auto &struct_type = to_struct_type(type); | ||
exprt::operandst member_values; | ||
for(auto &component : struct_type.components()) | ||
{ | ||
auto member_value_opt = verilog_zero_initializer(component.type()); | ||
if(!member_value_opt.has_value()) | ||
return {}; | ||
member_values.push_back(*member_value_opt); | ||
} | ||
return struct_exprt{std::move(member_values), struct_type}; | ||
} | ||
else | ||
return {}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would seem safe to just use zero_initializer
from CBMC's code base?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping? ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need to make CBMC's zero_initializer
easier to extend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's either that or a copy.
The SystemVerilog standard specifies that variables are to be zero initialized before simulation begins. Some synthesis tools generate logic to achieve this, whereas others do not. This adds the option --initial-zero to match the synthesis semantics when appropriate.
86bf699
to
91db9b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm always opposed to code duplication so I'd strongly favour an approach that will facilitate code reuse, but I understand that this may require more effort than is possible to put in right now.
We also need extensibility for the solvers, the SMT-LIB converter, and the simplifier. |
The SystemVerilog standard specifies that variables are to be zero initialized before simulation begins. Some synthesis tools generate logic to achieve this, whereas others do not.
This adds the option
--initial-zero
to match the synthesis semantics when appropriate.