Paweł Bylica
10 years ago
7 changed files with 82 additions and 125 deletions
@ -1,59 +0,0 @@ |
|||
|
|||
#include "Stack.h" |
|||
|
|||
#include <cassert> |
|||
|
|||
#include <llvm/IR/Instructions.h> |
|||
|
|||
#include "BasicBlock.h" |
|||
|
|||
namespace evmcc |
|||
{ |
|||
|
|||
void BBStack::push(llvm::Value* _value) |
|||
{ |
|||
m_block->getState().push_back(_value); |
|||
} |
|||
|
|||
llvm::Value* BBStack::pop() |
|||
{ |
|||
auto&& state = m_block->getState(); |
|||
if (state.empty()) |
|||
{ |
|||
// Create PHI node
|
|||
auto i256Ty = llvm::Type::getIntNTy(m_block->llvm()->getContext(), 256); |
|||
auto llvmBB = m_block->llvm(); |
|||
if (llvmBB->empty()) |
|||
return llvm::PHINode::Create(i256Ty, 0, {}, m_block->llvm()); |
|||
return llvm::PHINode::Create(i256Ty, 0, {}, llvmBB->getFirstNonPHI()); |
|||
} |
|||
|
|||
auto top = state.back(); |
|||
state.pop_back(); |
|||
return top; |
|||
} |
|||
|
|||
void BBStack::setBasicBlock(BasicBlock& _newBlock) |
|||
{ |
|||
// Current block keeps end state
|
|||
// Just update pointer to current block
|
|||
// New block should have empty state
|
|||
assert(_newBlock.getState().empty()); |
|||
m_block = &_newBlock; |
|||
} |
|||
|
|||
void BBStack::dup(size_t _index) |
|||
{ |
|||
auto&& state = m_block->getState(); |
|||
auto value = *(state.rbegin() + _index); |
|||
state.push_back(value); |
|||
} |
|||
|
|||
void BBStack::swap(size_t _index) |
|||
{ |
|||
assert(_index != 0); |
|||
auto&& state = m_block->getState(); |
|||
std::swap(*state.rbegin(), *(state.rbegin() + _index)); |
|||
} |
|||
|
|||
} |
@ -1,47 +0,0 @@ |
|||
|
|||
#pragma once |
|||
|
|||
#include <llvm/IR/Value.h> |
|||
|
|||
namespace evmcc |
|||
{ |
|||
class BasicBlock; |
|||
|
|||
/**
|
|||
Stack adapter for Basic Block |
|||
|
|||
Transforms stack to SSA: tracks values and their positions on the imaginary stack used inside a basic block. |
|||
TODO: Integrate into BasicBlock class |
|||
*/ |
|||
class BBStack |
|||
{ |
|||
public: |
|||
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); |
|||
|
|||
/**
|
|||
Swaps _index'th value on stack with a value on stack top. |
|||
@param _index Index of value to be swaped. Cannot be 0. |
|||
*/ |
|||
void swap(size_t _index); |
|||
|
|||
private: |
|||
BasicBlock* m_block = nullptr; ///< Current basic block
|
|||
}; |
|||
|
|||
|
|||
} |
Loading…
Reference in new issue