From 70d02b1d661b4c057f53bb1c5ca563e289c80dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 15 Jan 2015 16:27:57 +0100 Subject: [PATCH] RETURN implementation: JIT returns data --- libevmjit/interface.cpp | 39 ++++++++++++--------------------------- libevmjit/interface.h | 11 ++++++++++- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/libevmjit/interface.cpp b/libevmjit/interface.cpp index 6a729f3d0..eef92d00f 100644 --- a/libevmjit/interface.cpp +++ b/libevmjit/interface.cpp @@ -5,14 +5,12 @@ extern "C" { -int evmjit_run(void* _data, void* _env) +evmjit_result evmjit_run(void* _data, void* _env) { using namespace dev::eth::jit; auto data = static_cast(_data); - std::cerr << "GAS: " << data->elems[RuntimeData::Gas].a << "\n"; - ExecutionEngine engine; auto codePtr = data->code; @@ -20,30 +18,17 @@ int evmjit_run(void* _data, void* _env) bytes bytecode; bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize); - auto result = engine.run(bytecode, data, static_cast(_env)); - return static_cast(result); -} - -// Runtime callback functions - implementations must be provided by external language (Go, C++, Python) -void evm_jit_rt_sload(evm_jit_rt* _rt, i256* _index, i256* _ret); -void evm_jit_rt_sstore(evm_jit_rt* _rt, i256* _index, i256* _value); -void evm_jit_rt_balance(evm_jit_rt* _rt, h256* _address, i256* _ret); -// And so on... - -evm_jit* evm_jit_create(evm_jit_rt*) -{ - printf("EVM JIT create"); - - int* a = nullptr; - *a = 1; - - return nullptr; + auto returnCode = engine.run(bytecode, data, static_cast(_env)); + evmjit_result result = {static_cast(returnCode), 0, nullptr}; + if (returnCode == ReturnCode::Return && !engine.returnData.empty()) + { + // TODO: Optimized returning data. Allocating memory on client side by callback function might be a good idea + result.returnDataSize = engine.returnData.size(); + result.returnData = std::malloc(result.returnDataSize); + std::memcpy(result.returnData, engine.returnData.data(), result.returnDataSize); + } + + return result; } -evm_jit_return_code evm_jit_execute(evm_jit* _jit); - -void evm_jit_get_return_data(evm_jit* _jit, char* _return_data_offset, size_t* _return_data_size); - -void evm_jit_destroy(evm_jit* _jit); - } diff --git a/libevmjit/interface.h b/libevmjit/interface.h index 1515fed86..5d9307ab2 100644 --- a/libevmjit/interface.h +++ b/libevmjit/interface.h @@ -1,10 +1,19 @@ #include +#include #ifdef __cplusplus extern "C" { #endif -int evmjit_run(void* _data, void* _env); +typedef struct evmjit_result +{ + int32_t returnCode; + uint64_t returnDataSize; + void* returnData; + +} evmjit_result; + +evmjit_result evmjit_run(void* _data, void* _env); // JIT object opaque type typedef struct evm_jit evm_jit;