Create dedicated function for pushdata reading

This commit is contained in:
Paweł Bylica 2014-10-30 19:17:55 +01:00
parent 4ff7ba015d
commit 1008c70a14
2 changed files with 23 additions and 0 deletions

View file

@ -35,6 +35,23 @@ i256 eth2llvm(u256 _u)
return i;
}
u256 readPushData(const byte*& _curr, const byte* _end)
{
auto pushInst = *_curr;
assert(Instruction(pushInst) >= Instruction::PUSH1 && Instruction(pushInst) <= Instruction::PUSH32);
auto numBytes = pushInst - static_cast<size_t>(Instruction::PUSH1) + 1;
u256 value;
++_curr; // Point the data
for (decltype(numBytes) i = 0; i < numBytes; ++i)
{
byte b = (_curr != _end) ? *_curr++ : 0;
value <<= 8;
value |= b;
}
--_curr; // Point the last real byte read
return value;
}
}
}
}

View file

@ -5,6 +5,7 @@
#include <libdevcore/Common.h>
#include <libdevcore/Log.h>
#include <libevmface/Instruction.h>
namespace dev
{
@ -29,6 +30,11 @@ static_assert(sizeof(i256) == 32, "Wrong i265 size");
u256 llvm2eth(i256);
i256 eth2llvm(u256);
/// Reads PUSH data from pointed fragment of bytecode and constructs number out of it
/// Reading out of bytecode means reading 0
/// @param _curr is updates and points the last real byte read
u256 readPushData(const byte*& _curr, const byte* _end);
#define ANY_PUSH PUSH1: \
case Instruction::PUSH2: \
case Instruction::PUSH3: \