Skip to content

Commit cbad677

Browse files
authored
Merge pull request #838 from diffblue/verilog_string
SystemVerilog: `string` data type
2 parents 698d536 + 30190ba commit cbad677

File tree

10 files changed

+55
-2
lines changed

10 files changed

+55
-2
lines changed

CHANGELOG

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Verilog: fix for nor/nand/xnor primitive gates
99
* SystemVerilog: $bitstoreal/$bitstoshortreal, $realtobits/$shortrealtobits
1010
* SystemVerilog: $itor, $rtoi
11-
* SystemVerilog: chandle, event
11+
* SystemVerilog: chandle, event, string
1212
* SystemVerilog: package scope operator
1313

1414
# EBMC 5.4
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
string1.sv
3+
--bound 0
4+
^no properties$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module main;
2+
3+
// IEEE 1800-2017 6.16
4+
string xyz;
5+
string my_string = xyz;
6+
7+
endmodule

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ IREP_ID_ONE(verilog_chandle)
108108
IREP_ID_ONE(verilog_null)
109109
IREP_ID_ONE(verilog_event)
110110
IREP_ID_ONE(verilog_event_trigger)
111+
IREP_ID_ONE(verilog_string)
111112
IREP_ID_ONE(reg)
112113
IREP_ID_ONE(macromodule)
113114
IREP_ID_ONE(output_register)

src/verilog/expr2verilog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,8 @@ std::string expr2verilogt::convert(const typet &type)
19881988
return "logic";
19891989
else if(type.id() == ID_verilog_integer)
19901990
return "integer";
1991+
else if(type.id() == ID_verilog_string)
1992+
return "string";
19911993
else if(type.id() == ID_verilog_reg)
19921994
return "reg";
19931995
else if(type.id() == ID_verilog_time)

src/verilog/parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ data_type:
14791479
stack_expr($$).set(ID_identifier, id);
14801480
}
14811481
| TOK_STRING
1482-
{ init($$, ID_string); }
1482+
{ init($$, ID_verilog_string); }
14831483
| TOK_CHANDLE
14841484
{ init($$, ID_verilog_chandle); }
14851485
| TOK_VIRTUAL interface_opt interface_identifier

src/verilog/verilog_elaborate_type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ typet verilog_typecheck_exprt::elaborate_type(const typet &src)
379379
return struct_union_typet{src.id(), std::move(components)}
380380
.with_source_location(src.source_location());
381381
}
382+
else if(src.id() == ID_verilog_string)
383+
{
384+
return src;
385+
}
382386
else if(src.id() == ID_type)
383387
{
384388
return src;

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,10 @@ exprt verilog_typecheck_exprt::typename_string(const exprt &expr)
761761
{
762762
s = "event";
763763
}
764+
else if(type.id() == ID_verilog_string)
765+
{
766+
s = "string";
767+
}
764768
else
765769
s = "?";
766770

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

2338+
if(
2339+
vt0.is_string() && (vt1.is_signed() || vt1.is_unsigned() ||
2340+
vt1.is_verilog_signed() || vt1.is_verilog_unsigned()))
2341+
{
2342+
return t0;
2343+
}
2344+
2345+
if(
2346+
(vt0.is_signed() || vt0.is_unsigned() || vt0.is_verilog_signed() ||
2347+
vt0.is_verilog_unsigned()) &&
2348+
vt0.is_string())
2349+
{
2350+
return t1;
2351+
}
2352+
23342353
if(vt0.is_other() || vt1.is_other())
23352354
return static_cast<const typet &>(get_nil_irep());
23362355

src/verilog/vtype.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ vtypet::vtypet(const typet &type)
8383
vtype = EVENT;
8484
width = 32;
8585
}
86+
else if(type.id() == ID_verilog_string)
87+
{
88+
vtype = STRING;
89+
width = 0;
90+
}
8691
else
8792
{
8893
width=0;
@@ -136,6 +141,9 @@ std::ostream &operator << (std::ostream &out, const vtypet &vtype)
136141
case vtypet::EVENT:
137142
return out << "event";
138143

144+
case vtypet::STRING:
145+
return out << "string";
146+
139147
case vtypet::UNKNOWN:
140148
case vtypet::OTHER:
141149
default:

src/verilog/vtype.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class vtypet
4343
{
4444
return vtype == EVENT;
4545
}
46+
bool is_string() const
47+
{
48+
return vtype == STRING;
49+
}
4650
inline bool is_other() const { return vtype==OTHER; }
4751

4852
protected:
@@ -59,6 +63,7 @@ class vtypet
5963
NULL_TYPE,
6064
CHANDLE,
6165
EVENT,
66+
STRING,
6267
OTHER
6368
} _vtypet;
6469
_vtypet vtype;

0 commit comments

Comments
 (0)