diff options
author | chriseth <chris@ethereum.org> | 2018-02-22 06:43:40 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-03-02 00:19:34 +0800 |
commit | 5ab4a1ae7819004415293bf72a86824beb43cd51 (patch) | |
tree | 6129bf94bcc3c9ab581bbae48a0d5b7449de65c9 /libsolidity | |
parent | c9840c98f45e6fa9258ec4624219622f5f71c75c (diff) | |
download | dexon-solidity-5ab4a1ae7819004415293bf72a86824beb43cd51.tar.gz dexon-solidity-5ab4a1ae7819004415293bf72a86824beb43cd51.tar.zst dexon-solidity-5ab4a1ae7819004415293bf72a86824beb43cd51.zip |
Add ability to set the target EVM version.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 7 | ||||
-rw-r--r-- | libsolidity/interface/CompilerStack.h | 27 | ||||
-rw-r--r-- | libsolidity/interface/EVMVersion.h | 81 | ||||
-rw-r--r-- | libsolidity/interface/StandardCompiler.cpp | 8 |
4 files changed, 114 insertions, 9 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 3b5e65e8..7bc31c17 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -74,6 +74,12 @@ void CompilerStack::setRemappings(vector<string> const& _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) { if (_keepSources) @@ -88,6 +94,7 @@ void CompilerStack::reset(bool _keepSources) m_sources.clear(); } m_libraries.clear(); + m_evmVersion = EVMVersion(); m_optimize = false; m_optimizeRuns = 200; m_globalContext.reset(); diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index b377b3aa..13c9cc7a 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -23,20 +23,26 @@ #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 <string> #include <memory> #include <vector> #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 { @@ -116,6 +122,8 @@ public: m_optimizeRuns = _runs; } + void setEVMVersion(EVMVersion _version = EVMVersion{}); + /// 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. void setRequestedContractNames(std::set<std::string> const& _contractNames = std::set<std::string>{}) @@ -310,6 +318,7 @@ private: ReadCallback::Callback m_smtQuery; bool m_optimize = false; unsigned m_optimizeRuns = 200; + EVMVersion m_evmVersion; std::set<std::string> m_requestedContractNames; std::map<std::string, h160> m_libraries; /// list of path prefix remappings, e.g. mylibrary: github.com/ethereum = /usr/local/ethereum diff --git a/libsolidity/interface/EVMVersion.h b/libsolidity/interface/EVMVersion.h new file mode 100644 index 00000000..1ddcd218 --- /dev/null +++ b/libsolidity/interface/EVMVersion.h @@ -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; +}; + + +} +} diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 91fe72ae..ee9b1440 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -318,6 +318,14 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) 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; for (auto const& remapping: settings.get("remappings", Json::Value())) remappings.push_back(remapping.asString()); |