Skip to content
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

Verilog: expr2verilog can now decode aval/bval constants #570

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/verilog/aval_bval_encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,25 @@ exprt aval_bval_conversion(const exprt &src, const typet &dest)
return combine_aval_bval(new_aval, new_bval, dest);
}
}

std::string decode_aval_bval(const constant_exprt &expr)
{
PRECONDITION(is_aval_bval(expr.type()));
auto width = aval_bval_width(expr.type());
auto &src_value = expr.get_value();
std::string result;
result.reserve(width);

for(std::size_t i = 0; i < width; i++)
{
auto bit_index = width - 1 - i;
auto aval = get_bvrep_bit(src_value, width * 2, bit_index);
auto bval = get_bvrep_bit(src_value, width * 2, bit_index + width);
if(bval)
result += aval ? 'x' : 'z';
else
result += aval ? '1' : '0';
}

return result;
}
2 changes: 2 additions & 0 deletions src/verilog/aval_bval_encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ exprt bval(const exprt &);

exprt aval_bval_conversion(const exprt &, const typet &);

std::string decode_aval_bval(const constant_exprt &);

#endif
7 changes: 7 additions & 0 deletions src/verilog/expr2verilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
#include <util/std_expr.h>
#include <util/symbol.h>

#include "aval_bval_encoding.h"
#include "sva_expr.h"
#include "verilog_expr.h"
#include "verilog_types.h"
Expand Down Expand Up @@ -954,6 +955,12 @@ std::string expr2verilogt::convert_constant(
const irep_idt &value = src.get_value();
dest=id2string(value);
}
else if(is_aval_bval(type))
{
// these have a 'dual rail' encoding into aval/bval
auto width = aval_bval_width(type);
return std::to_string(width) + "'b" + decode_aval_bval(src);
}
else
return convert_norep(src, precedence);

Expand Down