From 68648a2fb5438e21d5a3341a0a54ddfe811a9f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 3 Dec 2014 11:59:24 +0100 Subject: [PATCH] Separating EVM JIT from CPP client (WIP) --- {libevmjit => libevmjit-cpp}/VM.cpp | 0 {libevmjit => libevmjit-cpp}/VM.h | 0 libevmjit/Arith256.cpp | 43 +++--- libevmjit/Common.h | 24 +++ libevmjit/Compiler.cpp | 9 +- libevmjit/Compiler.h | 7 +- libevmjit/ExecutionEngine.h | 4 +- libevmjit/Ext.cpp | 4 +- libevmjit/Ext.h | 3 +- libevmjit/GasMeter.cpp | 42 +++-- libevmjit/GasMeter.h | 3 +- libevmjit/Instruction.h | 230 ++++++++++++++++++++++++++++ libevmjit/Memory.cpp | 4 +- libevmjit/Memory.h | 2 - libevmjit/Runtime.cpp | 5 +- libevmjit/Runtime.h | 5 +- libevmjit/Type.h | 2 +- libevmjit/Utils.cpp | 1 + libevmjit/Utils.h | 78 +--------- 19 files changed, 327 insertions(+), 139 deletions(-) rename {libevmjit => libevmjit-cpp}/VM.cpp (100%) rename {libevmjit => libevmjit-cpp}/VM.h (100%) create mode 100644 libevmjit/Common.h create mode 100644 libevmjit/Instruction.h diff --git a/libevmjit/VM.cpp b/libevmjit-cpp/VM.cpp similarity index 100% rename from libevmjit/VM.cpp rename to libevmjit-cpp/VM.cpp diff --git a/libevmjit/VM.h b/libevmjit-cpp/VM.h similarity index 100% rename from libevmjit/VM.h rename to libevmjit-cpp/VM.h diff --git a/libevmjit/Arith256.cpp b/libevmjit/Arith256.cpp index 79a8fe79c6..aa76ec0ef2 100644 --- a/libevmjit/Arith256.cpp +++ b/libevmjit/Arith256.cpp @@ -4,8 +4,6 @@ #include -#include - namespace dev { namespace eth @@ -102,56 +100,57 @@ extern "C" { using namespace dev::eth::jit; + using s256 = boost::multiprecision::int256_t; EXPORT void arith_mul(i256* _arg1, i256* _arg2, i256* o_result) { - dev::u256 arg1 = llvm2eth(*_arg1); - dev::u256 arg2 = llvm2eth(*_arg2); + auto arg1 = llvm2eth(*_arg1); + auto arg2 = llvm2eth(*_arg2); *o_result = eth2llvm(arg1 * arg2); } EXPORT void arith_div(i256* _arg1, i256* _arg2, i256* o_result) { - dev::u256 arg1 = llvm2eth(*_arg1); - dev::u256 arg2 = llvm2eth(*_arg2); + auto arg1 = llvm2eth(*_arg1); + auto arg2 = llvm2eth(*_arg2); *o_result = eth2llvm(arg2 == 0 ? arg2 : arg1 / arg2); } EXPORT void arith_mod(i256* _arg1, i256* _arg2, i256* o_result) { - dev::u256 arg1 = llvm2eth(*_arg1); - dev::u256 arg2 = llvm2eth(*_arg2); + auto arg1 = llvm2eth(*_arg1); + auto arg2 = llvm2eth(*_arg2); *o_result = eth2llvm(arg2 == 0 ? arg2 : arg1 % arg2); } EXPORT void arith_sdiv(i256* _arg1, i256* _arg2, i256* o_result) { - dev::u256 arg1 = llvm2eth(*_arg1); - dev::u256 arg2 = llvm2eth(*_arg2); - *o_result = eth2llvm(arg2 == 0 ? arg2 : dev::s2u(dev::u2s(arg1) / dev::u2s(arg2))); + auto arg1 = llvm2eth(*_arg1); + auto arg2 = llvm2eth(*_arg2); + *o_result = eth2llvm(arg2 == 0 ? arg2 : (arg1.convert_to() / arg2.convert_to()).convert_to()); } EXPORT void arith_smod(i256* _arg1, i256* _arg2, i256* o_result) { - dev::u256 arg1 = llvm2eth(*_arg1); - dev::u256 arg2 = llvm2eth(*_arg2); - *o_result = eth2llvm(arg2 == 0 ? arg2 : dev::s2u(dev::u2s(arg1) % dev::u2s(arg2))); + auto arg1 = llvm2eth(*_arg1); + auto arg2 = llvm2eth(*_arg2); + *o_result = eth2llvm(arg2 == 0 ? arg2 : (arg1.convert_to() % arg2.convert_to()).convert_to()); } EXPORT void arith_mulmod(i256* _arg1, i256* _arg2, i256* _arg3, i256* o_result) { - dev::u256 arg1 = llvm2eth(*_arg1); - dev::u256 arg2 = llvm2eth(*_arg2); - dev::u256 arg3 = llvm2eth(*_arg3); - *o_result = eth2llvm(dev::u256((dev::bigint(arg1) * dev::bigint(arg2)) % arg3)); + auto arg1 = llvm2eth(*_arg1); + auto arg2 = llvm2eth(*_arg2); + auto arg3 = llvm2eth(*_arg3); + *o_result = eth2llvm(u256((bigint(arg1) * bigint(arg2)) % arg3)); } EXPORT void arith_addmod(i256* _arg1, i256* _arg2, i256* _arg3, i256* o_result) { - dev::u256 arg1 = llvm2eth(*_arg1); - dev::u256 arg2 = llvm2eth(*_arg2); - dev::u256 arg3 = llvm2eth(*_arg3); - *o_result = eth2llvm(dev::u256((dev::bigint(arg1) + dev::bigint(arg2)) % arg3)); + auto arg1 = llvm2eth(*_arg1); + auto arg2 = llvm2eth(*_arg2); + auto arg3 = llvm2eth(*_arg3); + *o_result = eth2llvm(u256((bigint(arg1) + bigint(arg2)) % arg3)); } } diff --git a/libevmjit/Common.h b/libevmjit/Common.h new file mode 100644 index 0000000000..dfc60f4d40 --- /dev/null +++ b/libevmjit/Common.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +namespace dev +{ +namespace eth +{ +namespace jit +{ + +using byte = uint8_t; +using bytes = std::vector; +using u256 = boost::multiprecision::uint256_t; +using bigint = boost::multiprecision::cpp_int; + +struct NoteChannel {}; // FIXME: Use some log library? + +struct ExtVMFace; + +} +} +} diff --git a/libevmjit/Compiler.cpp b/libevmjit/Compiler.cpp index 1cc86d8aab..beb3d022d9 100644 --- a/libevmjit/Compiler.cpp +++ b/libevmjit/Compiler.cpp @@ -13,8 +13,7 @@ #include #include -#include - +#include "Instruction.h" #include "Type.h" #include "Memory.h" #include "Stack.h" @@ -248,7 +247,7 @@ std::unique_ptr Compiler::compile(bytes const& _bytecode) 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 _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 result = m_builder.CreateSelect(kInRange, - m_builder.CreateSelect(bittest, val1, val0), - word); + m_builder.CreateSelect(bittest, val1, val0), + word); stack.push(result); break; } diff --git a/libevmjit/Compiler.h b/libevmjit/Compiler.h index a618f41a31..e021bfdefa 100644 --- a/libevmjit/Compiler.h +++ b/libevmjit/Compiler.h @@ -3,8 +3,7 @@ #include -#include - +#include "Common.h" #include "BasicBlock.h" namespace dev @@ -44,9 +43,9 @@ public: 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(); diff --git a/libevmjit/ExecutionEngine.h b/libevmjit/ExecutionEngine.h index 8cf1ec7461..932c193041 100644 --- a/libevmjit/ExecutionEngine.h +++ b/libevmjit/ExecutionEngine.h @@ -3,8 +3,8 @@ #include -#include -#include +#include "Common.h" +//#include namespace dev { diff --git a/libevmjit/Ext.cpp b/libevmjit/Ext.cpp index 6eb35acdad..588ba46525 100644 --- a/libevmjit/Ext.cpp +++ b/libevmjit/Ext.cpp @@ -5,8 +5,8 @@ #include #include -#include -#include +//#include +//#include #include "Runtime.h" #include "Type.h" diff --git a/libevmjit/Ext.h b/libevmjit/Ext.h index 54380dda69..ad4649177e 100644 --- a/libevmjit/Ext.h +++ b/libevmjit/Ext.h @@ -1,8 +1,7 @@ #pragma once -#include - +#include #include "CompilerHelper.h" namespace dev diff --git a/libevmjit/GasMeter.cpp b/libevmjit/GasMeter.cpp index 48499259a4..d4a5dbfc31 100644 --- a/libevmjit/GasMeter.cpp +++ b/libevmjit/GasMeter.cpp @@ -5,9 +5,6 @@ #include #include -#include -#include - #include "Type.h" #include "Ext.h" #include "Runtime.h" @@ -22,6 +19,26 @@ namespace jit 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) { 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() return 0; - case Instruction::SLOAD: - return static_cast(c_sloadGas); + case Instruction::SLOAD: return c_sloadGas; - case Instruction::SHA3: - return static_cast(c_sha3Gas); + case Instruction::SHA3: return c_sha3Gas; - case Instruction::BALANCE: - return static_cast(c_sha3Gas); + case Instruction::BALANCE: return c_balanceGas; case Instruction::CALL: - case Instruction::CALLCODE: - return static_cast(c_callGas); + case Instruction::CALLCODE: return c_callGas; - case Instruction::CREATE: - return static_cast(c_createGas); + case Instruction::CREATE: return c_createGas; case Instruction::LOG0: case Instruction::LOG1: @@ -54,11 +66,11 @@ uint64_t getStepCost(Instruction inst) // TODO: Add this function to FeeSructure case Instruction::LOG4: { auto numTopics = static_cast(inst) - static_cast(Instruction::LOG0); - return static_cast(c_logGas) + numTopics * static_cast(c_logTopicGas); + return c_logGas + numTopics * c_logTopicGas; } default: // Assumes instruction code is valid - return static_cast(c_stepGas); + return 1; } } diff --git a/libevmjit/GasMeter.h b/libevmjit/GasMeter.h index dfb4fb5489..85ef59a0f8 100644 --- a/libevmjit/GasMeter.h +++ b/libevmjit/GasMeter.h @@ -1,9 +1,8 @@ #pragma once -#include - #include "CompilerHelper.h" +#include "Instruction.h" namespace dev { diff --git a/libevmjit/Instruction.h b/libevmjit/Instruction.h new file mode 100644 index 0000000000..efc43552cc --- /dev/null +++ b/libevmjit/Instruction.h @@ -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 + +} +} +} diff --git a/libevmjit/Memory.cpp b/libevmjit/Memory.cpp index 53cccf92b9..288b33df9a 100644 --- a/libevmjit/Memory.cpp +++ b/libevmjit/Memory.cpp @@ -10,8 +10,6 @@ #include #include -#include - #include "Type.h" #include "Runtime.h" #include "GasMeter.h" @@ -208,7 +206,7 @@ extern "C" { 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& memory = _rt->getMemory(); diff --git a/libevmjit/Memory.h b/libevmjit/Memory.h index c6ba02a54b..bbd35b973d 100644 --- a/libevmjit/Memory.h +++ b/libevmjit/Memory.h @@ -1,7 +1,5 @@ #pragma once -#include - #include "CompilerHelper.h" namespace dev diff --git a/libevmjit/Runtime.cpp b/libevmjit/Runtime.cpp index 8e52b648ae..b5254c0358 100644 --- a/libevmjit/Runtime.cpp +++ b/libevmjit/Runtime.cpp @@ -91,7 +91,7 @@ u256 Runtime::getGas() const return llvm2eth(m_data.elems[RuntimeData::Gas]); } -bytesConstRef Runtime::getReturnData() const +bytes Runtime::getReturnData() const // FIXME: Reconsider returning by copy { // TODO: Handle large indexes auto offset = static_cast(llvm2eth(m_data.elems[RuntimeData::ReturnDataOffset])); @@ -99,7 +99,8 @@ bytesConstRef Runtime::getReturnData() const assert(offset + size <= m_memory.size()); // 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 diff --git a/libevmjit/Runtime.h b/libevmjit/Runtime.h index 8f485794a9..1acda23b42 100644 --- a/libevmjit/Runtime.h +++ b/libevmjit/Runtime.h @@ -4,8 +4,9 @@ #include #include -#include +//#include +#include "Instruction.h" #include "CompilerHelper.h" #include "Utils.h" #include "Type.h" @@ -75,7 +76,7 @@ public: ExtVMFace& getExt() { return m_ext; } u256 getGas() const; - bytesConstRef getReturnData() const; + bytes getReturnData() const; decltype(&jmp_buf{}[0]) getJmpBuf() { return m_data.jmpBuf; } bool outputLogs() const; diff --git a/libevmjit/Type.h b/libevmjit/Type.h index 0d8c6c5304..d0534bd75c 100644 --- a/libevmjit/Type.h +++ b/libevmjit/Type.h @@ -3,7 +3,7 @@ #include #include -#include +#include "Common.h" namespace dev { diff --git a/libevmjit/Utils.cpp b/libevmjit/Utils.cpp index 548ee0e1ff..0dad565481 100644 --- a/libevmjit/Utils.cpp +++ b/libevmjit/Utils.cpp @@ -1,5 +1,6 @@ #include "Utils.h" +#include "Instruction.h" namespace dev { diff --git a/libevmjit/Utils.h b/libevmjit/Utils.h index 54291f3e0d..06ef9af81d 100644 --- a/libevmjit/Utils.h +++ b/libevmjit/Utils.h @@ -3,9 +3,7 @@ #include -#include -#include -#include +#include "Common.h" namespace dev { @@ -16,6 +14,8 @@ namespace 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 // TODO: Replace with h256 struct i256 @@ -30,78 +30,6 @@ static_assert(sizeof(i256) == 32, "Wrong i265 size"); u256 llvm2eth(i256); 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 - } } }