mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Export runtime data to global variable in main function
This commit is contained in:
parent
6c2a120dc1
commit
8da55ff8c0
5 changed files with 48 additions and 4 deletions
|
|
@ -175,6 +175,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(bytesConstRef bytecode)
|
|||
createBasicBlocks(bytecode);
|
||||
|
||||
// Init runtime structures.
|
||||
RuntimeManager runtimeManager(m_builder);
|
||||
GasMeter gasMeter(m_builder);
|
||||
Memory memory(m_builder, gasMeter);
|
||||
Ext ext(m_builder);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,14 @@ llvm::Module* CompilerHelper::getModule()
|
|||
return m_builder.GetInsertBlock()->getParent()->getParent();
|
||||
}
|
||||
|
||||
llvm::Function* CompilerHelper::getMainFunction()
|
||||
{
|
||||
assert(m_builder.GetInsertBlock());
|
||||
auto mainFunc = m_builder.GetInsertBlock()->getParent();
|
||||
assert(mainFunc && mainFunc->getName() == "main");
|
||||
return mainFunc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ protected:
|
|||
/// Reference to the IR module being compiled
|
||||
llvm::Module* getModule();
|
||||
|
||||
/// Reference to the main module function
|
||||
llvm::Function* getMainFunction();
|
||||
|
||||
/// Reference to parent compiler IR builder
|
||||
llvm::IRBuilder<>& m_builder;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
|
||||
#include "Runtime.h"
|
||||
|
||||
#include <llvm/IR/GlobalVariable.h>
|
||||
#include <llvm/IR/Function.h>
|
||||
|
||||
#include <libevm/VM.h>
|
||||
|
||||
#include "Type.h"
|
||||
|
|
@ -14,11 +17,16 @@ namespace jit
|
|||
|
||||
llvm::StructType* RuntimeData::getType()
|
||||
{
|
||||
llvm::Type* elems[] =
|
||||
static llvm::StructType* type = nullptr;
|
||||
if (!type)
|
||||
{
|
||||
Type::i256,
|
||||
};
|
||||
return llvm::StructType::create(elems, "RuntimeData");
|
||||
llvm::Type* elems[] =
|
||||
{
|
||||
Type::i256,
|
||||
};
|
||||
type = llvm::StructType::create(elems, "RuntimeData");
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
static Runtime* g_runtime;
|
||||
|
|
@ -61,6 +69,18 @@ u256 Runtime::getGas()
|
|||
return llvm2eth(gas);
|
||||
}
|
||||
|
||||
|
||||
RuntimeManager::RuntimeManager(llvm::IRBuilder<>& _builder): CompilerHelper(_builder)
|
||||
{
|
||||
auto dataPtrType = RuntimeData::getType()->getPointerTo();
|
||||
m_dataPtr = new llvm::GlobalVariable(*getModule(), dataPtrType, false, llvm::GlobalVariable::PrivateLinkage, llvm::UndefValue::get(dataPtrType), "rt");
|
||||
|
||||
// Export data
|
||||
auto mainFunc = getMainFunction();
|
||||
llvm::Value* dataPtr = &mainFunc->getArgumentList().back();
|
||||
m_builder.CreateStore(dataPtr, m_dataPtr);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <libevm/ExtVMFace.h>
|
||||
|
||||
#include "CompilerHelper.h"
|
||||
#include "Utils.h"
|
||||
|
||||
|
||||
|
|
@ -56,6 +57,17 @@ private:
|
|||
ExtVMFace& m_ext;
|
||||
};
|
||||
|
||||
class RuntimeManager: public CompilerHelper
|
||||
{
|
||||
public:
|
||||
RuntimeManager(llvm::IRBuilder<>& _builder);
|
||||
|
||||
llvm::Value* getGas();
|
||||
|
||||
private:
|
||||
llvm::GlobalVariable* m_dataPtr;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue