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

SystemVerilog: string data type #838

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
SystemVerilog: string data type
This adds 1800-2017 6.16 string.
  • Loading branch information
kroening committed Jan 9, 2025
commit 3fb4d16541439478b36e58b558dd6dce75b5f665
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Verilog: fix for nor/nand/xnor primitive gates
* SystemVerilog: $bitstoreal/$bitstoshortreal, $realtobits/$shortrealtobits
* SystemVerilog: $itor, $rtoi
* SystemVerilog: chandle, event
* SystemVerilog: chandle, event, string

# EBMC 5.4

Expand Down
7 changes: 7 additions & 0 deletions regression/verilog/data-types/string1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
string1.sv
--bound 0
^no properties$
^EXIT=10$
^SIGNAL=0$
--
7 changes: 7 additions & 0 deletions regression/verilog/data-types/string1.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module main;

// IEEE 1800-2017 6.16
string xyz;
string my_string = xyz;

endmodule
1 change: 1 addition & 0 deletions src/hw_cbmc_irep_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ IREP_ID_ONE(verilog_chandle)
IREP_ID_ONE(verilog_null)
IREP_ID_ONE(verilog_event)
IREP_ID_ONE(verilog_event_trigger)
IREP_ID_ONE(verilog_string)
IREP_ID_ONE(reg)
IREP_ID_ONE(macromodule)
IREP_ID_ONE(output_register)
Expand Down
2 changes: 2 additions & 0 deletions src/verilog/expr2verilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,8 @@ std::string expr2verilogt::convert(const typet &type)
return "logic";
else if(type.id() == ID_verilog_integer)
return "integer";
else if(type.id() == ID_verilog_string)
return "string";
else if(type.id() == ID_verilog_reg)
return "reg";
else if(type.id() == ID_verilog_time)
Expand Down
2 changes: 1 addition & 1 deletion src/verilog/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ data_type:
stack_expr($$).set(ID_identifier, id);
}
| TOK_STRING
{ init($$, ID_string); }
{ init($$, ID_verilog_string); }
| TOK_CHANDLE
{ init($$, ID_verilog_chandle); }
| TOK_VIRTUAL interface_opt interface_identifier
Expand Down
4 changes: 4 additions & 0 deletions src/verilog/verilog_elaborate_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ typet verilog_typecheck_exprt::elaborate_type(const typet &src)
return struct_union_typet{src.id(), std::move(components)}
.with_source_location(src.source_location());
}
else if(src.id() == ID_verilog_string)
{
return src;
}
else if(src.id() == ID_type)
{
return src;
Expand Down
19 changes: 19 additions & 0 deletions src/verilog/verilog_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,10 @@ exprt verilog_typecheck_exprt::typename_string(const exprt &expr)
{
s = "event";
}
else if(type.id() == ID_verilog_string)
{
s = "string";
}
else
s = "?";

Expand Down Expand Up @@ -2331,6 +2335,21 @@ typet verilog_typecheck_exprt::max_type(
if(vt0.is_event() || vt1.is_null())
return t0;

if(
vt0.is_string() && (vt1.is_signed() || vt1.is_unsigned() ||
vt1.is_verilog_signed() || vt1.is_verilog_unsigned()))
{
return t0;
}

if(
(vt0.is_signed() || vt0.is_unsigned() || vt0.is_verilog_signed() ||
vt0.is_verilog_unsigned()) &&
vt0.is_string())
{
return t1;
}

if(vt0.is_other() || vt1.is_other())
return static_cast<const typet &>(get_nil_irep());

Expand Down
8 changes: 8 additions & 0 deletions src/verilog/vtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ vtypet::vtypet(const typet &type)
vtype = EVENT;
width = 32;
}
else if(type.id() == ID_verilog_string)
{
vtype = STRING;
width = 0;
}
else
{
width=0;
Expand Down Expand Up @@ -136,6 +141,9 @@ std::ostream &operator << (std::ostream &out, const vtypet &vtype)
case vtypet::EVENT:
return out << "event";

case vtypet::STRING:
return out << "string";

case vtypet::UNKNOWN:
case vtypet::OTHER:
default:
Expand Down
5 changes: 5 additions & 0 deletions src/verilog/vtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class vtypet
{
return vtype == EVENT;
}
bool is_string() const
{
return vtype == STRING;
}
inline bool is_other() const { return vtype==OTHER; }

protected:
Expand All @@ -59,6 +63,7 @@ class vtypet
NULL_TYPE,
CHANDLE,
EVENT,
STRING,
OTHER
} _vtypet;
_vtypet vtype;
Expand Down
Loading