mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Separating EVM JIT from CPP client (WIP)
This commit is contained in:
parent
99c7113079
commit
68648a2fb5
19 changed files with 327 additions and 139 deletions
|
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
#include <llvm/IR/Function.h>
|
#include <llvm/IR/Function.h>
|
||||||
|
|
||||||
#include <libdevcore/Common.h>
|
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
namespace eth
|
namespace eth
|
||||||
|
|
@ -102,56 +100,57 @@ extern "C"
|
||||||
{
|
{
|
||||||
|
|
||||||
using namespace dev::eth::jit;
|
using namespace dev::eth::jit;
|
||||||
|
using s256 = boost::multiprecision::int256_t;
|
||||||
|
|
||||||
EXPORT void arith_mul(i256* _arg1, i256* _arg2, i256* o_result)
|
EXPORT void arith_mul(i256* _arg1, i256* _arg2, i256* o_result)
|
||||||
{
|
{
|
||||||
dev::u256 arg1 = llvm2eth(*_arg1);
|
auto arg1 = llvm2eth(*_arg1);
|
||||||
dev::u256 arg2 = llvm2eth(*_arg2);
|
auto arg2 = llvm2eth(*_arg2);
|
||||||
*o_result = eth2llvm(arg1 * arg2);
|
*o_result = eth2llvm(arg1 * arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT void arith_div(i256* _arg1, i256* _arg2, i256* o_result)
|
EXPORT void arith_div(i256* _arg1, i256* _arg2, i256* o_result)
|
||||||
{
|
{
|
||||||
dev::u256 arg1 = llvm2eth(*_arg1);
|
auto arg1 = llvm2eth(*_arg1);
|
||||||
dev::u256 arg2 = llvm2eth(*_arg2);
|
auto arg2 = llvm2eth(*_arg2);
|
||||||
*o_result = eth2llvm(arg2 == 0 ? arg2 : arg1 / arg2);
|
*o_result = eth2llvm(arg2 == 0 ? arg2 : arg1 / arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT void arith_mod(i256* _arg1, i256* _arg2, i256* o_result)
|
EXPORT void arith_mod(i256* _arg1, i256* _arg2, i256* o_result)
|
||||||
{
|
{
|
||||||
dev::u256 arg1 = llvm2eth(*_arg1);
|
auto arg1 = llvm2eth(*_arg1);
|
||||||
dev::u256 arg2 = llvm2eth(*_arg2);
|
auto arg2 = llvm2eth(*_arg2);
|
||||||
*o_result = eth2llvm(arg2 == 0 ? arg2 : arg1 % arg2);
|
*o_result = eth2llvm(arg2 == 0 ? arg2 : arg1 % arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT void arith_sdiv(i256* _arg1, i256* _arg2, i256* o_result)
|
EXPORT void arith_sdiv(i256* _arg1, i256* _arg2, i256* o_result)
|
||||||
{
|
{
|
||||||
dev::u256 arg1 = llvm2eth(*_arg1);
|
auto arg1 = llvm2eth(*_arg1);
|
||||||
dev::u256 arg2 = llvm2eth(*_arg2);
|
auto arg2 = llvm2eth(*_arg2);
|
||||||
*o_result = eth2llvm(arg2 == 0 ? arg2 : dev::s2u(dev::u2s(arg1) / dev::u2s(arg2)));
|
*o_result = eth2llvm(arg2 == 0 ? arg2 : (arg1.convert_to<s256>() / arg2.convert_to<s256>()).convert_to<u256>());
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT void arith_smod(i256* _arg1, i256* _arg2, i256* o_result)
|
EXPORT void arith_smod(i256* _arg1, i256* _arg2, i256* o_result)
|
||||||
{
|
{
|
||||||
dev::u256 arg1 = llvm2eth(*_arg1);
|
auto arg1 = llvm2eth(*_arg1);
|
||||||
dev::u256 arg2 = llvm2eth(*_arg2);
|
auto arg2 = llvm2eth(*_arg2);
|
||||||
*o_result = eth2llvm(arg2 == 0 ? arg2 : dev::s2u(dev::u2s(arg1) % dev::u2s(arg2)));
|
*o_result = eth2llvm(arg2 == 0 ? arg2 : (arg1.convert_to<s256>() % arg2.convert_to<s256>()).convert_to<u256>());
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT void arith_mulmod(i256* _arg1, i256* _arg2, i256* _arg3, i256* o_result)
|
EXPORT void arith_mulmod(i256* _arg1, i256* _arg2, i256* _arg3, i256* o_result)
|
||||||
{
|
{
|
||||||
dev::u256 arg1 = llvm2eth(*_arg1);
|
auto arg1 = llvm2eth(*_arg1);
|
||||||
dev::u256 arg2 = llvm2eth(*_arg2);
|
auto arg2 = llvm2eth(*_arg2);
|
||||||
dev::u256 arg3 = llvm2eth(*_arg3);
|
auto arg3 = llvm2eth(*_arg3);
|
||||||
*o_result = eth2llvm(dev::u256((dev::bigint(arg1) * dev::bigint(arg2)) % arg3));
|
*o_result = eth2llvm(u256((bigint(arg1) * bigint(arg2)) % arg3));
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT void arith_addmod(i256* _arg1, i256* _arg2, i256* _arg3, i256* o_result)
|
EXPORT void arith_addmod(i256* _arg1, i256* _arg2, i256* _arg3, i256* o_result)
|
||||||
{
|
{
|
||||||
dev::u256 arg1 = llvm2eth(*_arg1);
|
auto arg1 = llvm2eth(*_arg1);
|
||||||
dev::u256 arg2 = llvm2eth(*_arg2);
|
auto arg2 = llvm2eth(*_arg2);
|
||||||
dev::u256 arg3 = llvm2eth(*_arg3);
|
auto arg3 = llvm2eth(*_arg3);
|
||||||
*o_result = eth2llvm(dev::u256((dev::bigint(arg1) + dev::bigint(arg2)) % arg3));
|
*o_result = eth2llvm(u256((bigint(arg1) + bigint(arg2)) % arg3));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
libevmjit/Common.h
Normal file
24
libevmjit/Common.h
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <boost/multiprecision/cpp_int.hpp>
|
||||||
|
|
||||||
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
|
{
|
||||||
|
|
||||||
|
using byte = uint8_t;
|
||||||
|
using bytes = std::vector<byte>;
|
||||||
|
using u256 = boost::multiprecision::uint256_t;
|
||||||
|
using bigint = boost::multiprecision::cpp_int;
|
||||||
|
|
||||||
|
struct NoteChannel {}; // FIXME: Use some log library?
|
||||||
|
|
||||||
|
struct ExtVMFace;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,8 +13,7 @@
|
||||||
#include <llvm/PassManager.h>
|
#include <llvm/PassManager.h>
|
||||||
#include <llvm/Transforms/Scalar.h>
|
#include <llvm/Transforms/Scalar.h>
|
||||||
|
|
||||||
#include <libevmcore/Instruction.h>
|
#include "Instruction.h"
|
||||||
|
|
||||||
#include "Type.h"
|
#include "Type.h"
|
||||||
#include "Memory.h"
|
#include "Memory.h"
|
||||||
#include "Stack.h"
|
#include "Stack.h"
|
||||||
|
|
@ -248,7 +247,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(bytes const& _bytecode)
|
||||||
|
|
||||||
|
|
||||||
void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode, RuntimeManager& _runtimeManager,
|
void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode, RuntimeManager& _runtimeManager,
|
||||||
Arith256& _arith, Memory& _memory, Ext& _ext, GasMeter& _gasMeter, llvm::BasicBlock* _nextBasicBlock)
|
Arith256& _arith, Memory& _memory, Ext& _ext, GasMeter& _gasMeter, llvm::BasicBlock* _nextBasicBlock)
|
||||||
{
|
{
|
||||||
if (!_nextBasicBlock) // this is the last block in the code
|
if (!_nextBasicBlock) // this is the last block in the code
|
||||||
_nextBasicBlock = m_stopBB;
|
_nextBasicBlock = m_stopBB;
|
||||||
|
|
@ -490,8 +489,8 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
|
||||||
|
|
||||||
auto kInRange = m_builder.CreateICmpULE(idx, llvm::ConstantInt::get(Type::Word, 30));
|
auto kInRange = m_builder.CreateICmpULE(idx, llvm::ConstantInt::get(Type::Word, 30));
|
||||||
auto result = m_builder.CreateSelect(kInRange,
|
auto result = m_builder.CreateSelect(kInRange,
|
||||||
m_builder.CreateSelect(bittest, val1, val0),
|
m_builder.CreateSelect(bittest, val1, val0),
|
||||||
word);
|
word);
|
||||||
stack.push(result);
|
stack.push(result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@
|
||||||
|
|
||||||
#include <llvm/IR/IRBuilder.h>
|
#include <llvm/IR/IRBuilder.h>
|
||||||
|
|
||||||
#include <libdevcore/Common.h>
|
#include "Common.h"
|
||||||
|
|
||||||
#include "BasicBlock.h"
|
#include "BasicBlock.h"
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
|
|
@ -44,9 +43,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void createBasicBlocks(bytes const& _bytecode);
|
void createBasicBlocks(bytes const& _bytecode);
|
||||||
|
|
||||||
void compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode, class RuntimeManager& _runtimeManager, class Arith256& _arith, class Memory& _memory, class Ext& _ext, class GasMeter& _gasMeter, llvm::BasicBlock* _nextBasicBlock);
|
void compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode, class RuntimeManager& _runtimeManager, class Arith256& _arith, class Memory& _memory, class Ext& _ext, class GasMeter& _gasMeter, llvm::BasicBlock* _nextBasicBlock);
|
||||||
|
|
||||||
void removeDeadBlocks();
|
void removeDeadBlocks();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
#include <llvm/IR/Module.h>
|
#include <llvm/IR/Module.h>
|
||||||
|
|
||||||
#include <libdevcore/Common.h>
|
#include "Common.h"
|
||||||
#include <libevm/ExtVMFace.h>
|
//#include <libevm/ExtVMFace.h>
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
#include <llvm/IR/TypeBuilder.h>
|
#include <llvm/IR/TypeBuilder.h>
|
||||||
#include <llvm/IR/IntrinsicInst.h>
|
#include <llvm/IR/IntrinsicInst.h>
|
||||||
|
|
||||||
#include <libdevcrypto/SHA3.h>
|
//#include <libdevcrypto/SHA3.h>
|
||||||
#include <libevm/FeeStructure.h>
|
//#include <libevm/FeeStructure.h>
|
||||||
|
|
||||||
#include "Runtime.h"
|
#include "Runtime.h"
|
||||||
#include "Type.h"
|
#include "Type.h"
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <libevm/ExtVMFace.h>
|
#include <array>
|
||||||
|
|
||||||
#include "CompilerHelper.h"
|
#include "CompilerHelper.h"
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,6 @@
|
||||||
#include <llvm/IR/Function.h>
|
#include <llvm/IR/Function.h>
|
||||||
#include <llvm/IR/IntrinsicInst.h>
|
#include <llvm/IR/IntrinsicInst.h>
|
||||||
|
|
||||||
#include <libevmcore/Instruction.h>
|
|
||||||
#include <libevm/FeeStructure.h>
|
|
||||||
|
|
||||||
#include "Type.h"
|
#include "Type.h"
|
||||||
#include "Ext.h"
|
#include "Ext.h"
|
||||||
#include "Runtime.h"
|
#include "Runtime.h"
|
||||||
|
|
@ -22,6 +19,26 @@ namespace jit
|
||||||
namespace // Helper functions
|
namespace // Helper functions
|
||||||
{
|
{
|
||||||
|
|
||||||
|
uint64_t const c_stepGas = 1;
|
||||||
|
uint64_t const c_balanceGas = 20;
|
||||||
|
uint64_t const c_sha3Gas = 20;
|
||||||
|
uint64_t const c_sloadGas = 20;
|
||||||
|
uint64_t const c_sstoreSetGas = 300;
|
||||||
|
uint64_t const c_sstoreResetGas = 100;
|
||||||
|
uint64_t const c_sstoreRefundGas = 100;
|
||||||
|
uint64_t const c_createGas = 100;
|
||||||
|
uint64_t const c_callGas = 20;
|
||||||
|
uint64_t const c_expGas = 1;
|
||||||
|
uint64_t const c_expByteGas = 1;
|
||||||
|
uint64_t const c_memoryGas = 1;
|
||||||
|
uint64_t const c_txDataZeroGas = 1;
|
||||||
|
uint64_t const c_txDataNonZeroGas = 5;
|
||||||
|
uint64_t const c_txGas = 500;
|
||||||
|
uint64_t const c_logGas = 32;
|
||||||
|
uint64_t const c_logDataGas = 1;
|
||||||
|
uint64_t const c_logTopicGas = 32;
|
||||||
|
uint64_t const c_copyGas = 1;
|
||||||
|
|
||||||
uint64_t getStepCost(Instruction inst) // TODO: Add this function to FeeSructure (pull request submitted)
|
uint64_t getStepCost(Instruction inst) // TODO: Add this function to FeeSructure (pull request submitted)
|
||||||
{
|
{
|
||||||
switch (inst)
|
switch (inst)
|
||||||
|
|
@ -31,21 +48,16 @@ uint64_t getStepCost(Instruction inst) // TODO: Add this function to FeeSructure
|
||||||
case Instruction::SSTORE: // Handle cost of SSTORE separately in GasMeter::countSStore()
|
case Instruction::SSTORE: // Handle cost of SSTORE separately in GasMeter::countSStore()
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case Instruction::SLOAD:
|
case Instruction::SLOAD: return c_sloadGas;
|
||||||
return static_cast<uint64_t>(c_sloadGas);
|
|
||||||
|
|
||||||
case Instruction::SHA3:
|
case Instruction::SHA3: return c_sha3Gas;
|
||||||
return static_cast<uint64_t>(c_sha3Gas);
|
|
||||||
|
|
||||||
case Instruction::BALANCE:
|
case Instruction::BALANCE: return c_balanceGas;
|
||||||
return static_cast<uint64_t>(c_sha3Gas);
|
|
||||||
|
|
||||||
case Instruction::CALL:
|
case Instruction::CALL:
|
||||||
case Instruction::CALLCODE:
|
case Instruction::CALLCODE: return c_callGas;
|
||||||
return static_cast<uint64_t>(c_callGas);
|
|
||||||
|
|
||||||
case Instruction::CREATE:
|
case Instruction::CREATE: return c_createGas;
|
||||||
return static_cast<uint64_t>(c_createGas);
|
|
||||||
|
|
||||||
case Instruction::LOG0:
|
case Instruction::LOG0:
|
||||||
case Instruction::LOG1:
|
case Instruction::LOG1:
|
||||||
|
|
@ -54,11 +66,11 @@ uint64_t getStepCost(Instruction inst) // TODO: Add this function to FeeSructure
|
||||||
case Instruction::LOG4:
|
case Instruction::LOG4:
|
||||||
{
|
{
|
||||||
auto numTopics = static_cast<uint64_t>(inst) - static_cast<uint64_t>(Instruction::LOG0);
|
auto numTopics = static_cast<uint64_t>(inst) - static_cast<uint64_t>(Instruction::LOG0);
|
||||||
return static_cast<uint64_t>(c_logGas) + numTopics * static_cast<uint64_t>(c_logTopicGas);
|
return c_logGas + numTopics * c_logTopicGas;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: // Assumes instruction code is valid
|
default: // Assumes instruction code is valid
|
||||||
return static_cast<uint64_t>(c_stepGas);
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <libevmcore/Instruction.h>
|
|
||||||
|
|
||||||
#include "CompilerHelper.h"
|
#include "CompilerHelper.h"
|
||||||
|
#include "Instruction.h"
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
|
|
|
||||||
230
libevmjit/Instruction.h
Normal file
230
libevmjit/Instruction.h
Normal file
|
|
@ -0,0 +1,230 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
|
|
||||||
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
|
{
|
||||||
|
|
||||||
|
/// Virtual machine bytecode instruction.
|
||||||
|
enum class Instruction : uint8_t
|
||||||
|
{
|
||||||
|
STOP = 0x00, ///< halts execution
|
||||||
|
ADD, ///< addition operation
|
||||||
|
MUL, ///< mulitplication operation
|
||||||
|
SUB, ///< subtraction operation
|
||||||
|
DIV, ///< integer division operation
|
||||||
|
SDIV, ///< signed integer division operation
|
||||||
|
MOD, ///< modulo remainder operation
|
||||||
|
SMOD, ///< signed modulo remainder operation
|
||||||
|
ADDMOD, ///< unsigned modular addition
|
||||||
|
MULMOD, ///< unsigned modular multiplication
|
||||||
|
EXP, ///< exponential operation
|
||||||
|
SIGNEXTEND, ///< extend length of signed integer
|
||||||
|
|
||||||
|
LT = 0x10, ///< less-than comparision
|
||||||
|
GT, ///< greater-than comparision
|
||||||
|
SLT, ///< signed less-than comparision
|
||||||
|
SGT, ///< signed greater-than comparision
|
||||||
|
EQ, ///< equality comparision
|
||||||
|
ISZERO, ///< simple not operator
|
||||||
|
AND, ///< bitwise AND operation
|
||||||
|
OR, ///< bitwise OR operation
|
||||||
|
XOR, ///< bitwise XOR operation
|
||||||
|
NOT, ///< bitwise NOT opertation
|
||||||
|
BYTE, ///< retrieve single byte from word
|
||||||
|
|
||||||
|
SHA3 = 0x20, ///< compute SHA3-256 hash
|
||||||
|
|
||||||
|
ADDRESS = 0x30, ///< get address of currently executing account
|
||||||
|
BALANCE, ///< get balance of the given account
|
||||||
|
ORIGIN, ///< get execution origination address
|
||||||
|
CALLER, ///< get caller address
|
||||||
|
CALLVALUE, ///< get deposited value by the instruction/transaction responsible for this execution
|
||||||
|
CALLDATALOAD, ///< get input data of current environment
|
||||||
|
CALLDATASIZE, ///< get size of input data in current environment
|
||||||
|
CALLDATACOPY, ///< copy input data in current environment to memory
|
||||||
|
CODESIZE, ///< get size of code running in current environment
|
||||||
|
CODECOPY, ///< copy code running in current environment to memory
|
||||||
|
GASPRICE, ///< get price of gas in current environment
|
||||||
|
EXTCODESIZE, ///< get external code size (from another contract)
|
||||||
|
EXTCODECOPY, ///< copy external code (from another contract)
|
||||||
|
|
||||||
|
PREVHASH = 0x40, ///< get hash of most recent complete block
|
||||||
|
COINBASE, ///< get the block's coinbase address
|
||||||
|
TIMESTAMP, ///< get the block's timestamp
|
||||||
|
NUMBER, ///< get the block's number
|
||||||
|
DIFFICULTY, ///< get the block's difficulty
|
||||||
|
GASLIMIT, ///< get the block's gas limit
|
||||||
|
|
||||||
|
POP = 0x50, ///< remove item from stack
|
||||||
|
MLOAD, ///< load word from memory
|
||||||
|
MSTORE, ///< save word to memory
|
||||||
|
MSTORE8, ///< save byte to memory
|
||||||
|
SLOAD, ///< load word from storage
|
||||||
|
SSTORE, ///< save word to storage
|
||||||
|
JUMP, ///< alter the program counter
|
||||||
|
JUMPI, ///< conditionally alter the program counter
|
||||||
|
PC, ///< get the program counter
|
||||||
|
MSIZE, ///< get the size of active memory
|
||||||
|
GAS, ///< get the amount of available gas
|
||||||
|
JUMPDEST, ///< set a potential jump destination
|
||||||
|
|
||||||
|
PUSH1 = 0x60, ///< place 1 byte item on stack
|
||||||
|
PUSH2, ///< place 2 byte item on stack
|
||||||
|
PUSH3, ///< place 3 byte item on stack
|
||||||
|
PUSH4, ///< place 4 byte item on stack
|
||||||
|
PUSH5, ///< place 5 byte item on stack
|
||||||
|
PUSH6, ///< place 6 byte item on stack
|
||||||
|
PUSH7, ///< place 7 byte item on stack
|
||||||
|
PUSH8, ///< place 8 byte item on stack
|
||||||
|
PUSH9, ///< place 9 byte item on stack
|
||||||
|
PUSH10, ///< place 10 byte item on stack
|
||||||
|
PUSH11, ///< place 11 byte item on stack
|
||||||
|
PUSH12, ///< place 12 byte item on stack
|
||||||
|
PUSH13, ///< place 13 byte item on stack
|
||||||
|
PUSH14, ///< place 14 byte item on stack
|
||||||
|
PUSH15, ///< place 15 byte item on stack
|
||||||
|
PUSH16, ///< place 16 byte item on stack
|
||||||
|
PUSH17, ///< place 17 byte item on stack
|
||||||
|
PUSH18, ///< place 18 byte item on stack
|
||||||
|
PUSH19, ///< place 19 byte item on stack
|
||||||
|
PUSH20, ///< place 20 byte item on stack
|
||||||
|
PUSH21, ///< place 21 byte item on stack
|
||||||
|
PUSH22, ///< place 22 byte item on stack
|
||||||
|
PUSH23, ///< place 23 byte item on stack
|
||||||
|
PUSH24, ///< place 24 byte item on stack
|
||||||
|
PUSH25, ///< place 25 byte item on stack
|
||||||
|
PUSH26, ///< place 26 byte item on stack
|
||||||
|
PUSH27, ///< place 27 byte item on stack
|
||||||
|
PUSH28, ///< place 28 byte item on stack
|
||||||
|
PUSH29, ///< place 29 byte item on stack
|
||||||
|
PUSH30, ///< place 30 byte item on stack
|
||||||
|
PUSH31, ///< place 31 byte item on stack
|
||||||
|
PUSH32, ///< place 32 byte item on stack
|
||||||
|
|
||||||
|
DUP1 = 0x80, ///< copies the highest item in the stack to the top of the stack
|
||||||
|
DUP2, ///< copies the second highest item in the stack to the top of the stack
|
||||||
|
DUP3, ///< copies the third highest item in the stack to the top of the stack
|
||||||
|
DUP4, ///< copies the 4th highest item in the stack to the top of the stack
|
||||||
|
DUP5, ///< copies the 5th highest item in the stack to the top of the stack
|
||||||
|
DUP6, ///< copies the 6th highest item in the stack to the top of the stack
|
||||||
|
DUP7, ///< copies the 7th highest item in the stack to the top of the stack
|
||||||
|
DUP8, ///< copies the 8th highest item in the stack to the top of the stack
|
||||||
|
DUP9, ///< copies the 9th highest item in the stack to the top of the stack
|
||||||
|
DUP10, ///< copies the 10th highest item in the stack to the top of the stack
|
||||||
|
DUP11, ///< copies the 11th highest item in the stack to the top of the stack
|
||||||
|
DUP12, ///< copies the 12th highest item in the stack to the top of the stack
|
||||||
|
DUP13, ///< copies the 13th highest item in the stack to the top of the stack
|
||||||
|
DUP14, ///< copies the 14th highest item in the stack to the top of the stack
|
||||||
|
DUP15, ///< copies the 15th highest item in the stack to the top of the stack
|
||||||
|
DUP16, ///< copies the 16th highest item in the stack to the top of the stack
|
||||||
|
|
||||||
|
SWAP1 = 0x90, ///< swaps the highest and second highest value on the stack
|
||||||
|
SWAP2, ///< swaps the highest and third highest value on the stack
|
||||||
|
SWAP3, ///< swaps the highest and 4th highest value on the stack
|
||||||
|
SWAP4, ///< swaps the highest and 5th highest value on the stack
|
||||||
|
SWAP5, ///< swaps the highest and 6th highest value on the stack
|
||||||
|
SWAP6, ///< swaps the highest and 7th highest value on the stack
|
||||||
|
SWAP7, ///< swaps the highest and 8th highest value on the stack
|
||||||
|
SWAP8, ///< swaps the highest and 9th highest value on the stack
|
||||||
|
SWAP9, ///< swaps the highest and 10th highest value on the stack
|
||||||
|
SWAP10, ///< swaps the highest and 11th highest value on the stack
|
||||||
|
SWAP11, ///< swaps the highest and 12th highest value on the stack
|
||||||
|
SWAP12, ///< swaps the highest and 13th highest value on the stack
|
||||||
|
SWAP13, ///< swaps the highest and 14th highest value on the stack
|
||||||
|
SWAP14, ///< swaps the highest and 15th highest value on the stack
|
||||||
|
SWAP15, ///< swaps the highest and 16th highest value on the stack
|
||||||
|
SWAP16, ///< swaps the highest and 17th highest value on the stack
|
||||||
|
|
||||||
|
LOG0 = 0xa0, ///< Makes a log entry; no topics.
|
||||||
|
LOG1, ///< Makes a log entry; 1 topic.
|
||||||
|
LOG2, ///< Makes a log entry; 2 topics.
|
||||||
|
LOG3, ///< Makes a log entry; 3 topics.
|
||||||
|
LOG4, ///< Makes a log entry; 4 topics.
|
||||||
|
|
||||||
|
CREATE = 0xf0, ///< create a new account with associated code
|
||||||
|
CALL, ///< message-call into an account
|
||||||
|
RETURN, ///< halt execution returning output data
|
||||||
|
CALLCODE,
|
||||||
|
SUICIDE = 0xff ///< halt execution and register account for later deletion
|
||||||
|
};
|
||||||
|
|
||||||
|
/// 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);
|
||||||
|
|
||||||
|
#define ANY_PUSH PUSH1: \
|
||||||
|
case Instruction::PUSH2: \
|
||||||
|
case Instruction::PUSH3: \
|
||||||
|
case Instruction::PUSH4: \
|
||||||
|
case Instruction::PUSH5: \
|
||||||
|
case Instruction::PUSH6: \
|
||||||
|
case Instruction::PUSH7: \
|
||||||
|
case Instruction::PUSH8: \
|
||||||
|
case Instruction::PUSH9: \
|
||||||
|
case Instruction::PUSH10: \
|
||||||
|
case Instruction::PUSH11: \
|
||||||
|
case Instruction::PUSH12: \
|
||||||
|
case Instruction::PUSH13: \
|
||||||
|
case Instruction::PUSH14: \
|
||||||
|
case Instruction::PUSH15: \
|
||||||
|
case Instruction::PUSH16: \
|
||||||
|
case Instruction::PUSH17: \
|
||||||
|
case Instruction::PUSH18: \
|
||||||
|
case Instruction::PUSH19: \
|
||||||
|
case Instruction::PUSH20: \
|
||||||
|
case Instruction::PUSH21: \
|
||||||
|
case Instruction::PUSH22: \
|
||||||
|
case Instruction::PUSH23: \
|
||||||
|
case Instruction::PUSH24: \
|
||||||
|
case Instruction::PUSH25: \
|
||||||
|
case Instruction::PUSH26: \
|
||||||
|
case Instruction::PUSH27: \
|
||||||
|
case Instruction::PUSH28: \
|
||||||
|
case Instruction::PUSH29: \
|
||||||
|
case Instruction::PUSH30: \
|
||||||
|
case Instruction::PUSH31: \
|
||||||
|
case Instruction::PUSH32
|
||||||
|
|
||||||
|
#define ANY_DUP DUP1: \
|
||||||
|
case Instruction::DUP2: \
|
||||||
|
case Instruction::DUP3: \
|
||||||
|
case Instruction::DUP4: \
|
||||||
|
case Instruction::DUP5: \
|
||||||
|
case Instruction::DUP6: \
|
||||||
|
case Instruction::DUP7: \
|
||||||
|
case Instruction::DUP8: \
|
||||||
|
case Instruction::DUP9: \
|
||||||
|
case Instruction::DUP10: \
|
||||||
|
case Instruction::DUP11: \
|
||||||
|
case Instruction::DUP12: \
|
||||||
|
case Instruction::DUP13: \
|
||||||
|
case Instruction::DUP14: \
|
||||||
|
case Instruction::DUP15: \
|
||||||
|
case Instruction::DUP16
|
||||||
|
|
||||||
|
#define ANY_SWAP SWAP1: \
|
||||||
|
case Instruction::SWAP2: \
|
||||||
|
case Instruction::SWAP3: \
|
||||||
|
case Instruction::SWAP4: \
|
||||||
|
case Instruction::SWAP5: \
|
||||||
|
case Instruction::SWAP6: \
|
||||||
|
case Instruction::SWAP7: \
|
||||||
|
case Instruction::SWAP8: \
|
||||||
|
case Instruction::SWAP9: \
|
||||||
|
case Instruction::SWAP10: \
|
||||||
|
case Instruction::SWAP11: \
|
||||||
|
case Instruction::SWAP12: \
|
||||||
|
case Instruction::SWAP13: \
|
||||||
|
case Instruction::SWAP14: \
|
||||||
|
case Instruction::SWAP15: \
|
||||||
|
case Instruction::SWAP16
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,8 +10,6 @@
|
||||||
#include <llvm/IR/Function.h>
|
#include <llvm/IR/Function.h>
|
||||||
#include <llvm/IR/IntrinsicInst.h>
|
#include <llvm/IR/IntrinsicInst.h>
|
||||||
|
|
||||||
#include <libdevcore/Common.h>
|
|
||||||
|
|
||||||
#include "Type.h"
|
#include "Type.h"
|
||||||
#include "Runtime.h"
|
#include "Runtime.h"
|
||||||
#include "GasMeter.h"
|
#include "GasMeter.h"
|
||||||
|
|
@ -208,7 +206,7 @@ extern "C"
|
||||||
{
|
{
|
||||||
using namespace dev::eth::jit;
|
using namespace dev::eth::jit;
|
||||||
|
|
||||||
EXPORT uint8_t* mem_resize(Runtime* _rt, i256* _size)
|
EXPORT byte* mem_resize(Runtime* _rt, i256* _size)
|
||||||
{
|
{
|
||||||
auto size = _size->a; // Trunc to 64-bit
|
auto size = _size->a; // Trunc to 64-bit
|
||||||
auto& memory = _rt->getMemory();
|
auto& memory = _rt->getMemory();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <libdevcore/Common.h>
|
|
||||||
|
|
||||||
#include "CompilerHelper.h"
|
#include "CompilerHelper.h"
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ u256 Runtime::getGas() const
|
||||||
return llvm2eth(m_data.elems[RuntimeData::Gas]);
|
return llvm2eth(m_data.elems[RuntimeData::Gas]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bytesConstRef Runtime::getReturnData() const
|
bytes Runtime::getReturnData() const // FIXME: Reconsider returning by copy
|
||||||
{
|
{
|
||||||
// TODO: Handle large indexes
|
// TODO: Handle large indexes
|
||||||
auto offset = static_cast<size_t>(llvm2eth(m_data.elems[RuntimeData::ReturnDataOffset]));
|
auto offset = static_cast<size_t>(llvm2eth(m_data.elems[RuntimeData::ReturnDataOffset]));
|
||||||
|
|
@ -99,7 +99,8 @@ bytesConstRef Runtime::getReturnData() const
|
||||||
|
|
||||||
assert(offset + size <= m_memory.size());
|
assert(offset + size <= m_memory.size());
|
||||||
// TODO: Handle invalid data access by returning empty ref
|
// TODO: Handle invalid data access by returning empty ref
|
||||||
return {m_memory.data() + offset, size};
|
auto dataBeg = m_memory.begin() + offset;
|
||||||
|
return {dataBeg, dataBeg + size};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Runtime::outputLogs() const
|
bool Runtime::outputLogs() const
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,9 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <csetjmp>
|
#include <csetjmp>
|
||||||
|
|
||||||
#include <libevm/ExtVMFace.h>
|
//#include <libevm/ExtVMFace.h>
|
||||||
|
|
||||||
|
#include "Instruction.h"
|
||||||
#include "CompilerHelper.h"
|
#include "CompilerHelper.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Type.h"
|
#include "Type.h"
|
||||||
|
|
@ -75,7 +76,7 @@ public:
|
||||||
ExtVMFace& getExt() { return m_ext; }
|
ExtVMFace& getExt() { return m_ext; }
|
||||||
|
|
||||||
u256 getGas() const;
|
u256 getGas() const;
|
||||||
bytesConstRef getReturnData() const;
|
bytes getReturnData() const;
|
||||||
decltype(&jmp_buf{}[0]) getJmpBuf() { return m_data.jmpBuf; }
|
decltype(&jmp_buf{}[0]) getJmpBuf() { return m_data.jmpBuf; }
|
||||||
bool outputLogs() const;
|
bool outputLogs() const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <llvm/IR/Type.h>
|
#include <llvm/IR/Type.h>
|
||||||
#include <llvm/IR/Constants.h>
|
#include <llvm/IR/Constants.h>
|
||||||
#include <libdevcore/Common.h>
|
#include "Common.h"
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
#include "Instruction.h"
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,7 @@
|
||||||
|
|
||||||
#include <llvm/IR/IRBuilder.h>
|
#include <llvm/IR/IRBuilder.h>
|
||||||
|
|
||||||
#include <libdevcore/Common.h>
|
#include "Common.h"
|
||||||
#include <libdevcore/Log.h>
|
|
||||||
#include <libevmcore/Instruction.h>
|
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
|
|
@ -16,6 +14,8 @@ namespace jit
|
||||||
|
|
||||||
struct JIT: public NoteChannel { static const char* name() { return "JIT"; } };
|
struct JIT: public NoteChannel { static const char* name() { return "JIT"; } };
|
||||||
|
|
||||||
|
#define clog(CHANNEL) std::cerr << CHANNEL::name() << ": "
|
||||||
|
|
||||||
/// Representation of 256-bit value binary compatible with LLVM i256
|
/// Representation of 256-bit value binary compatible with LLVM i256
|
||||||
// TODO: Replace with h256
|
// TODO: Replace with h256
|
||||||
struct i256
|
struct i256
|
||||||
|
|
@ -30,78 +30,6 @@ static_assert(sizeof(i256) == 32, "Wrong i265 size");
|
||||||
u256 llvm2eth(i256);
|
u256 llvm2eth(i256);
|
||||||
i256 eth2llvm(u256);
|
i256 eth2llvm(u256);
|
||||||
|
|
||||||
/// 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);
|
|
||||||
|
|
||||||
#define ANY_PUSH PUSH1: \
|
|
||||||
case Instruction::PUSH2: \
|
|
||||||
case Instruction::PUSH3: \
|
|
||||||
case Instruction::PUSH4: \
|
|
||||||
case Instruction::PUSH5: \
|
|
||||||
case Instruction::PUSH6: \
|
|
||||||
case Instruction::PUSH7: \
|
|
||||||
case Instruction::PUSH8: \
|
|
||||||
case Instruction::PUSH9: \
|
|
||||||
case Instruction::PUSH10: \
|
|
||||||
case Instruction::PUSH11: \
|
|
||||||
case Instruction::PUSH12: \
|
|
||||||
case Instruction::PUSH13: \
|
|
||||||
case Instruction::PUSH14: \
|
|
||||||
case Instruction::PUSH15: \
|
|
||||||
case Instruction::PUSH16: \
|
|
||||||
case Instruction::PUSH17: \
|
|
||||||
case Instruction::PUSH18: \
|
|
||||||
case Instruction::PUSH19: \
|
|
||||||
case Instruction::PUSH20: \
|
|
||||||
case Instruction::PUSH21: \
|
|
||||||
case Instruction::PUSH22: \
|
|
||||||
case Instruction::PUSH23: \
|
|
||||||
case Instruction::PUSH24: \
|
|
||||||
case Instruction::PUSH25: \
|
|
||||||
case Instruction::PUSH26: \
|
|
||||||
case Instruction::PUSH27: \
|
|
||||||
case Instruction::PUSH28: \
|
|
||||||
case Instruction::PUSH29: \
|
|
||||||
case Instruction::PUSH30: \
|
|
||||||
case Instruction::PUSH31: \
|
|
||||||
case Instruction::PUSH32
|
|
||||||
|
|
||||||
#define ANY_DUP DUP1: \
|
|
||||||
case Instruction::DUP2: \
|
|
||||||
case Instruction::DUP3: \
|
|
||||||
case Instruction::DUP4: \
|
|
||||||
case Instruction::DUP5: \
|
|
||||||
case Instruction::DUP6: \
|
|
||||||
case Instruction::DUP7: \
|
|
||||||
case Instruction::DUP8: \
|
|
||||||
case Instruction::DUP9: \
|
|
||||||
case Instruction::DUP10: \
|
|
||||||
case Instruction::DUP11: \
|
|
||||||
case Instruction::DUP12: \
|
|
||||||
case Instruction::DUP13: \
|
|
||||||
case Instruction::DUP14: \
|
|
||||||
case Instruction::DUP15: \
|
|
||||||
case Instruction::DUP16
|
|
||||||
|
|
||||||
#define ANY_SWAP SWAP1: \
|
|
||||||
case Instruction::SWAP2: \
|
|
||||||
case Instruction::SWAP3: \
|
|
||||||
case Instruction::SWAP4: \
|
|
||||||
case Instruction::SWAP5: \
|
|
||||||
case Instruction::SWAP6: \
|
|
||||||
case Instruction::SWAP7: \
|
|
||||||
case Instruction::SWAP8: \
|
|
||||||
case Instruction::SWAP9: \
|
|
||||||
case Instruction::SWAP10: \
|
|
||||||
case Instruction::SWAP11: \
|
|
||||||
case Instruction::SWAP12: \
|
|
||||||
case Instruction::SWAP13: \
|
|
||||||
case Instruction::SWAP14: \
|
|
||||||
case Instruction::SWAP15: \
|
|
||||||
case Instruction::SWAP16
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue