Skip to content

Commit 4314098

Browse files
committed
Verilog: ref port type
1 parent aea0e0c commit 4314098

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ 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+
}
64+
else
65+
DATA_INVARIANT(false, "unexpected port class");
5966

6067
new_symbol.module = module_identifier;
6168
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_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)