Skip to content

Commit 1f31730

Browse files
committed
Verilog: use direction field instead of input/output for module_typet
This replaces the boolean input and output fields of the port class by a single field direction, to enable ref ports.
1 parent 591ddea commit 1f31730

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

src/ebmc/output_verilog.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, kroening@kroening.com
1616
#include <verilog/verilog_language.h>
1717
#include <verilog/verilog_synthesis.h>
1818
#include <verilog/verilog_typecheck.h>
19+
#include <verilog/verilog_types.h>
1920

2021
#include "output_verilog.h"
2122

@@ -585,17 +586,17 @@ void output_verilog_baset::module_header(const symbolt &symbol)
585586
{
586587
out << "module " << symbol.base_name;
587588

588-
const irept &ports=symbol.type.find(ID_ports);
589-
589+
const auto &ports = to_module_type(symbol.type).ports();
590+
590591
//
591592
// print port in module statement
592593
//
593-
if(!ports.get_sub().empty())
594+
if(!ports.empty())
594595
{
595596
out << '(';
596597

597598
bool first = true;
598-
for(auto &port : ports.get_sub())
599+
for(auto &port : ports)
599600
{
600601
if(first)
601602
first = false;
@@ -615,10 +616,10 @@ void output_verilog_baset::module_header(const symbolt &symbol)
615616
//
616617
// port declarations
617618
//
618-
for(auto &port : ports.get_sub())
619+
for(auto &port : ports)
619620
{
620-
bool is_input = port.get_bool(ID_input);
621-
bool is_output = port.get_bool(ID_output);
621+
bool is_input = port.input();
622+
bool is_output = port.output();
622623

623624
out << " ";
624625

@@ -629,7 +630,7 @@ void output_verilog_baset::module_header(const symbolt &symbol)
629630
else
630631
out << "output";
631632

632-
const typet &type = static_cast<const typet &>(port.find(ID_type));
633+
const typet &type = port.type();
633634

634635
if(type.id()==ID_named_block)
635636
continue;

src/ebmc/transition_system.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Author: Daniel Kroening, dkr@amazon.com
2222
#include <langapi/mode.h>
2323
#include <trans-word-level/show_module_hierarchy.h>
2424
#include <trans-word-level/show_modules.h>
25+
#include <verilog/verilog_types.h>
2526

2627
#include "ebmc_error.h"
2728
#include "ebmc_version.h"
@@ -424,17 +425,14 @@ std::vector<symbol_exprt> transition_systemt::inputs() const
424425
DATA_INVARIANT(
425426
module_symbol.type.id() == ID_module, "main_symbol must be module");
426427

427-
const auto &ports_irep = module_symbol.type.find(ID_ports);
428-
429428
// filter out the inputs
430-
auto &ports = static_cast<const exprt &>(ports_irep).operands();
429+
auto &ports = to_module_type(module_symbol.type).ports();
431430
for(auto &port : ports)
432431
{
433432
DATA_INVARIANT(port.id() == ID_symbol, "port must be a symbol");
434-
if(port.get_bool(ID_input) && !port.get_bool(ID_output))
433+
if(port.input() && !port.output())
435434
{
436-
symbol_exprt input_symbol(
437-
to_symbol_expr(port).get_identifier(), port.type());
435+
symbol_exprt input_symbol(port.identifier(), port.type());
438436
input_symbol.add_source_location() = port.source_location();
439437
inputs.push_back(std::move(input_symbol));
440438
}

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ IREP_ID_ONE(module_instance)
107107
IREP_ID_TWO(C_const, #const)
108108
IREP_ID_TWO(C_offset, #offset)
109109
IREP_ID_TWO(C_increasing, #increasing)
110+
IREP_ID_ONE(direction)
110111
IREP_ID_ONE(ports)
111112
IREP_ID_ONE(inst)
112113
IREP_ID_ONE(Verilog)

src/verilog/verilog_interfaces.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ void verilog_typecheckt::check_module_ports(
9898
<< "port `" << base_name << "' not declared as input or output";
9999
}
100100

101-
ports.emplace_back(
102-
identifier,
103-
port_symbol->type,
104-
port_symbol->is_input,
105-
port_symbol->is_output);
101+
ports.emplace_back(identifier, port_symbol->type, decl.get_class());
106102

107103
ports.back().set("#name", base_name);
108104
ports.back().set(ID_C_source_location, declarator.source_location());

src/verilog/verilog_types.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,12 @@ class module_typet:public typet
145145
class portt : public irept
146146
{
147147
public:
148-
portt(irep_idt _identifier, typet _type, bool _input, bool _output)
148+
portt(irep_idt _identifier, typet _type, irep_idt _direction)
149149
: irept(ID_symbol)
150150
{
151-
type() = std::move(_type);
152151
identifier(_identifier);
153-
input(_input);
154-
output(_output);
152+
type() = std::move(_type);
153+
direction(_direction);
155154
}
156155

157156
typet &type()
@@ -174,24 +173,29 @@ class module_typet:public typet
174173
set(ID_identifier, _identifier);
175174
}
176175

177-
bool output() const
176+
irep_idt direction() const
177+
{
178+
return get(ID_direction);
179+
}
180+
181+
void direction(irep_idt _direction)
178182
{
179-
return get_bool(ID_output);
183+
set(ID_direction, _direction);
180184
}
181185

182-
void output(bool _output)
186+
bool output() const
183187
{
184-
set(ID_output, _output);
188+
return direction() == ID_output || direction() == ID_inout;
185189
}
186190

187191
bool input() const
188192
{
189-
return get_bool(ID_input);
193+
return direction() == ID_input || direction() == ID_inout;
190194
}
191195

192-
void input(bool _input)
196+
const source_locationt &source_location() const
193197
{
194-
set(ID_input, _input);
198+
return (const source_locationt &)find(ID_C_source_location);
195199
}
196200
};
197201

0 commit comments

Comments
 (0)