-
Notifications
You must be signed in to change notification settings - Fork 478
/
smtchecker.ts
42 lines (37 loc) · 1.2 KB
/
smtchecker.ts
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
// This function checks the standard JSON output for auxiliaryInputRequested,
// where smtlib2queries represent the queries created by the SMTChecker.
// The function runs an SMT solver on each query and adjusts the input for
// another run.
// Returns null if no solving is requested.
function handleSMTQueries (inputJSON: any, outputJSON: any, solverFunction: any, solver?: any) {
const auxInputReq = outputJSON.auxiliaryInputRequested;
if (!auxInputReq) {
return null;
}
const queries = auxInputReq.smtlib2queries;
if (!queries || Object.keys(queries).length === 0) {
return null;
}
const responses = {};
for (const query in queries) {
responses[query] = solverFunction(queries[query], solver);
}
// Note: all existing solved queries are replaced.
// This assumes that all necessary queries are quested above.
inputJSON.auxiliaryInput = { smtlib2responses: responses };
return inputJSON;
}
function smtCallback (solverFunction, solver?: any) {
return function (query) {
try {
const result = solverFunction(query, solver);
return { contents: result };
} catch (err) {
return { error: err };
}
};
}
export = {
handleSMTQueries,
smtCallback
};