From 7e2e58aaa5793620a7f2e0860e811c86861bb1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 11 Dec 2014 15:41:19 +0100 Subject: [PATCH] VM::go detemplatized. Cleanups. --- libevm/VM.cpp | 8 -------- libevm/VM.h | 13 +++++-------- libevm/VMFace.h | 12 +++--------- libevm/VMFactory.cpp | 3 --- libevm/VMFactory.h | 2 -- 5 files changed, 8 insertions(+), 30 deletions(-) diff --git a/libevm/VM.cpp b/libevm/VM.cpp index 44620a3d5..b8452e4f5 100644 --- a/libevm/VM.cpp +++ b/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(&_ext)) - return goImpl(*defaultExt, _onOp, _steps); - else - return goImpl(_ext, _onOp, _steps); -} diff --git a/libevm/VM.h b/libevm/VM.h index d03760a78..c427802f6 100644 --- a/libevm/VM.h +++ b/libevm/VM.h @@ -68,10 +68,7 @@ private: friend class VMFactory; /// Construct VM object. - explicit VM(u256 _gas = 0): VMFace(_gas) {} - - template - 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 m_onFail; }; -} - -// INLINE: -template 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 dev::bytesConstRef dev::eth::VM::goImpl(Ext& _ext, OnOpFunc BOOST_THROW_EXCEPTION(StepsDone()); return bytesConstRef(); } + +} } diff --git a/libevm/VMFace.h b/libevm/VMFace.h index 319da7fc1..44ae03868 100644 --- a/libevm/VMFace.h +++ b/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 . */ - #pragma once #include @@ -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; }; diff --git a/libevm/VMFactory.cpp b/libevm/VMFactory.cpp index 90e17c553..af37ec710 100644 --- a/libevm/VMFactory.cpp +++ b/libevm/VMFactory.cpp @@ -40,6 +40,3 @@ std::unique_ptr VMFactory::create(u256 _gas) } } - - - diff --git a/libevm/VMFactory.h b/libevm/VMFactory.h index c5d9c4f65..d0d02e0c4 100644 --- a/libevm/VMFactory.h +++ b/libevm/VMFactory.h @@ -35,9 +35,7 @@ public: VMFactory() = delete; static std::unique_ptr create(u256 _gas); - static void setKind(VMKind _kind); - }; }