Browse Source

skipPushData() helper function

cl-refactor
Paweł Bylica 10 years ago
parent
commit
b4284f05dc
  1. 4
      libevmjit/Compiler.cpp
  2. 40
      libevmjit/Instruction.cpp
  3. 6
      libevmjit/Instruction.h
  4. 19
      libevmjit/Utils.cpp

4
libevmjit/Compiler.cpp

@ -57,10 +57,8 @@ void Compiler::createBasicBlocks(bytes const& _bytecode)
{
case Instruction::ANY_PUSH:
{
readPushData(curr, _bytecode.end());
skipPushData(curr, _bytecode.end());
break;
}
case Instruction::JUMPDEST:
{

40
libevmjit/Instruction.cpp

@ -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) {}
}
}
}
}

6
libevmjit/Instruction.h

@ -160,9 +160,13 @@ enum class Instruction: uint8_t
/// 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
/// @param _curr is updated and points the last real byte read
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: \
case Instruction::PUSH2: \
case Instruction::PUSH3: \

19
libevmjit/Utils.cpp

@ -1,7 +1,5 @@
#include <llvm/ADT/APInt.h>
#include "Utils.h"
#include "Instruction.h"
namespace dev
{
@ -37,23 +35,6 @@ i256 eth2llvm(u256 _u)
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…
Cancel
Save