Browse Source

Merge commit '7906cdd2e8ba2a46763d45e4df8c57642d5df84c' into evmjit

Conflicts:
	evmjit/libevmjit/Arith256.cpp
	evmjit/libevmjit/Cache.cpp
	evmjit/libevmjit/Ext.cpp
	evmjit/libevmjit/GasMeter.cpp
	evmjit/libevmjit/Runtime.cpp
cl-refactor
Paweł Bylica 10 years ago
parent
commit
f55ef44ce3
  1. 10
      evmjit/libevmjit/Arith256.cpp
  2. 6
      evmjit/libevmjit/Cache.cpp
  3. 8
      evmjit/libevmjit/Ext.cpp
  4. 8
      evmjit/libevmjit/GasMeter.cpp
  5. 6
      evmjit/libevmjit/Runtime.cpp

10
evmjit/libevmjit/Arith256.cpp

@ -178,7 +178,10 @@ extern "C"
auto arg1 = llvm2eth(*_arg1);
auto arg2 = llvm2eth(*_arg2);
auto arg3 = llvm2eth(*_arg3);
*o_result = eth2llvm(u256((bigint(arg1) * bigint(arg2)) % arg3));
if (arg3 != 0)
*o_result = eth2llvm(u256((bigint(arg1) * bigint(arg2)) % arg3));
else
*o_result = {};
}
EXPORT void arith_addmod(i256* _arg1, i256* _arg2, i256* _arg3, i256* o_result)
@ -186,7 +189,10 @@ extern "C"
auto arg1 = llvm2eth(*_arg1);
auto arg2 = llvm2eth(*_arg2);
auto arg3 = llvm2eth(*_arg3);
*o_result = eth2llvm(u256((bigint(arg1) + bigint(arg2)) % arg3));
if (arg3 != 0)
*o_result = eth2llvm(u256((bigint(arg1) + bigint(arg2)) % arg3));
else
*o_result = {};
}
}

6
evmjit/libevmjit/Cache.cpp

@ -45,8 +45,7 @@ std::unique_ptr<llvm::Module> Cache::getObject(std::string const& id)
{
auto module = std::unique_ptr<llvm::Module>(new llvm::Module(id, llvm::getGlobalContext()));
auto mainFuncType = llvm::FunctionType::get(llvm::IntegerType::get(llvm::getGlobalContext(), 32), {}, false);
auto func = llvm::Function::Create(mainFuncType, llvm::Function::ExternalLinkage, id, module.get());
(void)func;
llvm::Function::Create(mainFuncType, llvm::Function::ExternalLinkage, id, module.get());
}
return nullptr;
}
@ -69,9 +68,8 @@ void ObjectCache::notifyObjectCompiled(llvm::Module const* _module, llvm::Memory
cacheFile << _object->getBuffer();
}
llvm::MemoryBuffer* ObjectCache::getObject(llvm::Module const* _module)
llvm::MemoryBuffer* ObjectCache::getObject(llvm::Module const*)
{
(void)_module;
auto o = lastObject;
lastObject = nullptr;
return o;

8
evmjit/libevmjit/Ext.cpp

@ -22,11 +22,9 @@ namespace jit
Ext::Ext(RuntimeManager& _runtimeManager, Memory& _memoryMan):
RuntimeHelper(_runtimeManager),
m_memoryMan(_memoryMan)
// TODO: fix: either initialise properly or don't specify in constructor.
/*,
m_funcs{},
m_argAllocas{}*/
m_memoryMan(_memoryMan),
m_funcs({}), // The only std::array initialization that works in both Visual Studio & GCC
m_argAllocas({})
{
m_size = m_builder.CreateAlloca(Type::Size, nullptr, "env.size");
}

8
evmjit/libevmjit/GasMeter.cpp

@ -173,10 +173,12 @@ void GasMeter::countSha3Data(llvm::Value* _dataLength)
assert(m_blockCost > 0); // SHA3 instruction is already counted
// TODO: This round ups to 32 happens in many places
// FIXME: Overflow possible but Memory::require() also called. Probably 64-bit arith can be used.
// FIXME: 64-bit arith used, but not verified
static_assert(c_sha3WordGas != 1, "SHA3 data cost has changed. Update GasMeter");
auto words = m_builder.CreateUDiv(m_builder.CreateAdd(_dataLength, Constant::get(31)), Constant::get(32));
auto cost = m_builder.CreateNUWMul(Constant::get(c_sha3WordGas), words);
auto dataLength64 = getBuilder().CreateTrunc(_dataLength, Type::lowPrecision);
auto words64 = m_builder.CreateUDiv(m_builder.CreateAdd(dataLength64, getBuilder().getInt64(31)), getBuilder().getInt64(32));
auto cost64 = m_builder.CreateNUWMul(getBuilder().getInt64(c_sha3WordGas), words64);
auto cost = getBuilder().CreateZExt(cost64, Type::Word);
count(cost);
}

6
evmjit/libevmjit/Runtime.cpp

@ -24,8 +24,10 @@ bytes Runtime::getReturnData() const // FIXME: Reconsider returning by copy
auto offset = static_cast<size_t>(llvm2eth(m_data.elems[RuntimeData::ReturnDataOffset]));
auto size = static_cast<size_t>(llvm2eth(m_data.elems[RuntimeData::ReturnDataSize]));
assert(offset + size <= m_memory.size());
// TODO: Handle invalid data access by returning empty ref
assert(offset + size <= m_memory.size() || size == 0);
if (offset + size > m_memory.size())
return {};
auto dataBeg = m_memory.begin() + offset;
return {dataBeg, dataBeg + size};
}

Loading…
Cancel
Save