Paweł Bylica
10 years ago
4 changed files with 27 additions and 31 deletions
@ -1,34 +1,36 @@ |
|||||
#include "interface.h" |
|
||||
#include <cstring> |
|
||||
#include "ExecutionEngine.h" |
#include "ExecutionEngine.h" |
||||
|
|
||||
extern "C" |
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; |
int evmjit_run(ExecutionEngine* _engine, RuntimeData* _data, Env* _env) noexcept |
||||
auto codeSize = data->codeSize; |
{ |
||||
|
try |
||||
|
{ |
||||
|
auto codePtr = _data->code; |
||||
|
auto codeSize = _data->codeSize; |
||||
bytes bytecode; |
bytes bytecode; |
||||
bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize); |
bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize); |
||||
|
|
||||
auto returnCode = engine.run(bytecode, data, static_cast<Env*>(_env)); |
auto returnCode = _engine->run(bytecode, _data, _env); |
||||
evmjit_result result = {static_cast<int32_t>(returnCode), 0, nullptr}; |
return static_cast<int>(returnCode); |
||||
if (returnCode == ReturnCode::Return && std::get<0>(engine.returnData)) |
} |
||||
|
catch(...) |
||||
{ |
{ |
||||
// TODO: Optimized returning data. Allocating memory on client side by callback function might be a good idea
|
return static_cast<int>(ReturnCode::UnexpectedException); |
||||
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 result; |
|
||||
} |
} |
||||
|
|
||||
} |
} |
||||
|
Loading…
Reference in new issue