mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
env_call updated
This commit is contained in:
parent
69dae9a83a
commit
63719d24bc
4 changed files with 23 additions and 25 deletions
|
|
@ -36,6 +36,7 @@ extern "C"
|
|||
_env->setStore(index, value); // Interface uses native endianness
|
||||
}
|
||||
|
||||
// TODO: Move to Memory/Runtime
|
||||
EXPORT void ext_calldataload(ExtVMFace* _env, i256* _index, ::byte* o_value)
|
||||
{
|
||||
auto index = static_cast<size_t>(llvm2eth(*_index));
|
||||
|
|
@ -72,32 +73,24 @@ extern "C"
|
|||
*o_address = {};
|
||||
}
|
||||
|
||||
EXPORT void ext_call(ExtVMFace* _env, i256* io_gas, h256* _receiveAddress, i256* _value, i256* _inOff, i256* _inSize, i256* _outOff, i256* _outSize, h256* _codeAddress, i256* o_ret)
|
||||
EXPORT bool env_call(ExtVMFace* _env, i256* io_gas, h256* _receiveAddress, i256* _value, byte* _inBeg, uint64_t _inSize, byte* _outBeg, uint64_t _outSize, h256* _codeAddress)
|
||||
{
|
||||
auto&& ext = *_env;
|
||||
auto value = llvm2eth(*_value);
|
||||
|
||||
auto ret = false;
|
||||
auto gas = llvm2eth(*io_gas);
|
||||
if (ext.balance(ext.myAddress) >= value)
|
||||
if (_env->balance(_env->myAddress) >= value)
|
||||
{
|
||||
ext.subBalance(value);
|
||||
_env->subBalance(value);
|
||||
auto receiveAddress = right160(*_receiveAddress);
|
||||
auto inOff = static_cast<size_t>(llvm2eth(*_inOff));
|
||||
auto inSize = static_cast<size_t>(llvm2eth(*_inSize));
|
||||
auto outOff = static_cast<size_t>(llvm2eth(*_outOff));
|
||||
auto outSize = static_cast<size_t>(llvm2eth(*_outSize));
|
||||
//auto&& inRef = bytesConstRef(_rt->getMemory().data() + inOff, inSize);
|
||||
//auto&& outRef = bytesConstRef(_rt->getMemory().data() + outOff, outSize);
|
||||
auto inRef = bytesConstRef(); // FIXME: Handle memory
|
||||
auto outRef = bytesConstRef(); // FIXME: Handle memory
|
||||
auto inRef = bytesConstRef{_inBeg, _inSize};
|
||||
auto outRef = bytesConstRef{_outBeg, _outSize};
|
||||
OnOpFunc onOp {}; // TODO: Handle that thing
|
||||
auto codeAddress = right160(*_codeAddress);
|
||||
ret = ext.call(receiveAddress, value, inRef, &gas, outRef, onOp, {}, codeAddress);
|
||||
auto gas = llvm2eth(*io_gas);
|
||||
auto ret = _env->call(receiveAddress, value, inRef, &gas, outRef, onOp, {}, codeAddress);
|
||||
*io_gas = eth2llvm(gas);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*io_gas = eth2llvm(gas);
|
||||
o_ret->a = ret ? 1 : 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
EXPORT void env_sha3(byte* _begin, uint64_t _size, h256* o_hash)
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ Ext::Ext(RuntimeManager& _runtimeManager, Memory& _memoryMan):
|
|||
m_calldataload = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "ext_calldataload", module);
|
||||
m_balance = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "ext_balance", module);
|
||||
m_suicide = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 2}, false), Linkage::ExternalLinkage, "ext_suicide", module);
|
||||
m_call = llvm::Function::Create(llvm::FunctionType::get(Type::Void, argsTypes, false), Linkage::ExternalLinkage, "ext_call", module);
|
||||
m_exp = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 4}, false), Linkage::ExternalLinkage, "ext_exp", module);
|
||||
m_codeAt = llvm::Function::Create(llvm::FunctionType::get(Type::BytePtr, {argsTypes, 2}, false), Linkage::ExternalLinkage, "ext_codeAt", module);
|
||||
m_codesizeAt = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "ext_codesizeAt", module);
|
||||
|
|
@ -63,6 +62,9 @@ Ext::Ext(RuntimeManager& _runtimeManager, Memory& _memoryMan):
|
|||
|
||||
llvm::Type* createArgsTypes[] = {Type::EnvPtr, Type::WordPtr, Type::BytePtr, Type::Size, Type::WordPtr};
|
||||
m_create = llvm::Function::Create(llvm::FunctionType::get(Type::Void, createArgsTypes, false), Linkage::ExternalLinkage, "env_create", module);
|
||||
|
||||
llvm::Type* callArgsTypes[] = {Type::EnvPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::BytePtr, Type::Size, Type::BytePtr, Type::Size, Type::WordPtr};
|
||||
m_call = llvm::Function::Create(llvm::FunctionType::get(Type::Bool, callArgsTypes, false), Linkage::ExternalLinkage, "env_call", module);
|
||||
}
|
||||
|
||||
llvm::Value* Ext::sload(llvm::Value* _index)
|
||||
|
|
@ -119,15 +121,15 @@ llvm::Value* Ext::call(llvm::Value*& _gas, llvm::Value* _receiveAddress, llvm::V
|
|||
auto receiveAddress = Endianness::toBE(m_builder, _receiveAddress);
|
||||
m_builder.CreateStore(receiveAddress, m_arg2);
|
||||
m_builder.CreateStore(_value, m_arg3);
|
||||
m_builder.CreateStore(_inOff, m_arg4);
|
||||
m_builder.CreateStore(_inSize, m_arg5);
|
||||
m_builder.CreateStore(_outOff, m_arg6);
|
||||
m_builder.CreateStore(_outSize, m_arg7);
|
||||
auto inBeg = m_memoryMan.getBytePtr(_inOff);
|
||||
auto inSize = m_builder.CreateTrunc(_inSize, Type::Size, "in.size");
|
||||
auto outBeg = m_memoryMan.getBytePtr(_outOff);
|
||||
auto outSize = m_builder.CreateTrunc(_outSize, Type::Size, "out.size");
|
||||
auto codeAddress = Endianness::toBE(m_builder, _codeAddress);
|
||||
m_builder.CreateStore(codeAddress, m_arg8);
|
||||
createCall(m_call, getRuntimeManager().getEnv(), m_args[0], m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8, m_args[1]);
|
||||
auto ret = createCall(m_call, getRuntimeManager().getEnv(), m_args[0], m_arg2, m_arg3, inBeg, inSize, outBeg, outSize, m_arg8);
|
||||
_gas = m_builder.CreateLoad(m_args[0]); // Return gas
|
||||
return m_builder.CreateLoad(m_args[1]);
|
||||
return m_builder.CreateZExt(ret, Type::Word, "ret");
|
||||
}
|
||||
|
||||
llvm::Value* Ext::sha3(llvm::Value* _inOff, llvm::Value* _inSize)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace jit
|
|||
llvm::IntegerType* Type::Word;
|
||||
llvm::PointerType* Type::WordPtr;
|
||||
llvm::IntegerType* Type::lowPrecision;
|
||||
llvm::IntegerType* Type::Bool;
|
||||
llvm::IntegerType* Type::Size;
|
||||
llvm::IntegerType* Type::Byte;
|
||||
llvm::PointerType* Type::BytePtr;
|
||||
|
|
@ -32,6 +33,7 @@ void Type::init(llvm::LLVMContext& _context)
|
|||
WordPtr = Word->getPointerTo();
|
||||
lowPrecision = llvm::Type::getInt64Ty(_context);
|
||||
// TODO: Size should be architecture-dependent
|
||||
Bool = llvm::Type::getInt1Ty(_context);
|
||||
Size = llvm::Type::getInt64Ty(_context);
|
||||
Byte = llvm::Type::getInt8Ty(_context);
|
||||
BytePtr = Byte->getPointerTo();
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ struct Type
|
|||
/// @TODO: Use 64-bit for now. In 128-bit compiler-rt library functions are required
|
||||
static llvm::IntegerType* lowPrecision;
|
||||
|
||||
static llvm::IntegerType* Bool;
|
||||
static llvm::IntegerType* Size;
|
||||
|
||||
static llvm::IntegerType* Byte;
|
||||
|
|
|
|||
Loading…
Reference in a new issue