#pragma once #include #include namespace evmcc { class Stack { public: Stack(llvm::IRBuilder<>& _builder, llvm::Module* _module); void push(llvm::Value* _value); llvm::Value* pop(); llvm::Value* top(); llvm::Value* get(uint32_t _index); void set(uint32_t _index, llvm::Value* _value); private: llvm::IRBuilder<>& m_builder; llvm::Value* m_stackVal; llvm::Function* m_stackPush; llvm::Function* m_stackPop; llvm::Function* m_stackGet; llvm::Function* m_stackSet; }; /** Stack adapter for Basic Block Transforms stack to SSA: tracks values and their positions on the imaginary stack used inside a basic block. */ class BBStack { public: BBStack(Stack& _extStack); void push(llvm::Value* _value); llvm::Value* pop(); void dup(size_t _index); void swap(size_t _index); /** Resets stack on basic block change. Values left on local stack are pushed on external stack. Local stack is empty after this operation and compilation of new basic block can be started. */ void reset(); /** Dumps values on stack. */ void clear(); /// Debug only bool empty() const; private: std::vector m_state; ///< Basic black state vector - current values and their positions Stack& m_extStack; ///< External (global) stack }; }