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

Loading…
Cancel
Save