1
- use std:: collections:: { HashMap } ;
2
- use std:: fmt;
3
- use crate :: ast:: { Decl , DeclX , Ident , SnapShots , Typ , TypX } ;
1
+ use crate :: ast:: { Decl , DeclX , Ident , SnapShots , Typ , TypX } ;
4
2
use crate :: context:: Context ;
3
+ use std:: collections:: HashMap ;
4
+ use std:: fmt;
5
5
use z3:: ast:: { Bool , Dynamic , Int } ;
6
6
//use z3::{FuncDecl, Sort};
7
7
8
8
#[ derive( Debug ) ]
9
9
pub struct Model < ' a > {
10
10
z3_model : z3:: Model < ' a > ,
11
11
id_snapshots : SnapShots ,
12
- value_snapshots : HashMap < Ident , HashMap < Ident , String > >
12
+ value_snapshots : HashMap < Ident , HashMap < Ident , String > > ,
13
13
}
14
14
15
15
// TODO: Duplicated from smt_verify
@@ -25,21 +25,16 @@ fn new_const<'ctx>(context: &mut Context<'ctx>, name: &String, typ: &Typ) -> Dyn
25
25
}
26
26
}
27
27
28
-
29
28
impl < ' a > Model < ' a > {
30
- pub fn new ( model : z3:: Model < ' a > , snapshots : SnapShots ) -> Model < ' a > {
29
+ pub fn new ( model : z3:: Model < ' a > , snapshots : SnapShots ) -> Model < ' a > {
31
30
println ! ( "Creating a new model with {} snapshots" , snapshots. len( ) ) ;
32
- Model {
33
- z3_model : model,
34
- id_snapshots : snapshots,
35
- value_snapshots : HashMap :: new ( ) ,
36
- }
31
+ Model { z3_model : model, id_snapshots : snapshots, value_snapshots : HashMap :: new ( ) }
37
32
}
38
33
39
- // pub fn save_snapshots(&self, snapshots: SnapShots) {
40
- // self.snapshots = snapshots.clone();
41
- // }
42
- fn lookup_z3_var ( & self , var_name : & String , var_smt : & Dynamic ) -> String {
34
+ // pub fn save_snapshots(&self, snapshots: SnapShots) {
35
+ // self.snapshots = snapshots.clone();
36
+ // }
37
+ fn lookup_z3_var ( & self , var_name : & String , var_smt : & Dynamic ) -> String {
43
38
if let Some ( x) = self . z3_model . eval ( var_smt) {
44
39
if let Some ( b) = x. as_bool ( ) {
45
40
format ! ( "{}" , b)
@@ -55,17 +50,19 @@ impl<'a> Model<'a> {
55
50
}
56
51
}
57
52
58
-
59
53
/// Reconstruct an AIR-level model based on the Z3 model
60
54
pub fn build ( & mut self , context : & mut Context , local_vars : Vec < Decl > ) {
61
- println ! ( "Building the AIR model" ) ;
55
+ println ! ( "Building the AIR model" ) ;
62
56
for ( snap_id, id_snapshot) in & self . id_snapshots {
63
57
let mut value_snapshot = HashMap :: new ( ) ;
64
58
println ! ( "Snapshot {} has {} variables" , snap_id, id_snapshot. len( ) ) ;
65
59
for ( var_id, var_count) in & * id_snapshot {
66
60
let var_name = crate :: var_to_const:: rename_var ( & * var_id, * var_count) ;
67
61
println ! ( "\t {}" , var_name) ;
68
- let var_smt = context. vars . get ( & var_name) . unwrap_or_else ( || panic ! ( "internal error: variable {} not found" , var_name) ) ;
62
+ let var_smt = context
63
+ . vars
64
+ . get ( & var_name)
65
+ . unwrap_or_else ( || panic ! ( "internal error: variable {} not found" , var_name) ) ;
69
66
let val = self . lookup_z3_var ( & var_name, var_smt) ;
70
67
value_snapshot. insert ( var_id. clone ( ) , val) ;
71
68
}
@@ -86,7 +83,7 @@ impl<'a> Model<'a> {
86
83
}
87
84
}
88
85
89
- pub fn query_variable ( & self , snapshot : Ident , name : Ident ) -> Option < String > {
86
+ pub fn query_variable ( & self , snapshot : Ident , name : Ident ) -> Option < String > {
90
87
Some ( self . value_snapshots . get ( & snapshot) ?. get ( & name) ?. to_string ( ) )
91
88
}
92
89
}
@@ -103,4 +100,3 @@ impl<'a> fmt::Display for Model<'a> {
103
100
Ok ( ( ) )
104
101
}
105
102
}
106
-
0 commit comments