|
@ -60,6 +60,7 @@ Ext::Ext(llvm::IRBuilder<>& _builder, llvm::Module* module) |
|
|
m_arg5 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg5"); |
|
|
m_arg5 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg5"); |
|
|
m_arg6 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg6"); |
|
|
m_arg6 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg6"); |
|
|
m_arg7 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg7"); |
|
|
m_arg7 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg7"); |
|
|
|
|
|
m_arg7 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg8"); |
|
|
|
|
|
|
|
|
Type* elements[] = { |
|
|
Type* elements[] = { |
|
|
i256Ty, // i256 address;
|
|
|
i256Ty, // i256 address;
|
|
@ -90,12 +91,12 @@ Ext::Ext(llvm::IRBuilder<>& _builder, llvm::Module* module) |
|
|
m_balance = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_balance", module); |
|
|
m_balance = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_balance", module); |
|
|
m_suicide = Function::Create(TypeBuilder<void(i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_suicide", module); |
|
|
m_suicide = Function::Create(TypeBuilder<void(i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_suicide", module); |
|
|
m_create = Function::Create(TypeBuilder<void(i<256>*, i<256>*, i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_create", module); |
|
|
m_create = Function::Create(TypeBuilder<void(i<256>*, i<256>*, i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_create", module); |
|
|
Type* args[] = {i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy}; |
|
|
Type* args[] = {i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy, i256PtrTy}; |
|
|
m_call = Function::Create(FunctionType::get(m_builder.getVoidTy(), args, false), Linkage::ExternalLinkage, "ext_call", module); |
|
|
m_call = Function::Create(FunctionType::get(m_builder.getVoidTy(), args, false), Linkage::ExternalLinkage, "ext_call", module); |
|
|
m_bswap = Intrinsic::getDeclaration(module, Intrinsic::bswap, i256Ty); |
|
|
m_bswap = Intrinsic::getDeclaration(module, Intrinsic::bswap, i256Ty); |
|
|
m_sha3 = Function::Create(TypeBuilder<void(i<256>*, i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_sha3", module); |
|
|
m_sha3 = Function::Create(TypeBuilder<void(i<256>*, i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_sha3", module); |
|
|
m_exp = Function::Create(TypeBuilder<void(i<256>*, i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_exp", module); |
|
|
m_exp = Function::Create(TypeBuilder<void(i<256>*, i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_exp", module); |
|
|
m_codeAt = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_codeAt", module); |
|
|
m_codeAt = Function::Create(TypeBuilder<i<8>*(i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_codeAt", module); |
|
|
m_codesizeAt = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_codesizeAt", module); |
|
|
m_codesizeAt = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_codesizeAt", module); |
|
|
|
|
|
|
|
|
m_builder.CreateCall(m_init, m_data); |
|
|
m_builder.CreateCall(m_init, m_data); |
|
@ -176,7 +177,7 @@ Value* Ext::create(llvm::Value* _endowment, llvm::Value* _initOff, llvm::Value* |
|
|
return address; |
|
|
return address; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
llvm::Value* Ext::call(llvm::Value*& _gas, llvm::Value* _receiveAddress, llvm::Value* _value, llvm::Value* _inOff, llvm::Value* _inSize, llvm::Value* _outOff, llvm::Value* _outSize) |
|
|
llvm::Value* Ext::call(llvm::Value*& _gas, llvm::Value* _receiveAddress, llvm::Value* _value, llvm::Value* _inOff, llvm::Value* _inSize, llvm::Value* _outOff, llvm::Value* _outSize, llvm::Value* _codeAddress) |
|
|
{ |
|
|
{ |
|
|
m_builder.CreateStore(_gas, m_args[0]); |
|
|
m_builder.CreateStore(_gas, m_args[0]); |
|
|
auto receiveAddress = bswap(_receiveAddress); // to BE
|
|
|
auto receiveAddress = bswap(_receiveAddress); // to BE
|
|
@ -186,7 +187,10 @@ llvm::Value* Ext::call(llvm::Value*& _gas, llvm::Value* _receiveAddress, llvm::V |
|
|
m_builder.CreateStore(_inSize, m_arg5); |
|
|
m_builder.CreateStore(_inSize, m_arg5); |
|
|
m_builder.CreateStore(_outOff, m_arg6); |
|
|
m_builder.CreateStore(_outOff, m_arg6); |
|
|
m_builder.CreateStore(_outSize, m_arg7); |
|
|
m_builder.CreateStore(_outSize, m_arg7); |
|
|
llvm::Value* args[] = {m_args[0], m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_args[1]}; |
|
|
auto codeAddress = bswap(_codeAddress); // toBE
|
|
|
|
|
|
m_builder.CreateStore(codeAddress, m_arg8); |
|
|
|
|
|
|
|
|
|
|
|
llvm::Value* args[] = {m_args[0], m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8, m_args[1]}; |
|
|
m_builder.CreateCall(m_call, args); |
|
|
m_builder.CreateCall(m_call, args); |
|
|
_gas = m_builder.CreateLoad(m_args[0]); // Return gas
|
|
|
_gas = m_builder.CreateLoad(m_args[0]); // Return gas
|
|
|
return m_builder.CreateLoad(m_args[1]); |
|
|
return m_builder.CreateLoad(m_args[1]); |
|
@ -216,9 +220,7 @@ llvm::Value* Ext::codeAt(llvm::Value* _addr) |
|
|
{ |
|
|
{ |
|
|
auto addr = bswap(_addr); |
|
|
auto addr = bswap(_addr); |
|
|
m_builder.CreateStore(addr, m_args[0]); |
|
|
m_builder.CreateStore(addr, m_args[0]); |
|
|
llvm::Value* args[] = {m_args[0], m_args[1]}; |
|
|
return m_builder.CreateCall(m_codeAt, m_args[0]); |
|
|
m_builder.CreateCall(m_codeAt, args); |
|
|
|
|
|
return m_builder.CreateLoad(m_args[1]); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
llvm::Value* Ext::codesizeAt(llvm::Value* _addr) |
|
|
llvm::Value* Ext::codesizeAt(llvm::Value* _addr) |
|
@ -315,7 +317,7 @@ EXPORT void ext_create(i256* _endowment, i256* _initOff, i256* _initSize, h256* |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPORT void ext_call(i256* _gas, h256* _receiveAddress, i256* _value, i256* _inOff, i256* _inSize, i256* _outOff, i256* _outSize, i256* _ret) |
|
|
EXPORT void ext_call(i256* _gas, h256* _receiveAddress, i256* _value, i256* _inOff, i256* _inSize, i256* _outOff, i256* _outSize, h256* _codeAddress, i256* _ret) |
|
|
{ |
|
|
{ |
|
|
auto&& ext = Runtime::getExt(); |
|
|
auto&& ext = Runtime::getExt(); |
|
|
auto value = llvm2eth(*_value); |
|
|
auto value = llvm2eth(*_value); |
|
@ -333,7 +335,8 @@ EXPORT void ext_call(i256* _gas, h256* _receiveAddress, i256* _value, i256* _inO |
|
|
auto&& inRef = dev::bytesConstRef(Runtime::getMemory().data() + inOff, inSize); |
|
|
auto&& inRef = dev::bytesConstRef(Runtime::getMemory().data() + inOff, inSize); |
|
|
auto&& outRef = dev::bytesConstRef(Runtime::getMemory().data() + outOff, outSize); |
|
|
auto&& outRef = dev::bytesConstRef(Runtime::getMemory().data() + outOff, outSize); |
|
|
dev::eth::OnOpFunc onOp{}; // TODO: Handle that thing
|
|
|
dev::eth::OnOpFunc onOp{}; // TODO: Handle that thing
|
|
|
ret = ext.call(receiveAddress, value, inRef, &gas, outRef, onOp, {}, receiveAddress); |
|
|
auto codeAddress = dev::right160(*_codeAddress); |
|
|
|
|
|
ret = ext.call(receiveAddress, value, inRef, &gas, outRef, onOp, {}, codeAddress); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
*_gas = eth2llvm(gas); |
|
|
*_gas = eth2llvm(gas); |
|
@ -357,12 +360,12 @@ EXPORT void ext_exp(i256* _left, i256* _right, i256* _ret) |
|
|
*_ret = eth2llvm(ret); |
|
|
*_ret = eth2llvm(ret); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
EXPORT void ext_codeAt(h256* _addr256, i256* _ret) |
|
|
EXPORT unsigned char* ext_codeAt(h256* _addr256) |
|
|
{ |
|
|
{ |
|
|
auto&& ext = Runtime::getExt(); |
|
|
auto&& ext = Runtime::getExt(); |
|
|
auto addr = dev::right160(*_addr256); |
|
|
auto addr = dev::right160(*_addr256); |
|
|
auto& code = ext.codeAt(addr); |
|
|
auto& code = ext.codeAt(addr); |
|
|
*_ret = *reinterpret_cast<i256*>(const_cast<unsigned char*>(&code[0])); |
|
|
return const_cast<unsigned char*>(code.data()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
EXPORT void ext_codesizeAt(h256* _addr256, i256* _ret) |
|
|
EXPORT void ext_codesizeAt(h256* _addr256, i256* _ret) |
|
|