From d8867b7a66562a893515b422d72e5b43d7287d18 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 12 Jan 2023 23:39:12 +0000 Subject: [PATCH] Remove attempting to parse SPICE text items when generating netlists. We don't do anything with the parse tree, and we have to check it for directives again afterwards to account for when our parsing failed, so there's not much point in parsing it to begin with. --- .../netlist_exporter_spice.cpp | 92 +++++++++++-------- .../netlist_exporter_spice.h | 1 - 2 files changed, 53 insertions(+), 40 deletions(-) diff --git a/eeschema/netlist_exporters/netlist_exporter_spice.cpp b/eeschema/netlist_exporters/netlist_exporter_spice.cpp index db72d058db..88ca903237 100644 --- a/eeschema/netlist_exporters/netlist_exporter_spice.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_spice.cpp @@ -46,12 +46,15 @@ #include #include #include -#include -#include #include #include #include "markup_parser.h" +#if 0 + +#include +#include + namespace NETLIST_EXPORTER_SPICE_PARSER { using namespace SPICE_GRAMMAR; @@ -75,6 +78,7 @@ namespace NETLIST_EXPORTER_SPICE_PARSER template <> struct textSelector : std::true_type {}; } +#endif std::string NAME_GENERATOR::Generate( const std::string& aProposedName ) @@ -120,9 +124,6 @@ bool NETLIST_EXPORTER_SPICE::DoWriteNetlist( OUTPUTFORMATTER& aFormatter, unsign // Cleanup list to avoid duplicate if the netlist exporter is run more than once. m_rawIncludes.clear(); - // Default title. - m_title = "KiCad schematic"; - if( !ReadSchematicAndLibraries( aNetlistOptions, aReporter ) ) return false; @@ -145,7 +146,7 @@ bool NETLIST_EXPORTER_SPICE::DoWriteNetlist( OUTPUTFORMATTER& aFormatter, unsign void NETLIST_EXPORTER_SPICE::WriteHead( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions ) { - aFormatter.Print( 0, ".title %s\n", m_title.c_str() ); + aFormatter.Print( 0, "KiCad schematic\n" ); } @@ -380,46 +381,59 @@ void NETLIST_EXPORTER_SPICE::ReadDirectives( unsigned aNetlistOptions ) else continue; - tao::pegtl::string_input<> in( text.ToUTF8(), "from_content" ); - std::unique_ptr root; + // Send anything that contains directives to SPICE + wxStringTokenizer tokenizer( text, wxT( "\r\n" ), wxTOKEN_STRTOK ); + bool foundDirective = false; - try + while( tokenizer.HasMoreTokens() ) { - root = tao::pegtl::parse_tree::parse - ( in ); - } - catch( const tao::pegtl::parse_error& ) - { - // Even if we couldn't parse it, send anything that _looks_ like it contains - // directives straight through to SPICE - wxStringTokenizer tokenizer( text, wxT( "\r\n" ), wxTOKEN_STRTOK ); + wxString line = tokenizer.GetNextToken().Upper(); - while( tokenizer.HasMoreTokens() ) + if( line.StartsWith( wxT( ".AC" ) ) + || line.StartsWith( wxT( ".CONTROL" ) ) + || line.StartsWith( wxT( ".CSPARAM" ) ) + || line.StartsWith( wxT( ".DISTO" ) ) + || line.StartsWith( wxT( ".ELSE" ) ) + || line.StartsWith( wxT( ".ELSEIF" ) ) + || line.StartsWith( wxT( ".END" ) ) + || line.StartsWith( wxT( ".ENDC" ) ) + || line.StartsWith( wxT( ".ENDIF" ) ) + || line.StartsWith( wxT( ".ENDS" ) ) + || line.StartsWith( wxT( ".FOUR" ) ) + || line.StartsWith( wxT( ".FUNC" ) ) + || line.StartsWith( wxT( ".GLOBAL" ) ) + || line.StartsWith( wxT( ".IC" ) ) + || line.StartsWith( wxT( ".IF" ) ) + || line.StartsWith( wxT( ".INCLUDE" ) ) + || line.StartsWith( wxT( ".LIB" ) ) + || line.StartsWith( wxT( ".MEAS" ) ) + || line.StartsWith( wxT( ".MODEL" ) ) + || line.StartsWith( wxT( ".NODESET" ) ) + || line.StartsWith( wxT( ".NOISE" ) ) + || line.StartsWith( wxT( ".OP" ) ) + || line.StartsWith( wxT( ".OPTIONS" ) ) + || line.StartsWith( wxT( ".PARAM" ) ) + || line.StartsWith( wxT( ".PLOT" ) ) + || line.StartsWith( wxT( ".PRINT" ) ) + || line.StartsWith( wxT( ".PROBE" ) ) + || line.StartsWith( wxT( ".PZ" ) ) + || line.StartsWith( wxT( ".SAVE" ) ) + || line.StartsWith( wxT( ".SENS" ) ) + || line.StartsWith( wxT( ".SP" ) ) + || line.StartsWith( wxT( ".SUBCKT" ) ) + || line.StartsWith( wxT( ".TEMP" ) ) + || line.StartsWith( wxT( ".TF" ) ) + || line.StartsWith( wxT( ".TITLE" ) ) + || line.StartsWith( wxT( ".TRAN" ) ) + || line.StartsWith( wxT( ".WIDTH" ) ) ) { - wxString line = tokenizer.GetNextToken(); - - if( line.StartsWith( "." ) ) - { - m_directives.emplace_back( text ); - break; - } + foundDirective = true; + break; } - - continue; } - wxASSERT( root ); - - for( const auto& node : root->children ) - { - if( node->is_type() ) - m_title = node->children.at( 0 )->string(); - else - m_directives.emplace_back( node->string() ); - } + if( foundDirective ) + m_directives.emplace_back( text ); } } } diff --git a/eeschema/netlist_exporters/netlist_exporter_spice.h b/eeschema/netlist_exporters/netlist_exporter_spice.h index 6176e1b29d..a75d377643 100644 --- a/eeschema/netlist_exporters/netlist_exporter_spice.h +++ b/eeschema/netlist_exporters/netlist_exporter_spice.h @@ -153,7 +153,6 @@ private: SIM_LIB_MGR m_libMgr; ///< Holds libraries and models NAME_GENERATOR m_modelNameGenerator; ///< Generates unique model names NAME_GENERATOR m_netNameGenerator; ///< Generates unique net names (only unique for NC nets for now) - std::string m_title; ///< Spice simulation title found in the schematic sheet std::vector m_directives; ///< Spice directives found in the schematic sheet //std::map> m_libraries; ///< Spice libraries std::set m_rawIncludes; ///< include directives found in symbols