#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