Browse Source

Create helper/external functions on demand (env_balance for now)

cl-refactor
Paweł Bylica 10 years ago
parent
commit
533531bd07
  1. 2
      libevmjit-cpp/Env.cpp
  2. 13
      libevmjit/Ext.cpp
  3. 4
      libevmjit/Ext.h

2
libevmjit-cpp/Env.cpp

@ -36,7 +36,7 @@ extern "C"
_env->setStore(index, value); // Interface uses native endianness
}
EXPORT void ext_balance(ExtVMFace* _env, h256* _address, i256* o_value)
EXPORT void env_balance(ExtVMFace* _env, h256* _address, i256* o_value)
{
auto u = _env->balance(right160(*_address));
*o_value = eth2llvm(u);

13
libevmjit/Ext.cpp

@ -43,7 +43,6 @@ Ext::Ext(RuntimeManager& _runtimeManager, Memory& _memoryMan):
m_sload = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "env_sload", module);
m_sstore = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "env_sstore", module);
m_balance = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "ext_balance", module);
llvm::Type* sha3ArgsTypes[] = {Type::BytePtr, Type::Size, Type::WordPtr};
m_sha3 = llvm::Function::Create(llvm::FunctionType::get(Type::Void, sha3ArgsTypes, false), Linkage::ExternalLinkage, "env_sha3", module);
@ -65,6 +64,16 @@ Ext::Ext(RuntimeManager& _runtimeManager, Memory& _memoryMan):
m_calldataload = llvm::Function::Create(llvm::FunctionType::get(Type::Void, callDataLoadArgsTypes, false), Linkage::ExternalLinkage, "ext_calldataload", module);
}
llvm::Function* Ext::getBalanceFunc()
{
if (!m_balance)
{
llvm::Type* argsTypes[] = {Type::EnvPtr, Type::WordPtr, Type::WordPtr};
m_balance = llvm::Function::Create(llvm::FunctionType::get(Type::Void, argsTypes, false), llvm::Function::ExternalLinkage, "env_balance", getModule());
}
return m_balance;
}
llvm::Value* Ext::sload(llvm::Value* _index)
{
m_builder.CreateStore(_index, m_args[0]);
@ -91,7 +100,7 @@ llvm::Value* Ext::balance(llvm::Value* _address)
{
auto address = Endianness::toBE(m_builder, _address);
m_builder.CreateStore(address, m_args[0]);
m_builder.CreateCall3(m_balance, getRuntimeManager().getEnvPtr(), m_args[0], m_args[1]);
createCall(getBalanceFunc(), getRuntimeManager().getEnvPtr(), m_args[0], m_args[1]);
return m_builder.CreateLoad(m_args[1]);
}

4
libevmjit/Ext.h

@ -52,12 +52,14 @@ private:
llvm::Function* m_sload;
llvm::Function* m_sstore;
llvm::Function* m_calldataload;
llvm::Function* m_balance;
llvm::Function* m_balance = nullptr;
llvm::Function* m_create;
llvm::Function* m_call;
llvm::Function* m_sha3;
llvm::Function* m_getExtCode;
llvm::Function* m_log;
llvm::Function* getBalanceFunc();
};

Loading…
Cancel
Save