Browse Source

MEMSIZE -> MSIZE

cl-refactor
Gav Wood 11 years ago
parent
commit
46b837d4d0
  1. 7
      libethereum/Executive.cpp
  2. 2
      libethereum/Executive.h
  3. 34
      libevm/VM.h
  4. 4
      libevmface/Instruction.cpp
  5. 2
      libevmface/Instruction.h
  6. 4
      liblll/CodeFragment.cpp

7
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

2
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<Manifest>;

34
libevm/VM.h

@ -21,7 +21,13 @@
#pragma once
#define ETH_VMTRACE 1
#include <unordered_map>
#if ETH_VMTRACE
#include <sstream>
#include <libethential/Log.h>
#endif
#include <libethential/Exceptions.h>
#include <libethcore/CommonEth.h>
#include <libevmface/Instruction.h>
@ -67,7 +73,7 @@ public:
void reset(u256 _gas = 0);
template <class Ext>
bytesConstRef go(Ext& _ext, uint64_t _steps = (uint64_t)-1);
bytesConstRef go(Ext& _ext, uint64_t _steps = (uint64_t)-1, std::map<u256, u256> 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 <class Ext> eth::bytesConstRef eth::VM::go(Ext& _ext, uint64_t _steps)
template <class Ext> eth::bytesConstRef eth::VM::go(Ext& _ext, uint64_t _steps, std::map<u256, u256> 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<VMTraceChannel, false>(true) << o.str();
eth::LogOutputStream<VMTraceChannel, false>(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 <class Ext> 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:

4
libevmface/Instruction.cpp

@ -76,7 +76,7 @@ const std::map<std::string, Instruction> 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<Instruction, InstructionInfo> 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 } },

2
libevmface/Instruction.h

@ -89,7 +89,7 @@ enum class Instruction: uint8_t
JUMP,
JUMPI,
PC,
MEMSIZE,
MSIZE,
GAS,
PUSH1 = 0x60,

4
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);

Loading…
Cancel
Save