Skip to content

Verilog: fix for signed constants #660

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

Merged
merged 1 commit into from
Sep 6, 2024
Merged

Verilog: fix for signed constants #660

merged 1 commit into from
Sep 6, 2024

Conversation

kroening
Copy link
Member

@kroening kroening commented Sep 1, 2024

Verilog allows constants to be marked as signed (e.g., 'sb1). When using base 2, 8 and 16, these need to be sign extended to 32 bits unless the number of bits is given.

@kroening kroening force-pushed the fix-signed-constants branch 6 times, most recently from f2736e5 to ca96560 Compare September 4, 2024 21:03
@kroening kroening marked this pull request as ready for review September 4, 2024 21:05
bool bits_given=false;

if(pos!=std::string::npos) // size given?
{
if(rest[0]!='\'')
{
bits=atoi(rest.c_str());
bits = atol(rest.c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably safe because of the lexer rules, but I would feel better if this used one of the safe_string2... functions instead of atol.

Verilog allows constants to be marked as signed (e.g., 'sb1).  When using
base 2, 8 and 16, these need to be sign extended to 32 bits unless the
number of bits is given.
@kroening kroening force-pushed the fix-signed-constants branch from ca96560 to a8115a8 Compare September 6, 2024 21:02
@kroening kroening merged commit 03d9ee4 into main Sep 6, 2024
8 checks passed
@kroening kroening deleted the fix-signed-constants branch September 6, 2024 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants