|
|
@ -1,3 +1,5 @@ |
|
|
|
|
|
|
|
var solc = require('solc/wrapper'); |
|
|
|
|
|
|
|
|
|
|
|
var webworkify = require('webworkify'); |
|
|
|
var webworkify = require('webworkify'); |
|
|
|
var utils = require('./utils'); |
|
|
|
var utils = require('./utils'); |
|
|
|
|
|
|
|
|
|
|
@ -65,49 +67,34 @@ function Compiler (editor, renderer, queryParams, handleGithubCall, outputField, |
|
|
|
|
|
|
|
|
|
|
|
function onInternalCompilerLoaded (setVersionText) { |
|
|
|
function onInternalCompilerLoaded (setVersionText) { |
|
|
|
if (worker === null) { |
|
|
|
if (worker === null) { |
|
|
|
var compile; |
|
|
|
var compiler = solc(window.Module); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
compilerAcceptsMultipleFiles = compiler.supportsMulti; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
compileJSON = function (source, optimize, cb) { |
|
|
|
var missingInputs = []; |
|
|
|
var missingInputs = []; |
|
|
|
var Module = window.Module; |
|
|
|
var missingInputsCallback = function (path) { |
|
|
|
if ('_compileJSONCallback' in Module) { |
|
|
|
missingInputs.push(path); |
|
|
|
compilerAcceptsMultipleFiles = true; |
|
|
|
return { error: 'Deferred import' }; |
|
|
|
var missingInputsCallback = Module.Runtime.addFunction(function (path, contents, error) { |
|
|
|
|
|
|
|
missingInputs.push(Module.Pointer_stringify(path)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
var compileInternal = Module.cwrap('compileJSONCallback', 'string', [ 'string', 'number', 'number' ]); |
|
|
|
|
|
|
|
compile = function (input, optimize) { |
|
|
|
|
|
|
|
missingInputs.length = 0; |
|
|
|
|
|
|
|
return compileInternal(input, optimize, missingInputsCallback); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
} else if ('_compileJSONMulti' in Module) { |
|
|
|
|
|
|
|
compilerAcceptsMultipleFiles = true; |
|
|
|
var result; |
|
|
|
compile = Module.cwrap('compileJSONMulti', 'string', [ 'string', 'number' ]); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
compilerAcceptsMultipleFiles = false; |
|
|
|
|
|
|
|
compile = Module.cwrap('compileJSON', 'string', [ 'string', 'number' ]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setCompileJSON(function (source, optimize, cb) { |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
var result = compile(source, optimize); |
|
|
|
result = compiler.compile(source, optimize, missingInputsCallback); |
|
|
|
} catch (exception) { |
|
|
|
} catch (exception) { |
|
|
|
result = JSON.stringify({ error: 'Uncaught JavaScript exception:\n' + exception }); |
|
|
|
result = { error: 'Uncaught JavaScript exception:\n' + exception }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
compilationFinished(result, missingInputs); |
|
|
|
compilationFinished(result, missingInputs); |
|
|
|
}); |
|
|
|
}; |
|
|
|
onCompilerLoaded(setVersionText, Module.cwrap('version', 'string', [])()); |
|
|
|
|
|
|
|
|
|
|
|
onCompilerLoaded(setVersionText, compiler.version()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function compilationFinished (result, missingInputs) { |
|
|
|
function compilationFinished (data, missingInputs) { |
|
|
|
var data; |
|
|
|
|
|
|
|
var noFatalErrors = true; // ie warnings are ok
|
|
|
|
var noFatalErrors = true; // ie warnings are ok
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
data = JSON.parse(result); |
|
|
|
|
|
|
|
} catch (exception) { |
|
|
|
|
|
|
|
renderer.error('Invalid JSON output from the compiler: ' + exception); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (data['error'] !== undefined) { |
|
|
|
if (data['error'] !== undefined) { |
|
|
|
renderer.error(data['error']); |
|
|
|
renderer.error(data['error']); |
|
|
|
if (utils.errortype(data['error']) !== 'warning') { |
|
|
|
if (utils.errortype(data['error']) !== 'warning') { |
|
|
@ -132,6 +119,7 @@ function Compiler (editor, renderer, queryParams, handleGithubCall, outputField, |
|
|
|
|
|
|
|
|
|
|
|
this.loadVersion = function (usingWorker, version, setVersionText) { |
|
|
|
this.loadVersion = function (usingWorker, version, setVersionText) { |
|
|
|
var url = 'https://ethereum.github.io/solc-bin/bin/' + version; |
|
|
|
var url = 'https://ethereum.github.io/solc-bin/bin/' + version; |
|
|
|
|
|
|
|
console.log('Loading ' + url + ' ' + (usingWorker ? 'with worker' : 'without worker')); |
|
|
|
|
|
|
|
|
|
|
|
if (usingWorker) { |
|
|
|
if (usingWorker) { |
|
|
|
loadWorker(url, setVersionText); |
|
|
|
loadWorker(url, setVersionText); |
|
|
@ -171,15 +159,21 @@ function Compiler (editor, renderer, queryParams, handleGithubCall, outputField, |
|
|
|
onCompilerLoaded(setVersionText, data.data); |
|
|
|
onCompilerLoaded(setVersionText, data.data); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'compiled': |
|
|
|
case 'compiled': |
|
|
|
compilationFinished(data.data, data.missingInputs); |
|
|
|
var result; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
result = JSON.parse(data.data); |
|
|
|
|
|
|
|
} catch (exception) { |
|
|
|
|
|
|
|
result = { 'error': 'Invalid JSON output from the compiler: ' + exception }; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
compilationFinished(result, data.missingInputs); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
worker.onerror = function (msg) { console.log(msg.data); }; |
|
|
|
worker.onerror = function (msg) { console.log(msg.data); }; |
|
|
|
worker.addEventListener('error', function (msg) { console.log(msg.data); }); |
|
|
|
worker.addEventListener('error', function (msg) { console.log(msg.data); }); |
|
|
|
setCompileJSON(function (source, optimize) { |
|
|
|
compileJSON = function (source, optimize) { |
|
|
|
worker.postMessage({cmd: 'compile', source: source, optimize: optimize}); |
|
|
|
worker.postMessage({cmd: 'compile', source: JSON.stringify(source), optimize: optimize}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
worker.postMessage({cmd: 'loadVersion', data: url}); |
|
|
|
worker.postMessage({cmd: 'loadVersion', data: url}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -235,7 +229,7 @@ function Compiler (editor, renderer, queryParams, handleGithubCall, outputField, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} while (reloop); |
|
|
|
} while (reloop); |
|
|
|
cb(JSON.stringify({ 'sources': files })); |
|
|
|
cb({ 'sources': files }); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|