Browse Source

RETURN implementation: JIT returns data

cl-refactor
Paweł Bylica 10 years ago
parent
commit
70d02b1d66
  1. 39
      libevmjit/interface.cpp
  2. 11
      libevmjit/interface.h

39
libevmjit/interface.cpp

@ -5,14 +5,12 @@
extern "C" extern "C"
{ {
int evmjit_run(void* _data, void* _env) evmjit_result evmjit_run(void* _data, void* _env)
{ {
using namespace dev::eth::jit; using namespace dev::eth::jit;
auto data = static_cast<RuntimeData*>(_data); auto data = static_cast<RuntimeData*>(_data);
std::cerr << "GAS: " << data->elems[RuntimeData::Gas].a << "\n";
ExecutionEngine engine; ExecutionEngine engine;
auto codePtr = data->code; auto codePtr = data->code;
@ -20,30 +18,17 @@ int evmjit_run(void* _data, void* _env)
bytes bytecode; bytes bytecode;
bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize); bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize);
auto result = engine.run(bytecode, data, static_cast<Env*>(_env)); auto returnCode = engine.run(bytecode, data, static_cast<Env*>(_env));
return static_cast<int>(result); evmjit_result result = {static_cast<int32_t>(returnCode), 0, nullptr};
} if (returnCode == ReturnCode::Return && !engine.returnData.empty())
{
// Runtime callback functions - implementations must be provided by external language (Go, C++, Python) // TODO: Optimized returning data. Allocating memory on client side by callback function might be a good idea
void evm_jit_rt_sload(evm_jit_rt* _rt, i256* _index, i256* _ret); result.returnDataSize = engine.returnData.size();
void evm_jit_rt_sstore(evm_jit_rt* _rt, i256* _index, i256* _value); result.returnData = std::malloc(result.returnDataSize);
void evm_jit_rt_balance(evm_jit_rt* _rt, h256* _address, i256* _ret); std::memcpy(result.returnData, engine.returnData.data(), result.returnDataSize);
// And so on... }
evm_jit* evm_jit_create(evm_jit_rt*) return result;
{
printf("EVM JIT create");
int* a = nullptr;
*a = 1;
return nullptr;
} }
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);
} }

11
libevmjit/interface.h

@ -1,10 +1,19 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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 // JIT object opaque type
typedef struct evm_jit evm_jit; typedef struct evm_jit evm_jit;

Loading…
Cancel
Save