Browse Source

Introducing RuntimeData struct - a data that will be provided to running program

cl-refactor
Paweł Bylica 10 years ago
parent
commit
6c2a120dc1
  1. 5
      libevmjit/Compiler.cpp
  2. 2
      libevmjit/ExecutionEngine.cpp
  3. 9
      libevmjit/Runtime.cpp
  4. 12
      libevmjit/Runtime.h

5
libevmjit/Compiler.cpp

@ -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);

2
libevmjit/ExecutionEngine.cpp

@ -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

9
libevmjit/Runtime.cpp

@ -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"

12
libevmjit/Runtime.h

@ -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…
Cancel
Save