mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add ability to set the target EVM version.
This commit is contained in:
parent
c9840c98f4
commit
5ab4a1ae78
@ -74,6 +74,12 @@ void CompilerStack::setRemappings(vector<string> const& _remappings)
|
|||||||
swap(m_remappings, remappings);
|
swap(m_remappings, remappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CompilerStack::setEVMVersion(EVMVersion _version)
|
||||||
|
{
|
||||||
|
solAssert(m_stackState < State::ParsingSuccessful, "Set EVM version after parsing.");
|
||||||
|
m_evmVersion = _version;
|
||||||
|
}
|
||||||
|
|
||||||
void CompilerStack::reset(bool _keepSources)
|
void CompilerStack::reset(bool _keepSources)
|
||||||
{
|
{
|
||||||
if (_keepSources)
|
if (_keepSources)
|
||||||
@ -88,6 +94,7 @@ void CompilerStack::reset(bool _keepSources)
|
|||||||
m_sources.clear();
|
m_sources.clear();
|
||||||
}
|
}
|
||||||
m_libraries.clear();
|
m_libraries.clear();
|
||||||
|
m_evmVersion = EVMVersion();
|
||||||
m_optimize = false;
|
m_optimize = false;
|
||||||
m_optimizeRuns = 200;
|
m_optimizeRuns = 200;
|
||||||
m_globalContext.reset();
|
m_globalContext.reset();
|
||||||
|
@ -23,20 +23,26 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <libsolidity/interface/ErrorReporter.h>
|
||||||
|
#include <libsolidity/interface/ReadFile.h>
|
||||||
|
#include <libsolidity/interface/EVMVersion.h>
|
||||||
|
|
||||||
|
#include <libevmasm/SourceLocation.h>
|
||||||
|
#include <libevmasm/LinkerObject.h>
|
||||||
|
|
||||||
|
#include <libdevcore/Common.h>
|
||||||
|
#include <libdevcore/FixedHash.h>
|
||||||
|
|
||||||
|
#include <json/json.h>
|
||||||
|
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <boost/noncopyable.hpp>
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
#include <json/json.h>
|
|
||||||
#include <libdevcore/Common.h>
|
|
||||||
#include <libdevcore/FixedHash.h>
|
|
||||||
#include <libevmasm/SourceLocation.h>
|
|
||||||
#include <libevmasm/LinkerObject.h>
|
|
||||||
#include <libsolidity/interface/ErrorReporter.h>
|
|
||||||
#include <libsolidity/interface/ReadFile.h>
|
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
@ -116,6 +122,8 @@ public:
|
|||||||
m_optimizeRuns = _runs;
|
m_optimizeRuns = _runs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setEVMVersion(EVMVersion _version = EVMVersion{});
|
||||||
|
|
||||||
/// Sets the list of requested contract names. If empty, no filtering is performed and every contract
|
/// Sets the list of requested contract names. If empty, no filtering is performed and every contract
|
||||||
/// found in the supplied sources is compiled. Names are cleared iff @a _contractNames is missing.
|
/// found in the supplied sources is compiled. Names are cleared iff @a _contractNames is missing.
|
||||||
void setRequestedContractNames(std::set<std::string> const& _contractNames = std::set<std::string>{})
|
void setRequestedContractNames(std::set<std::string> const& _contractNames = std::set<std::string>{})
|
||||||
@ -310,6 +318,7 @@ private:
|
|||||||
ReadCallback::Callback m_smtQuery;
|
ReadCallback::Callback m_smtQuery;
|
||||||
bool m_optimize = false;
|
bool m_optimize = false;
|
||||||
unsigned m_optimizeRuns = 200;
|
unsigned m_optimizeRuns = 200;
|
||||||
|
EVMVersion m_evmVersion;
|
||||||
std::set<std::string> m_requestedContractNames;
|
std::set<std::string> m_requestedContractNames;
|
||||||
std::map<std::string, h160> m_libraries;
|
std::map<std::string, h160> m_libraries;
|
||||||
/// list of path prefix remappings, e.g. mylibrary: github.com/ethereum = /usr/local/ethereum
|
/// list of path prefix remappings, e.g. mylibrary: github.com/ethereum = /usr/local/ethereum
|
||||||
|
81
libsolidity/interface/EVMVersion.h
Normal file
81
libsolidity/interface/EVMVersion.h
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* EVM versioning.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace solidity
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A version specifier of the EVM we want to compile to.
|
||||||
|
* Defaults to the latest version.
|
||||||
|
*/
|
||||||
|
class EVMVersion
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EVMVersion() {}
|
||||||
|
|
||||||
|
static EVMVersion homestead() { return {Version::Homestead}; }
|
||||||
|
static EVMVersion byzantium() { return {Version::Byzantium}; }
|
||||||
|
|
||||||
|
static boost::optional<EVMVersion> fromString(std::string const& _version)
|
||||||
|
{
|
||||||
|
if (_version == "homestead")
|
||||||
|
return homestead();
|
||||||
|
else if (_version == "byzantium")
|
||||||
|
return byzantium();
|
||||||
|
else
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(EVMVersion const& _other) const { return m_version == _other.m_version; }
|
||||||
|
bool operator!=(EVMVersion const& _other) const { return !this->operator==(_other); }
|
||||||
|
|
||||||
|
std::string name() const { return m_version == Version::Byzantium ? "byzantium" : "homestead"; }
|
||||||
|
|
||||||
|
/// Has the RETURNDATACOPY and RETURNDATASIZE opcodes.
|
||||||
|
bool supportsReturndata() const { return *this >= byzantium(); }
|
||||||
|
bool hasStaticCall() const { return *this >= byzantium(); }
|
||||||
|
|
||||||
|
/// Whether we have to retain the costs for the call opcode itself (false),
|
||||||
|
/// or whether we can just forward easily all remaining gas (true).
|
||||||
|
bool canOverchargeGasForCall() const
|
||||||
|
{
|
||||||
|
// @TODO when exactly was this introduced? Was together with the call stack fix.
|
||||||
|
return m_version == Version::Byzantium;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class Version { Homestead, Byzantium };
|
||||||
|
|
||||||
|
EVMVersion(Version _version): m_version(_version) {}
|
||||||
|
|
||||||
|
Version m_version = Version::Byzantium;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -318,6 +318,14 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
|
|||||||
|
|
||||||
Json::Value const& settings = _input.get("settings", Json::Value());
|
Json::Value const& settings = _input.get("settings", Json::Value());
|
||||||
|
|
||||||
|
if (settings.isMember("evmVersion"))
|
||||||
|
{
|
||||||
|
boost::optional<EVMVersion> version = EVMVersion::fromString(settings.get("evmVersion", {}).asString());
|
||||||
|
if (!version)
|
||||||
|
return formatFatalError("JSONError", "Invalid EVM version requested.");
|
||||||
|
m_compilerStack.setEVMVersion(*version);
|
||||||
|
}
|
||||||
|
|
||||||
vector<string> remappings;
|
vector<string> remappings;
|
||||||
for (auto const& remapping: settings.get("remappings", Json::Value()))
|
for (auto const& remapping: settings.get("remappings", Json::Value()))
|
||||||
remappings.push_back(remapping.asString());
|
remappings.push_back(remapping.asString());
|
||||||
|
@ -71,7 +71,6 @@ namespace solidity
|
|||||||
|
|
||||||
static string const g_stdinFileNameStr = "<stdin>";
|
static string const g_stdinFileNameStr = "<stdin>";
|
||||||
static string const g_strAbi = "abi";
|
static string const g_strAbi = "abi";
|
||||||
static string const g_strAddStandard = "add-std";
|
|
||||||
static string const g_strAllowPaths = "allow-paths";
|
static string const g_strAllowPaths = "allow-paths";
|
||||||
static string const g_strAsm = "asm";
|
static string const g_strAsm = "asm";
|
||||||
static string const g_strAsmJson = "asm-json";
|
static string const g_strAsmJson = "asm-json";
|
||||||
@ -87,6 +86,7 @@ static string const g_strCompactJSON = "compact-format";
|
|||||||
static string const g_strContracts = "contracts";
|
static string const g_strContracts = "contracts";
|
||||||
static string const g_strEVM = "evm";
|
static string const g_strEVM = "evm";
|
||||||
static string const g_strEVM15 = "evm15";
|
static string const g_strEVM15 = "evm15";
|
||||||
|
static string const g_strEVMVersion = "evm-version";
|
||||||
static string const g_streWasm = "ewasm";
|
static string const g_streWasm = "ewasm";
|
||||||
static string const g_strFormal = "formal";
|
static string const g_strFormal = "formal";
|
||||||
static string const g_strGas = "gas";
|
static string const g_strGas = "gas";
|
||||||
@ -118,7 +118,6 @@ static string const g_strPrettyJson = "pretty-json";
|
|||||||
static string const g_strVersion = "version";
|
static string const g_strVersion = "version";
|
||||||
|
|
||||||
static string const g_argAbi = g_strAbi;
|
static string const g_argAbi = g_strAbi;
|
||||||
static string const g_argAddStandard = g_strAddStandard;
|
|
||||||
static string const g_argPrettyJson = g_strPrettyJson;
|
static string const g_argPrettyJson = g_strPrettyJson;
|
||||||
static string const g_argAllowPaths = g_strAllowPaths;
|
static string const g_argAllowPaths = g_strAllowPaths;
|
||||||
static string const g_argAsm = g_strAsm;
|
static string const g_argAsm = g_strAsm;
|
||||||
@ -537,13 +536,17 @@ Allowed options)",
|
|||||||
(g_argHelp.c_str(), "Show help message and exit.")
|
(g_argHelp.c_str(), "Show help message and exit.")
|
||||||
(g_argVersion.c_str(), "Show version and exit.")
|
(g_argVersion.c_str(), "Show version and exit.")
|
||||||
(g_strLicense.c_str(), "Show licensing information and exit.")
|
(g_strLicense.c_str(), "Show licensing information and exit.")
|
||||||
|
(
|
||||||
|
g_strEVMVersion.c_str(),
|
||||||
|
po::value<string>()->value_name("version"),
|
||||||
|
"Select desired EVM version. Either homestead or byzantium (default)."
|
||||||
|
)
|
||||||
(g_argOptimize.c_str(), "Enable bytecode optimizer.")
|
(g_argOptimize.c_str(), "Enable bytecode optimizer.")
|
||||||
(
|
(
|
||||||
g_argOptimizeRuns.c_str(),
|
g_argOptimizeRuns.c_str(),
|
||||||
po::value<unsigned>()->value_name("n")->default_value(200),
|
po::value<unsigned>()->value_name("n")->default_value(200),
|
||||||
"Estimated number of contract runs for optimizer tuning."
|
"Estimated number of contract runs for optimizer tuning."
|
||||||
)
|
)
|
||||||
(g_argAddStandard.c_str(), "Add standard contracts.")
|
|
||||||
(g_argPrettyJson.c_str(), "Output JSON in pretty format. Currently it only works with the combined JSON output.")
|
(g_argPrettyJson.c_str(), "Output JSON in pretty format. Currently it only works with the combined JSON output.")
|
||||||
(
|
(
|
||||||
g_argLibraries.c_str(),
|
g_argLibraries.c_str(),
|
||||||
@ -779,6 +782,19 @@ bool CommandLineInterface::processInput()
|
|||||||
|
|
||||||
m_compiler.reset(new CompilerStack(fileReader));
|
m_compiler.reset(new CompilerStack(fileReader));
|
||||||
|
|
||||||
|
EVMVersion evmVersion;
|
||||||
|
if (m_args.count(g_strEVMVersion))
|
||||||
|
{
|
||||||
|
string versionOptionStr = m_args[g_strEVMVersion].as<string>();
|
||||||
|
boost::optional<EVMVersion> versionOption = EVMVersion::fromString(versionOptionStr);
|
||||||
|
if (!versionOption)
|
||||||
|
{
|
||||||
|
cerr << "Invalid option for --evm-version: " << versionOptionStr << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
evmVersion = *versionOption;
|
||||||
|
}
|
||||||
|
|
||||||
auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compiler->scanner(_sourceName); };
|
auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compiler->scanner(_sourceName); };
|
||||||
SourceReferenceFormatter formatter(cerr, scannerFromSourceName);
|
SourceReferenceFormatter formatter(cerr, scannerFromSourceName);
|
||||||
|
|
||||||
@ -792,6 +808,8 @@ bool CommandLineInterface::processInput()
|
|||||||
m_compiler->addSource(sourceCode.first, sourceCode.second);
|
m_compiler->addSource(sourceCode.first, sourceCode.second);
|
||||||
if (m_args.count(g_argLibraries))
|
if (m_args.count(g_argLibraries))
|
||||||
m_compiler->setLibraries(m_libraries);
|
m_compiler->setLibraries(m_libraries);
|
||||||
|
if (m_args.count(g_strEVMVersion))
|
||||||
|
m_compiler->setEVMVersion(evmVersion);
|
||||||
// TODO: Perhaps we should not compile unless requested
|
// TODO: Perhaps we should not compile unless requested
|
||||||
bool optimize = m_args.count(g_argOptimize) > 0;
|
bool optimize = m_args.count(g_argOptimize) > 0;
|
||||||
unsigned runs = m_args[g_argOptimizeRuns].as<unsigned>();
|
unsigned runs = m_args[g_argOptimizeRuns].as<unsigned>();
|
||||||
|
Loading…
Reference in New Issue
Block a user