mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Use code hash as main function name
This commit is contained in:
parent
e3245e140b
commit
6643af5224
4 changed files with 9 additions and 4 deletions
|
|
@ -18,10 +18,12 @@ class ExecBundle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::unique_ptr<llvm::ExecutionEngine> engine;
|
std::unique_ptr<llvm::ExecutionEngine> engine;
|
||||||
|
std::string mainFuncName;
|
||||||
|
|
||||||
ExecBundle() = default;
|
ExecBundle() = default;
|
||||||
ExecBundle(ExecBundle&& _other):
|
ExecBundle(ExecBundle&& _other):
|
||||||
engine(std::move(_other.engine))
|
engine(std::move(_other.engine)),
|
||||||
|
mainFuncName(std::move(_other.mainFuncName))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ExecBundle(ExecBundle const&) = delete;
|
ExecBundle(ExecBundle const&) = delete;
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(bytes const& _bytecode)
|
||||||
|
|
||||||
// Create main function
|
// Create main function
|
||||||
auto mainFuncType = llvm::FunctionType::get(Type::MainReturn, Type::RuntimePtr, false);
|
auto mainFuncType = llvm::FunctionType::get(Type::MainReturn, Type::RuntimePtr, false);
|
||||||
m_mainFunc = llvm::Function::Create(mainFuncType, llvm::Function::ExternalLinkage, "main", module.get());
|
m_mainFunc = llvm::Function::Create(mainFuncType, llvm::Function::ExternalLinkage, strHash, module.get());
|
||||||
m_mainFunc->getArgumentList().front().setName("rt");
|
m_mainFunc->getArgumentList().front().setName("rt");
|
||||||
|
|
||||||
// Create the basic blocks.
|
// Create the basic blocks.
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include "CompilerHelper.h"
|
#include "CompilerHelper.h"
|
||||||
|
|
||||||
#include <llvm/IR/Function.h>
|
#include <llvm/IR/Function.h>
|
||||||
|
#include <llvm/IR/Module.h>
|
||||||
|
|
||||||
#include "RuntimeManager.h"
|
#include "RuntimeManager.h"
|
||||||
|
|
||||||
|
|
@ -25,10 +26,11 @@ llvm::Module* CompilerHelper::getModule()
|
||||||
|
|
||||||
llvm::Function* CompilerHelper::getMainFunction()
|
llvm::Function* CompilerHelper::getMainFunction()
|
||||||
{
|
{
|
||||||
|
// TODO: Rename or change semantics of getMainFunction() function
|
||||||
assert(m_builder.GetInsertBlock());
|
assert(m_builder.GetInsertBlock());
|
||||||
auto mainFunc = m_builder.GetInsertBlock()->getParent();
|
auto mainFunc = m_builder.GetInsertBlock()->getParent();
|
||||||
assert(mainFunc);
|
assert(mainFunc);
|
||||||
if (mainFunc->getName() == "main")
|
if (mainFunc == &mainFunc->getParent()->getFunctionList().front()) // Main function is the first one in module
|
||||||
return mainFunc;
|
return mainFunc;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeDa
|
||||||
_module->setTargetTriple(triple.str());
|
_module->setTargetTriple(triple.str());
|
||||||
|
|
||||||
ExecBundle exec;
|
ExecBundle exec;
|
||||||
|
exec.mainFuncName = _module->getModuleIdentifier();
|
||||||
exec.engine.reset(builder.create());
|
exec.engine.reset(builder.create());
|
||||||
if (!exec.engine)
|
if (!exec.engine)
|
||||||
return ReturnCode::LLVMConfigError;
|
return ReturnCode::LLVMConfigError;
|
||||||
|
|
@ -110,7 +111,7 @@ ReturnCode runEntryFunc(ExecBundle const& _exec, Runtime* _runtime)
|
||||||
// to allow function to be executed.
|
// to allow function to be executed.
|
||||||
// That might be related to memory manager. Can we share one?
|
// That might be related to memory manager. Can we share one?
|
||||||
typedef ReturnCode(*EntryFuncPtr)(Runtime*);
|
typedef ReturnCode(*EntryFuncPtr)(Runtime*);
|
||||||
auto entryFuncPtr = (EntryFuncPtr)_exec.engine->getFunctionAddress("main");
|
auto entryFuncPtr = (EntryFuncPtr)_exec.engine->getFunctionAddress(_exec.mainFuncName);
|
||||||
|
|
||||||
ReturnCode returnCode{};
|
ReturnCode returnCode{};
|
||||||
auto sj = setjmp(_runtime->getJmpBuf());
|
auto sj = setjmp(_runtime->getJmpBuf());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue