Skip to content

Commit c0a19aa

Browse files
committed
Split SMTChecker and SMTSolver
1 parent 9c2512e commit c0a19aa

File tree

4 files changed

+43
-38
lines changed

4 files changed

+43
-38
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"index.js",
2929
"linker.js",
3030
"smtchecker.js",
31+
"smtsolver.js",
3132
"solcjs",
3233
"soljson.js",
3334
"translate.js",

smtchecker.js

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,9 @@
1-
var commandExistsSync = require('command-exists').sync;
2-
var execSync = require('child_process').execSync;
3-
var fs = require('fs-extra');
4-
var tmp = require('tmp');
5-
6-
var potentialSolvers = [
7-
{
8-
name: 'z3',
9-
params: ''
10-
},
11-
{
12-
name: 'cvc4',
13-
params: '--lang=smt2'
14-
}
15-
];
16-
var solvers = potentialSolvers.filter(solver => commandExistsSync(solver.name));
17-
18-
function solve (query) {
19-
var tmpFile = tmp.fileSync();
20-
fs.writeFileSync(tmpFile.name, query);
21-
// TODO For now only the first SMT solver found is used.
22-
// At some point a computation similar to the one done in
23-
// SMTPortfolio::check should be performed, where the results
24-
// given by different solvers are compared and an error is
25-
// reported if solvers disagree (i.e. SAT vs UNSAT).
26-
var solverOutput = execSync(solvers[0].name + ' ' + solvers[0].params + ' ' + tmpFile.name);
27-
// Trigger early manual cleanup
28-
tmpFile.removeCallback();
29-
return solverOutput.toString();
30-
}
31-
321
// This function checks the standard JSON output for auxiliaryInputRequested,
332
// where smtlib2queries represent the queries created by the SMTChecker.
343
// The function runs an SMT solver on each query and adjusts the input for
354
// another run.
365
// Returns null if no solving is requested.
37-
function handleSMTQueries (inputJSON, outputJSON) {
6+
function handleSMTQueries (inputJSON, outputJSON, solver) {
387
var auxInputReq = outputJSON.auxiliaryInputRequested;
398
if (!auxInputReq) {
409
return null;
@@ -45,13 +14,9 @@ function handleSMTQueries (inputJSON, outputJSON) {
4514
return null;
4615
}
4716

48-
if (solvers.length === 0) {
49-
throw new Error('No SMT solver available. Assertion checking will not be performed.');
50-
}
51-
5217
var responses = {};
5318
for (var query in queries) {
54-
responses[query] = solve(queries[query]);
19+
responses[query] = solver(queries[query]);
5520
}
5621

5722
// Note: all existing solved queries are replaced.

smtsolver.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var commandExistsSync = require('command-exists').sync;
2+
var execSync = require('child_process').execSync;
3+
var fs = require('fs-extra');
4+
var tmp = require('tmp');
5+
6+
var potentialSolvers = [
7+
{
8+
name: 'z3',
9+
params: ''
10+
},
11+
{
12+
name: 'cvc4',
13+
params: '--lang=smt2'
14+
}
15+
];
16+
var solvers = potentialSolvers.filter(solver => commandExistsSync(solver.name));
17+
18+
function solve (query) {
19+
if (solvers.length === 0) {
20+
throw new Error('No SMT solver available. Assertion checking will not be performed.');
21+
}
22+
23+
var tmpFile = tmp.fileSync();
24+
fs.writeFileSync(tmpFile.name, query);
25+
// TODO For now only the first SMT solver found is used.
26+
// At some point a computation similar to the one done in
27+
// SMTPortfolio::check should be performed, where the results
28+
// given by different solvers are compared and an error is
29+
// reported if solvers disagree (i.e. SAT vs UNSAT).
30+
var solverOutput = execSync(solvers[0].name + ' ' + solvers[0].params + ' ' + tmpFile.name);
31+
// Trigger early manual cleanup
32+
tmpFile.removeCallback();
33+
return solverOutput.toString();
34+
}
35+
36+
module.exports = {
37+
smtSolver: solve
38+
};

solcjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var fs = require('fs-extra');
77
var path = require('path');
88
var solc = require('./index.js');
99
var smtchecker = require('./smtchecker.js');
10+
var smtsolver = require('./smtsolver.js');
1011
// FIXME: remove annoying exception catcher of Emscripten
1112
// see https://github.com/chriseth/browser-solidity/issues/167
1213
process.removeAllListeners('uncaughtException');
@@ -56,7 +57,7 @@ if (argv['standard-json']) {
5657
var output = solc.compileStandardWrapper(input);
5758

5859
try {
59-
var inputJSON = smtchecker.handleSMTQueries(JSON.parse(input), JSON.parse(output));
60+
var inputJSON = smtchecker.handleSMTQueries(JSON.parse(input), JSON.parse(output), smtsolver.smtSolver);
6061
if (inputJSON) {
6162
output = solc.compileStandardWrapper(JSON.stringify(inputJSON));
6263
}

0 commit comments

Comments
 (0)