Browse Source

VM::go detemplatized. Cleanups.

cl-refactor
Paweł Bylica 10 years ago
parent
commit
7e2e58aaa5
  1. 8
      libevm/VM.cpp
  2. 13
      libevm/VM.h
  3. 12
      libevm/VMFace.h
  4. 3
      libevm/VMFactory.cpp
  5. 2
      libevm/VMFactory.h

8
libevm/VM.cpp

@ -31,11 +31,3 @@ void VM::reset(u256 _gas) noexcept
m_curPC = 0;
m_jumpDests.clear();
}
bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
{
if (auto defaultExt = dynamic_cast<ExtVM*>(&_ext))
return goImpl<ExtVM>(*defaultExt, _onOp, _steps);
else
return goImpl<ExtVMFace>(_ext, _onOp, _steps);
}

13
libevm/VM.h

@ -68,10 +68,7 @@ private:
friend class VMFactory;
/// Construct VM object.
explicit VM(u256 _gas = 0): VMFace(_gas) {}
template <class Ext>
bytesConstRef goImpl(Ext& _ext, OnOpFunc const& _onOp = OnOpFunc(), uint64_t _steps = (uint64_t)-1);
explicit VM(u256 _gas): VMFace(_gas) {}
u256 m_curPC = 0;
bytes m_temp;
@ -80,10 +77,8 @@ private:
std::function<void()> m_onFail;
};
}
// INLINE:
template <class Ext> dev::bytesConstRef dev::eth::VM::goImpl(Ext& _ext, OnOpFunc const& _onOp, uint64_t _steps)
// TODO: Move it to cpp file. Not done to make review easier.
inline bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
{
auto memNeed = [](dev::u256 _offset, dev::u256 _size) { return _size ? (bigint)_offset + _size : (bigint)0; };
@ -864,4 +859,6 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::goImpl(Ext& _ext, OnOpFunc
BOOST_THROW_EXCEPTION(StepsDone());
return bytesConstRef();
}
}
}

12
libevm/VMFace.h

@ -14,7 +14,6 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
@ -34,25 +33,20 @@ struct BadJumpDestination: virtual VMException {};
struct OutOfGas: virtual VMException {};
struct StackTooSmall: virtual VMException {};
/**
*/
/// EVM Virtual Machine interface
class VMFace
{
public:
/// Construct VM object.
explicit VMFace(u256 _gas = 0): m_gas(_gas) {}
explicit VMFace(u256 _gas): m_gas(_gas) {}
virtual ~VMFace() = default;
VMFace(VMFace const&) = delete;
void operator=(VMFace const&) = delete;
virtual void reset(u256 _gas = 0) noexcept { m_gas = _gas; }
u256 gas() const noexcept { return m_gas; }
virtual bytesConstRef go(ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) = 0;
u256 gas() const { return m_gas; }
protected:
u256 m_gas = 0;
};

3
libevm/VMFactory.cpp

@ -40,6 +40,3 @@ std::unique_ptr<VMFace> VMFactory::create(u256 _gas)
}
}

2
libevm/VMFactory.h

@ -35,9 +35,7 @@ public:
VMFactory() = delete;
static std::unique_ptr<VMFace> create(u256 _gas);
static void setKind(VMKind _kind);
};
}

Loading…
Cancel
Save