Skip to content

Commit 42bc94b

Browse files
committed
Verilog: error connecting the same port twice
This fixes the check that errors when a module port is connected a second time.
1 parent efa2b5f commit 42bc94b

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
named_port_connection1.sv
3+
4+
^file .* line 8: port name a assigned twice$
5+
^EXIT=2$
6+
^SIGNAL=0$
7+
--
8+
--
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module my_module(input a, b);
2+
3+
endmodule
4+
5+
module main();
6+
7+
// a is connected twice
8+
my_module m1(.a(1), .a(1));
9+
10+
endmodule

src/verilog/verilog_typecheck.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,26 @@ void verilog_typecheckt::typecheck_port_connections(
133133
to_verilog_named_port_connection(connection);
134134

135135
exprt &value = named_port_connection.value();
136-
const irep_idt &name = named_port_connection.port().get(ID_identifier);
136+
const irep_idt &base_name =
137+
to_symbol_expr(named_port_connection.port()).get_identifier();
137138

138139
bool found=false;
139140

140-
std::string identifier=
141-
id2string(symbol.module)+"."+id2string(name);
141+
std::string full_identifier =
142+
id2string(symbol.module) + "." + id2string(base_name);
142143

143-
named_port_connection.port().set(ID_identifier, identifier);
144+
to_symbol_expr(named_port_connection.port())
145+
.set_identifier(full_identifier);
144146

145-
if(assigned_ports.find(name)!=
146-
assigned_ports.end())
147+
if(assigned_ports.find(base_name) != assigned_ports.end())
147148
{
148149
throw errort().with_location(connection.source_location())
149-
<< "port name " << name << " assigned twice";
150+
<< "port name " << base_name << " assigned twice";
150151
}
151152

152153
for(auto &port : ports)
153154
{
154-
if(port.get(ID_identifier) == identifier)
155+
if(port.identifier() == full_identifier)
155156
{
156157
found=true;
157158
typecheck_port_connection(value, port);
@@ -163,10 +164,10 @@ void verilog_typecheckt::typecheck_port_connections(
163164
if(!found)
164165
{
165166
throw errort().with_location(connection.source_location())
166-
<< "port name " << identifier << " not found";
167+
<< "port name " << base_name << " not found";
167168
}
168169

169-
assigned_ports.insert(identifier);
170+
assigned_ports.insert(base_name);
170171
}
171172
}
172173
else // just a list without names

0 commit comments

Comments
 (0)