Skip to content

Commit 4cf6979

Browse files
committed
Verilog: ref port direction
SystemVerilog adds the ref port direction, usable for passing a reference to a variable to a module.
1 parent 1f31730 commit 4cf6979

File tree

7 files changed

+51
-7
lines changed

7 files changed

+51
-7
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Verilog: $isunknown
88
* SystemVerilog: fix for #-# and #=# for empty matches
99
* SystemVerilog: fix for |-> and |=> for empty matches
10+
* SystemVerilog: ref module port direction
1011
* LTL/SVA to Buechi with --buechi
1112
* SMV: abs, bool, count, max, min, toint, word1
1213
* BMC: new encoding for F, avoiding spurious traces
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
KNOWNBUG
2+
ref1.sv
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

regression/verilog/modules/ref1.sv

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module M(ref [31:0] some_ref);
2+
initial some_ref = 123;
3+
endmodule
4+
5+
module main;
6+
bit [31:0] some_var;
7+
M m(some_var);
8+
assert final (some_var == 123);
9+
endmodule

src/verilog/verilog_elaborate.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ void verilog_typecheckt::collect_port_symbols(const verilog_declt &decl)
5656
new_symbol.is_input = true;
5757
new_symbol.is_output = true;
5858
}
59+
else if(port_class == ID_verilog_ref)
60+
{
61+
new_symbol.is_input = false;
62+
new_symbol.is_output = false;
63+
new_symbol.is_state_var = true;
64+
}
65+
else
66+
DATA_INVARIANT(false, "unexpected port class");
5967

6068
new_symbol.module = module_identifier;
6169
new_symbol.value.make_nil();

src/verilog/verilog_interfaces.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,24 @@ void verilog_typecheckt::check_module_ports(
9292
<< "port `" << base_name << "' not declared";
9393
}
9494

95-
if(!port_symbol->is_input && !port_symbol->is_output)
95+
irep_idt direction = decl.get_class();
96+
97+
if(direction.empty())
9698
{
97-
throw errort().with_location(declarator.source_location())
98-
<< "port `" << base_name << "' not declared as input or output";
99+
if(!port_symbol->is_input && !port_symbol->is_output)
100+
{
101+
throw errort().with_location(declarator.source_location())
102+
<< "port `" << base_name << "' not declared as input or output";
103+
}
104+
else if(port_symbol->is_input && !port_symbol->is_output)
105+
direction = ID_input;
106+
else if(!port_symbol->is_input && port_symbol->is_output)
107+
direction = ID_output;
108+
else
109+
direction = ID_inout;
99110
}
100111

101-
ports.emplace_back(identifier, port_symbol->type, decl.get_class());
112+
ports.emplace_back(identifier, port_symbol->type, direction);
102113

103114
ports.back().set("#name", base_name);
104115
ports.back().set(ID_C_source_location, declarator.source_location());

src/verilog/verilog_typecheck.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ void verilog_typecheckt::typecheck_port_connection(
4343
{
4444
const symbolt &symbol = ns.lookup(port.identifier());
4545

46-
if(!symbol.is_input && !symbol.is_output)
46+
if(port.direction() != ID_verilog_ref)
4747
{
48-
throw errort().with_location(op.source_location())
49-
<< "port `" << symbol.name << "' is neither input nor output";
48+
if(!symbol.is_input && !symbol.is_output)
49+
{
50+
throw errort().with_location(op.source_location())
51+
<< "port `" << symbol.name << "' is neither input nor output";
52+
}
5053
}
5154

5255
if(op.is_nil())

src/verilog/verilog_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ class module_typet:public typet
193193
return direction() == ID_input || direction() == ID_inout;
194194
}
195195

196+
bool ref() const
197+
{
198+
return direction() == ID_verilog_ref;
199+
}
200+
196201
const source_locationt &source_location() const
197202
{
198203
return (const source_locationt &)find(ID_C_source_location);

0 commit comments

Comments
 (0)