Browse Source

Use code hash as main function name

cl-refactor
Paweł Bylica 10 years ago
parent
commit
6643af5224
  1. 4
      libevmjit/Cache.h
  2. 2
      libevmjit/Compiler.cpp
  3. 4
      libevmjit/CompilerHelper.cpp
  4. 3
      libevmjit/ExecutionEngine.cpp

4
libevmjit/Cache.h

@ -18,10 +18,12 @@ class ExecBundle
{
public:
std::unique_ptr<llvm::ExecutionEngine> engine;
std::string mainFuncName;
ExecBundle() = default;
ExecBundle(ExecBundle&& _other):
engine(std::move(_other.engine))
engine(std::move(_other.engine)),
mainFuncName(std::move(_other.mainFuncName))
{}
ExecBundle(ExecBundle const&) = delete;

2
libevmjit/Compiler.cpp

@ -164,7 +164,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(bytes const& _bytecode)
// Create main function
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");
// Create the basic blocks.

4
libevmjit/CompilerHelper.cpp

@ -2,6 +2,7 @@
#include "CompilerHelper.h"
#include <llvm/IR/Function.h>
#include <llvm/IR/Module.h>
#include "RuntimeManager.h"
@ -25,10 +26,11 @@ llvm::Module* CompilerHelper::getModule()
llvm::Function* CompilerHelper::getMainFunction()
{
// TODO: Rename or change semantics of getMainFunction() function
assert(m_builder.GetInsertBlock());
auto mainFunc = m_builder.GetInsertBlock()->getParent();
assert(mainFunc);
if (mainFunc->getName() == "main")
if (mainFunc == &mainFunc->getParent()->getFunctionList().front()) // Main function is the first one in module
return mainFunc;
return nullptr;
}

3
libevmjit/ExecutionEngine.cpp

@ -68,6 +68,7 @@ ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeDa
_module->setTargetTriple(triple.str());
ExecBundle exec;
exec.mainFuncName = _module->getModuleIdentifier();
exec.engine.reset(builder.create());
if (!exec.engine)
return ReturnCode::LLVMConfigError;
@ -110,7 +111,7 @@ ReturnCode runEntryFunc(ExecBundle const& _exec, Runtime* _runtime)
// to allow function to be executed.
// That might be related to memory manager. Can we share one?
typedef ReturnCode(*EntryFuncPtr)(Runtime*);
auto entryFuncPtr = (EntryFuncPtr)_exec.engine->getFunctionAddress("main");
auto entryFuncPtr = (EntryFuncPtr)_exec.engine->getFunctionAddress(_exec.mainFuncName);
ReturnCode returnCode{};
auto sj = setjmp(_runtime->getJmpBuf());

Loading…
Cancel
Save