mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Create dedicated function for pushdata reading
This commit is contained in:
parent
4ff7ba015d
commit
1008c70a14
2 changed files with 23 additions and 0 deletions
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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…
Reference in a new issue