Browse Source
Conflicts: evmjit/libevmjit/Runtime.cpp evmjit/libevmjit/RuntimeData.h evmjit/libevmjit/interface.cppcl-refactor
Paweł Bylica
10 years ago
6 changed files with 40 additions and 42 deletions
@ -1,34 +1,36 @@ |
|||
#include "interface.h" |
|||
#include <cstring> |
|||
#include "ExecutionEngine.h" |
|||
|
|||
extern "C" |
|||
{ |
|||
|
|||
evmjit_result evmjit_run(void* _data, void* _env) |
|||
{ |
|||
using namespace dev::eth::jit; |
|||
using namespace dev::eth::jit; |
|||
|
|||
auto data = static_cast<RuntimeData*>(_data); |
|||
void* evmjit_create() noexcept |
|||
{ |
|||
return new(std::nothrow) ExecutionEngine; |
|||
} |
|||
|
|||
ExecutionEngine engine; |
|||
void evmjit_destroy(ExecutionEngine* _engine) noexcept |
|||
{ |
|||
delete _engine; |
|||
} |
|||
|
|||
auto codePtr = data->code; |
|||
auto codeSize = data->codeSize; |
|||
bytes bytecode; |
|||
bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize); |
|||
int evmjit_run(ExecutionEngine* _engine, RuntimeData* _data, Env* _env) noexcept |
|||
{ |
|||
try |
|||
{ |
|||
auto codePtr = _data->code; |
|||
auto codeSize = _data->codeSize; |
|||
bytes bytecode; |
|||
bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize); |
|||
|
|||
auto returnCode = engine.run(bytecode, data, static_cast<Env*>(_env)); |
|||
evmjit_result result = {static_cast<int32_t>(returnCode), 0, nullptr}; |
|||
if (returnCode == ReturnCode::Return && std::get<0>(engine.returnData)) |
|||
auto returnCode = _engine->run(bytecode, _data, _env); |
|||
return static_cast<int>(returnCode); |
|||
} |
|||
catch(...) |
|||
{ |
|||
// TODO: Optimized returning data. Allocating memory on client side by callback function might be a good idea
|
|||
result.returnDataSize = std::get<1>(engine.returnData); |
|||
result.returnData = std::malloc(result.returnDataSize); |
|||
std::memcpy(result.returnData, std::get<0>(engine.returnData), result.returnDataSize); |
|||
return static_cast<int>(ReturnCode::UnexpectedException); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
} |
|||
|
Loading…
Reference in new issue