From 5ab4a1ae7819004415293bf72a86824beb43cd51 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 21 Feb 2018 23:43:40 +0100 Subject: Add ability to set the target EVM version. --- libsolidity/interface/EVMVersion.h | 81 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 libsolidity/interface/EVMVersion.h (limited to 'libsolidity/interface/EVMVersion.h') 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 . +*/ +/** + * EVM versioning. + */ + +#pragma once + +#include + +#include + +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 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; +}; + + +} +} -- cgit v1.2.3 From 982476f99d085072d25b703a146a6d92cd280714 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 26 Feb 2018 19:53:38 +0100 Subject: Add TangerineWhistle. --- libsolidity/interface/EVMVersion.h | 39 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'libsolidity/interface/EVMVersion.h') diff --git a/libsolidity/interface/EVMVersion.h b/libsolidity/interface/EVMVersion.h index 1ddcd218..954a9f8f 100644 --- a/libsolidity/interface/EVMVersion.h +++ b/libsolidity/interface/EVMVersion.h @@ -23,6 +23,7 @@ #include #include +#include namespace dev { @@ -33,28 +34,40 @@ namespace solidity * A version specifier of the EVM we want to compile to. * Defaults to the latest version. */ -class EVMVersion +class EVMVersion: + boost::less_than_comparable, + boost::equality_comparable { public: EVMVersion() {} static EVMVersion homestead() { return {Version::Homestead}; } + static EVMVersion tangerineWhistle() { return {Version::TangerineWhistle}; } + static EVMVersion spuriousDragon() { return {Version::SpuriousDragon}; } static EVMVersion byzantium() { return {Version::Byzantium}; } static boost::optional fromString(std::string const& _version) { - if (_version == "homestead") - return homestead(); - else if (_version == "byzantium") - return byzantium(); - else - return {}; + for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium()}) + if (_version == v.name()) + return v; + return {}; } bool operator==(EVMVersion const& _other) const { return m_version == _other.m_version; } - bool operator!=(EVMVersion const& _other) const { return !this->operator==(_other); } + bool operator<(EVMVersion const& _other) const { return m_version < _other.m_version; } - std::string name() const { return m_version == Version::Byzantium ? "byzantium" : "homestead"; } + std::string name() const + { + switch (m_version) + { + case Version::Byzantium: return "byzantium"; + case Version::TangerineWhistle: return "tangerineWhistle"; + case Version::SpuriousDragon: return "spuriousDragon"; + case Version::Homestead: return "homestead"; + } + return "INVALID"; + } /// Has the RETURNDATACOPY and RETURNDATASIZE opcodes. bool supportsReturndata() const { return *this >= byzantium(); } @@ -62,14 +75,10 @@ public: /// 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; - } + bool canOverchargeGasForCall() const { return *this >= tangerineWhistle(); } private: - enum class Version { Homestead, Byzantium }; + enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium }; EVMVersion(Version _version): m_version(_version) {} -- cgit v1.2.3 From 4ce0e7775d86076b2f1d0e1d1390f7a76636d257 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 27 Feb 2018 18:51:12 +0100 Subject: Add constantinople. --- libsolidity/interface/EVMVersion.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libsolidity/interface/EVMVersion.h') diff --git a/libsolidity/interface/EVMVersion.h b/libsolidity/interface/EVMVersion.h index 954a9f8f..738bf203 100644 --- a/libsolidity/interface/EVMVersion.h +++ b/libsolidity/interface/EVMVersion.h @@ -45,6 +45,7 @@ public: static EVMVersion tangerineWhistle() { return {Version::TangerineWhistle}; } static EVMVersion spuriousDragon() { return {Version::SpuriousDragon}; } static EVMVersion byzantium() { return {Version::Byzantium}; } + static EVMVersion constantinople() { return {Version::Constantinople}; } static boost::optional fromString(std::string const& _version) { @@ -61,10 +62,11 @@ public: { switch (m_version) { - case Version::Byzantium: return "byzantium"; + case Version::Homestead: return "homestead"; case Version::TangerineWhistle: return "tangerineWhistle"; case Version::SpuriousDragon: return "spuriousDragon"; - case Version::Homestead: return "homestead"; + case Version::Byzantium: return "byzantium"; + case Version::Constantinople: return "constantinople"; } return "INVALID"; } @@ -78,7 +80,7 @@ public: bool canOverchargeGasForCall() const { return *this >= tangerineWhistle(); } private: - enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium }; + enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium, Constantinople }; EVMVersion(Version _version): m_version(_version) {} -- cgit v1.2.3 From 5a54cd5c708227ad6982b06de7b799ece5065917 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 28 Feb 2018 08:43:18 +0100 Subject: Only warn for shift instructions if not using constantinople --- libsolidity/interface/EVMVersion.h | 1 + 1 file changed, 1 insertion(+) (limited to 'libsolidity/interface/EVMVersion.h') diff --git a/libsolidity/interface/EVMVersion.h b/libsolidity/interface/EVMVersion.h index 738bf203..13c4ec94 100644 --- a/libsolidity/interface/EVMVersion.h +++ b/libsolidity/interface/EVMVersion.h @@ -74,6 +74,7 @@ public: /// Has the RETURNDATACOPY and RETURNDATASIZE opcodes. bool supportsReturndata() const { return *this >= byzantium(); } bool hasStaticCall() const { return *this >= byzantium(); } + bool hasBitwiseShifting() const { return *this >= constantinople(); } /// Whether we have to retain the costs for the call opcode itself (false), /// or whether we can just forward easily all remaining gas (true). -- cgit v1.2.3