Browse Source

Improve Stack code formatting

cl-refactor
Paweł Bylica 10 years ago
parent
commit
fa6d4c63dc
  1. 86
      libevmjit/Stack.cpp
  2. 2
      libevmjit/Stack.h

86
libevmjit/Stack.cpp

@ -14,8 +14,8 @@ namespace eth
namespace jit namespace jit
{ {
Stack::Stack(llvm::IRBuilder<>& _builder, RuntimeManager& _runtimeManager) Stack::Stack(llvm::IRBuilder<>& _builder, RuntimeManager& _runtimeManager):
: CompilerHelper(_builder), CompilerHelper(_builder),
m_runtimeManager(_runtimeManager) m_runtimeManager(_runtimeManager)
{ {
m_arg = m_builder.CreateAlloca(Type::i256, nullptr, "stack.arg"); m_arg = m_builder.CreateAlloca(Type::i256, nullptr, "stack.arg");
@ -36,9 +36,6 @@ Stack::Stack(llvm::IRBuilder<>& _builder, RuntimeManager& _runtimeManager)
m_set = Function::Create(FunctionType::get(Type::Void, getSetArgTypes, false), Linkage::ExternalLinkage, "stack_set", module); m_set = Function::Create(FunctionType::get(Type::Void, getSetArgTypes, false), Linkage::ExternalLinkage, "stack_set", module);
} }
Stack::~Stack()
{}
llvm::Value* Stack::get(size_t _index) llvm::Value* Stack::get(size_t _index)
{ {
m_builder.CreateCall3(m_get, m_runtimeManager.getRuntimePtr(), llvm::ConstantInt::get(Type::Size, _index, false), m_arg); m_builder.CreateCall3(m_get, m_runtimeManager.getRuntimePtr(), llvm::ConstantInt::get(Type::Size, _index, false), m_arg);
@ -71,46 +68,45 @@ size_t Stack::maxStackSize = 0;
extern "C" extern "C"
{ {
using namespace dev::eth::jit;
using namespace dev::eth::jit;
EXPORT void stack_pop(Runtime* _rt, uint64_t _count)
EXPORT void stack_pop(Runtime* _rt, uint64_t _count) {
{ auto& stack = _rt->getStack();
auto& stack = _rt->getStack(); if (stack.size() < _count)
if (stack.size() < _count) longjmp(_rt->getJmpBuf(), static_cast<uint64_t>(ReturnCode::StackTooSmall));
longjmp(_rt->getJmpBuf(), static_cast<uint64_t>(ReturnCode::StackTooSmall));
stack.erase(stack.end() - _count, stack.end());
stack.erase(stack.end() - _count, stack.end()); }
}
EXPORT void stack_push(Runtime* _rt, i256* _word)
EXPORT void stack_push(Runtime* _rt, i256* _word) {
{ auto& stack = _rt->getStack();
auto& stack = _rt->getStack(); stack.push_back(*_word);
stack.push_back(*_word);
if (stack.size() > Stack::maxStackSize)
if (stack.size() > Stack::maxStackSize) Stack::maxStackSize = stack.size();
Stack::maxStackSize = stack.size(); }
}
EXPORT void stack_get(Runtime* _rt, uint64_t _index, i256* _ret)
EXPORT void stack_get(Runtime* _rt, uint64_t _index, i256* _ret) {
{ auto& stack = _rt->getStack();
auto& stack = _rt->getStack(); // TODO: encode _index and stack size in the return code
// TODO: encode _index and stack size in the return code if (stack.size() <= _index)
if (stack.size() <= _index) longjmp(_rt->getJmpBuf(), static_cast<uint64_t>(ReturnCode::StackTooSmall));
longjmp(_rt->getJmpBuf(), static_cast<uint64_t>(ReturnCode::StackTooSmall));
*_ret = *(stack.rbegin() + _index);
*_ret = *(stack.rbegin() + _index); }
}
EXPORT void stack_set(Runtime* _rt, uint64_t _index, i256* _word)
EXPORT void stack_set(Runtime* _rt, uint64_t _index, i256* _word) {
{ auto& stack = _rt->getStack();
auto& stack = _rt->getStack(); // TODO: encode _index and stack size in the return code
// TODO: encode _index and stack size in the return code if (stack.size() <= _index)
if (stack.size() <= _index) longjmp(_rt->getJmpBuf(), static_cast<uint64_t>(ReturnCode::StackTooSmall));
longjmp(_rt->getJmpBuf(), static_cast<uint64_t>(ReturnCode::StackTooSmall));
*(stack.rbegin() + _index) = *_word;
*(stack.rbegin() + _index) = *_word; }
}
} // extern "C" } // extern "C"

2
libevmjit/Stack.h

@ -15,9 +15,7 @@ class RuntimeManager;
class Stack : public CompilerHelper class Stack : public CompilerHelper
{ {
public: public:
Stack(llvm::IRBuilder<>& builder, RuntimeManager& runtimeManager); Stack(llvm::IRBuilder<>& builder, RuntimeManager& runtimeManager);
virtual ~Stack();
llvm::Value* get(size_t _index); llvm::Value* get(size_t _index);
void set(size_t _index, llvm::Value* _value); void set(size_t _index, llvm::Value* _value);

Loading…
Cancel
Save