-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathProverInterface.cs
More file actions
325 lines (270 loc) · 7.64 KB
/
ProverInterface.cs
File metadata and controls
325 lines (270 loc) · 7.64 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Boogie.SMTLib;
using Microsoft.Boogie.VCExprAST;
namespace Microsoft.Boogie;
public enum SolverOutcome
{
Valid,
Invalid,
TimeOut,
OutOfMemory,
OutOfResource,
Undetermined,
Bounded
}
public abstract class ProverInterface
{
public int SentSize { get; protected set; }
public static ProverInterface CreateProver(SMTLibOptions libOptions, Program prog,
string /*?*/ logFilePath, bool appendLogFile, uint timeout,
int taskID = -1)
{
Contract.Requires(prog != null);
ProverOptions options = cce.NonNull(libOptions.TheProverFactory).BlankProverOptions(libOptions);
if (logFilePath != null)
{
options.LogFilename = logFilePath;
if (appendLogFile)
{
options.AppendLogFile = appendLogFile;
}
}
if (timeout > 0)
{
options.TimeLimit = Util.BoundedMultiply(timeout, 1000);
}
if (taskID >= 0)
{
options.Parse(libOptions.Cho[taskID].ProverOptions);
}
else
{
options.Parse(libOptions.ProverOptions);
}
ProverContext ctx = libOptions.TheProverFactory.NewProverContext(options);
// set up the context
foreach (Declaration decl in prog.TopLevelDeclarations)
{
Contract.Assert(decl != null);
TypeCtorDecl t = decl as TypeCtorDecl;
if (t != null)
{
ctx.DeclareType(t, null);
}
}
foreach (Declaration decl in prog.TopLevelDeclarations)
{
Contract.Assert(decl != null);
Constant c = decl as Constant;
if (c != null)
{
ctx.DeclareConstant(c, c.Unique, null);
}
else
{
Function f = decl as Function;
if (f != null)
{
ctx.DeclareFunction(f, null);
}
}
}
foreach (var ax in prog.Axioms)
{
ctx.AddAxiom(ax, null);
}
foreach (Declaration decl in prog.TopLevelDeclarations)
{
Contract.Assert(decl != null);
GlobalVariable v = decl as GlobalVariable;
if (v != null)
{
ctx.DeclareGlobalVariable(v, null);
}
}
return libOptions.TheProverFactory.SpawnProver(libOptions, options, ctx);
}
public readonly ISet<VCExprVar> NamedAssumes = new HashSet<VCExprVar>();
public class ErrorHandler
{
protected SMTLibOptions options;
protected ErrorHandler(SMTLibOptions options)
{
this.options = options;
}
public virtual void AddCoveredElement(TrackedNodeComponent elt)
{
throw new System.NotImplementedException();
}
// Used in CheckOutcomeCore
public virtual int StartingProcId()
{
return 0;
}
public virtual void OnModel(IList<string> labels, Model model, SolverOutcome proverOutcome)
{
Contract.Requires(cce.NonNullElements(labels));
}
public virtual void OnResourceExceeded(string message,
IEnumerable<Tuple<AssertCmd, TransferCmd>> assertCmds = null)
{
Contract.Requires(message != null);
}
public virtual void OnProverWarning(string message)
{
Contract.Requires(message != null);
switch (options.PrintProverWarnings)
{
case CoreOptions.ProverWarnings.None:
break;
case CoreOptions.ProverWarnings.Stdout:
options.OutputWriter.WriteLine("Prover warning: " + message);
break;
case CoreOptions.ProverWarnings.Stderr:
Console.Error.WriteLine("Prover warning: " + message);
break;
default:
Contract.Assume(false);
throw new cce.UnreachableException(); // unexpected case
}
}
public virtual void OnProverError(string message)
{
// no-op by default.
//Errors are always printed to console by the prover
}
public virtual Absy Label2Absy(string label)
{
Contract.Requires(label != null);
Contract.Ensures(Contract.Result<Absy>() != null);
throw new System.NotImplementedException();
}
}
public abstract Task<SolverOutcome> Check(string descriptiveName, VCExpr vc, ErrorHandler handler, int errorLimit, CancellationToken cancellationToken);
public virtual void LogComment(string comment)
{
Contract.Requires(comment != null);
}
public virtual void Close()
{
}
public abstract Task Reset(VCExpressionGenerator gen);
public abstract void FullReset(VCExpressionGenerator gen);
/// <summary>
/// MSchaef: Allows to Push a VCExpression as Axiom on the prover stack (beta)
/// for now it is only implemented by ProcessTheoremProver and still requires some
/// testing
/// </summary>
public virtual void PushVCExpression(VCExpr vc)
{
Contract.Requires(vc != null);
throw new NotImplementedException();
}
public virtual string VCExpressionToString(VCExpr vc)
{
Contract.Requires(vc != null);
Contract.Ensures(Contract.Result<string>() != null);
throw new NotImplementedException();
}
public virtual void Pop()
{
Contract.EnsuresOnThrow<UnexpectedProverOutputException>(true);
throw new NotImplementedException();
}
public virtual int NumAxiomsPushed()
{
throw new NotImplementedException();
}
public virtual int FlushAxiomsToTheoremProver()
{
Contract.EnsuresOnThrow<UnexpectedProverOutputException>(true);
throw new NotImplementedException();
}
// (assert vc)
public virtual void Assert(VCExpr vc, bool polarity, bool isSoft = false, int weight = 1, string name = null)
{
throw new NotImplementedException();
}
public virtual Task<List<string>> UnsatCore()
{
throw new NotImplementedException();
}
// (assert implicit-axioms)
public virtual void AssertAxioms()
{
throw new NotImplementedException();
}
// (check-sat)
public virtual void Check()
{
throw new NotImplementedException();
}
// (check-sat + get-unsat-core + checkOutcome)
public virtual Task<(SolverOutcome, List<int>)> CheckAssumptions(List<VCExpr> assumptions, ErrorHandler handler,
CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public virtual Task<(SolverOutcome, List<int>)> CheckAssumptions(List<VCExpr> hardAssumptions, List<VCExpr> softAssumptions,
ErrorHandler handler, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
// (push 1)
public virtual void Push()
{
throw new NotImplementedException();
}
// Set theorem prover timeout for the next "check-sat"
public virtual void SetTimeout(uint ms)
{
}
public virtual void SetRlimit(uint limit)
{
}
public virtual void SetAdditionalSmtOptions(IEnumerable<OptionValue> entries)
{
}
public virtual int GetRCount()
{
throw new NotImplementedException();
}
public abstract ProverContext Context { get; }
public abstract VCExpressionGenerator VCExprGen { get; }
public virtual void DefineMacro(Macro fun, VCExpr vc)
{
throw new NotImplementedException();
}
public class VCExprEvaluationException : Exception
{
}
public virtual Task<object> Evaluate(VCExpr expr)
{
throw new NotImplementedException();
}
// Assert vc tagged with a name
public virtual void AssertNamed(VCExpr vc, bool polarity, string name)
{
throw new NotImplementedException();
}
public abstract Task GoBackToIdle();
}
public class UnexpectedProverOutputException : ProverException
{
public UnexpectedProverOutputException(string s)
: base(s)
{
}
}
public class ProverDiedException : UnexpectedProverOutputException
{
public ProverDiedException()
: base("Prover died with no further output, perhaps it ran out of memory or was killed.")
{
}
}