mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +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)
|
||||
{
|
||||
// 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());
|
||||
|
|
|
|||
|
|
@ -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: \
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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…
Reference in a new issue