OpenSTA/liberty/LibertyParser.hh

285 lines
9.1 KiB
C++
Raw Normal View History

2018-09-28 17:54:21 +02:00
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2025, Parallax Software, Inc.
2018-09-28 17:54:21 +02:00
//
// 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
2018-09-28 17:54:21 +02:00
// 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, see <https://www.gnu.org/licenses/>.
//
// The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software.
//
// Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// This notice may not be removed or altered from any source distribution.
2018-09-28 17:54:21 +02:00
2020-02-16 01:13:16 +01:00
#pragma once
2018-09-28 17:54:21 +02:00
#include <vector>
#include <map>
2021-03-10 17:45:17 +01:00
#include "Zlib.hh"
2020-04-05 23:53:44 +02:00
#include "StringUtil.hh"
2018-09-28 17:54:21 +02:00
namespace sta {
class Report;
class LibertyGroupVisitor;
class LibertyGroup;
class LibertyDefine;
class LibertySimpleAttr;
class LibertyComplexAttr;
2018-09-28 17:54:21 +02:00
class LibertyAttrValue;
class LibertyVariable;
liberty parser c++ commit 1abf72bc3430d34a51d82992f1c753f0274a662a Author: James Cherry <cherry@parallaxsw.com> Date: Mon Jan 27 08:01:04 2025 -0700 rm unused lib visitors Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 1e76acfc7829a8ba82f96d369fae6225a7361844 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 21:15:46 2025 -0700 verilog/sdf stream->is_open Signed-off-by: James Cherry <cherry@parallaxsw.com> commit c4a57c0354ffb6c4edfc3269d56a937c11ad9609 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 19:54:41 2025 -0700 leak Signed-off-by: James Cherry <cherry@parallaxsw.com> commit b992ed1124a862cb04f0c7617a4575f916c3fe01 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:39:16 2025 -0700 liberty mv string_buf to scanner Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 894cbfa5d5b731738dcc60d492689fad9d13bd40 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:29:42 2025 -0700 liberty use regex to parse include file Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 176225849d3fcac0b2be1a5b623270c386daed3d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:48:09 2025 -0700 liberty include filename Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 516e12721d7185015d8c29e8b16fa185f0f46983 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:31:18 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 32098a2159798dfbb80140927949bb36f480093d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:01:47 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 880214e632d756c3199b000fee88fd4fdffac371 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 13:55:02 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit ad1efca842a6d7ee608ffd5a19a69885786b77fa Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:11:07 2025 -0700 liberty passes all but include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit e71cf1f39dd09e81cf2b0e5a12dcf51675f2a6fd Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:01:08 2025 -0700 liberty parser use class compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 02dea0ff753b0fa12f280661a46e2c0ef2432357 Author: James Cherry <cherry@parallaxsw.com> Date: Sat Jan 25 19:08:06 2025 -0700 liberty parser compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> Signed-off-by: James Cherry <cherry@parallaxsw.com>
2025-01-27 16:33:35 +01:00
class LibertyScanner;
2018-09-28 17:54:21 +02:00
using LibertyGroupSeq = std::vector<LibertyGroup*>;
using LibertySubGroupMap = std::map<std::string, LibertyGroupSeq>;
using LibertySimpleAttrMap = std::map<std::string, LibertySimpleAttr*>;
using LibertyComplexAttrSeq = std::vector<LibertyComplexAttr*>;
using LibertyComplexAttrMap = std::map<std::string, LibertyComplexAttrSeq>;
using LibertyDefineMap = std::map<std::string, LibertyDefine*>;
using LibertyAttrValueSeq = std::vector<LibertyAttrValue*>;
using LibertyVariableSeq = std::vector<LibertyVariable*>;
using LibertyVariableMap = std::map<std::string, float>;
using LibertyGroupVisitorMap = std::map<std::string, LibertyGroupVisitor*>;
2018-09-28 17:54:21 +02:00
2019-03-13 01:25:53 +01:00
enum class LibertyAttrType { attr_string, attr_int, attr_double,
attr_boolean, attr_unknown };
2019-03-13 01:25:53 +01:00
enum class LibertyGroupType { library, cell, pin, timing, unknown };
2018-09-28 17:54:21 +02:00
liberty parser c++ commit 1abf72bc3430d34a51d82992f1c753f0274a662a Author: James Cherry <cherry@parallaxsw.com> Date: Mon Jan 27 08:01:04 2025 -0700 rm unused lib visitors Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 1e76acfc7829a8ba82f96d369fae6225a7361844 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 21:15:46 2025 -0700 verilog/sdf stream->is_open Signed-off-by: James Cherry <cherry@parallaxsw.com> commit c4a57c0354ffb6c4edfc3269d56a937c11ad9609 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 19:54:41 2025 -0700 leak Signed-off-by: James Cherry <cherry@parallaxsw.com> commit b992ed1124a862cb04f0c7617a4575f916c3fe01 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:39:16 2025 -0700 liberty mv string_buf to scanner Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 894cbfa5d5b731738dcc60d492689fad9d13bd40 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:29:42 2025 -0700 liberty use regex to parse include file Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 176225849d3fcac0b2be1a5b623270c386daed3d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:48:09 2025 -0700 liberty include filename Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 516e12721d7185015d8c29e8b16fa185f0f46983 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:31:18 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 32098a2159798dfbb80140927949bb36f480093d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:01:47 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 880214e632d756c3199b000fee88fd4fdffac371 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 13:55:02 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit ad1efca842a6d7ee608ffd5a19a69885786b77fa Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:11:07 2025 -0700 liberty passes all but include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit e71cf1f39dd09e81cf2b0e5a12dcf51675f2a6fd Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:01:08 2025 -0700 liberty parser use class compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 02dea0ff753b0fa12f280661a46e2c0ef2432357 Author: James Cherry <cherry@parallaxsw.com> Date: Sat Jan 25 19:08:06 2025 -0700 liberty parser compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> Signed-off-by: James Cherry <cherry@parallaxsw.com>
2025-01-27 16:33:35 +01:00
class LibertyParser
{
public:
LibertyParser(const char *filename,
LibertyGroupVisitor *library_visitor,
Report *report);
const std::string &filename() const { return filename_; }
void setFilename(const std::string &filename);
liberty parser c++ commit 1abf72bc3430d34a51d82992f1c753f0274a662a Author: James Cherry <cherry@parallaxsw.com> Date: Mon Jan 27 08:01:04 2025 -0700 rm unused lib visitors Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 1e76acfc7829a8ba82f96d369fae6225a7361844 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 21:15:46 2025 -0700 verilog/sdf stream->is_open Signed-off-by: James Cherry <cherry@parallaxsw.com> commit c4a57c0354ffb6c4edfc3269d56a937c11ad9609 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 19:54:41 2025 -0700 leak Signed-off-by: James Cherry <cherry@parallaxsw.com> commit b992ed1124a862cb04f0c7617a4575f916c3fe01 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:39:16 2025 -0700 liberty mv string_buf to scanner Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 894cbfa5d5b731738dcc60d492689fad9d13bd40 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:29:42 2025 -0700 liberty use regex to parse include file Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 176225849d3fcac0b2be1a5b623270c386daed3d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:48:09 2025 -0700 liberty include filename Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 516e12721d7185015d8c29e8b16fa185f0f46983 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:31:18 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 32098a2159798dfbb80140927949bb36f480093d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:01:47 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 880214e632d756c3199b000fee88fd4fdffac371 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 13:55:02 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit ad1efca842a6d7ee608ffd5a19a69885786b77fa Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:11:07 2025 -0700 liberty passes all but include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit e71cf1f39dd09e81cf2b0e5a12dcf51675f2a6fd Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:01:08 2025 -0700 liberty parser use class compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 02dea0ff753b0fa12f280661a46e2c0ef2432357 Author: James Cherry <cherry@parallaxsw.com> Date: Sat Jan 25 19:08:06 2025 -0700 liberty parser compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> Signed-off-by: James Cherry <cherry@parallaxsw.com>
2025-01-27 16:33:35 +01:00
Report *report() const { return report_; }
LibertyDefine *makeDefine(const LibertyAttrValueSeq *values,
int line);
LibertyAttrType attrValueType(const std::string &value_type_name);
LibertyGroupType groupType(const std::string &group_type_name);
void groupBegin(const std::string type,
liberty parser c++ commit 1abf72bc3430d34a51d82992f1c753f0274a662a Author: James Cherry <cherry@parallaxsw.com> Date: Mon Jan 27 08:01:04 2025 -0700 rm unused lib visitors Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 1e76acfc7829a8ba82f96d369fae6225a7361844 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 21:15:46 2025 -0700 verilog/sdf stream->is_open Signed-off-by: James Cherry <cherry@parallaxsw.com> commit c4a57c0354ffb6c4edfc3269d56a937c11ad9609 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 19:54:41 2025 -0700 leak Signed-off-by: James Cherry <cherry@parallaxsw.com> commit b992ed1124a862cb04f0c7617a4575f916c3fe01 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:39:16 2025 -0700 liberty mv string_buf to scanner Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 894cbfa5d5b731738dcc60d492689fad9d13bd40 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:29:42 2025 -0700 liberty use regex to parse include file Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 176225849d3fcac0b2be1a5b623270c386daed3d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:48:09 2025 -0700 liberty include filename Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 516e12721d7185015d8c29e8b16fa185f0f46983 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:31:18 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 32098a2159798dfbb80140927949bb36f480093d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:01:47 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 880214e632d756c3199b000fee88fd4fdffac371 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 13:55:02 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit ad1efca842a6d7ee608ffd5a19a69885786b77fa Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:11:07 2025 -0700 liberty passes all but include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit e71cf1f39dd09e81cf2b0e5a12dcf51675f2a6fd Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:01:08 2025 -0700 liberty parser use class compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 02dea0ff753b0fa12f280661a46e2c0ef2432357 Author: James Cherry <cherry@parallaxsw.com> Date: Sat Jan 25 19:08:06 2025 -0700 liberty parser compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> Signed-off-by: James Cherry <cherry@parallaxsw.com>
2025-01-27 16:33:35 +01:00
LibertyAttrValueSeq *params,
int line);
LibertyGroup *groupEnd();
LibertyGroup *group();
void deleteGroups();
LibertySimpleAttr *makeSimpleAttr(const std::string name,
const LibertyAttrValue *value,
int line);
LibertyComplexAttr *makeComplexAttr(const std::string name,
const LibertyAttrValueSeq *values,
int line);
LibertyAttrValue *makeAttrValueString(const std::string value);
LibertyAttrValue *makeAttrValueFloat(float value);
LibertyVariable *makeVariable(const std::string var,
float value,
int line);
2021-03-10 17:45:17 +01:00
liberty parser c++ commit 1abf72bc3430d34a51d82992f1c753f0274a662a Author: James Cherry <cherry@parallaxsw.com> Date: Mon Jan 27 08:01:04 2025 -0700 rm unused lib visitors Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 1e76acfc7829a8ba82f96d369fae6225a7361844 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 21:15:46 2025 -0700 verilog/sdf stream->is_open Signed-off-by: James Cherry <cherry@parallaxsw.com> commit c4a57c0354ffb6c4edfc3269d56a937c11ad9609 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 19:54:41 2025 -0700 leak Signed-off-by: James Cherry <cherry@parallaxsw.com> commit b992ed1124a862cb04f0c7617a4575f916c3fe01 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:39:16 2025 -0700 liberty mv string_buf to scanner Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 894cbfa5d5b731738dcc60d492689fad9d13bd40 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:29:42 2025 -0700 liberty use regex to parse include file Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 176225849d3fcac0b2be1a5b623270c386daed3d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:48:09 2025 -0700 liberty include filename Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 516e12721d7185015d8c29e8b16fa185f0f46983 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:31:18 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 32098a2159798dfbb80140927949bb36f480093d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:01:47 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 880214e632d756c3199b000fee88fd4fdffac371 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 13:55:02 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit ad1efca842a6d7ee608ffd5a19a69885786b77fa Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:11:07 2025 -0700 liberty passes all but include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit e71cf1f39dd09e81cf2b0e5a12dcf51675f2a6fd Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:01:08 2025 -0700 liberty parser use class compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 02dea0ff753b0fa12f280661a46e2c0ef2432357 Author: James Cherry <cherry@parallaxsw.com> Date: Sat Jan 25 19:08:06 2025 -0700 liberty parser compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> Signed-off-by: James Cherry <cherry@parallaxsw.com>
2025-01-27 16:33:35 +01:00
private:
std::string filename_;
liberty parser c++ commit 1abf72bc3430d34a51d82992f1c753f0274a662a Author: James Cherry <cherry@parallaxsw.com> Date: Mon Jan 27 08:01:04 2025 -0700 rm unused lib visitors Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 1e76acfc7829a8ba82f96d369fae6225a7361844 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 21:15:46 2025 -0700 verilog/sdf stream->is_open Signed-off-by: James Cherry <cherry@parallaxsw.com> commit c4a57c0354ffb6c4edfc3269d56a937c11ad9609 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 19:54:41 2025 -0700 leak Signed-off-by: James Cherry <cherry@parallaxsw.com> commit b992ed1124a862cb04f0c7617a4575f916c3fe01 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:39:16 2025 -0700 liberty mv string_buf to scanner Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 894cbfa5d5b731738dcc60d492689fad9d13bd40 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 16:29:42 2025 -0700 liberty use regex to parse include file Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 176225849d3fcac0b2be1a5b623270c386daed3d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:48:09 2025 -0700 liberty include filename Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 516e12721d7185015d8c29e8b16fa185f0f46983 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:31:18 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 32098a2159798dfbb80140927949bb36f480093d Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 15:01:47 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 880214e632d756c3199b000fee88fd4fdffac371 Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 13:55:02 2025 -0700 liberty include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit ad1efca842a6d7ee608ffd5a19a69885786b77fa Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:11:07 2025 -0700 liberty passes all but include Signed-off-by: James Cherry <cherry@parallaxsw.com> commit e71cf1f39dd09e81cf2b0e5a12dcf51675f2a6fd Author: James Cherry <cherry@parallaxsw.com> Date: Sun Jan 26 10:01:08 2025 -0700 liberty parser use class compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> commit 02dea0ff753b0fa12f280661a46e2c0ef2432357 Author: James Cherry <cherry@parallaxsw.com> Date: Sat Jan 25 19:08:06 2025 -0700 liberty parser compiles Signed-off-by: James Cherry <cherry@parallaxsw.com> Signed-off-by: James Cherry <cherry@parallaxsw.com>
2025-01-27 16:33:35 +01:00
LibertyGroupVisitor *group_visitor_;
Report *report_;
LibertyGroupSeq group_stack_;
};
2021-03-10 17:45:17 +01:00
// Attribute values are a string or float.
class LibertyAttrValue
2018-09-28 17:54:21 +02:00
{
public:
LibertyAttrValue() {}
LibertyAttrValue(float value);
LibertyAttrValue(std::string value);
bool isString() const;
bool isFloat() const;
float floatValue() const;
void floatValue(// Return values.
float &value,
bool &valid) const;
const std::string &stringValue() const { return string_value_; }
2018-09-28 17:54:21 +02:00
private:
float float_value_;
std::string string_value_;
2018-09-28 17:54:21 +02:00
};
// Groups are a type keyword with a set of parameters and statements
// enclosed in brackets.
// type([param1][, param2]...) { stmts.. }
class LibertyGroup
2018-09-28 17:54:21 +02:00
{
public:
LibertyGroup(const std::string type,
const LibertyAttrValueSeq params,
int line);
~LibertyGroup();
void clear();
const std::string &type() const { return type_; }
const LibertyAttrValueSeq &params() const { return params_; }
2018-09-28 17:54:21 +02:00
// First param as a string.
const char *firstName() const;
2018-09-28 17:54:21 +02:00
// Second param as a string.
const char *secondName() const;
int line() const { return line_; }
2018-09-28 17:54:21 +02:00
const LibertyGroupSeq &findSubgroups(const std::string type) const;
const LibertyGroup *findSubgroup(const std::string type) const;
const LibertySimpleAttr *findSimpleAttr(const std::string attr_name) const;
const LibertyComplexAttrSeq &findComplexAttrs(const std::string attr_name) const;
const LibertyComplexAttr *findComplexAttr(const std::string attr_name) const;
const std::string *findAttrString(const std::string attr_name) const;
void findAttrFloat(const std::string attr_name,
// Return values.
float &value,
bool &exists) const;
void findAttrInt(const std::string attr_name,
// Return values.
int &value,
bool &exists) const;
const LibertyGroupSeq &subgroups() const { return subgroups_; }
const LibertyDefineMap &defineMap() const { return define_map_; }
void addSubgroup(LibertyGroup *subgroup);
void deleteSubgroup(const LibertyGroup *subgroup);
void addAttr(LibertySimpleAttr *attr);
void addAttr(LibertyComplexAttr *attr);
void addDefine(LibertyDefine *define);
void addVariable(LibertyVariable *var);
2018-09-28 17:54:21 +02:00
protected:
std::string type_;
LibertyAttrValueSeq params_;
int line_;
LibertySimpleAttrMap simple_attr_map_;
LibertyComplexAttrMap complex_attr_map_;
LibertyGroupSeq subgroups_;
LibertySubGroupMap subgroup_map_;
LibertyDefineMap define_map_;
LibertyVariableSeq variables_;
2018-09-28 17:54:21 +02:00
};
class LibertyGroupLineLess
2018-09-28 17:54:21 +02:00
{
public:
bool
operator()(const LibertyGroup *group1,
const LibertyGroup *group2) const {
return group1->line() < group2->line();
}
2018-09-28 17:54:21 +02:00
};
// Simple attributes: name : value;
class LibertySimpleAttr
2018-09-28 17:54:21 +02:00
{
public:
LibertySimpleAttr(const std::string name,
const LibertyAttrValue value,
int line);
const std::string &name() const { return name_; }
const LibertyAttrValue &value() const { return value_; };
const std::string *stringValue() const;
int line() const { return line_; }
2018-09-28 17:54:21 +02:00
private:
std::string name_;
int line_;
LibertyAttrValue value_;
2018-09-28 17:54:21 +02:00
};
// Complex attributes have multiple values.
// name(attr_value1[, attr_value2]...);
class LibertyComplexAttr
2018-09-28 17:54:21 +02:00
{
public:
LibertyComplexAttr(const std::string name,
const LibertyAttrValueSeq values,
int line);
~LibertyComplexAttr();
const std::string &name() const { return name_; }
const LibertyAttrValue *firstValue() const;
const LibertyAttrValueSeq &values() const { return values_; }
int line() const { return line_; }
2018-09-28 17:54:21 +02:00
private:
std::string name_;
LibertyAttrValueSeq values_;
int line_;
2018-09-28 17:54:21 +02:00
};
// Define statements define new simple attributes.
// define(attribute_name, group_name, attribute_type);
// attribute_type is string|integer|float.
class LibertyDefine
2018-09-28 17:54:21 +02:00
{
public:
LibertyDefine(std::string name,
LibertyGroupType group_type,
LibertyAttrType value_type,
int line);
const std::string &name() const { return name_; }
2019-03-13 01:25:53 +01:00
LibertyGroupType groupType() const { return group_type_; }
LibertyAttrType valueType() const { return value_type_; }
int line() const { return line_; }
2018-09-28 17:54:21 +02:00
private:
std::string name_;
2018-09-28 17:54:21 +02:00
LibertyGroupType group_type_;
2019-03-13 01:25:53 +01:00
LibertyAttrType value_type_;
int line_;
2018-09-28 17:54:21 +02:00
};
// The Liberty User Guide Version 2003.12 fails to document variables.
// var = value;
// The only example I have only uses float values, so I am assuming
// that is all that is supported (which is probably wrong).
class LibertyVariable
2018-09-28 17:54:21 +02:00
{
public:
LibertyVariable(std::string var,
float value,
int line);
int line() const { return line_; }
const std::string &variable() const { return var_; }
2018-09-28 17:54:21 +02:00
float value() const { return value_; }
private:
std::string var_;
2018-09-28 17:54:21 +02:00
float value_;
int line_;
2018-09-28 17:54:21 +02:00
};
class LibertyGroupVisitor
{
public:
LibertyGroupVisitor() {}
virtual ~LibertyGroupVisitor() {}
virtual void begin(const LibertyGroup *group,
LibertyGroup *parent_group) = 0;
virtual void end(const LibertyGroup *group,
LibertyGroup *parent_group) = 0;
virtual void visitAttr(const LibertySimpleAttr *attr) = 0;
virtual void visitAttr(const LibertyComplexAttr *attr) = 0;
2018-09-28 17:54:21 +02:00
virtual void visitVariable(LibertyVariable *variable) = 0;
};
void
parseLibertyFile(const char *filename,
LibertyGroupVisitor *library_visitor,
Report *report);
2018-09-28 17:54:21 +02:00
} // namespace