Browse Source

Create dedicated function for pushdata reading

cl-refactor
Paweł Bylica 10 years ago
parent
commit
1008c70a14
  1. 17
      libevmjit/Utils.cpp
  2. 6
      libevmjit/Utils.h

17
libevmjit/Utils.cpp

@ -35,6 +35,23 @@ i256 eth2llvm(u256 _u)
return i; 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;
}
} }
} }
} }

6
libevmjit/Utils.h

@ -5,6 +5,7 @@
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libevmface/Instruction.h>
namespace dev namespace dev
{ {
@ -29,6 +30,11 @@ static_assert(sizeof(i256) == 32, "Wrong i265 size");
u256 llvm2eth(i256); u256 llvm2eth(i256);
i256 eth2llvm(u256); 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: \ #define ANY_PUSH PUSH1: \
case Instruction::PUSH2: \ case Instruction::PUSH2: \
case Instruction::PUSH3: \ case Instruction::PUSH3: \

Loading…
Cancel
Save