Skip to content

Commit c43cd1b

Browse files
committed
Verilog: stengthen typing when using verilog_instt
This adds typing for the sub-ireps of verilog_instt.
1 parent 2d26bc6 commit c43cd1b

File tree

4 files changed

+80
-46
lines changed

4 files changed

+80
-46
lines changed

src/verilog/verilog_expr.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,38 @@ class verilog_instt:public verilog_module_itemt
392392
{
393393
return static_cast<const exprt &>(find(ID_parameter_assignments)).operands();
394394
}
395+
396+
class instancet : public exprt
397+
{
398+
public:
399+
const irep_idt &name() const
400+
{
401+
return get(ID_instance);
402+
}
403+
404+
const exprt::operandst &connections() const
405+
{
406+
return operands();
407+
}
408+
409+
protected:
410+
using exprt::operands;
411+
};
412+
413+
using instancest = std::vector<instancet>;
414+
415+
const instancest &instances() const
416+
{
417+
return (const instancest &)(operands());
418+
}
419+
420+
instancest &instances()
421+
{
422+
return (instancest &)(operands());
423+
}
424+
425+
protected:
426+
using exprt::operands;
395427
};
396428

397429
inline const verilog_instt &to_verilog_inst(const exprt &expr)

src/verilog/verilog_synthesis.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,8 @@ void verilog_synthesist::synth_module_instance(
10581058
verilog_synthesis(
10591059
symbol_table, identifier, get_message_handler(), options);
10601060

1061-
forall_operands(it, statement)
1062-
expand_module_instance(symbol, *it, trans);
1061+
for(auto &instance : statement.instances())
1062+
expand_module_instance(symbol, instance, trans);
10631063
}
10641064

10651065
/*******************************************************************\
@@ -1249,20 +1249,21 @@ Function: verilog_synthesist::expand_module_instance
12491249
\*******************************************************************/
12501250

