mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 12:16:44 +00:00
Introducing RuntimeData struct - a data that will be provided to running program
This commit is contained in:
parent
6580a9b286
commit
6c2a120dc1
4 changed files with 26 additions and 2 deletions
|
|
@ -17,6 +17,7 @@
|
|||
#include "GasMeter.h"
|
||||
#include "Utils.h"
|
||||
#include "Endianness.h"
|
||||
#include "Runtime.h"
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
|
@ -163,7 +164,9 @@ std::unique_ptr<llvm::Module> Compiler::compile(bytesConstRef bytecode)
|
|||
auto module = std::make_unique<llvm::Module>("main", m_builder.getContext());
|
||||
|
||||
// Create main function
|
||||
m_mainFunc = llvm::Function::Create(llvm::FunctionType::get(Type::MainReturn, false), llvm::Function::ExternalLinkage, "main", module.get());
|
||||
llvm::Type* mainFuncArgTypes[] = {m_builder.getInt32Ty(), RuntimeData::getType()->getPointerTo()}; // There must be int in first place because LLVM does not support other signatures
|
||||
auto mainFuncType = llvm::FunctionType::get(Type::MainReturn, mainFuncArgTypes, false);
|
||||
m_mainFunc = llvm::Function::Create(mainFuncType, llvm::Function::ExternalLinkage, "main", module.get());
|
||||
|
||||
// Create the basic blocks.
|
||||
auto entryBlock = llvm::BasicBlock::Create(m_builder.getContext(), "entry", m_mainFunc);
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, u256& _gas, ExtV
|
|||
if (r == 0)
|
||||
{
|
||||
rt_jmpBuf = &buf;
|
||||
auto result = exec->runFunction(entryFunc, {});
|
||||
auto result = exec->runFunction(entryFunc, {{}, llvm::GenericValue(runtime.getDataPtr())});
|
||||
returnCode = static_cast<ReturnCode>(result.IntVal.getZExtValue());
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -12,6 +12,15 @@ namespace eth
|
|||
namespace jit
|
||||
{
|
||||
|
||||
llvm::StructType* RuntimeData::getType()
|
||||
{
|
||||
llvm::Type* elems[] =
|
||||
{
|
||||
Type::i256,
|
||||
};
|
||||
return llvm::StructType::create(elems, "RuntimeData");
|
||||
}
|
||||
|
||||
static Runtime* g_runtime;
|
||||
|
||||
extern "C"
|
||||
|
|
|
|||
|
|
@ -21,6 +21,13 @@ namespace eth
|
|||
namespace jit
|
||||
{
|
||||
|
||||
struct RuntimeData
|
||||
{
|
||||
static llvm::StructType* getType();
|
||||
|
||||
i256 gas;
|
||||
};
|
||||
|
||||
using StackImpl = std::vector<i256>;
|
||||
using MemoryImpl = bytes;
|
||||
|
||||
|
|
@ -33,12 +40,17 @@ public:
|
|||
Runtime(const Runtime&) = delete;
|
||||
void operator=(const Runtime&) = delete;
|
||||
|
||||
RuntimeData* getDataPtr() { return &m_data; }
|
||||
|
||||
static StackImpl& getStack();
|
||||
static MemoryImpl& getMemory();
|
||||
static ExtVMFace& getExt();
|
||||
static u256 getGas();
|
||||
|
||||
private:
|
||||
|
||||
/// @internal Must be the first element to asure Runtime* === RuntimeData*
|
||||
RuntimeData m_data;
|
||||
StackImpl m_stack;
|
||||
MemoryImpl m_memory;
|
||||
ExtVMFace& m_ext;
|
||||
|
|
|
|||
Loading…
Reference in a new issue