#ifndef GOOSE_CIR_ALLOCVAR_H
#define GOOSE_CIR_ALLOCVAR_H

namespace goose::cir
{
    class AllocVar : public Operation< 0, false >
    {
      public:
        template< typename T >
        AllocVar( T&& type, uint32_t index, LocationId loc ) :
            Operation( loc ),
            m_type( forward< T >( type ) ),
            m_index( index )
        {
        }

        const auto& type() const { return m_type; }

        const auto& index() const { return m_index; }

        void setIndex( uint32_t index ) { m_index = index; }

        bool canBeExecuted() const { return true; }

        bool canBeEagerlyEvaluated() const { return false; }

        bool haveSideEffects() const { return true; }

        bool operator<( const AllocVar& rhs ) const
        {
            if( m_index != rhs.m_index )
                return m_index < rhs.m_index;
            return m_type < rhs.m_type;
        }

        friend ostream& operator<<( ostream& out, const AllocVar& ins )
        {
            return out << "ALLOCVAR(" << ins.m_index << ", " << ins.m_type.type() << ')';
        }

      private:
        LowerableType m_type;
        uint32_t m_index = 0;
    };
} // namespace goose::cir

#endif
