Browse Source

LOGs reimplemented

cl-refactor
Paweł Bylica 10 years ago
parent
commit
4366542b63
  1. 67
      libevmjit-cpp/Env.cpp
  2. 4
      libevmjit/Compiler.cpp
  3. 38
      libevmjit/Ext.cpp
  4. 8
      libevmjit/Ext.h

67
libevmjit-cpp/Env.cpp

@ -113,68 +113,23 @@ extern "C"
*o_ret = eth2llvm(u256(code.size()));
}
EXPORT void ext_log0(ExtVMFace* _env, i256* _memIdx, i256* _numBytes)
EXPORT void env_log(ExtVMFace* _env, byte* _beg, uint64_t _size, h256* _topic1, h256* _topic2, h256* _topic3, h256* _topic4)
{
auto memIdx = llvm2eth(*_memIdx).convert_to<size_t>();
auto numBytes = llvm2eth(*_numBytes).convert_to<size_t>();
dev::h256s topics;
//auto dataRef = bytesConstRef(_rt->getMemory().data() + memIdx, numBytes);
auto dataRef = bytesConstRef(); // FIXME: Handle memory
_env->log({}, dataRef);
}
EXPORT void ext_log1(ExtVMFace* _env, i256* _memIdx, i256* _numBytes, i256* _topic1)
{
auto memIdx = static_cast<size_t>(llvm2eth(*_memIdx));
auto numBytes = static_cast<size_t>(llvm2eth(*_numBytes));
auto topic1 = llvm2eth(*_topic1);
//auto dataRef = bytesConstRef(_rt->getMemory().data() + memIdx, numBytes);
auto dataRef = bytesConstRef(); // FIXME: Handle memory
_env->log({topic1}, dataRef);
}
EXPORT void ext_log2(ExtVMFace* _env, i256* _memIdx, i256* _numBytes, i256* _topic1, i256* _topic2)
{
auto memIdx = static_cast<size_t>(llvm2eth(*_memIdx));
auto numBytes = static_cast<size_t>(llvm2eth(*_numBytes));
if (_topic1)
topics.push_back(*_topic1);
auto topic1 = llvm2eth(*_topic1);
auto topic2 = llvm2eth(*_topic2);
if (_topic2)
topics.push_back(*_topic2);
//auto dataRef = bytesConstRef(_rt->getMemory().data() + memIdx, numBytes);
auto dataRef = bytesConstRef(); // FIXME: Handle memory
_env->log({ topic1, topic2 }, dataRef);
}
EXPORT void ext_log3(ExtVMFace* _env, i256* _memIdx, i256* _numBytes, i256* _topic1, i256* _topic2, i256* _topic3)
{
auto memIdx = static_cast<size_t>(llvm2eth(*_memIdx));
auto numBytes = static_cast<size_t>(llvm2eth(*_numBytes));
auto topic1 = llvm2eth(*_topic1);
auto topic2 = llvm2eth(*_topic2);
auto topic3 = llvm2eth(*_topic3);
//auto dataRef = bytesConstRef(_rt->getMemory().data() + memIdx, numBytes);
auto dataRef = bytesConstRef(); // FIXME: Handle memory
_env->log({ topic1, topic2, topic3 }, dataRef);
}
EXPORT void ext_log4(ExtVMFace* _env, i256* _memIdx, i256* _numBytes, i256* _topic1, i256* _topic2, i256* _topic3, i256* _topic4)
{
auto memIdx = static_cast<size_t>(llvm2eth(*_memIdx));
auto numBytes = static_cast<size_t>(llvm2eth(*_numBytes));
if (_topic3)
topics.push_back(*_topic3);
auto topic1 = llvm2eth(*_topic1);
auto topic2 = llvm2eth(*_topic2);
auto topic3 = llvm2eth(*_topic3);
auto topic4 = llvm2eth(*_topic4);
if (_topic4)
topics.push_back(*_topic4);
//auto dataRef = bytesConstRef(_rt->getMemory().data() + memIdx, numBytes);
auto dataRef = bytesConstRef(); // FIXME: Handle memory
_env->log({ topic1, topic2, topic3, topic4 }, dataRef);
_env->log(std::move(topics), {_beg, _size});
}
}

4
libevmjit/Compiler.cpp

@ -811,12 +811,12 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
// This will commit the current cost block
_gasMeter.countLogData(numBytes);
std::array<llvm::Value*,4> topics;
std::array<llvm::Value*, 4> topics{};
auto numTopics = static_cast<size_t>(inst) - static_cast<size_t>(Instruction::LOG0);
for (size_t i = 0; i < numTopics; ++i)
topics[i] = stack.pop();
_ext.log(beginIdx, numBytes, numTopics, topics);
_ext.log(beginIdx, numBytes, topics);
break;
}

38
libevmjit/Ext.cpp

