solidity/liblangutil/EVMVersion.h

92 lines
2.8 KiB
C
Raw Normal View History

/*
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>
2018-02-26 18:53:38 +00:00
#include <boost/operators.hpp>
namespace langutil
{
/**
* A version specifier of the EVM we want to compile to.
* Defaults to the latest version.
*/
2018-02-26 18:53:38 +00:00
class EVMVersion:
boost::less_than_comparable<EVMVersion>,
boost::equality_comparable<EVMVersion>
{
public:
EVMVersion() = default;
static EVMVersion homestead() { return {Version::Homestead}; }
2018-02-26 18:53:38 +00:00
static EVMVersion tangerineWhistle() { return {Version::TangerineWhistle}; }
static EVMVersion spuriousDragon() { return {Version::SpuriousDragon}; }
static EVMVersion byzantium() { return {Version::Byzantium}; }
2018-02-27 17:51:12 +00:00
static EVMVersion constantinople() { return {Version::Constantinople}; }
static boost::optional<EVMVersion> fromString(std::string const& _version)
{
2018-03-12 17:11:08 +00:00
for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium(), constantinople()})
2018-02-26 18:53:38 +00:00
if (_version == v.name())
return v;
return {};
}
bool operator==(EVMVersion const& _other) const { return m_version == _other.m_version; }
2018-02-26 18:53:38 +00:00
bool operator<(EVMVersion const& _other) const { return m_version < _other.m_version; }
2018-02-26 18:53:38 +00:00
std::string name() const
{
switch (m_version)
{
2018-02-27 17:51:12 +00:00
case Version::Homestead: return "homestead";
2018-02-26 18:53:38 +00:00
case Version::TangerineWhistle: return "tangerineWhistle";
case Version::SpuriousDragon: return "spuriousDragon";
2018-02-27 17:51:12 +00:00
case Version::Byzantium: return "byzantium";
case Version::Constantinople: return "constantinople";
2018-02-26 18:53:38 +00:00
}
return "INVALID";
}
/// Has the RETURNDATACOPY and RETURNDATASIZE opcodes.
bool supportsReturndata() const { return *this >= byzantium(); }
bool hasStaticCall() const { return *this >= byzantium(); }
bool hasBitwiseShifting() const { return *this >= constantinople(); }
bool hasCreate2() 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).
2018-02-26 18:53:38 +00:00
bool canOverchargeGasForCall() const { return *this >= tangerineWhistle(); }
private:
2018-02-27 17:51:12 +00:00
enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium, Constantinople };
EVMVersion(Version _version): m_version(_version) {}
Version m_version = Version::Byzantium;
};
}