12511251
void verilog_synthesist::expand_module_instance(
1252-
const symbolt &symbol,
1253-
const exprt &op,
1252+
const symbolt &module_symbol,
1253+
const verilog_instt::instancet &instance,
12541254
transt &trans)
12551255
{
12561256
construct=constructt::OTHER;
12571257

1258-
const irep_idt &instance=op.get(ID_instance);
1258+
const irep_idt &instance_name = instance.name();
12591259

12601260
replace_mapt replace_map;
12611261

12621262
std::list<irep_idt> new_symbols;
12631263

1264-
for(auto it=symbol_table.symbol_module_map.lower_bound(symbol.module);
1265-
it!=symbol_table.symbol_module_map.upper_bound(symbol.module);
1264+
for(auto it =
1265+
symbol_table.symbol_module_map.lower_bound(module_symbol.module);
1266+
it != symbol_table.symbol_module_map.upper_bound(module_symbol.module);
12661267
it++)
12671268
{
12681269
const symbolt &symbol=ns.lookup(it->second);
@@ -1285,7 +1286,7 @@ void verilog_synthesist::expand_module_instance(
12851286

12861287
full_identifier=id2string(mode)+"::";
12871288
full_identifier+=id2string(verilog_module_name(module));
1288-
full_identifier+="."+id2string(instance);
1289+
full_identifier += "." + id2string(instance_name);
12891290
full_identifier+=identifier_without_module;
12901291

12911292
new_symbol.pretty_name=strip_verilog_prefix(full_identifier);
@@ -1320,11 +1321,11 @@ void verilog_synthesist::expand_module_instance(
13201321
// do the trans
13211322

13221323
{
1323-
exprt tmp=symbol.value;
1324+
exprt tmp = module_symbol.value;
13241325

13251326
if(tmp.id()!=ID_trans || tmp.operands().size()!=3)
13261327
{
1327-
error().source_location=op.source_location();
1328+
error().source_location = instance.source_location();
13281329
error() << "Expected transition system, but got `"
13291330
<< tmp.id() << '\'' << eom;
13301331
throw 0;
@@ -1336,7 +1337,7 @@ void verilog_synthesist::expand_module_instance(
13361337
trans.operands()[i].add_to_operands(std::move(tmp.operands()[i]));
13371338
}
13381339

1339-
instantiate_ports(instance, op, symbol, replace_map, trans);
1340+
instantiate_ports(instance_name, instance, module_symbol, replace_map, trans);
13401341
}
13411342

13421343
/*******************************************************************\

src/verilog/verilog_synthesis_class.h

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ Author: Daniel Kroening, [email protected]
99
#ifndef CPROVER_VERILOG_SYNTHESIS_CLASS_H
1010
#define CPROVER_VERILOG_SYNTHESIS_CLASS_H
1111

12-
#include <cassert>
13-
#include <map>
14-
#include <set>
15-
#include <unordered_set>
16-
1712
#include <util/mathematical_expr.h>
1813
#include <util/mp_arith.h>
1914
#include <util/options.h>
2015
#include <util/std_expr.h>
2116
#include <util/string_hash.h>
2217

23-
#include "verilog_typecheck_base.h"
18+
#include "verilog_expr.h"
2419
#include "verilog_symbol_table.h"
20+
#include "verilog_typecheck_base.h"
21+
22+
#include <cassert>
23+
#include <map>
24+
#include <set>
25+
#include <unordered_set>
2526

2627
/*******************************************************************\
2728
@@ -201,36 +202,36 @@ class verilog_synthesist:
201202

202203
// module items
203204
virtual void convert_module_items(symbolt &);
204-
void synth_module_item(const class verilog_module_itemt &, transt &);
205-
void synth_always(const class verilog_alwayst &);
206-
void synth_initial(const class verilog_initialt &);
207-
void synth_assert_module_item(const class verilog_module_itemt &);
208-
void synth_assume_module_item(const class verilog_module_itemt &);
209-
void synth_continuous_assign(const class verilog_continuous_assignt &);
205+
void synth_module_item(const verilog_module_itemt &, transt &);
206+
void synth_always(const verilog_alwayst &);
207+
void synth_initial(const verilog_initialt &);
208+
void synth_assert_module_item(const verilog_module_itemt &);
209+
void synth_assume_module_item(const verilog_module_itemt &);
210+
void synth_continuous_assign(const verilog_continuous_assignt &);
210211
void synth_force_rec(exprt &lhs, exprt &rhs, transt &);
211-
void synth_module_instance(const class verilog_instt &, transt &);
212-
void synth_module_instance_builtin(const class verilog_inst_builtint &, transt &);
212+
void synth_module_instance(const verilog_instt &, transt &);
213+
void synth_module_instance_builtin(const verilog_inst_builtint &, transt &);
213214

214215
// statements
215-
void synth_statement(const class verilog_statementt &);
216-
void synth_decl(const class verilog_declt &);
217-
void synth_block(const class verilog_blockt &);
218-
void synth_case(const class verilog_statementt &);
219-
void synth_if(const class verilog_ift &);
220-
void synth_event_guard(const class verilog_event_guardt &);
221-
void synth_delay(const class verilog_delayt &);
222-
void synth_for(const class verilog_fort &);
223-
void synth_force(const class verilog_forcet &);
216+
void synth_statement(const verilog_statementt &);
217+
void synth_decl(const verilog_declt &);
218+
void synth_block(const verilog_blockt &);
219+
void synth_case(const verilog_statementt &);
220+
void synth_if(const verilog_ift &);
221+
void synth_event_guard(const verilog_event_guardt &);
222+
void synth_delay(const verilog_delayt &);
223+
void synth_for(const verilog_fort &);
224+
void synth_force(const verilog_forcet &);
224225
void synth_force_rec(const exprt &lhs, const exprt &rhs);
225-
void synth_forever(const class verilog_forevert &);
226-
void synth_while(const class verilog_whilet &);
227-
void synth_repeat(const class verilog_repeatt &);
228-
void synth_function_call_or_task_enable(const class verilog_function_callt &);
226+
void synth_forever(const verilog_forevert &);
227+
void synth_while(const verilog_whilet &);
228+
void synth_repeat(const verilog_repeatt &);
229+
void synth_function_call_or_task_enable(const verilog_function_callt &);
229230
[[nodiscard]] exprt synth_expr(exprt expr, symbol_statet symbol_state);
230231
void synth_assign(const exprt &, bool blocking);
231-
void synth_assert(const class verilog_assertt &);
232-
void synth_assume(const class verilog_assumet &);
233-
void synth_prepostincdec(const class verilog_statementt &);
232+
void synth_assert(const verilog_assertt &);
233+
void synth_assume(const verilog_assumet &);
234+
void synth_prepostincdec(const verilog_statementt &);
234235
void synth_assignments(transt &);
235236

236237
exprt make_supply_value(const irep_idt &decl_class, const typet &);
@@ -259,8 +260,8 @@ class verilog_synthesist:
259260
const exprt &case_operand);
260261

261262
void expand_module_instance(
262-
const symbolt &symbol,
263-
const exprt &op,
263+
const symbolt &module_symbol,
264+
const verilog_instt::instancet &,
264265
transt &trans);
265266

266267
void expand_hierarchical_identifier(

src/verilog/verilog_typecheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,9 @@ void verilog_typecheckt::convert_inst(verilog_instt &inst)
571571
}
572572

573573
// get the instance symbols
574-
Forall_operands(it, inst)
574+
for(auto &instance : inst.instances())
575575
{
576-
const auto instance_name = it->get(ID_instance);
576+
const auto instance_name = instance.name();
577577

578578
const irep_idt instance_identifier =
579579
id2string(module_symbol.name) + "." + id2string(instance_name);
@@ -598,7 +598,7 @@ void verilog_typecheckt::convert_inst(verilog_instt &inst)
598598
symbol_table_lookup(new_module_identifier);
599599

600600
// check the port connections
601-
typecheck_port_connections(*it, parameterized_module_symbol);
601+
typecheck_port_connections(instance, parameterized_module_symbol);
602602
}
603603
}
604604

0 commit comments

Comments
 (0)