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"
{
int evmjit_run(void* _data, void* _env)
evmjit_result evmjit_run(void* _data, void* _env)
{
using namespace dev::eth::jit;
auto data = static_cast<RuntimeData*>(_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*>(_env));
return static_cast<int>(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*>(_env));
evmjit_result result = {static_cast<int32_t>(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);
}

11
libevmjit/interface.h

@ -1,10 +1,19 @@
#include <stddef.h>
#include <stdint.h>
#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;

Loading…
Cancel
Save