2017-03-30 02:50:05 +09:00
|
|
|
let utils = require('../utils/utils.js');
|
|
|
|
let solcProcess;
|
|
|
|
let compilerLoaded = false;
|
2017-02-24 19:27:27 -05:00
|
|
|
|
2017-03-30 20:12:39 +09:00
|
|
|
class SolcW {
|
2017-02-24 19:27:27 -05:00
|
|
|
|
2017-03-30 20:12:39 +09:00
|
|
|
load_compiler(done) {
|
|
|
|
if (compilerLoaded) {
|
|
|
|
done();
|
2017-02-24 22:49:34 -05:00
|
|
|
}
|
2017-03-30 20:12:39 +09:00
|
|
|
solcProcess = require('child_process').fork(utils.joinPath(__dirname, '/solcP.js'));
|
|
|
|
solcProcess.once('message', function (msg) {
|
|
|
|
if (msg.result !== 'loadedCompiler') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
compilerLoaded = true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
solcProcess.send({action: 'loadCompiler'});
|
|
|
|
}
|
2017-02-24 22:49:34 -05:00
|
|
|
|
2017-03-30 20:12:39 +09:00
|
|
|
isCompilerLoaded() {
|
|
|
|
return (compilerLoaded === true);
|
|
|
|
}
|
2017-02-25 15:47:35 -05:00
|
|
|
|
2017-03-30 20:12:39 +09:00
|
|
|
compile(obj, optimize, done) {
|
|
|
|
solcProcess.once('message', function (msg) {
|
|
|
|
if (msg.result !== 'compilation') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
done(msg.output);
|
|
|
|
});
|
|
|
|
solcProcess.send({action: 'compile', obj: obj, optimize: optimize});
|
|
|
|
}
|
|
|
|
}
|
2017-02-24 19:27:27 -05:00
|
|
|
|
|
|
|
module.exports = SolcW;
|
|
|
|
|