Merge pull request #1193 from thundercore/scottt-remix-solidity-add-compiler-setEvmVersion

remix-solidity: add compiler.setEvmVersion()
pull/5370/head
yann300 6 years ago committed by GitHub
commit 4ee057bae0
  1. 8
      remix-solidity/src/compiler/compiler-input.js
  2. 20
      remix-solidity/src/compiler/compiler.js

@ -1,7 +1,7 @@
'use strict'
module.exports = (sources, opts) => {
return JSON.stringify({
const o = {
language: 'Solidity',
sources: sources,
settings: {
@ -17,5 +17,9 @@ module.exports = (sources, opts) => {
}
}
}
})
}
if (opts.evmVersion) {
o.settings.evmVersion = opts.evmVersion
}
return JSON.stringify(o)
}

@ -27,10 +27,16 @@ function Compiler (handleImportCall) {
var optimize = false
var evmVersion = null
this.setOptimize = function (_optimize) {
optimize = _optimize
}
this.setEvmVersion = function (_evmVersion) {
evmVersion = _evmVersion
}
var compilationStartTime = null
this.event.register('compilationFinished', (success, data, source) => {
if (success && compilationStartTime) {
@ -49,7 +55,7 @@ function Compiler (handleImportCall) {
self.lastCompilationResult = null
self.event.trigger('compilationFinished', [false, {'error': { formattedMessage: error, severity: 'error' }}, files])
} else {
compileJSON(input, optimize ? 1 : 0)
compileJSON(input)
}
})
}
@ -73,14 +79,13 @@ function Compiler (handleImportCall) {
function onInternalCompilerLoaded () {
if (worker === null) {
var compiler
var userAgent = (typeof (navigator) !== 'undefined') && navigator.userAgent ? navigator.userAgent.toLowerCase() : '-'
if (typeof (window) === 'undefined') {
compiler = require('solc')
} else {
compiler = solc(window.Module)
}
compileJSON = function (source, optimize, cb) {
compileJSON = function (source) {
var missingInputs = []
var missingInputsCallback = function (path) {
missingInputs.push(path)
@ -89,7 +94,7 @@ function Compiler (handleImportCall) {
var result
try {
var input = compilerInput(source.sources, {optimize: optimize, target: source.target})
var input = compilerInput(source.sources, {optimize: optimize, evmVersion: evmVersion, target: source.target})
result = compiler.compile(input, missingInputsCallback)
result = JSON.parse(result)
} catch (exception) {
@ -242,7 +247,7 @@ function Compiler (handleImportCall) {
window.Module = undefined
// Set a safe fallback until the new one is loaded
setCompileJSON(function (source, optimize) {
setCompileJSON(function (source) {
compilationFinished({ error: { formattedMessage: 'Compiler not yet loaded.' } })
})
@ -293,9 +298,10 @@ function Compiler (handleImportCall) {
worker.addEventListener('error', function (msg) {
compilationFinished({ error: 'Worker error: ' + msg.data })
})
compileJSON = function (source, optimize) {
compileJSON = function (source) {
jobs.push({sources: source})
worker.postMessage({cmd: 'compile', job: jobs.length - 1, input: compilerInput(source.sources, {optimize: optimize, target: source.target})})
worker.postMessage({cmd: 'compile', job: jobs.length - 1, input: compilerInput(source.sources,
{optimize: optimize, evmVersion: evmVersion, target: source.target})})
}
worker.postMessage({cmd: 'loadVersion', data: url})
}

Loading…
Cancel
Save