Skip to content

Commit 3281369

Browse files
committed
Verilog system tasks and functions are always base names
Verilog system tasks and functions are never qualified or decorated, hence use verilog_identifier_exprt for their name.
1 parent 455c55d commit 3281369

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

src/verilog/parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3718,7 +3718,7 @@ function_statement: statement
37183718
;
37193719

37203720
system_task_name: TOK_SYSIDENT
3721-
{ new_symbol($$, $1); }
3721+
{ new_symbol($$, $1); stack_expr($$).id(ID_verilog_identifier); }
37223722
;
37233723

37243724
// System Verilog standard 1800-2017

src/verilog/verilog_expr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ typet verilog_declaratort::merged_type(const typet &declaration_type) const
5252

5353
static bool is_system_function_identifier(const exprt &function)
5454
{
55-
return function.id() == ID_symbol &&
56-
has_prefix(id2string(to_symbol_expr(function).get_identifier()), "$");
55+
return function.id() == ID_verilog_identifier &&
56+
has_prefix(
57+
id2string(to_verilog_identifier_expr(function).base_name()), "$");
5758
}
5859

5960
bool function_call_exprt::is_system_function_call() const

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,12 @@ exprt verilog_typecheck_exprt::convert_expr_function_call(
632632
}
633633

634634
// built-in functions
635-
symbol_exprt &f_op=to_symbol_expr(expr.function());
636-
637-
const irep_idt &identifier=f_op.get_identifier();
638-
639635
if(expr.is_system_function_call())
640-
return convert_system_function(identifier, expr);
636+
return convert_system_function(expr);
637+
638+
symbol_exprt &f_op=to_symbol_expr(expr.function());
639+
640+
const irep_idt &identifier = f_op.get_identifier();
641641

642642
std::string full_identifier=
643643
id2string(module_identifier)+"."+id2string(identifier);
@@ -901,13 +901,13 @@ Function: verilog_typecheck_exprt::convert_system_function
901901
902902
\*******************************************************************/
903903

