You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
954 B
35 lines
954 B
10 years ago
|
#include "interface.h"
|
||
|
#include <cstdio>
|
||
|
#include "ExecutionEngine.h"
|
||
|
|
||
|
extern "C"
|
||
|
{
|
||
|
|
||
10 years ago
|
evmjit_result evmjit_run(void* _data, void* _env)
|
||
10 years ago
|
{
|
||
|
using namespace dev::eth::jit;
|
||
|
|
||
10 years ago
|
auto data = static_cast<RuntimeData*>(_data);
|
||
|
|
||
10 years ago
|
ExecutionEngine engine;
|
||
10 years ago
|
|
||
|
auto codePtr = data->code;
|
||
|
auto codeSize = data->elems[RuntimeData::CodeSize].a;
|
||
|
bytes bytecode;
|
||
|
bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize);
|
||
|
|
||
10 years ago
|
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;
|
||
10 years ago
|
}
|
||
|
|
||
|
}
|