|
|
@ -40,7 +40,7 @@ Ext::Ext(RuntimeManager& _runtimeManager): |
|
|
|
|
|
|
|
using Linkage = llvm::GlobalValue::LinkageTypes; |
|
|
|
|
|
|
|
llvm::Type* argsTypes[] = {Type::RuntimePtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr}; |
|
|
|
llvm::Type* argsTypes[] = {Type::EnvPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr}; |
|
|
|
|
|
|
|
m_store = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "ext_store", module); |
|
|
|
m_setStore = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "ext_setStore", module); |
|
|
@ -63,7 +63,7 @@ Ext::Ext(RuntimeManager& _runtimeManager): |
|
|
|
llvm::Value* Ext::store(llvm::Value* _index) |
|
|
|
{ |
|
|
|
m_builder.CreateStore(_index, m_args[0]); |
|
|
|
m_builder.CreateCall3(m_store, getRuntimeManager().getRuntimePtr(), m_args[0], m_args[1]); // Uses native endianness
|
|
|
|
m_builder.CreateCall3(m_store, getRuntimeManager().getEnv(), m_args[0], m_args[1]); // Uses native endianness
|
|
|
|
return m_builder.CreateLoad(m_args[1]); |
|
|
|
} |
|
|
|
|
|
|
@ -71,13 +71,13 @@ void Ext::setStore(llvm::Value* _index, llvm::Value* _value) |
|
|
|
{ |
|
|
|
m_builder.CreateStore(_index, m_args[0]); |
|
|
|
m_builder.CreateStore(_value, m_args[1]); |
|
|
|
m_builder.CreateCall3(m_setStore, getRuntimeManager().getRuntimePtr(), m_args[0], m_args[1]); // Uses native endianness
|
|
|
|
m_builder.CreateCall3(m_setStore, getRuntimeManager().getEnv(), m_args[0], m_args[1]); // Uses native endianness
|
|
|
|
} |
|
|
|
|
|
|
|
llvm::Value* Ext::calldataload(llvm::Value* _index) |
|
|
|
{ |
|
|
|
m_builder.CreateStore(_index, m_args[0]); |
|
|
|
m_builder.CreateCall3(m_calldataload, getRuntimeManager().getRuntimePtr(), m_args[0], m_args[1]); |
|
|
|
m_builder.CreateCall3(m_calldataload, getRuntimeManager().getEnv(), m_args[0], m_args[1]); |
|
|
|
auto ret = m_builder.CreateLoad(m_args[1]); |
|
|
|
return Endianness::toNative(m_builder, ret); |
|
|
|
} |
|
|
@ -86,7 +86,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().getRuntimePtr(), m_args[0], m_args[1]); |
|
|
|
m_builder.CreateCall3(m_balance, getRuntimeManager().getEnv(), m_args[0], m_args[1]); |
|
|
|
return m_builder.CreateLoad(m_args[1]); |
|
|
|
} |
|
|
|
|
|
|
@ -94,7 +94,7 @@ void Ext::suicide(llvm::Value* _address) |
|
|
|
{ |
|
|
|
auto address = Endianness::toBE(m_builder, _address); |
|
|
|
m_builder.CreateStore(address, m_args[0]); |
|
|
|
m_builder.CreateCall2(m_suicide, getRuntimeManager().getRuntimePtr(), m_args[0]); |
|
|
|
m_builder.CreateCall2(m_suicide, getRuntimeManager().getEnv(), m_args[0]); |
|
|
|
} |
|
|
|
|
|
|
|
llvm::Value* Ext::create(llvm::Value* _endowment, llvm::Value* _initOff, llvm::Value* _initSize) |
|
|
@ -120,7 +120,7 @@ llvm::Value* Ext::call(llvm::Value*& _gas, llvm::Value* _receiveAddress, llvm::V |
|
|
|
m_builder.CreateStore(_outSize, m_arg7); |
|
|
|
auto codeAddress = Endianness::toBE(m_builder, _codeAddress); |
|
|
|
m_builder.CreateStore(codeAddress, m_arg8); |
|
|
|
createCall(m_call, getRuntimeManager().getRuntimePtr(), m_args[0], m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8, m_args[1]); |
|
|
|
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]); |
|
|
|
_gas = m_builder.CreateLoad(m_args[0]); // Return gas
|
|
|
|
return m_builder.CreateLoad(m_args[1]); |
|
|
|
} |
|
|
@ -129,7 +129,7 @@ llvm::Value* Ext::sha3(llvm::Value* _inOff, llvm::Value* _inSize) |
|
|
|
{ |
|
|
|
m_builder.CreateStore(_inOff, m_args[0]); |
|
|
|
m_builder.CreateStore(_inSize, m_arg2); |
|
|
|
createCall(m_sha3, getRuntimeManager().getRuntimePtr(), m_args[0], m_arg2, m_args[1]); |
|
|
|
createCall(m_sha3, getRuntimeManager().getEnv(), m_args[0], m_arg2, m_args[1]); |
|
|
|
llvm::Value* hash = m_builder.CreateLoad(m_args[1]); |
|
|
|
hash = Endianness::toNative(m_builder, hash); |
|
|
|
return hash; |
|
|
@ -139,14 +139,14 @@ llvm::Value* Ext::codeAt(llvm::Value* _addr) |
|
|
|
{ |
|
|
|
auto addr = Endianness::toBE(m_builder, _addr); |
|
|
|
m_builder.CreateStore(addr, m_args[0]); |
|
|
|
return m_builder.CreateCall2(m_codeAt, getRuntimeManager().getRuntimePtr(), m_args[0]); |
|
|
|
return m_builder.CreateCall2(m_codeAt, getRuntimeManager().getEnv(), m_args[0]); |
|
|
|
} |
|
|
|
|
|
|
|
llvm::Value* Ext::codesizeAt(llvm::Value* _addr) |
|
|
|
{ |
|
|
|
auto addr = Endianness::toBE(m_builder, _addr); |
|
|
|
m_builder.CreateStore(addr, m_args[0]); |
|
|
|
createCall(m_codesizeAt, getRuntimeManager().getRuntimePtr(), m_args[0], m_args[1]); |
|
|
|
createCall(m_codesizeAt, getRuntimeManager().getEnv(), m_args[0], m_args[1]); |
|
|
|
return m_builder.CreateLoad(m_args[1]); |
|
|
|
} |
|
|
|
|
|
|
@ -155,7 +155,7 @@ void Ext::log(llvm::Value* _memIdx, llvm::Value* _numBytes, size_t _numTopics, s |
|
|
|
llvm::Value* args[] = {nullptr, m_args[0], m_args[1], m_arg2, m_arg3, m_arg4, m_arg5}; |
|
|
|
llvm::Value* funcs[] = {m_log0, m_log1, m_log2, m_log3, m_log4}; |
|
|
|
|
|
|
|
args[0] = getRuntimeManager().getRuntimePtr(); |
|
|
|
args[0] = getRuntimeManager().getEnv(); |
|
|
|
m_builder.CreateStore(_memIdx, m_args[0]); |
|
|
|
m_builder.CreateStore(_numBytes, m_args[1]); |
|
|
|
|
|
|
|