Skip to content

Commit

Permalink
Verilog: set type of implicit nets
Browse files Browse the repository at this point in the history
1800 2017 6.10 allows implicit declarations of nets.  The type of these nets
is to be derived from the LHS of the assignment or the type of the port
connection.
  • Loading branch information
kroening committed Oct 4, 2024
1 parent 84373de commit 534bf9e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
6 changes: 3 additions & 3 deletions regression/verilog/nets/implicit5.desc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
KNOWNBUG
CORE
implicit5.sv
--bound 0
^EXIT=0$
^file .* line 4: unknown identifier O$
^EXIT=2$
^SIGNAL=0$
--
^warning: ignoring
--
This case should be errored.
32 changes: 19 additions & 13 deletions src/verilog/verilog_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ exprt verilog_typecheck_exprt::convert_nullary_expr(nullary_exprt expr)
}
else if(expr.id()==ID_symbol)
{
return convert_symbol(to_symbol_expr(std::move(expr)));
return convert_symbol(to_symbol_expr(std::move(expr)), {});
}
else if(expr.id()==ID_verilog_star_event)
{
Expand Down Expand Up @@ -936,7 +936,9 @@ Function: verilog_typecheck_exprt::convert_symbol
\*******************************************************************/

exprt verilog_typecheck_exprt::convert_symbol(symbol_exprt expr)
exprt verilog_typecheck_exprt::convert_symbol(
symbol_exprt expr,
const std::optional<typet> &implicit_net_type)
{
const irep_idt &identifier = expr.get_identifier();

Expand Down Expand Up @@ -1023,19 +1025,23 @@ exprt verilog_typecheck_exprt::convert_symbol(symbol_exprt expr)
return std::move(expr);
}
}
else if(!implicit_wire(identifier, symbol))
{
// this should become an error
warning().source_location=expr.source_location();
warning() << "implicit wire " << symbol->display_name() << eom;
expr.type()=symbol->type;
expr.set_identifier(symbol->name);
return std::move(expr);
}
else
{
throw errort().with_location(expr.source_location())
<< "unknown identifier " << identifier;
if(implicit_net_type.has_value())
{
implicit_wire(identifier, symbol);

warning().source_location = expr.source_location();
warning() << "implicit wire " << symbol->display_name() << eom;
expr.type() = symbol->type;
expr.set_identifier(symbol->name);
return std::move(expr);
}
else
{
throw errort().with_location(expr.source_location())
<< "unknown identifier " << identifier;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/verilog/verilog_typecheck_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class verilog_typecheck_exprt:public verilog_typecheck_baset
private:
[[nodiscard]] exprt convert_expr_rec(exprt expr);
[[nodiscard]] exprt convert_constant(constant_exprt);
[[nodiscard]] exprt convert_symbol(symbol_exprt);
[[nodiscard]] exprt
convert_symbol(symbol_exprt, const std::optional<typet> &implicit_net_type);
[[nodiscard]] exprt
convert_hierarchical_identifier(class hierarchical_identifier_exprt);
[[nodiscard]] exprt convert_nullary_expr(nullary_exprt);
Expand Down

0 comments on commit 534bf9e

Please sign in to comment.