2022-11-11 02:07:34 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Mikolaj Wielgus
|
|
|
|
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2022-12-21 00:38:52 +00:00
|
|
|
#ifndef SIM_MODEL_SERIALIZER_H
|
|
|
|
#define SIM_MODEL_SERIALIZER_H
|
2022-11-11 02:07:34 +00:00
|
|
|
|
|
|
|
#include <sim/sim_model.h>
|
|
|
|
|
|
|
|
|
2022-12-21 00:38:52 +00:00
|
|
|
namespace SIM_MODEL_SERIALIZER_GRAMMAR
|
2022-11-11 02:07:34 +00:00
|
|
|
{
|
|
|
|
using namespace SIM_VALUE_GRAMMAR;
|
|
|
|
|
|
|
|
struct sep : plus<space> {};
|
|
|
|
|
|
|
|
|
|
|
|
struct legacyPinNumber : digits {};
|
|
|
|
struct legacyPinSequence : list<legacyPinNumber, sep> {};
|
|
|
|
|
|
|
|
struct legacyPinSequenceGrammar : must<legacyPinSequence,
|
|
|
|
tao::pegtl::eof> {};
|
|
|
|
|
|
|
|
|
2022-11-25 04:31:03 +00:00
|
|
|
struct pinSymbolPinNumber : plus<not_at<sep>, not_one<'='>> {};
|
|
|
|
struct pinName : plus<not_at<sep>, any> {};
|
|
|
|
struct pinAssignment : seq<pinSymbolPinNumber,
|
|
|
|
one<'='>,
|
|
|
|
pinName> {};
|
|
|
|
struct pinSequence : list<pinAssignment,
|
|
|
|
sep> {};
|
2022-11-11 02:07:34 +00:00
|
|
|
struct pinSequenceGrammar : must<opt<sep>,
|
|
|
|
opt<pinSequence>,
|
|
|
|
opt<sep>,
|
|
|
|
tao::pegtl::eof> {};
|
|
|
|
|
2023-03-16 23:40:20 +00:00
|
|
|
struct param : identifier {};
|
2022-11-11 02:07:34 +00:00
|
|
|
|
|
|
|
struct unquotedString : plus<not_at<sep>, any> {};
|
|
|
|
struct quotedStringContent : star<not_at<one<'"'>>, any> {}; // TODO: Allow escaping '"'.
|
|
|
|
struct quotedString : seq<one<'"'>,
|
|
|
|
quotedStringContent,
|
|
|
|
one<'"'>> {};
|
|
|
|
|
2023-03-22 01:37:55 +00:00
|
|
|
struct flagParam : sor<TAO_PEGTL_ISTRING( "off" ), // VDMOS
|
|
|
|
TAO_PEGTL_ISTRING( "thermal" ), // VDMOS
|
|
|
|
TAO_PEGTL_ISTRING( "xpart" )> {}; // BSIM1
|
|
|
|
|
2024-01-06 18:00:50 +00:00
|
|
|
struct fieldParamValuePair : sor<if_must<param,
|
2023-03-22 01:37:55 +00:00
|
|
|
opt<sep>,
|
|
|
|
one<'='>,
|
|
|
|
opt<sep>,
|
|
|
|
sor<quotedString,
|
2024-01-06 18:00:50 +00:00
|
|
|
unquotedString>>,
|
|
|
|
flagParam> {};
|
2022-11-11 02:07:34 +00:00
|
|
|
struct fieldParamValuePairs : list<fieldParamValuePair, sep> {};
|
|
|
|
struct fieldParamValuePairsGrammar : must<opt<sep>,
|
|
|
|
opt<fieldParamValuePairs>,
|
|
|
|
opt<sep>,
|
|
|
|
tao::pegtl::eof> {};
|
|
|
|
|
2022-11-22 06:06:53 +00:00
|
|
|
struct fieldInferValue : sor<one<'R', 'C', 'L', 'V', 'I'>,
|
|
|
|
number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>> {};
|
2022-11-11 02:07:34 +00:00
|
|
|
struct fieldInferValueGrammar : must<opt<sep>,
|
|
|
|
fieldInferValue,
|
|
|
|
opt<sep>,
|
|
|
|
tao::pegtl::eof> {};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename> inline constexpr const char* errorMessage = nullptr;
|
|
|
|
template <> inline constexpr auto errorMessage<opt<sep>> = "";
|
|
|
|
template <> inline constexpr auto errorMessage<opt<pinSequence>> = "";
|
|
|
|
template <> inline constexpr auto errorMessage<one<'='>> =
|
|
|
|
"expected '='";
|
|
|
|
template <> inline constexpr auto errorMessage<sor<quotedString,
|
|
|
|
unquotedString>> =
|
|
|
|
"expected quoted or unquoted string";
|
|
|
|
template <> inline constexpr auto errorMessage<fieldParamValuePairs> =
|
|
|
|
"expected parameter=value pairs";
|
|
|
|
template <> inline constexpr auto errorMessage<opt<fieldParamValuePairs>> = "";
|
|
|
|
template <> inline constexpr auto errorMessage<fieldInferValue> =
|
2022-11-22 06:06:53 +00:00
|
|
|
"expected 'R', 'C', 'L', 'V', 'I' or a number";
|
2022-11-11 02:07:34 +00:00
|
|
|
template <> inline constexpr auto errorMessage<tao::pegtl::eof> =
|
|
|
|
"expected end of string";
|
|
|
|
|
|
|
|
struct error
|
|
|
|
{
|
|
|
|
template <typename Rule> static constexpr bool raise_on_failure = false;
|
|
|
|
template <typename Rule> static constexpr auto message = errorMessage<Rule>;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Rule> using control = must_if<error>::control<Rule>;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-12-21 00:38:52 +00:00
|
|
|
* Serializes/deserializes a SIM_MODEL for storage in LIB_FIELDs/SCH_FIELDs.
|
2022-11-11 02:07:34 +00:00
|
|
|
*/
|
2022-12-21 00:38:52 +00:00
|
|
|
class SIM_MODEL_SERIALIZER
|
2022-11-11 02:07:34 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto REFERENCE_FIELD = "Reference";
|
|
|
|
static constexpr auto VALUE_FIELD = "Value";
|
|
|
|
|
2022-12-21 00:38:52 +00:00
|
|
|
virtual ~SIM_MODEL_SERIALIZER() = default;
|
|
|
|
SIM_MODEL_SERIALIZER( SIM_MODEL& aModel ) : m_model( aModel ) {}
|
2022-11-11 02:07:34 +00:00
|
|
|
|
|
|
|
std::string GenerateDevice() const;
|
2024-01-21 22:25:24 +00:00
|
|
|
std::string GenerateDeviceSubtype() const;
|
2022-11-11 02:07:34 +00:00
|
|
|
std::string GenerateValue() const;
|
|
|
|
std::string GenerateParams() const;
|
|
|
|
std::string GeneratePins() const;
|
|
|
|
std::string GenerateEnable() const;
|
|
|
|
|
|
|
|
void ParseValue( const std::string& aValue );
|
2022-11-22 06:06:53 +00:00
|
|
|
bool ParseParams( const std::string& aParams );
|
2022-11-11 02:07:34 +00:00
|
|
|
void ParsePins( const std::string& aPins );
|
|
|
|
void ParseEnable( const std::string& aEnable );
|
|
|
|
|
|
|
|
protected:
|
2023-01-06 13:44:45 +00:00
|
|
|
std::string generateParamValuePair( const SIM_MODEL::PARAM& aParam ) const;
|
2022-11-11 02:07:34 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SIM_MODEL& m_model;
|
|
|
|
};
|
|
|
|
|
2022-12-21 00:38:52 +00:00
|
|
|
#endif // SIM_MODEL_SERIALIZER_H
|