File tree 7 files changed +101
-2
lines changed
regression/smt2_solver/get-assignment
7 files changed +101
-2
lines changed Original file line number Diff line number Diff line change
1
+ CORE
2
+ get-assignment1.smt2
3
+
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^sat$
7
+ ^\(\(y_equality true\)\)$
8
+ --
Original file line number Diff line number Diff line change
1
+ (set-logic QF_BV)
2
+ (set-option :produce-assignments true )
3
+
4
+ (declare-const var_x (_ BitVec 8 )) ; nullary function
5
+ (declare-const var_y (_ BitVec 8 )) ; nullary function
6
+ (declare-const var_z (_ BitVec 8 )) ; nullary function
7
+
8
+ (assert (= var_x #x01 ))
9
+ (assert (! (= var_y #x02 ) :name d y_equality))
10
+ (assert (= var_z (bvadd var_x var_y)))
11
+
12
+ (check-sat )
13
+ (get-assignment )
Original file line number Diff line number Diff line change @@ -427,6 +427,39 @@ exprt smt2_parsert::function_application()
427
427
throw error (msg.str ());
428
428
}
429
429
}
430
+ else if (buffer == " !" )
431
+ {
432
+ // these are "term attributes"
433
+ const auto term = expression ();
434
+
435
+ while (peek () == KEYWORD)
436
+ {
437
+ next_token (); // eat the keyword
438
+ if (buffer == " named" )
439
+ {
440
+ // 'named terms' must be Boolean
441
+ if (term.type ().id () != ID_bool)
442
+ throw error (" named terms must be Boolean" );
443
+
444
+ if (next_token () == SYMBOL)
445
+ {
446
+ const symbol_exprt symbol_expr (buffer, bool_typet ());
447
+ auto &named_term = named_terms[symbol_expr.get_identifier ()];
448
+ named_term.term = term;
449
+ named_term.name = symbol_expr;
450
+ }
451
+ else
452
+ throw error (" invalid name attribute, expected symbol" );
453
+ }
454
+ else
455
+ throw error (" unknown term attribute" );
456
+ }
457
+
458
+ if (next_token () != CLOSE)
459
+ throw error (" expected ')' at end of term attribute" );
460
+ else
461
+ return term;
462
+ }
430
463
else
431
464
{
432
465
// non-indexed symbol; hash it
Original file line number Diff line number Diff line change @@ -42,6 +42,15 @@ class smt2_parsert:public smt2_tokenizert
42
42
using id_mapt=std::map<irep_idt, idt>;
43
43
id_mapt id_map;
44
44
45
+ struct named_termt
46
+ {
47
+ exprt term;
48
+ symbol_exprt name;
49
+ };
50
+
51
+ using named_termst = std::map<irep_idt, named_termt>;
52
+ named_termst named_terms;
53
+
45
54
bool exit;
46
55
47
56
// / This skips tokens until all bracketed expressions are closed
Original file line number Diff line number Diff line change @@ -232,6 +232,36 @@ void smt2_solvert::command(const std::string &c)
232
232
233
233
std::cout << smt2_format (constant_exprt (buffer, string_typet ())) << ' \n ' ;
234
234
}
235
+ else if (c == " get-assignment" )
236
+ {
237
+ // print satisfying assignment for all named expressions
238
+
239
+ if (status != SAT)
240
+ throw error (" model is not available" );
241
+
242
+ bool first = true ;
243
+
244
+ std::cout << ' (' ;
245
+ for (const auto &named_term : named_terms)
246
+ {
247
+ const symbol_tablet symbol_table;
248
+ const namespacet ns (symbol_table);
249
+ const auto value =
250
+ simplify_expr (solver.get (named_term.second .term ), ns);
251
+
252
+ if (value.is_constant ())
253
+ {
254
+ if (first)
255
+ first = false ;
256
+ else
257
+ std::cout << ' \n ' << ' ' ;
258
+
259
+ std::cout << ' (' << smt2_format (named_term.second .name ) << ' '
260
+ << smt2_format (value) << ' )' ;
261
+ }
262
+ }
263
+ std::cout << ' )' << ' \n ' ;
264
+ }
235
265
else if (c == " simplify" )
236
266
{
237
267
// this is a command that Z3 appears to implement
@@ -256,7 +286,6 @@ void smt2_solvert::command(const std::string &c)
256
286
| ( define-funs-rec ( hfunction_deci n+1 ) ( htermi n+1 ) )
257
287
| ( define-sort hsymboli ( hsymboli ??? ) hsorti )
258
288
| ( get-assertions )
259
- | ( get-assignment )
260
289
| ( get-info hinfo_flag i )
261
290
| ( get-model )
262
291
| ( get-option hkeywordi )
Original file line number Diff line number Diff line change @@ -254,7 +254,13 @@ void smt2_tokenizert::get_token_from_stream()
254
254
255
255
case ' :' : // keyword
256
256
token = get_simple_symbol ();
257
- return ;
257
+ if (token == SYMBOL)
258
+ {
259
+ token = KEYWORD;
260
+ return ;
261
+ }
262
+ else
263
+ throw error (" expecting symbol after colon" );
258
264
259
265
case ' #' :
260
266
if (in->get (ch))
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ class smt2_tokenizert:public parsert
60
60
STRING_LITERAL,
61
61
NUMERAL,
62
62
SYMBOL,
63
+ KEYWORD,
63
64
OPEN,
64
65
CLOSE
65
66
};
You can’t perform that action at this time.
0 commit comments