Goose  instruction.cpp at [a0a57b5e22]

File bs/cir/instruction.cpp artifact df1b6e84ae part of check-in a0a57b5e22


#include "cir/cir.h"

namespace goose::cir
{
    bool Instruction::canBeExecuted() const
    {
        return visit( []< typename ET >( const ET& e )
        {
            if constexpr( is_same_v< ET, monostate > )
                return false;
            else
                return e.canBeExecuted();
        }, m_content );
    }

    bool Instruction::canBeEagerlyEvaluated() const
    {
        return visit( []< typename ET >( const ET& e )
        {
            if constexpr( is_same_v< ET, monostate > )
                return false;
            else
                return e.canBeEagerlyEvaluated();
        }, m_content );
    }

    bool Instruction::haveSideEffects() const
    {
        return visit( []< typename ET >( const ET& e )
        {
            if constexpr( is_same_v< ET, monostate > )
                return false;
            else
                return e.haveSideEffects();
        }, m_content );
    }

    ostream& operator<<( ostream& out, const Instruction& inst )
    {
        return visit( [&]< typename ET >( const ET& e ) -> ostream&
        {
            if constexpr( is_same_v< ET, monostate > )
                return out << "NIL";
            else
                return out << e;
        }, inst.m_content );
    }

    ostream& operator<<( ostream& out, const Select& ins )
    {
        out << "SELECT(" << ins.m_memberIndex;
        return out << ')';
    }

    ostream& operator<<( ostream& out, const Load& ins )
    {
        out << "LOAD(";
        return out << ins.m_type << ')';
    }

    ostream& operator<<( ostream& out, const Store& ins )
    {
        return out << "STORE";
    }

    ostream& operator<<( ostream& out, const PHOverrideSet& ins )
    {
        return out << "PHOVERRIDESET(" << ins.m_name << ')';
    }

    ostream& operator<<( ostream& out, const PHOverrideClear& ins )
    {
        return out << "PHOVERRIDECLEAR(" << ins.m_name << ')';
    }

    bool Select::operator<( const Select& rhs ) const
    {
        return m_memberIndex < rhs.m_memberIndex;
    }

    bool Load::operator<( const Load& rhs ) const
    {
        return m_type < rhs.m_type;
    }

    bool Store::operator<( const Store& rhs ) const
    {
        return m_type < rhs.m_type;
    }

    bool PHOverrideSet::operator<( const PHOverrideSet& rhs ) const
    {
        return m_name < rhs.m_name;
    }

    bool PHOverrideClear::operator<( const PHOverrideClear& rhs ) const
    {
        return m_name < rhs.m_name;
    }
}