@ -48,14 +48,9 @@ Ext::Ext(RuntimeManager& _runtimeManager, Memory& _memoryMan):
m_calldataload = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "ext_calldataload", module);
m_balance = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "ext_balance", module);
m_suicide = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 2}, false), Linkage::ExternalLinkage, "ext_suicide", module);
m_exp = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 4}, false), Linkage::ExternalLinkage, "ext_exp", module);
m_exp = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 4}, false), Linkage::ExternalLinkage, "ext_exp", module); // FIXME: Remove
m_codeAt = llvm::Function::Create(llvm::FunctionType::get(Type::BytePtr, {argsTypes, 2}, false), Linkage::ExternalLinkage, "ext_codeAt", module);
m_codesizeAt = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "ext_codesizeAt", module);
m_log0 = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "ext_log0", module);
m_log1 = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 4}, false), Linkage::ExternalLinkage, "ext_log1", module);
m_log2 = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 5}, false), Linkage::ExternalLinkage, "ext_log2", module);
m_log3 = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 6}, false), Linkage::ExternalLinkage, "ext_log3", module);
m_log4 = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 7}, false), Linkage::ExternalLinkage, "ext_log4", module);
llvm::Type* sha3ArgsTypes[] = {Type::BytePtr, Type::Size, Type::WordPtr};
m_sha3 = llvm::Function::Create(llvm::FunctionType::get(Type::Void, sha3ArgsTypes, false), Linkage::ExternalLinkage, "env_sha3", module);
@ -65,6 +60,9 @@ Ext::Ext(RuntimeManager& _runtimeManager, Memory& _memoryMan):
llvm::Type* callArgsTypes[] = {Type::EnvPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::BytePtr, Type::Size, Type::BytePtr, Type::Size, Type::WordPtr};
m_call = llvm::Function::Create(llvm::FunctionType::get(Type::Bool, callArgsTypes, false), Linkage::ExternalLinkage, "env_call", module);
llvm::Type* logArgsTypes[] = {Type::EnvPtr, Type::BytePtr, Type::Size, Type::WordPtr, Type::WordPtr, Type::WordPtr, Type::WordPtr};
m_log = llvm::Function::Create(llvm::FunctionType::get(Type::Void, logArgsTypes, false), Linkage::ExternalLinkage, "env_log", module);
}
llvm::Value* Ext::sload(llvm::Value* _index)
@ -157,19 +155,23 @@ llvm::Value* Ext::codesizeAt(llvm::Value* _addr)
return m_builder.CreateLoad(m_args[1]);
}
void Ext::log(llvm::Value* _memIdx, llvm::Value* _numBytes, size_t _numTopics, std::array<llvm::Value*,4> const& _topics)
void Ext::log(llvm::Value* _memIdx, llvm::Value* _numBytes, std::array<llvm::Value*,4> const& _topics)
{
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().getEnv();
m_builder.CreateStore(_memIdx, m_args[0]);
m_builder.CreateStore(_numBytes, m_args[1]);
for (size_t i = 0; i < _numTopics; ++i)
m_builder.CreateStore(_topics[i], args[i + 3]);
m_builder.CreateCall(funcs[_numTopics], llvm::ArrayRef<llvm::Value*>(args, _numTopics + 3));
auto begin = m_memoryMan.getBytePtr(_memIdx);
auto size = m_builder.CreateTrunc(_numBytes, Type::Size, "size");
llvm::Value* args[] = {getRuntimeManager().getEnv(), begin, size, m_arg2, m_arg3, m_arg4, m_arg5};
auto topicArgPtr = &args[3];
for (auto&& topic : _topics)
{
if (topic)
m_builder.CreateStore(Endianness::toBE(m_builder, topic), *topicArgPtr);
else
*topicArgPtr = llvm::ConstantPointerNull::get(Type::WordPtr);
++topicArgPtr;
}
m_builder.CreateCall(m_log, args);
}
}

8
libevmjit/Ext.h

@ -30,7 +30,7 @@ public:
llvm::Value* codeAt(llvm::Value* _addr);
llvm::Value* codesizeAt(llvm::Value* _addr);
void log(llvm::Value* _memIdx, llvm::Value* _numBytes, size_t _numTopics, std::array<llvm::Value*,4> const& _topics);
void log(llvm::Value* _memIdx, llvm::Value* _numBytes, std::array<llvm::Value*,4> const& _topics);
private:
Memory& m_memoryMan;
@ -55,11 +55,7 @@ private:
llvm::Function* m_exp;
llvm::Function* m_codeAt;
llvm::Function* m_codesizeAt;
llvm::Function* m_log0;
llvm::Function* m_log1;
llvm::Function* m_log2;
llvm::Function* m_log3;
llvm::Function* m_log4;
llvm::Function* m_log;
};

Loading…
Cancel
Save