Move only-write-model-if-it-contains-overrides up to base class.

It's necessary to keep us from writing out model lines for included
models and fall-backs of included models.
This commit is contained in:
Jeff Young 2023-03-01 13:30:22 +00:00
parent a0f99ea8ba
commit f5edcf82f2
5 changed files with 29 additions and 46 deletions

View File

@ -1064,9 +1064,34 @@ void SIM_MODEL::doWriteFields( std::vector<T>& aFields ) const
bool SIM_MODEL::requiresSpiceModelLine( const SPICE_ITEM& aItem ) const
{
for( const PARAM& param : GetParams() )
// Model must be written if there's no base model or the base model is an internal model
if( !m_baseModel || aItem.baseModelName == "" )
return true;
for( int ii = 0; ii < GetParamCount(); ++ii )
{
if( !param.info.isSpiceInstanceParam )
const PARAM& param = m_params[ii];
// Instance parameters are written in item lines
if( param.info.isSpiceInstanceParam )
continue;
// Empty parameters are interpreted as default-value
if ( param.value == "" )
continue;
const SIM_MODEL* baseModel = dynamic_cast<const SIM_MODEL*>( m_baseModel );
std::string baseValue = baseModel->m_params[ii].value;
if( param.value == baseValue )
continue;
// One more check for equivalence, mostly for early 7.0 files which wrote all parameters
// to the Sim.Params field in normalized format
if( param.value == SIM_VALUE::Normalize( SIM_VALUE::ToDouble( baseValue ) ) )
continue;
// Overrides must be written
return true;
}

View File

@ -215,43 +215,6 @@ bool SIM_MODEL_NGSPICE::canSilentlyIgnoreParam( const std::string& aParamName )
}
bool SIM_MODEL_NGSPICE::requiresSpiceModelLine( const SPICE_ITEM& aItem ) const
{
// Model must be written if there's no base model or the base model is an internal model
if( !m_baseModel || aItem.baseModelName == "" )
return true;
for( int ii = 0; ii < GetParamCount(); ++ii )
{
const PARAM& param = m_params[ii];
// Instance parameters are written in item lines
if( param.info.isSpiceInstanceParam )
continue;
// Empty parameters are interpreted as default-value
if ( param.value == "" )
continue;
const SIM_MODEL_NGSPICE* baseModel = dynamic_cast<const SIM_MODEL_NGSPICE*>( m_baseModel );
std::string baseValue = baseModel->m_params[ii].value;
if( param.value == baseValue )
continue;
// One more check for equivalence, mostly for early 7.0 files which wrote all parameters
// to the Sim.Params field in normalized format
if( param.value == SIM_VALUE::Normalize( SIM_VALUE::ToDouble( baseValue ) ) )
continue;
// Overrides must be written
return true;
}
return false;
}
std::vector<std::string> SIM_MODEL_NGSPICE::GetPinNames() const
{
return ModelInfo( getModelType() ).pinNames;

View File

@ -109,8 +109,6 @@ protected:
int doFindParam( const std::string& aParamName ) const override;
private:
bool requiresSpiceModelLine( const SPICE_ITEM& aItem ) const override;
bool canSilentlyIgnoreParam( const std::string& aParamName );
MODEL_TYPE getModelType() const;

View File

@ -60,8 +60,6 @@ public:
std::string GetSpiceCode() const;
private:
bool requiresSpiceModelLine( const SPICE_ITEM& aItem ) const override { return true; }
std::vector<std::unique_ptr<PARAM::INFO>> m_paramInfos;
};

View File

@ -34,8 +34,7 @@ std::string SPICE_GENERATOR::ModelName( const SPICE_ITEM& aItem ) const
if( aItem.baseModelName == "" )
return fmt::format( "__{}", aItem.refName );
// FIXME: This ModelLine() call is relatively expensive.
if( ModelLine( aItem ) != "" )
if( m_model.requiresSpiceModelLine( aItem ) )
return fmt::format( "{}.{}", aItem.refName, aItem.baseModelName );
return aItem.baseModelName;