mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Changing Runtime interface
This commit is contained in:
parent
aa771582a7
commit
0509b3bddd
5 changed files with 150 additions and 50 deletions
70
libevmjit-cpp/Runtime.cpp
Normal file
70
libevmjit-cpp/Runtime.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
|
||||||
|
#include "Runtime.h"
|
||||||
|
|
||||||
|
#include <llvm/IR/GlobalVariable.h>
|
||||||
|
#include <llvm/IR/Function.h>
|
||||||
|
#include <llvm/IR/IntrinsicInst.h>
|
||||||
|
|
||||||
|
//#include <libevm/VM.h>
|
||||||
|
|
||||||
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
|
{
|
||||||
|
|
||||||
|
Runtime::Runtime(u256 _gas, ExtVMFace& _ext, jmp_buf _jmpBuf, bool _outputLogs):
|
||||||
|
m_ext(_ext),
|
||||||
|
m_outputLogs(_outputLogs)
|
||||||
|
{
|
||||||
|
set(RuntimeData::Gas, _gas);
|
||||||
|
set(RuntimeData::Address, fromAddress(_ext.myAddress));
|
||||||
|
set(RuntimeData::Caller, fromAddress(_ext.caller));
|
||||||
|
set(RuntimeData::Origin, fromAddress(_ext.origin));
|
||||||
|
set(RuntimeData::CallValue, _ext.value);
|
||||||
|
set(RuntimeData::CallDataSize, _ext.data.size());
|
||||||
|
set(RuntimeData::GasPrice, _ext.gasPrice);
|
||||||
|
set(RuntimeData::PrevHash, _ext.previousBlock.hash);
|
||||||
|
set(RuntimeData::CoinBase, fromAddress(_ext.currentBlock.coinbaseAddress));
|
||||||
|
set(RuntimeData::TimeStamp, _ext.currentBlock.timestamp);
|
||||||
|
set(RuntimeData::Number, _ext.currentBlock.number);
|
||||||
|
set(RuntimeData::Difficulty, _ext.currentBlock.difficulty);
|
||||||
|
set(RuntimeData::GasLimit, _ext.currentBlock.gasLimit);
|
||||||
|
set(RuntimeData::CodeSize, _ext.code.size()); // TODO: Use constant
|
||||||
|
m_data.callData = _ext.data.data();
|
||||||
|
m_data.code = _ext.code.data();
|
||||||
|
m_data.jmpBuf = _jmpBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Runtime::set(RuntimeData::Index _index, u256 _value)
|
||||||
|
{
|
||||||
|
m_data.elems[_index] = eth2llvm(_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
u256 Runtime::getGas() const
|
||||||
|
{
|
||||||
|
return llvm2eth(m_data.elems[RuntimeData::Gas]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes Runtime::getReturnData() const // FIXME: Reconsider returning by copy
|
||||||
|
{
|
||||||
|
// TODO: Handle large indexes
|
||||||
|
auto offset = static_cast<size_t>(llvm2eth(m_data.elems[RuntimeData::ReturnDataOffset]));
|
||||||
|
auto size = static_cast<size_t>(llvm2eth(m_data.elems[RuntimeData::ReturnDataSize]));
|
||||||
|
|
||||||
|
assert(offset + size <= m_memory.size());
|
||||||
|
// TODO: Handle invalid data access by returning empty ref
|
||||||
|
auto dataBeg = m_memory.begin() + offset;
|
||||||
|
return {dataBeg, dataBeg + size};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Runtime::outputLogs() const
|
||||||
|
{
|
||||||
|
return m_outputLogs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
64
libevmjit-cpp/Runtime.h
Normal file
64
libevmjit-cpp/Runtime.h
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <csetjmp>
|
||||||
|
|
||||||
|
//#include <libevm/ExtVMFace.h>
|
||||||
|
|
||||||
|
#include "Instruction.h"
|
||||||
|
#include "CompilerHelper.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
#include "Type.h"
|
||||||
|
#include "RuntimeData.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace dev
|
||||||
|
{
|
||||||
|
namespace eth
|
||||||
|
{
|
||||||
|
namespace jit
|
||||||
|
{
|
||||||
|
|
||||||
|
using StackImpl = std::vector<i256>;
|
||||||
|
using MemoryImpl = bytes;
|
||||||
|
|
||||||
|
class Runtime
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Runtime(u256 _gas, ExtVMFace& _ext, jmp_buf _jmpBuf, bool _outputLogs);
|
||||||
|
|
||||||
|
Runtime(const Runtime&) = delete;
|
||||||
|
void operator=(const Runtime&) = delete;
|
||||||
|
|
||||||
|
RuntimeData* getDataPtr() { return &m_data; }
|
||||||
|
|
||||||
|
StackImpl& getStack() { return m_stack; }
|
||||||
|
MemoryImpl& getMemory() { return m_memory; }
|
||||||
|
ExtVMFace& getExt() { return m_ext; }
|
||||||
|
|
||||||
|
u256 getGas() const;
|
||||||
|
bytes getReturnData() const;
|
||||||
|
decltype(&jmp_buf{}[0]) getJmpBuf() { return m_data.jmpBuf; }
|
||||||
|
bool outputLogs() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void set(RuntimeData::Index _index, u256 _value);
|
||||||
|
|
||||||
|
/// @internal Must be the first element to asure Runtime* === RuntimeData*
|
||||||
|
RuntimeData m_data;
|
||||||
|
StackImpl m_stack;
|
||||||
|
MemoryImpl m_memory;
|
||||||
|
ExtVMFace& m_ext;
|
||||||
|
bool m_outputLogs; ///< write LOG statements to console
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,33 +14,11 @@ namespace eth
|
||||||
namespace jit
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
Runtime::Runtime(u256 _gas, ExtVMFace& _ext, jmp_buf _jmpBuf, bool _outputLogs):
|
Runtime::Runtime(RuntimeData* _data, Env* _env, JmpBufRef _jmpBuf):
|
||||||
m_ext(_ext),
|
m_data(*_data),
|
||||||
m_outputLogs(_outputLogs)
|
m_env(*_env),
|
||||||
{
|
m_jmpBuf(_jmpBuf)
|
||||||
set(RuntimeData::Gas, _gas);
|
{}
|
||||||
set(RuntimeData::Address, fromAddress(_ext.myAddress));
|
|
||||||
set(RuntimeData::Caller, fromAddress(_ext.caller));
|
|
||||||
set(RuntimeData::Origin, fromAddress(_ext.origin));
|
|
||||||
set(RuntimeData::CallValue, _ext.value);
|
|
||||||
set(RuntimeData::CallDataSize, _ext.data.size());
|
|
||||||
set(RuntimeData::GasPrice, _ext.gasPrice);
|
|
||||||
set(RuntimeData::PrevHash, _ext.previousBlock.hash);
|
|
||||||
set(RuntimeData::CoinBase, fromAddress(_ext.currentBlock.coinbaseAddress));
|
|
||||||
set(RuntimeData::TimeStamp, _ext.currentBlock.timestamp);
|
|
||||||
set(RuntimeData::Number, _ext.currentBlock.number);
|
|
||||||
set(RuntimeData::Difficulty, _ext.currentBlock.difficulty);
|
|
||||||
set(RuntimeData::GasLimit, _ext.currentBlock.gasLimit);
|
|
||||||
set(RuntimeData::CodeSize, _ext.code.size()); // TODO: Use constant
|
|
||||||
m_data.callData = _ext.data.data();
|
|
||||||
m_data.code = _ext.code.data();
|
|
||||||
m_data.jmpBuf = _jmpBuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Runtime::set(RuntimeData::Index _index, u256 _value)
|
|
||||||
{
|
|
||||||
m_data.elems[_index] = eth2llvm(_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
u256 Runtime::getGas() const
|
u256 Runtime::getGas() const
|
||||||
{
|
{
|
||||||
|
|
@ -59,12 +37,6 @@ bytes Runtime::getReturnData() const // FIXME: Reconsider returning by copy
|
||||||
return {dataBeg, dataBeg + size};
|
return {dataBeg, dataBeg + size};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Runtime::outputLogs() const
|
|
||||||
{
|
|
||||||
return m_outputLogs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <csetjmp>
|
|
||||||
|
|
||||||
//#include <libevm/ExtVMFace.h>
|
|
||||||
|
|
||||||
#include "Instruction.h"
|
#include "Instruction.h"
|
||||||
#include "CompilerHelper.h"
|
#include "CompilerHelper.h"
|
||||||
|
|
@ -28,11 +25,15 @@ namespace jit
|
||||||
|
|
||||||
using StackImpl = std::vector<i256>;
|
using StackImpl = std::vector<i256>;
|
||||||
using MemoryImpl = bytes;
|
using MemoryImpl = bytes;
|
||||||
|
using JmpBufRef = decltype(&jmp_buf{}[0]);
|
||||||
|
|
||||||
|
/// VM Environment (ExtVM) opaque type
|
||||||
|
struct Env;
|
||||||
|
|
||||||
class Runtime
|
class Runtime
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Runtime(u256 _gas, ExtVMFace& _ext, jmp_buf _jmpBuf, bool _outputLogs);
|
Runtime(RuntimeData* _data, Env* _env, JmpBufRef _jmpBuf);
|
||||||
|
|
||||||
Runtime(const Runtime&) = delete;
|
Runtime(const Runtime&) = delete;
|
||||||
void operator=(const Runtime&) = delete;
|
void operator=(const Runtime&) = delete;
|
||||||
|
|
@ -41,22 +42,18 @@ public:
|
||||||
|
|
||||||
StackImpl& getStack() { return m_stack; }
|
StackImpl& getStack() { return m_stack; }
|
||||||
MemoryImpl& getMemory() { return m_memory; }
|
MemoryImpl& getMemory() { return m_memory; }
|
||||||
ExtVMFace& getExt() { return m_ext; }
|
Env* getEnvPtr() { return &m_env; }
|
||||||
|
|
||||||
u256 getGas() const;
|
u256 getGas() const;
|
||||||
bytes getReturnData() const;
|
bytes getReturnData() const;
|
||||||
decltype(&jmp_buf{}[0]) getJmpBuf() { return m_data.jmpBuf; }
|
JmpBufRef getJmpBuf() { return m_jmpBuf; }
|
||||||
bool outputLogs() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void set(RuntimeData::Index _index, u256 _value);
|
RuntimeData& m_data;
|
||||||
|
Env& m_env;
|
||||||
/// @internal Must be the first element to asure Runtime* === RuntimeData*
|
JmpBufRef m_jmpBuf;
|
||||||
RuntimeData m_data;
|
|
||||||
StackImpl m_stack;
|
StackImpl m_stack;
|
||||||
MemoryImpl m_memory;
|
MemoryImpl m_memory;
|
||||||
ExtVMFace& m_ext;
|
|
||||||
bool m_outputLogs; ///< write LOG statements to console
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ namespace eth
|
||||||
namespace jit
|
namespace jit
|
||||||
{
|
{
|
||||||
|
|
||||||
using jmpBufRef = decltype(&jmp_buf{}[0]);
|
|
||||||
|
|
||||||
struct RuntimeData
|
struct RuntimeData
|
||||||
{
|
{
|
||||||
enum Index
|
enum Index
|
||||||
|
|
@ -43,7 +41,6 @@ struct RuntimeData
|
||||||
i256 elems[_size];
|
i256 elems[_size];
|
||||||
byte const* callData;
|
byte const* callData;
|
||||||
byte const* code;
|
byte const* code;
|
||||||
jmpBufRef jmpBuf;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue