Skip to content

Commit 538cb98

Browse files
authored
Merge pull request #716 from diffblue/extract-sequence
BMC: extract instantiate_sequence into separate file
2 parents 1278e71 + a1b9dff commit 538cb98

File tree

4 files changed

+210
-181
lines changed

4 files changed

+210
-181
lines changed

src/trans-word-level/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SRC = counterexample_word_level.cpp \
44
property.cpp \
55
trans_trace_word_level.cpp \
66
instantiate_word_level.cpp \
7+
sequence.cpp \
78
show_modules.cpp \
89
show_module_hierarchy.cpp \
910
unwind.cpp \

src/trans-word-level/instantiate_word_level.cpp

Lines changed: 2 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Author: Daniel Kroening, [email protected]
1717
#include <verilog/sva_expr.h>
1818
#include <verilog/verilog_expr.h>
1919

20-
#include "property.h"
20+
#include "sequence.h"
2121

2222
/*******************************************************************\
2323
@@ -91,11 +91,6 @@ class wl_instantiatet
9191
[[nodiscard]] std::pair<mp_integer, exprt>
9292
instantiate_rec(exprt, const mp_integer &t) const;
9393
[[nodiscard]] typet instantiate_rec(typet, const mp_integer &t) const;
94-
95-
// Returns a list of match points and matching conditions
96-
// for the given sequence expression starting at time t
97-
[[nodiscard]] std::vector<std::pair<mp_integer, exprt>>
98-
instantiate_sequence(exprt, const mp_integer &t) const;
9994
};
10095

10196
/*******************************************************************\
@@ -121,180 +116,6 @@ static exprt default_value(const typet &type)
121116

122117
/*******************************************************************\
123118
124-
Function: wl_instantiatet::instantiate_sequence
125-
126-
Inputs:
127-
128-
Outputs:
129-
130-
Purpose:
131-
132-
\*******************************************************************/
133-
134-
std::vector<std::pair<mp_integer, exprt>>
135-
wl_instantiatet::instantiate_sequence(exprt expr, const mp_integer &t) const
136-
{
137-
if(expr.id() == ID_sva_cycle_delay) // ##[1:2] something
138-
{
139-
auto &sva_cycle_delay_expr = to_sva_cycle_delay_expr(expr);
140-
141-
if(sva_cycle_delay_expr.to().is_nil()) // ##1 something
142-
{
143-
mp_integer offset;
144-
if(to_integer_non_constant(sva_cycle_delay_expr.from(), offset))
145-
throw "failed to convert sva_cycle_delay offset";
146-
147-
const auto u = t + offset;
148-
149-
// Do we exceed the bound? Make it 'true'
150-
if(u >= no_timeframes)
151-
{
152-
DATA_INVARIANT(no_timeframes != 0, "must have timeframe");
153-
return {{no_timeframes - 1, true_exprt()}};
154-
}
155-
else
156-
return instantiate_sequence(sva_cycle_delay_expr.op(), u);
157-
}
158-
else
159-
{
160-
mp_integer from, to;
161-
if(to_integer_non_constant(sva_cycle_delay_expr.from(), from))
162-
throw "failed to convert sva_cycle_delay offsets";
163-
164-
if(sva_cycle_delay_expr.to().id() == ID_infinity)
165-
{
166-
DATA_INVARIANT(no_timeframes != 0, "must have timeframe");
167-
to = no_timeframes - 1;
168-
}
169-
else if(to_integer_non_constant(sva_cycle_delay_expr.to(), to))
170-
throw "failed to convert sva_cycle_delay offsets";
171-
172-
auto lower = t + from;
173-
auto upper = t + to;
174-
175-
// Do we exceed the bound? Make it 'true'
176-
if(upper >= no_timeframes)
177-
{
178-
DATA_INVARIANT(no_timeframes != 0, "must have timeframe");
179-
return {{no_timeframes - 1, true_exprt()}};
180-
}
181-
182-
std::vector<std::pair<mp_integer, exprt>> match_points;
183-
184-
for(mp_integer u = lower; u <= upper; ++u)
185-
{
186-
auto sub_result = instantiate_sequence(sva_cycle_delay_expr.op(), u);
187-
for(auto &match_point : sub_result)
188-
match_points.push_back(match_point);
189-
}
190-
191-
return match_points;
192-
}
193-
}
194-
else if(
195-
expr.id() == ID_sva_sequence_concatenation ||
196-
expr.id() == ID_sva_overlapped_implication ||
197-
expr.id() == ID_sva_non_overlapped_implication)
198-
{
199-
auto &implication = to_binary_expr(expr);
200-
std::vector<std::pair<mp_integer, exprt>> result;
201-
202-
// This is the product of the match points on the LHS and RHS
203-
const auto lhs_match_points = instantiate_sequence(implication.lhs(), t);
204-
for(auto &lhs_match_point : lhs_match_points)
205-
{
206-
// The RHS of the non-overlapped implication starts one timeframe later
207-
auto t_rhs = expr.id() == ID_sva_non_overlapped_implication
208-
? lhs_match_point.first + 1
209-
: lhs_match_point.first;
210-
211-
// Do we exceed the bound? Make it 'true'
212-
if(t_rhs >= no_timeframes)
213-
{
214-
DATA_INVARIANT(no_timeframes != 0, "must have timeframe");
215-
return {{no_timeframes - 1, true_exprt()}};
216-
}
217-
218-
const auto rhs_match_points =
219-
instantiate_sequence(implication.rhs(), t_rhs);
220-
221-
for(auto &rhs_match_point : rhs_match_points)
222-
{
223-
exprt cond;
224-
if(expr.id() == ID_sva_sequence_concatenation)
225-
{
226-
cond = and_exprt{lhs_match_point.second, rhs_match_point.second};
227-
}
228-
else if(
229-
expr.id() == ID_sva_overlapped_implication ||
230-
expr.id() == ID_sva_non_overlapped_implication)
231-
{
232-
cond = implies_exprt{lhs_match_point.second, rhs_match_point.second};
233-
}
234-
else
235-
PRECONDITION(false);
236-
237-
result.push_back({rhs_match_point.first, cond});
238-
}
239-
}
240-
241-
return result;
242-
}
243-
else if(expr.id() == ID_sva_sequence_intersect)
244-
{
245-
// IEEE 1800-2017 16.9.6
246-
PRECONDITION(false);
247-
}
248-
else if(expr.id() == ID_sva_sequence_first_match)
249-
{
250-
PRECONDITION(false);
251-
}
252-
else if(expr.id() == ID_sva_sequence_throughout)
253-
{
254-
PRECONDITION(false);
255-
}
256-
else if(expr.id() == ID_sva_sequence_within)
257-
{
258-
PRECONDITION(false);
259-
}
260-
else if(expr.id() == ID_sva_and)
261-
{
262-
// IEEE 1800-2017 16.9.5
263-
// 1. Both operands must match.
264-
// 2. Both sequences start at the same time.
265-
// 3. The end time of the composite sequence is
266-
// the end time of the operand sequence that completes last.
267-
// Condition (3) is TBD.
268-
exprt::operandst conjuncts;
269-
270-
for(auto &op : expr.operands())
271-
conjuncts.push_back(instantiate_rec(op, t).second);
272-
273-
exprt condition = conjunction(conjuncts);
274-
return {{t, condition}};
275-
}
276-
else if(expr.id() == ID_sva_or)
277-
{
278-
// IEEE 1800-2017 16.9.7
279-
// The set of matches of a or b is the set union of the matches of a
280-
// and the matches of b.
281-
std::vector<std::pair<mp_integer, exprt>> result;
282-
283-
for(auto &op : expr.operands())
284-
for(auto &match_point : instantiate_sequence(op, t))
285-
result.push_back(match_point);
286-
287-
return result;
288-
}
289-
else
290-
{
291-
// not a sequence, evaluate as state predicate
292-
return {instantiate_rec(expr, t)};
293-
}
294-
}
295-
296-
/*******************************************************************\
297-
298119
Function: wl_instantiatet::instantiate_rec
299120
300121
Inputs:
@@ -324,7 +145,7 @@ wl_instantiatet::instantiate_rec(exprt expr, const mp_integer &t) const
324145
{
325146
// sequence expressions -- these may have multiple potential
326147
// match points, and evaluate to true if any of them matches
327-
const auto match_points = instantiate_sequence(expr, t);
148+
const auto match_points = instantiate_sequence(expr, t, no_timeframes, ns);
328149
exprt::operandst disjuncts;
329150
disjuncts.reserve(match_points.size());
330151
mp_integer max = t;

0 commit comments

Comments
 (0)