904-
exprt verilog_typecheck_exprt::convert_system_function(
905-
const irep_idt &identifier,
906-
function_call_exprt expr)
904+
exprt verilog_typecheck_exprt::convert_system_function(function_call_exprt expr)
907905
{
906+
auto base_name = to_verilog_identifier_expr(expr.function()).base_name();
907+
908908
exprt::operandst &arguments=expr.arguments();
909909

910-
if(identifier=="$signed")
910+
if(base_name == "$signed")
911911
{
912912
// this is an explicit type cast
913913
if(arguments.size()!=1)
@@ -942,7 +942,7 @@ exprt verilog_typecheck_exprt::convert_system_function(
942942
<< to_string(argument.type()) << '\'';
943943
}
944944
}
945-
else if(identifier=="$unsigned")
945+
else if(base_name == "$unsigned")
946946
{
947947
// this is an explicit type cast
948948
if(arguments.size()!=1)
@@ -977,7 +977,7 @@ exprt verilog_typecheck_exprt::convert_system_function(
977977
<< to_string(argument.type()) << '\'';
978978
}
979979
}
980-
else if(identifier=="$ND")
980+
else if(base_name == "$ND")
981981
{
982982
// this is something from VIS
983983

@@ -991,21 +991,21 @@ exprt verilog_typecheck_exprt::convert_system_function(
991991
return std::move(expr);
992992
}
993993
else if(
994-
identifier == "$bits" || identifier == "$left" || identifier == "$right" ||
995-
identifier == "$increment" || identifier == "$low" || identifier == "$high")
994+
base_name == "$bits" || base_name == "$left" || base_name == "$right" ||
995+
base_name == "$increment" || base_name == "$low" || base_name == "$high")
996996
{
997997
if(arguments.size() != 1)
998998
{
999999
throw errort().with_location(expr.source_location())
1000-
<< identifier << " takes one argument";
1000+
<< base_name << " takes one argument";
10011001
}
10021002

10031003
// The return type is integer.
10041004
expr.type() = integer_typet();
10051005

10061006
return std::move(expr);
10071007
}
1008-
else if(identifier == "$countones") // SystemVerilog
1008+
else if(base_name == "$countones") // SystemVerilog
10091009
{
10101010
if(arguments.size() != 1)
10111011
{
@@ -1018,7 +1018,7 @@ exprt verilog_typecheck_exprt::convert_system_function(
10181018

10191019
return std::move(expr);
10201020
}
1021-
else if(identifier=="$onehot") // SystemVerilog
1021+
else if(base_name == "$onehot") // SystemVerilog
10221022
{
10231023
if(arguments.size()!=1)
10241024
{
@@ -1032,7 +1032,7 @@ exprt verilog_typecheck_exprt::convert_system_function(
10321032

10331033
return std::move(onehot);
10341034
}
1035-
else if(identifier=="$onehot0") // SystemVerilog
1035+
else if(base_name == "$onehot0") // SystemVerilog
10361036
{
10371037
if(arguments.size()!=1)
10381038
{
@@ -1046,7 +1046,7 @@ exprt verilog_typecheck_exprt::convert_system_function(
10461046

10471047
return std::move(onehot0);
10481048
}
1049-
else if(identifier == "$clog2") // Verilog-2005
1049+
else if(base_name == "$clog2") // Verilog-2005
10501050
{
10511051
if(arguments.size() != 1)
10521052
{
@@ -1058,7 +1058,7 @@ exprt verilog_typecheck_exprt::convert_system_function(
10581058

10591059
return std::move(expr);
10601060
}
1061-
else if(identifier == "$isunknown")
1061+
else if(base_name == "$isunknown")
10621062
{
10631063
if(arguments.size() != 1)
10641064
{
@@ -1070,7 +1070,7 @@ exprt verilog_typecheck_exprt::convert_system_function(
10701070

10711071
return std::move(expr);
10721072
}
1073-
else if(identifier == "$past")
1073+
else if(base_name == "$past")
10741074
{
10751075
if(arguments.size() == 0 || arguments.size() >= 4)
10761076
{
@@ -1089,73 +1089,73 @@ exprt verilog_typecheck_exprt::convert_system_function(
10891089
return std::move(expr);
10901090
}
10911091
else if(
1092-
identifier == "$stable" || identifier == "$rose" || identifier == "$fell" ||
1093-
identifier == "$changed")
1092+
base_name == "$stable" || base_name == "$rose" || base_name == "$fell" ||
1093+
base_name == "$changed")
10941094
{
10951095
if(arguments.size() != 1 && arguments.size() != 2)
10961096
{
10971097
throw errort().with_location(expr.source_location())
1098-
<< identifier << " takes one or two arguments";
1098+
<< base_name << " takes one or two arguments";
10991099
}
11001100

11011101
expr.type() = bool_typet();
11021102

11031103
return std::move(expr);
11041104
}
1105-
else if(identifier == "$rtoi")
1105+
else if(base_name == "$rtoi")
11061106
{
11071107
if(arguments.size() != 1)
11081108
{
11091109
throw errort().with_location(expr.source_location())
1110-
<< identifier << " takes one argument";
1110+
<< base_name << " takes one argument";
11111111
}
11121112

11131113
expr.type() = verilog_integer_typet();
11141114

11151115
return std::move(expr);
11161116
}
1117-
else if(identifier == "$itor")
1117+
else if(base_name == "$itor")
11181118
{
11191119
if(arguments.size() != 1)
11201120
{
11211121
throw errort().with_location(expr.source_location())
1122-
<< identifier << " takes one argument";
1122+
<< base_name << " takes one argument";
11231123
}
11241124

11251125
expr.type() = verilog_real_typet();
11261126

11271127
return std::move(expr);
11281128
}
1129-
else if(identifier == "$bitstoreal")
1129+
else if(base_name == "$bitstoreal")
11301130
{
11311131
if(arguments.size() != 1)
11321132
{
11331133
throw errort().with_location(expr.source_location())
1134-
<< identifier << " takes one argument";
1134+
<< base_name << " takes one argument";
11351135
}
11361136

11371137
expr.type() = verilog_real_typet();
11381138

11391139
return std::move(expr);
11401140
}
1141-
else if(identifier == "$bitstoshortreal")
1141+
else if(base_name == "$bitstoshortreal")
11421142
{
11431143
if(arguments.size() != 1)
11441144
{
11451145
throw errort().with_location(expr.source_location())
1146-
<< identifier << " takes one argument";
1146+
<< base_name << " takes one argument";
11471147
}
11481148

11491149
expr.type() = verilog_shortreal_typet();
11501150

11511151
return std::move(expr);
11521152
}
1153-
else if(identifier == "$realtobits")
1153+
else if(base_name == "$realtobits")
11541154
{
11551155
if(arguments.size() != 1)
11561156
{
11571157
throw errort().with_location(expr.source_location())
1158-
<< identifier << " takes one argument";
1158+
<< base_name << " takes one argument";
11591159
}
11601160

11611161
arguments[0] =
@@ -1165,12 +1165,12 @@ exprt verilog_typecheck_exprt::convert_system_function(
11651165

11661166
return std::move(expr);
11671167
}
1168-
else if(identifier == "$shortrealtobits")
1168+
else if(base_name == "$shortrealtobits")
11691169
{
11701170
if(arguments.size() != 1)
11711171
{
11721172
throw errort().with_location(expr.source_location())
1173-
<< identifier << " takes one argument";
1173+
<< base_name << " takes one argument";
11741174
}
11751175

11761176
arguments[0] =
@@ -1180,7 +1180,7 @@ exprt verilog_typecheck_exprt::convert_system_function(
11801180

11811181
return std::move(expr);
11821182
}
1183-
else if(identifier == "$typename")
1183+
else if(base_name == "$typename")
11841184
{
11851185
if(arguments.size() != 1)
11861186
{
@@ -1198,7 +1198,7 @@ exprt verilog_typecheck_exprt::convert_system_function(
11981198
else
11991199
{
12001200
throw errort().with_location(expr.function().source_location())
1201-
<< "unknown system function `" << identifier << "'";
1201+
<< "unknown system function `" << base_name << "'";
12021202
}
12031203
}
12041204

src/verilog/verilog_typecheck_expr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ class verilog_typecheck_exprt:public verilog_typecheck_baset
185185
[[nodiscard]] exprt convert_trinary_expr(ternary_exprt);
186186
[[nodiscard]] exprt convert_expr_concatenation(concatenation_exprt);
187187
[[nodiscard]] exprt convert_expr_function_call(function_call_exprt);
188-
[[nodiscard]] exprt
189-
convert_system_function(const irep_idt &identifier, function_call_exprt);
188+
[[nodiscard]] exprt convert_system_function(function_call_exprt);
190189
[[nodiscard]] exprt convert_bit_select_expr(binary_exprt);
191190
[[nodiscard]] exprt convert_replication_expr(replication_exprt);
192191
[[nodiscard]] exprt convert_power_expr(power_exprt);

0 commit comments

Comments
 (0)