Browse Source

Stack cleanups

cl-refactor
Paweł Bylica 10 years ago
parent
commit
1cbb9d57aa
  1. 2
      evmcc/Compiler.cpp
  2. 11
      evmcc/Stack.cpp
  3. 21
      evmcc/Stack.h

2
evmcc/Compiler.cpp

@ -186,7 +186,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
auto ext = Ext(builder, module.get());
BasicBlock* currentBlock = &basicBlocks.find(0)->second; // Any value, just to create branch for %entry to %Instr.0
BBStack stack(builder, extStack); // Stack for current block
BBStack stack; // Stack for current block
for (auto pc = bytecode.cbegin(); pc != bytecode.cend(); ++pc)
{

11
evmcc/Stack.cpp

@ -21,11 +21,6 @@
namespace evmcc
{
BBStack::BBStack(llvm::IRBuilder<>& _builder, Stack& _extStack):
m_extStack(_extStack),
m_builder(_builder)
{}
void BBStack::push(llvm::Value* _value)
{
m_block->getState().push_back(_value);
@ -37,11 +32,11 @@ llvm::Value* BBStack::pop()
if (state.empty())
{
// Create PHI node
auto first = m_block->llvm()->getFirstNonPHI();
auto i256Ty = llvm::Type::getIntNTy(m_block->llvm()->getContext(), 256);
auto llvmBB = m_block->llvm();
if (llvmBB->getInstList().empty())
return llvm::PHINode::Create(m_builder.getIntNTy(256), 0, {}, m_block->llvm());
return llvm::PHINode::Create(m_builder.getIntNTy(256), 0, {}, llvmBB->getFirstNonPHI());
return llvm::PHINode::Create(i256Ty, 0, {}, m_block->llvm());
return llvm::PHINode::Create(i256Ty, 0, {}, llvmBB->getFirstNonPHI());
}
auto top = state.back();

21
evmcc/Stack.h

@ -37,22 +37,31 @@ private:
class BBStack
{
public:
BBStack(llvm::IRBuilder<>& _builder, Stack& _extStack);
BBStack() = default;
BBStack(const BBStack&) = delete;
void operator=(const BBStack&) = delete;
/**
Changes current basic block (if any) with a new one with empty state.
*/
void setBasicBlock(BasicBlock& _newBlock);
void push(llvm::Value* _value);
llvm::Value* pop();
/**
Duplicates _index'th value on stack.
*/
void dup(size_t _index);
void swap(size_t _index);
/**
Changes current basic block with a new one with empty state.
Swaps _index'th value on stack with a value on stack top.
@param _index Index of value to be swaped. Cannot be 0.
*/
void setBasicBlock(BasicBlock& _newBlock);
void swap(size_t _index);
private:
Stack& m_extStack; ///< External (global) stack
BasicBlock* m_block = nullptr; ///< Current basic block
llvm::IRBuilder<>& m_builder;
};

Loading…
Cancel
Save