|
@ -3,6 +3,7 @@ |
|
|
|
|
|
|
|
|
#include <llvm/IR/Function.h> |
|
|
#include <llvm/IR/Function.h> |
|
|
#include <llvm/IR/TypeBuilder.h> |
|
|
#include <llvm/IR/TypeBuilder.h> |
|
|
|
|
|
#include <llvm/IR/IntrinsicInst.h> |
|
|
|
|
|
|
|
|
#include "Utils.h" |
|
|
#include "Utils.h" |
|
|
|
|
|
|
|
@ -15,6 +16,7 @@ |
|
|
using namespace llvm; |
|
|
using namespace llvm; |
|
|
using llvm::types::i; |
|
|
using llvm::types::i; |
|
|
using Linkage = llvm::GlobalValue::LinkageTypes; |
|
|
using Linkage = llvm::GlobalValue::LinkageTypes; |
|
|
|
|
|
using dev::h256; |
|
|
|
|
|
|
|
|
namespace evmcc |
|
|
namespace evmcc |
|
|
{ |
|
|
{ |
|
@ -69,6 +71,8 @@ Ext::Ext(llvm::IRBuilder<>& _builder, llvm::Module* module) |
|
|
m_store = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_store", module); |
|
|
m_store = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_store", module); |
|
|
m_setStore = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_setStore", module); |
|
|
m_setStore = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_setStore", module); |
|
|
m_calldataload = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_calldataload", module); |
|
|
m_calldataload = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_calldataload", module); |
|
|
|
|
|
m_balance = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_balance", module); |
|
|
|
|
|
m_bswap = Intrinsic::getDeclaration(module, Intrinsic::bswap, i256Ty); |
|
|
|
|
|
|
|
|
m_builder.CreateCall(m_init, m_data); |
|
|
m_builder.CreateCall(m_init, m_data); |
|
|
} |
|
|
} |
|
@ -107,6 +111,19 @@ Value* Ext::calldataload(Value* _index) |
|
|
return m_builder.CreateLoad(m_args[1]); |
|
|
return m_builder.CreateLoad(m_args[1]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Value* Ext::bswap(Value* _value) |
|
|
|
|
|
{ |
|
|
|
|
|
return m_builder.CreateCall(m_bswap, _value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Value* Ext::balance(Value* _address) |
|
|
|
|
|
{ |
|
|
|
|
|
auto address = bswap(_address); // to BigEndian // TODO: I don't get it. It seems not needed
|
|
|
|
|
|
m_builder.CreateStore(address, m_args[0]); |
|
|
|
|
|
m_builder.CreateCall(m_balance, m_args); |
|
|
|
|
|
return m_builder.CreateLoad(m_args[1]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
extern "C" |
|
|
extern "C" |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
@ -145,6 +162,12 @@ EXPORT void ext_calldataload(i256* _index, i256* _value) |
|
|
// TODO: It all can be done by adding padding to data or by using min() algorithm without branch
|
|
|
// TODO: It all can be done by adding padding to data or by using min() algorithm without branch
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EXPORT void ext_balance(h256* _address, i256* _value) |
|
|
|
|
|
{ |
|
|
|
|
|
auto u = g_ext->balance(dev::right160(*_address)); |
|
|
|
|
|
*_value = eth2llvm(u); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|