Browse Source

Move helper functions back to VM

cl-refactor
Paweł Bylica 10 years ago
parent
commit
72552c4936
  1. 19
      libevm/VM.h
  2. 15
      libevm/VMFace.h

19
libevm/VM.h

@ -38,6 +38,13 @@ namespace eth
class VMFactory; class VMFactory;
// Convert from a 256-bit integer stack/memory entry into a 160-bit Address hash.
// Currently we just pull out the right (low-order in BE) 160-bits.
inline Address asAddress(u256 _item)
{
return right160(h256(_item));
}
inline u256 fromAddress(Address _a) inline u256 fromAddress(Address _a)
{ {
return (u160)_a; return (u160)_a;
@ -151,7 +158,7 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
case Instruction::SLOAD: case Instruction::SLOAD:
require(1); require(1);
runGas = c_sloadGas; runGas = c_sloadGas;
break; break;
// These all operate on memory and therefore potentially expand it: // These all operate on memory and therefore potentially expand it:
@ -223,7 +230,7 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
u256 inOff = m_stack[m_stack.size() - 2]; u256 inOff = m_stack[m_stack.size() - 2];
u256 inSize = m_stack[m_stack.size() - 3]; u256 inSize = m_stack[m_stack.size() - 3];
newTempSize = (bigint)inOff + inSize; newTempSize = (bigint)inOff + inSize;
runGas = c_createGas; runGas = c_createGas;
break; break;
} }
case Instruction::EXP: case Instruction::EXP:
@ -399,7 +406,7 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
m_stack.pop_back(); m_stack.pop_back();
break; break;
case Instruction::SDIV: case Instruction::SDIV:
m_stack[m_stack.size() - 2] = m_stack[m_stack.size() - 2] ? s2u(u2s(m_stack.back()) / u2s(m_stack[m_stack.size() - 2])) : 0; m_stack[m_stack.size() - 2] = m_stack[m_stack.size() - 2] ? s2u(u2s(m_stack.back()) / u2s(m_stack[m_stack.size() - 2])) : 0;
m_stack.pop_back(); m_stack.pop_back();
break; break;
case Instruction::MOD: case Instruction::MOD:
@ -407,7 +414,7 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
m_stack.pop_back(); m_stack.pop_back();
break; break;
case Instruction::SMOD: case Instruction::SMOD:
m_stack[m_stack.size() - 2] = m_stack[m_stack.size() - 2] ? s2u(u2s(m_stack.back()) % u2s(m_stack[m_stack.size() - 2])) : 0; m_stack[m_stack.size() - 2] = m_stack[m_stack.size() - 2] ? s2u(u2s(m_stack.back()) % u2s(m_stack[m_stack.size() - 2])) : 0;
m_stack.pop_back(); m_stack.pop_back();
break; break;
case Instruction::EXP: case Instruction::EXP:
@ -430,11 +437,11 @@ template <class Ext> dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc con
m_stack.pop_back(); m_stack.pop_back();
break; break;
case Instruction::SLT: case Instruction::SLT:
m_stack[m_stack.size() - 2] = u2s(m_stack.back()) < u2s(m_stack[m_stack.size() - 2]) ? 1 : 0; m_stack[m_stack.size() - 2] = u2s(m_stack.back()) < u2s(m_stack[m_stack.size() - 2]) ? 1 : 0;
m_stack.pop_back(); m_stack.pop_back();
break; break;
case Instruction::SGT: case Instruction::SGT:
m_stack[m_stack.size() - 2] = u2s(m_stack.back()) > u2s(m_stack[m_stack.size() - 2]) ? 1 : 0; m_stack[m_stack.size() - 2] = u2s(m_stack.back()) > u2s(m_stack[m_stack.size() - 2]) ? 1 : 0;
m_stack.pop_back(); m_stack.pop_back();
break; break;
case Instruction::EQ: case Instruction::EQ:

15
libevm/VMFace.h

@ -34,21 +34,6 @@ struct BadJumpDestination: virtual VMException {};
struct OutOfGas: virtual VMException {}; struct OutOfGas: virtual VMException {};
struct StackTooSmall: virtual public VMException {}; struct StackTooSmall: virtual public VMException {};
// Convert from a 256-bit integer stack/memory entry into a 160-bit Address hash.
// Currently we just pull out the right (low-order in BE) 160-bits.
inline Address asAddress(u256 _item)
{
return right160(h256(_item));
}
inline u256 fromAddress(Address _a)
{
return (u160)_a;
// h256 ret;
// memcpy(&ret, &_a, sizeof(_a));
// return ret;
}
/** /**
*/ */
class VMFace class VMFace

Loading…
Cancel
Save