1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
use std::fmt ;
use self::SolverStyle::* ;
pub type ConfItem = Option<& 'static str> ;
#[inline(always)]
fn unsupported() -> ConfItem { None }
#[inline(always)]
fn supported(keyword: & 'static str) -> ConfItem { Some(keyword) }
#[derive(Debug, Clone)]
pub enum SolverStyle {
Z3,
CVC4,
}
impl SolverStyle {
pub fn default(self) -> SolverConf {
let cmd = self.cmd() ;
match self {
Z3 => SolverConf {
style: self,
cmd: cmd,
options: vec![
"-in", "-smt2"
],
parse_success: false,
unsat_cores: false,
check_sat_assuming: supported("check-sat"),
},
CVC4 => SolverConf {
style: self,
cmd: cmd,
options: vec![
"--smtlib-strict", "-qqqqq", "--interactive"
],
parse_success: false,
unsat_cores: false,
check_sat_assuming: unsupported(),
},
}
}
pub fn of_str(s: & str) -> Option<SolverStyle> {
match s {
"z3" | "Z3" => Some(Z3),
"cvc4" | "CVC4" => Some(CVC4),
_ => None,
}
}
pub fn str_keys() -> Vec<& 'static str> {
vec![ "z3", "Z3", "cvc4", "CVC4" ]
}
pub fn cmd(& self) -> String {
match * self {
Z3 => "z3".to_string(), CVC4 => "cvc4".to_string(),
}
}
}
impl fmt::Display for SolverStyle {
fn fmt(& self, fmt: & mut fmt::Formatter) -> fmt::Result {
match * self {
Z3 => write!(fmt, "z3"),
CVC4 => write!(fmt, "cvc4"),
}
}
}
#[derive(Debug, Clone)]
pub struct SolverConf {
style: SolverStyle,
cmd: String,
options: Vec<& 'static str>,
parse_success: bool,
unsat_cores: bool,
check_sat_assuming: ConfItem,
}
impl SolverConf {
#[inline(always)]
pub fn z3() -> Self { Z3.default() }
#[inline(always)]
pub fn cvc4() -> Self { CVC4.default() }
#[inline(always)]
pub fn style(& self) -> & SolverStyle { & self.style }
#[inline(always)]
pub fn get_cmd(& self) -> & str { & self.cmd }
#[inline(always)]
pub fn get_options(& self) -> & [& 'static str] { & self.options }
#[inline(always)]
pub fn get_parse_success(& self) -> bool { self.parse_success }
#[inline(always)]
pub fn get_check_sat_assuming(& self) -> & ConfItem {
& self.check_sat_assuming
}
#[inline(always)]
pub fn option(mut self, o: & 'static str) -> Self {
self.options.push(o) ;
self
}
#[inline(always)]
pub fn cmd(mut self, cmd: String) -> Self {
self.cmd = cmd ;
self
}
#[inline(always)]
#[cfg(not(no_parse_success))]
pub fn print_success(mut self) -> Self {
self.parse_success = true ;
self
}
#[inline(always)]
pub fn unsat_cores(mut self) -> Self {
self.unsat_cores = true ;
self
}
}