Skip to content

Commit

Permalink
SystemVerilog: string data type
Browse files Browse the repository at this point in the history
This adds 1800-2017 6.16 string.
  • Loading branch information
kroening committed Dec 29, 2024
1 parent 20645b2 commit b7f5809
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 1 deletion.
6 changes: 6 additions & 0 deletions regression/verilog/data-types/string1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
string1.sv
--bound 0
^EXIT=0$
^SIGNAL=0$
--
8 changes: 8 additions & 0 deletions regression/verilog/data-types/string1.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module main;

// IEEE 1800-2017 6.16
string my_string = "abc";

assert final(my_string == "abc");

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 @@ -1936,6 +1936,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 @@ -1471,7 +1471,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 @@ -333,6 +333,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 @@ -743,6 +743,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 @@ -2222,6 +2226,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

0 comments on commit b7f5809

Please sign in to comment.