mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Read push data using llvm::APInt
This commit is contained in:
parent
30f0a7a894
commit
eaed9c3c4f
5 changed files with 12 additions and 9 deletions
|
|
@ -71,7 +71,7 @@ void Compiler::createBasicBlocks(bytes const& _bytecode)
|
||||||
if (nextInst == Instruction::JUMP || nextInst == Instruction::JUMPI)
|
if (nextInst == Instruction::JUMP || nextInst == Instruction::JUMPI)
|
||||||
{
|
{
|
||||||
// Create a block for the JUMP target.
|
// 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);
|
splitPoints.insert(targetPC);
|
||||||
|
|
||||||
ProgramCounter jumpPC = (next - _bytecode.begin());
|
ProgramCounter jumpPC = (next - _bytecode.begin());
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
|
||||||
|
namespace llvm
|
||||||
|
{
|
||||||
|
class APInt;
|
||||||
|
}
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
namespace eth
|
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
|
/// 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 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: \
|
#define ANY_PUSH PUSH1: \
|
||||||
case Instruction::PUSH2: \
|
case Instruction::PUSH2: \
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,9 @@ llvm::ConstantInt* Constant::get(int64_t _n)
|
||||||
return llvm::ConstantInt::getSigned(Type::Word, _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);
|
return llvm::ConstantInt::get(Type::Word->getContext(), _n);
|
||||||
assert(n.toString(10, false) == _n.str());
|
|
||||||
return static_cast<llvm::ConstantInt*>(llvm::ConstantInt::get(Type::Word, n));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::ConstantInt* Constant::get(ReturnCode _returnCode)
|
llvm::ConstantInt* Constant::get(ReturnCode _returnCode)
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ struct Constant
|
||||||
{
|
{
|
||||||
/// Returns word-size constant
|
/// Returns word-size constant
|
||||||
static llvm::ConstantInt* get(int64_t _n);
|
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);
|
static llvm::ConstantInt* get(ReturnCode _returnCode);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,12 @@ i256 eth2llvm(u256 _u)
|
||||||
return i;
|
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;
|
auto pushInst = *_curr;
|
||||||
assert(Instruction(pushInst) >= Instruction::PUSH1 && Instruction(pushInst) <= Instruction::PUSH32);
|
assert(Instruction(pushInst) >= Instruction::PUSH1 && Instruction(pushInst) <= Instruction::PUSH32);
|
||||||
auto numBytes = pushInst - static_cast<size_t>(Instruction::PUSH1) + 1;
|
auto numBytes = pushInst - static_cast<size_t>(Instruction::PUSH1) + 1;
|
||||||
u256 value;
|
llvm::APInt value(256, 0);
|
||||||
++_curr; // Point the data
|
++_curr; // Point the data
|
||||||
for (decltype(numBytes) i = 0; i < numBytes; ++i)
|
for (decltype(numBytes) i = 0; i < numBytes; ++i)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue