Skip to content

Commit 00d17a8

Browse files
authored
Merge pull request #609 from diffblue/submodules-module-source
Verilog: use verilog_module_sourcet to discover instantiated modules
2 parents 5aa449b + 82da1dd commit 00d17a8

File tree

8 files changed

+51
-26
lines changed

8 files changed

+51
-26
lines changed

src/verilog/verilog_expr.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,29 @@ bool function_call_exprt::is_system_function_call() const
3030
has_prefix(
3131
id2string(to_symbol_expr(function()).get_identifier()), "$");
3232
}
33+
34+
void verilog_module_sourcet::show(std::ostream &out) const
35+
{
36+
out << "Module: " << base_name() << '\n';
37+
38+
out << " Parameters:\n";
39+
40+
for(auto &parameter : parameter_port_list())
41+
out << " " << parameter.pretty() << '\n';
42+
43+
out << '\n';
44+
45+
out << " Ports:\n";
46+
47+
for(auto &port : ports())
48+
out << " " << port.pretty() << '\n';
49+
50+
out << '\n';
51+
52+
out << " Module items:\n";
53+
54+
for(auto &item : module_items())
55+
out << " " << item.pretty() << '\n';
56+
57+
out << '\n';
58+
}

src/verilog/verilog_expr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,8 @@ class verilog_module_sourcet : public irept
19441944
{
19451945
return static_cast<source_locationt &>(add(ID_C_source_location));
19461946
}
1947+
1948+
void show(std::ostream &) const;
19471949
};
19481950

19491951
inline const verilog_module_sourcet &to_verilog_module_source(const irept &irep)

src/verilog/verilog_language.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ void verilog_languaget::dependencies(
134134
if(it!=parse_tree.module_map.end())
135135
{
136136
// dependencies on other Verilog modules
137-
138-
const verilog_modulet &module=(it->second)->verilog_module;
139137

140-
for(auto &identifier : module.submodules())
138+
const auto &module = (it->second)->verilog_module;
139+
140+
for(auto &identifier : submodules(module))
141141
module_set.insert(id2string(identifier));
142142
}
143143
}

src/verilog/verilog_module.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void verilog_modulet::show(std::ostream &out) const
5353

5454
/*******************************************************************\
5555
56-
Function: verilog_modulet::submodules_rec
56+
Function: submodules_rec
5757
5858
Inputs:
5959
@@ -63,8 +63,8 @@ Function: verilog_modulet::submodules_rec
6363
6464
\*******************************************************************/
6565

66-
void verilog_modulet::submodules_rec(
67-
const exprt &module_item,
66+
void submodules_rec(
67+
const verilog_module_itemt &module_item,
6868
std::vector<irep_idt> &dest)
6969
{
7070
if(module_item.id() == ID_inst)
@@ -92,7 +92,7 @@ void verilog_modulet::submodules_rec(
9292

9393
/*******************************************************************\
9494
95-
Function: verilog_modulet::submodules
95+
Function: submodules
9696
9797
Inputs:
9898
@@ -102,12 +102,12 @@ Function: verilog_modulet::submodules
102102
103103
\*******************************************************************/
104104

105-
std::vector<irep_idt> verilog_modulet::submodules() const
105+
std::vector<irep_idt> submodules(const verilog_module_sourcet &module)
106106
{
107107
std::vector<irep_idt> result;
108108

109-
for(auto &item : module_items.get_sub())
110-
submodules_rec(static_cast<const exprt &>(item), result);
109+
for(auto &item : module.module_items())
110+
submodules_rec(item, result);
111111

112112
return result;
113113
}

src/verilog/verilog_module.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,12 @@ struct verilog_modulet
3737
m.module_items.swap(module_items);
3838
m.location.swap(location);
3939
}
40-
41-
void show(std::ostream &out) const;
42-
43-
// The identifiers of the submodules
44-
// (not: the identifiers of the instances)
45-
std::vector<irep_idt> submodules() const;
4640

47-
private:
48-
static void
49-
submodules_rec(const exprt &module_item, std::vector<irep_idt> &dest);
41+
void show(std::ostream &out) const;
5042
};
5143

44+
// The identifiers of the submodules
45+
// (not: the identifiers of the instances)
46+
std::vector<irep_idt> submodules(const verilog_module_sourcet &);
47+
5248
#endif

src/verilog/verilog_parse_tree.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,21 @@ void verilog_parse_treet::create_module(
3030
exprt &module_items)
3131
{
3232
items.push_back(itemt(itemt::MODULE));
33-
itemt &item=items.back();
34-
35-
verilog_modulet &new_module=item.verilog_module;
3633

3734
if(ports.get_sub().size()==1 &&
3835
ports.get_sub().front().is_nil())
3936
ports.clear();
4037

38+
verilog_modulet new_module;
39+
4140
new_module.name=name.id();
4241
new_module.parameter_port_list.swap(parameter_port_list);
4342
new_module.ports.swap(ports);
4443
new_module.location=((const exprt &)module_keyword).source_location();
4544
new_module.module_items.swap(module_items);
4645

46+
items.back().verilog_module = new_module.to_irep();
47+
4748
// add to module map
4849
module_map[new_module.name]=--items.end();
4950
}
@@ -68,7 +69,7 @@ void verilog_parse_treet::modules_provided(
6869
it++)
6970
if(it->is_module())
7071
module_set.insert(
71-
id2string(verilog_module_symbol(it->verilog_module.name)));
72+
id2string(verilog_module_symbol(it->verilog_module.base_name())));
7273
}
7374

7475
/*******************************************************************\
@@ -91,7 +92,7 @@ void verilog_parse_treet::build_module_map()
9192
it!=items.end();
9293
it++)
9394
if(it->is_module())
94-
module_map[it->verilog_module.name]=it;
95+
module_map[it->verilog_module.base_name()] = it;
9596
}
9697

9798
/*******************************************************************\

src/verilog/verilog_parse_tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class verilog_parse_treet
4141
{
4242
}
4343

44-
verilog_modulet verilog_module;
44+
verilog_module_sourcet verilog_module;
4545

4646
exprt verilog_package_item;
4747

src/verilog/verilog_typecheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ bool verilog_typecheck(
18481848

18491849
return verilog_typecheck(
18501850
symbol_table,
1851-
it->second->verilog_module.to_irep(),
1851+
it->second->verilog_module,
18521852
parse_tree.standard,
18531853
message_handler);
18541854
}

0 commit comments

Comments
 (0)