From a751baadcb8b981167a6043a6cb03d37a9fc0db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 26 Jan 2015 00:04:59 +0100 Subject: [PATCH] Use uint64 type for code size --- libevmjit-cpp/JitVM.cpp | 2 +- libevmjit/Compiler.cpp | 8 ++++++-- libevmjit/RuntimeData.h | 2 +- libevmjit/RuntimeManager.cpp | 15 +++++++++++---- libevmjit/RuntimeManager.h | 1 + libevmjit/interface.cpp | 2 +- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/libevmjit-cpp/JitVM.cpp b/libevmjit-cpp/JitVM.cpp index ededbff52..1e73119bb 100644 --- a/libevmjit-cpp/JitVM.cpp +++ b/libevmjit-cpp/JitVM.cpp @@ -25,9 +25,9 @@ bytesConstRef JitVM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t) m_data.elems[RuntimeData::Number] = eth2llvm(_ext.currentBlock.number); m_data.elems[RuntimeData::Difficulty] = eth2llvm(_ext.currentBlock.difficulty); m_data.elems[RuntimeData::GasLimit] = eth2llvm(_ext.currentBlock.gasLimit); - m_data.elems[RuntimeData::CodeSize] = eth2llvm(_ext.code.size()); m_data.callData = _ext.data.data(); m_data.code = _ext.code.data(); + m_data.codeSize = _ext.code.size(); auto env = reinterpret_cast(&_ext); auto exitCode = m_engine.run(_ext.code, &m_data, env); diff --git a/libevmjit/Compiler.cpp b/libevmjit/Compiler.cpp index c8ab0d4c1..e380cde19 100644 --- a/libevmjit/Compiler.cpp +++ b/libevmjit/Compiler.cpp @@ -638,7 +638,6 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode case Instruction::ORIGIN: case Instruction::CALLVALUE: case Instruction::CALLDATASIZE: - case Instruction::CODESIZE: case Instruction::GASPRICE: case Instruction::COINBASE: case Instruction::TIMESTAMP: @@ -651,6 +650,11 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode break; } + case Instruction::CODESIZE: + // TODO: Use constant + stack.push(_runtimeManager.getCodeSize()); + break; + case Instruction::BLOCKHASH: { auto number = stack.pop(); @@ -695,7 +699,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode auto reqBytes = stack.pop(); auto srcPtr = _runtimeManager.getCode(); // TODO: Code & its size are constants, feature #80814234 - auto srcSize = _runtimeManager.get(RuntimeData::CodeSize); + auto srcSize = _runtimeManager.getCodeSize(); _memory.copyBytes(srcPtr, srcSize, srcIdx, destMemIdx, reqBytes); break; diff --git a/libevmjit/RuntimeData.h b/libevmjit/RuntimeData.h index a71cd468b..2ebb587cc 100644 --- a/libevmjit/RuntimeData.h +++ b/libevmjit/RuntimeData.h @@ -26,7 +26,6 @@ struct RuntimeData Number, Difficulty, GasLimit, - CodeSize, _size, @@ -38,6 +37,7 @@ struct RuntimeData i256 elems[_size] = {}; byte const* callData = nullptr; byte const* code = nullptr; + uint64_t codeSize = 0; }; /// VM Environment (ExtVM) opaque type diff --git a/libevmjit/RuntimeManager.cpp b/libevmjit/RuntimeManager.cpp index ea2fe20b5..73ce7e70d 100644 --- a/libevmjit/RuntimeManager.cpp +++ b/libevmjit/RuntimeManager.cpp @@ -24,7 +24,8 @@ llvm::StructType* RuntimeManager::getRuntimeDataType() { llvm::ArrayType::get(Type::Word, RuntimeData::_size), // i256[] Type::BytePtr, // callData - Type::BytePtr // code + Type::BytePtr, // code + Type::Size // codeSize }; type = llvm::StructType::create(elems, "RuntimeData"); } @@ -68,7 +69,6 @@ llvm::Twine getName(RuntimeData::Index _index) case RuntimeData::Number: return "number"; case RuntimeData::Difficulty: return "difficulty"; case RuntimeData::GasLimit: return "gaslimit"; - case RuntimeData::CodeSize: return "codesize"; } } } @@ -158,14 +158,13 @@ llvm::Value* RuntimeManager::get(Instruction _inst) case Instruction::NUMBER: return get(RuntimeData::Number); case Instruction::DIFFICULTY: return get(RuntimeData::Difficulty); case Instruction::GASLIMIT: return get(RuntimeData::GasLimit); - case Instruction::CODESIZE: return get(RuntimeData::CodeSize); } } llvm::Value* RuntimeManager::getCallData() { auto ptr = getBuilder().CreateStructGEP(getDataPtr(), 1, "calldataPtr"); - return getBuilder().CreateLoad(ptr, "calldata"); + return getBuilder().CreateLoad(ptr, "callData"); } llvm::Value* RuntimeManager::getCode() @@ -174,6 +173,14 @@ llvm::Value* RuntimeManager::getCode() return getBuilder().CreateLoad(ptr, "code"); } +llvm::Value* RuntimeManager::getCodeSize() +{ + auto ptr = getBuilder().CreateStructGEP(getDataPtr(), 3); + auto value = getBuilder().CreateLoad(ptr, "codeSize"); + assert(value->getType() == Type::Size); + return getBuilder().CreateZExt(value, Type::Word); +} + llvm::Value* RuntimeManager::getJmpBuf() { auto ptr = getBuilder().CreateStructGEP(getRuntimePtr(), 2, "jmpbufPtr"); diff --git a/libevmjit/RuntimeManager.h b/libevmjit/RuntimeManager.h index ce60424ac..21cb6df26 100644 --- a/libevmjit/RuntimeManager.h +++ b/libevmjit/RuntimeManager.h @@ -26,6 +26,7 @@ public: llvm::Value* getGas(); // TODO: Remove llvm::Value* getCallData(); llvm::Value* getCode(); + llvm::Value* getCodeSize(); void setGas(llvm::Value* _gas); void registerReturnData(llvm::Value* _index, llvm::Value* _size); diff --git a/libevmjit/interface.cpp b/libevmjit/interface.cpp index 5d2b97c2d..f8fa27408 100644 --- a/libevmjit/interface.cpp +++ b/libevmjit/interface.cpp @@ -14,7 +14,7 @@ evmjit_result evmjit_run(void* _data, void* _env) ExecutionEngine engine; auto codePtr = data->code; - auto codeSize = data->elems[RuntimeData::CodeSize].a; + auto codeSize = data->codeSize; bytes bytecode; bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize);