From 46b837d4d038d77863ce459066afca8f0de033e8 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 9 Jul 2014 16:05:07 +0100 Subject: [PATCH] MEMSIZE -> MSIZE --- libethereum/Executive.cpp | 7 +++++-- libethereum/Executive.h | 2 -- libevm/VM.h | 34 +++++++++++++++++++++++++++++++--- libevmface/Instruction.cpp | 4 ++-- libevmface/Instruction.h | 2 +- liblll/CodeFragment.cpp | 4 ++-- 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 3312e28d9..35f3bc156 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -26,7 +26,7 @@ using namespace std; using namespace eth; -#define EVM_TRACE 1 +#define ETH_VMTRACE 1 Executive::~Executive() { @@ -148,6 +148,7 @@ bool Executive::go(uint64_t _steps) try { #if ETH_VMTRACE + /* if (_steps == (uint64_t)0 - 1) for (uint64_t s = 0;; ++s) { @@ -171,7 +172,9 @@ bool Executive::go(uint64_t _steps) catch (StepsDone const&) {} } else - m_out = m_vm->go(*m_ext, _steps); + m_out = m_vm->go(*m_ext, _steps);*/ + auto s = state().storage(m_ext->myAddress); + m_out = m_vm->go(*m_ext, _steps, &s); #else m_out = m_vm->go(*m_ext, _steps); #endif diff --git a/libethereum/Executive.h b/libethereum/Executive.h index 653b94e71..91b7f1e2f 100644 --- a/libethereum/Executive.h +++ b/libethereum/Executive.h @@ -32,8 +32,6 @@ class VM; class ExtVM; class State; -struct VMTraceChannel: public LogChannel { static const char* name() { return "EVM"; } static const int verbosity = 11; }; - struct Manifest; using Manifests = std::vector; diff --git a/libevm/VM.h b/libevm/VM.h index b1d387708..e3d67ff86 100644 --- a/libevm/VM.h +++ b/libevm/VM.h @@ -21,7 +21,13 @@ #pragma once +#define ETH_VMTRACE 1 + #include +#if ETH_VMTRACE +#include +#include +#endif #include #include #include @@ -67,7 +73,7 @@ public: void reset(u256 _gas = 0); template - bytesConstRef go(Ext& _ext, uint64_t _steps = (uint64_t)-1); + bytesConstRef go(Ext& _ext, uint64_t _steps = (uint64_t)-1, std::map const* _storage = nullptr); void require(u256 _n) { if (m_stack.size() < _n) throw StackTooSmall(_n, m_stack.size()); } void requireMem(unsigned _n) { if (m_temp.size() < _n) { m_temp.resize(_n); } } @@ -84,14 +90,36 @@ private: u256s m_stack; }; +struct VMTraceChannel: public LogChannel { static const char* name() { return "EVM"; } static const int verbosity = 11; }; + } // INLINE: -template eth::bytesConstRef eth::VM::go(Ext& _ext, uint64_t _steps) +template eth::bytesConstRef eth::VM::go(Ext& _ext, uint64_t _steps, std::map const* _storage) { u256 nextPC = m_curPC + 1; + auto osteps = _steps; for (bool stopped = false; !stopped && _steps--; m_curPC = nextPC, nextPC = m_curPC + 1) { + // TRACE +#if ETH_VMTRACE + { + std::ostringstream o; + o << std::endl << " STACK" << std::endl; + for (auto i: stack()) + o << (h256)i << std::endl; + o << " MEMORY" << std::endl << memDump(memory()); + if (_storage) + { + o << " STORAGE" << std::endl; + for (auto const& i: *_storage) + o << std::showbase << std::hex << i.first << ": " << i.second << std::endl; + } + eth::LogOutputStream(true) << o.str(); + eth::LogOutputStream(false) << std::dec << " | #" << (osteps - _steps) << " | " << std::hex << std::setw(4) << std::setfill('0') << curPC() << " : " << c_instructionInfo.at((Instruction)_ext.getCode(curPC())).name << " | " << std::dec << gas() << " ]"; + } +#endif + // INSTRUCTION... Instruction inst = (Instruction)_ext.getCode(m_curPC); @@ -516,7 +544,7 @@ template eth::bytesConstRef eth::VM::go(Ext& _ext, uint64_t _steps) case Instruction::PC: m_stack.push_back(m_curPC); break; - case Instruction::MEMSIZE: + case Instruction::MSIZE: m_stack.push_back(m_temp.size()); break; case Instruction::GAS: diff --git a/libevmface/Instruction.cpp b/libevmface/Instruction.cpp index 7ee28b0be..559ebfb5b 100644 --- a/libevmface/Instruction.cpp +++ b/libevmface/Instruction.cpp @@ -76,7 +76,7 @@ const std::map eth::c_instructions = { "JUMP", Instruction::JUMP }, { "JUMPI", Instruction::JUMPI }, { "PC", Instruction::PC }, - { "MEMSIZE", Instruction::MEMSIZE }, + { "MSIZE", Instruction::MSIZE }, { "GAS", Instruction::GAS }, { "PUSH1", Instruction::PUSH1 }, { "PUSH2", Instruction::PUSH2 }, @@ -167,7 +167,7 @@ const std::map eth::c_instructionInfo = { Instruction::JUMP, { "JUMP", 0, 1, 0 } }, { Instruction::JUMPI, { "JUMPI", 0, 2, 0 } }, { Instruction::PC, { "PC", 0, 0, 1 } }, - { Instruction::MEMSIZE, { "MEMSIZE", 0, 0, 1 } }, + { Instruction::MSIZE, { "MSIZE", 0, 0, 1 } }, { Instruction::GAS, { "GAS", 0, 0, 1 } }, { Instruction::PUSH1, { "PUSH1", 1, 0, 1 } }, { Instruction::PUSH2, { "PUSH2", 2, 0, 1 } }, diff --git a/libevmface/Instruction.h b/libevmface/Instruction.h index a3ad334b1..4e0fe82b8 100644 --- a/libevmface/Instruction.h +++ b/libevmface/Instruction.h @@ -89,7 +89,7 @@ enum class Instruction: uint8_t JUMP, JUMPI, PC, - MEMSIZE, + MSIZE, GAS, PUSH1 = 0x60, diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index 47c83e635..d19d75090 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -482,11 +482,11 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) requireSize(1); requireDeposit(0, 1); - m_asm.append(Instruction::MEMSIZE); + m_asm.append(Instruction::MSIZE); m_asm.append(u256(0)); m_asm.append(u256(1)); m_asm.append(code[0].m_asm, 1); - m_asm.append(Instruction::MEMSIZE); + m_asm.append(Instruction::MSIZE); m_asm.append(Instruction::ADD); m_asm.append(Instruction::SUB); m_asm.append(Instruction::MSTORE8);