Skip to content

Commit 6c653e5

Browse files
committed
verilog_synthesist::current_value can be const
This method can be const by replacing the [] operator on a map that is used by .find(...).
1 parent ada2100 commit 6c653e5

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

src/verilog/verilog_synthesis.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,7 +3404,7 @@ Function: verilog_synthesist::symbol_expr
34043404

34053405
exprt verilog_synthesist::symbol_expr(
34063406
const symbolt &symbol,
3407-
curr_or_nextt curr_or_next)
3407+
curr_or_nextt curr_or_next) const
34083408
{
34093409
exprt result=exprt(curr_or_next==NEXT?ID_next_symbol:ID_symbol, symbol.type);
34103410
result.set(ID_identifier, symbol.name);
@@ -3527,21 +3527,23 @@ Function: verilog_synthesist::current_value
35273527
exprt verilog_synthesist::current_value(
35283528
const value_mapt::mapt &map,
35293529
const symbolt &symbol,
3530-
bool use_previous_assignments)
3530+
bool use_previous_assignments) const
35313531
{
35323532
if(!symbol.is_state_var)
35333533
{
35343534
if(use_previous_assignments)
35353535
{
35363536
// see if we have a previous assignment
3537-
const assignmentt &assignment=assignments[symbol.name];
3538-
const exprt &value=
3539-
(construct==constructt::INITIAL)?
3540-
assignment.init.value:
3541-
assignment.next.value;
3537+
auto assignment_it = assignments.find(symbol.name);
3538+
if(assignment_it != assignments.end())
3539+
{
3540+
const exprt &value = (construct == constructt::INITIAL)
3541+
? assignment_it->second.init.value
3542+
: assignment_it->second.next.value;
35423543

3543-
if(value.is_not_nil())
3544-
return value; // done
3544+
if(value.is_not_nil())
3545+
return value; // done
3546+
}
35453547
}
35463548

35473549
return symbol_expr(symbol, CURRENT);
@@ -3557,13 +3559,16 @@ exprt verilog_synthesist::current_value(
35573559
if(use_previous_assignments)
35583560
{
35593561
// see if we have a previous assignment
3560-
const assignmentt &assignment=assignments[symbol.name];
3561-
const exprt &value=
3562-
(construct==constructt::INITIAL)?
3563-
assignment.init.value:assignment.next.value;
3562+
auto assignment_it = assignments.find(symbol.name);
3563+
if(assignment_it != assignments.end())
3564+
{
3565+
const exprt &value = (construct == constructt::INITIAL)
3566+
? assignment_it->second.init.value
3567+
: assignment_it->second.next.value;
35643568

3565-
if(value.is_not_nil())
3566-
return value; // done
3569+
if(value.is_not_nil())
3570+
return value; // done
3571+
}
35673572
}
35683573

35693574
if(

src/verilog/verilog_synthesis_class.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,25 @@ class verilog_synthesist:
177177

178178
exprt guarded_expr(exprt) const;
179179
};
180-
180+
181181
exprt current_value(
182182
const value_mapt::mapt &map,
183-
const symbolt &symbol,
184-
bool use_previous_assignments);
183+
const symbolt &,
184+
bool use_previous_assignments) const;
185185

186186
exprt guarded_expr(exprt expr) const
187187
{
188188
PRECONDITION(value_map != NULL);
189189
return value_map->guarded_expr(expr);
190190
}
191191

192-
inline exprt current_value(const symbolt &symbol)
192+
inline exprt current_value(const symbolt &symbol) const
193193
{
194194
PRECONDITION(value_map != NULL);
195195
return current_value(value_map->current, symbol, false);
196196
}
197197

198-
inline exprt final_value(const symbolt &symbol)
198+
inline exprt final_value(const symbolt &symbol) const
199199
{
200200
PRECONDITION(value_map != NULL);
201201
return current_value(value_map->final, symbol, true);
@@ -279,9 +279,7 @@ class verilog_synthesist:
279279

280280
typedef enum { CURRENT, NEXT } curr_or_nextt;
281281

282-
exprt symbol_expr(
283-
const symbolt &symbol,
284-
curr_or_nextt curr_or_next);
282+
exprt symbol_expr(const symbolt &, curr_or_nextt curr_or_next) const;
285283

286284
void extract_expr(exprt &dest, unsigned bit);
287285

0 commit comments

Comments
 (0)