Goose  Artifact [c0898d3a28]

Artifact c0898d3a28b040fcae4afddc24ed1ca0c1b8934b6b593f643e18c4743ad4a747:

  • File bs/llr/helpers.h — part of check-in [8ddd71f9b2] at 2020-12-18 01:29:15 on branch trunk — References refactor: references are now values all the way to the llr, where a new "CalcAddress" instruction represents a conversion from a logical address (location + path) into an actual runtime or compilation time address. This is in preparation to allow references to be stored in variables or passed as parameters. (It just took 4.5 months to finish this... Refactoring just sucks) (user: achavasse size: 1405)

#ifndef GOOSE_LLR_HELPERS_H
#define GOOSE_LLR_HELPERS_H

namespace goose::llr
{
    class Instruction;

    bool IsValueConstantOrExecutable( const ir::Value& val );
    bool CanValueBeEagerlyEvaluated( const ir::Value& val );
    bool IsCompileTimeTempRef( const ir::Value& val );

    template< typename T, typename I >
    auto BuildComputedValue( T&& type, I&& instr )
    {
        return ir::Value( forward< T >( type ),
            make_shared< Instruction >( forward< I >( instr ) ) );
    }

    template< typename T >
    class TempStorage
    {
        public:
            template< typename TT >
            auto& set( uint32_t index, TT&& x )
            {
                auto [it, inserted] = m_storage.try_emplace( index );
                it->second = forward< TT >( x );
                return it->second;
            }

            const T* get( uint32_t index ) const
            {
                auto it = m_storage.find( index );
                if( it == m_storage.end() )
                    return nullptr;

                return &it->second;
            }

            T* get( uint32_t index )
            {
                auto it = m_storage.find( index );
                if( it == m_storage.end() )
                    return nullptr;

                return &it->second;
            }

        private:
            unordered_map< uint32_t, T > m_storage;
    };
}

#endif