mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
skipPushData() helper function
This commit is contained in:
parent
b8f9f3cffe
commit
b4284f05dc
4 changed files with 46 additions and 23 deletions
|
|
@ -57,10 +57,8 @@ void Compiler::createBasicBlocks(bytes const& _bytecode)
|
||||||
{
|
{
|
||||||
|
|
||||||
case Instruction::ANY_PUSH:
|
case Instruction::ANY_PUSH:
|
||||||
{
|
skipPushData(curr, _bytecode.end());
|
||||||
readPushData(curr, _bytecode.end());
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case Instruction::JUMPDEST:
|
case Instruction::JUMPDEST:
|
||||||
{
|
{
|
||||||
|
|
|
||||||
40
libevmjit/Instruction.cpp
Normal file
40
libevmjit/Instruction.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
|
||||||
|
#include "Instruction.h"
|
||||||
|
#include <llvm/ADT/APInt.h>
|
||||||
|
|
||||||
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
|
{
|
||||||
|
|
||||||
|
llvm::APInt readPushData(bytes::const_iterator& _curr, bytes::const_iterator _end)
|
||||||
|
{
|
||||||
|
auto pushInst = *_curr;
|
||||||
|
assert(Instruction(pushInst) >= Instruction::PUSH1 && Instruction(pushInst) <= Instruction::PUSH32);
|
||||||
|
auto numBytes = pushInst - static_cast<size_t>(Instruction::PUSH1) + 1;
|
||||||
|
llvm::APInt value(256, 0);
|
||||||
|
++_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void skipPushData(bytes::const_iterator& _curr, bytes::const_iterator _end)
|
||||||
|
{
|
||||||
|
auto pushInst = *_curr;
|
||||||
|
assert(Instruction(pushInst) >= Instruction::PUSH1 && Instruction(pushInst) <= Instruction::PUSH32);
|
||||||
|
auto numBytes = pushInst - static_cast<size_t>(Instruction::PUSH1) + 1;
|
||||||
|
--_end;
|
||||||
|
for (decltype(numBytes) i = 0; i < numBytes && _curr < _end; ++i, ++_curr) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -160,9 +160,13 @@ enum class Instruction: uint8_t
|
||||||
|
|
||||||
/// Reads PUSH data from pointed fragment of bytecode and constructs number out of it
|
/// Reads PUSH data from pointed fragment of bytecode and constructs number out of it
|
||||||
/// Reading out of bytecode means reading 0
|
/// Reading out of bytecode means reading 0
|
||||||
/// @param _curr is updates and points the last real byte read
|
/// @param _curr is updated and points the last real byte read
|
||||||
llvm::APInt readPushData(bytes::const_iterator& _curr, bytes::const_iterator _end);
|
llvm::APInt readPushData(bytes::const_iterator& _curr, bytes::const_iterator _end);
|
||||||
|
|
||||||
|
/// Skips PUSH data in pointed fragment of bytecode.
|
||||||
|
/// @param _curr is updated and points the last real byte skipped
|
||||||
|
void skipPushData(bytes::const_iterator& _curr, bytes::const_iterator _end);
|
||||||
|
|
||||||
#define ANY_PUSH PUSH1: \
|
#define ANY_PUSH PUSH1: \
|
||||||
case Instruction::PUSH2: \
|
case Instruction::PUSH2: \
|
||||||
case Instruction::PUSH3: \
|
case Instruction::PUSH3: \
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
#include <llvm/ADT/APInt.h>
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Instruction.h"
|
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
|
|
@ -37,23 +35,6 @@ i256 eth2llvm(u256 _u)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::APInt readPushData(bytes::const_iterator& _curr, bytes::const_iterator _end)
|
|
||||||
{
|
|
||||||
auto pushInst = *_curr;
|
|
||||||
assert(Instruction(pushInst) >= Instruction::PUSH1 && Instruction(pushInst) <= Instruction::PUSH32);
|
|
||||||
auto numBytes = pushInst - static_cast<size_t>(Instruction::PUSH1) + 1;
|
|
||||||
llvm::APInt value(256, 0);
|
|
||||||
++_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue