|
|
@ -10,6 +10,8 @@ |
|
|
|
|
|
|
|
#include <libdevcore/Common.h> |
|
|
|
|
|
|
|
#include "Utils.h" |
|
|
|
|
|
|
|
#ifdef _MSC_VER |
|
|
|
#define EXPORT __declspec(dllexport) |
|
|
|
#else |
|
|
@ -19,44 +21,42 @@ |
|
|
|
namespace evmcc |
|
|
|
{ |
|
|
|
|
|
|
|
struct i256 |
|
|
|
{ |
|
|
|
uint64_t a; |
|
|
|
uint64_t b; |
|
|
|
uint64_t c; |
|
|
|
uint64_t d; |
|
|
|
}; |
|
|
|
static_assert(sizeof(i256) == 32, "Wrong i256 size"); |
|
|
|
|
|
|
|
using MemoryImpl = dev::bytes; |
|
|
|
|
|
|
|
static MemoryImpl* evmccrt_memory; |
|
|
|
|
|
|
|
Memory::Memory(llvm::IRBuilder<>& _builder, llvm::Module* _module) |
|
|
|
|
|
|
|
Memory::Memory(llvm::IRBuilder<>& _builder) |
|
|
|
: m_builder(_builder) |
|
|
|
{ |
|
|
|
auto voidTy = m_builder.getVoidTy(); |
|
|
|
auto i64Ty = m_builder.getInt64Ty(); |
|
|
|
|
|
|
|
auto memoryCreate = llvm::Function::Create(llvm::FunctionType::get(voidTy, false), |
|
|
|
llvm::GlobalValue::LinkageTypes::ExternalLinkage, |
|
|
|
"evmccrt_memory_create", _module); |
|
|
|
m_builder.CreateCall(memoryCreate); |
|
|
|
auto module = _builder.GetInsertBlock()->getParent()->getParent(); |
|
|
|
|
|
|
|
|
|
|
|
auto memRequireTy = llvm::FunctionType::get(m_builder.getInt8PtrTy(), i64Ty, false); |
|
|
|
m_memRequire = llvm::Function::Create(memRequireTy, |
|
|
|
llvm::GlobalValue::LinkageTypes::ExternalLinkage, |
|
|
|
"evmccrt_memory_require", _module); |
|
|
|
"evmccrt_memory_require", module); |
|
|
|
|
|
|
|
auto memSizeTy = llvm::FunctionType::get(i64Ty, false); |
|
|
|
m_memSize = llvm::Function::Create(memSizeTy, |
|
|
|
llvm::GlobalValue::LinkageTypes::ExternalLinkage, |
|
|
|
"evmccrt_memory_size", _module); |
|
|
|
"evmccrt_memory_size", module); |
|
|
|
|
|
|
|
std::vector<llvm::Type*> argTypes = {i64Ty, i64Ty}; |
|
|
|
auto dumpTy = llvm::FunctionType::get(m_builder.getVoidTy(), llvm::ArrayRef<llvm::Type*>(argTypes), false); |
|
|
|
m_memDump = llvm::Function::Create(dumpTy, llvm::GlobalValue::LinkageTypes::ExternalLinkage, |
|
|
|
"evmccrt_memory_dump", _module); |
|
|
|
"evmccrt_memory_dump", module); |
|
|
|
} |
|
|
|
|
|
|
|
const dev::bytes& Memory::init() |
|
|
|
{ |
|
|
|
evmccrt_memory = new MemoryImpl(); |
|
|
|
std::cerr << "MEMORY: create(), initial size = " << evmccrt_memory->size() |
|
|
|
<< std::endl; |
|
|
|
|
|
|
|
return *evmccrt_memory; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -130,15 +130,6 @@ extern "C" |
|
|
|
{ |
|
|
|
using namespace evmcc; |
|
|
|
|
|
|
|
EXPORT MemoryImpl* evmccrt_memory; |
|
|
|
|
|
|
|
EXPORT void evmccrt_memory_create(void) |
|
|
|
{ |
|
|
|
evmccrt_memory = new MemoryImpl(); |
|
|
|
std::cerr << "MEMORY: create(), initial size = " << evmccrt_memory->size() |
|
|
|
<< std::endl; |
|
|
|
} |
|
|
|
|
|
|
|
// Resizes memory to contain at least _index + 1 bytes and returns the base address.
|
|
|
|
EXPORT uint8_t* evmccrt_memory_require(uint64_t _index) |
|
|
|
{ |
|
|
@ -154,7 +145,7 @@ EXPORT uint8_t* evmccrt_memory_require(uint64_t _index) |
|
|
|
evmccrt_memory->resize(requiredSize); |
|
|
|
} |
|
|
|
|
|
|
|
return &(*evmccrt_memory)[0]; |
|
|
|
return evmccrt_memory->data(); |
|
|
|
} |
|
|
|
|
|
|
|
EXPORT uint64_t evmccrt_memory_size() |
|
|
|