Browse Source

Read push data using llvm::APInt

cl-refactor
Paweł Bylica 10 years ago
parent
commit
eaed9c3c4f
  1. 2
      libevmjit/Compiler.cpp
  2. 7
      libevmjit/Instruction.h
  3. 6
      libevmjit/Type.cpp
  4. 2
      libevmjit/Type.h
  5. 4
      libevmjit/Utils.cpp

2
libevmjit/Compiler.cpp

@ -71,7 +71,7 @@ void Compiler::createBasicBlocks(bytes const& _bytecode)
if (nextInst == Instruction::JUMP || nextInst == Instruction::JUMPI)
{
// Create a block for the JUMP target.
ProgramCounter targetPC = val < _bytecode.size() ? val.convert_to<ProgramCounter>() : _bytecode.size();
ProgramCounter targetPC = val.ult(_bytecode.size()) ? val.getZExtValue() : _bytecode.size();
splitPoints.insert(targetPC);
ProgramCounter jumpPC = (next - _bytecode.begin());

7
libevmjit/Instruction.h

@ -2,6 +2,11 @@
#include "Common.h"
namespace llvm
{
class APInt;
}
namespace dev
{
namespace eth
@ -156,7 +161,7 @@ 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
u256 readPushData(bytes::const_iterator& _curr, bytes::const_iterator _end);
llvm::APInt readPushData(bytes::const_iterator& _curr, bytes::const_iterator _end);
#define ANY_PUSH PUSH1: \
case Instruction::PUSH2: \

6
libevmjit/Type.cpp

@ -51,11 +51,9 @@ llvm::ConstantInt* Constant::get(int64_t _n)
return llvm::ConstantInt::getSigned(Type::Word, _n);
}
llvm::ConstantInt* Constant::get(u256 _n)
llvm::ConstantInt* Constant::get(llvm::APInt const& _n)
{
llvm::APInt n(256, _n.str(0, std::ios_base::hex), 16);
assert(n.toString(10, false) == _n.str());
return static_cast<llvm::ConstantInt*>(llvm::ConstantInt::get(Type::Word, n));
return llvm::ConstantInt::get(Type::Word->getContext(), _n);
}
llvm::ConstantInt* Constant::get(ReturnCode _returnCode)

2
libevmjit/Type.h

@ -43,7 +43,7 @@ struct Constant
{
/// Returns word-size constant
static llvm::ConstantInt* get(int64_t _n);
static llvm::ConstantInt* get(u256 _n);
static llvm::ConstantInt* get(llvm::APInt const& _n);
static llvm::ConstantInt* get(ReturnCode _returnCode);
};

4
libevmjit/Utils.cpp

@ -38,12 +38,12 @@ i256 eth2llvm(u256 _u)
return i;
}
u256 readPushData(bytes::const_iterator& _curr, bytes::const_iterator _end)
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;
u256 value;
llvm::APInt value(256, 0);
++_curr; // Point the data
for (decltype(numBytes) i = 0; i < numBytes; ++i)
{

Loading…
Cancel
Save